"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested text file into HTML format (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 ## maps for kash ##
2
3 InstallDocumentation(
4 rec(
5 name := "Maps",
6 kind := "KEYWORD",
7 short:= "In KASH3 maps are functions with additional information, namely "+
8 "domain, codomain, and in some cases a map for computing preimages.",
9 see := [
10 DocHash("map"),
11 DocHash("Map(any,any,func)"),
12 DocHash("Map(any,any,func,func)"),
13 DocHash("Domain(map())"),
14 DocHash("Codomain(map())"),
15 DocHash("Image(any,map())"),
16 DocHash("Preimage(any,map())"),
17 DocHash("HasPreimage(any,map())"),
18 DocHash("Composition(map(),map())")
19 ]
20 )
21 );
22
23 __Print_map := function(phi)
24 local rf;
25 rf := RecFields(phi);
26 Print("Mapping ");
27 if "domain" in rf then
28 Print("from ",Type(phi.domain),": ",Name(phi.domain));
29 fi;
30 if "codomain" in rf then
31 Print(" to ",Type(phi.codomain),": ",Name(phi.codomain));
32 fi;
33 if "inv" in rf then
34 Print(" with inverse");
35 fi;
36 end;
37
38 _Composition_map_map := function(phi,psi)
39 local tau,sigma;
40
41 if not IsRec(phi) and not IsRec(psi) then
42 return phi*psi;
43 fi;
44
45 if Domain(phi) <> Codomain(psi) then
46 Error("Composition(phi,psi): Domain(phi) must equal Codomain(psi).");
47 fi;
48
49 tau := rec(base := function(a) return phi(psi(a)); end,
50 domain := Domain(psi),
51 codomain := Codomain(phi),
52 type := map(Type(Domain(psi)),Type(Codomain(phi))),
53 operations := rec(Print := __Print_map, \*:=_Composition_map_map)
54 );
55 if IsRec(phi) and IsRec(psi) then
56 if "inv" in RecFields(phi) and "inv" in RecFields(psi) then
57 sigma := function(a) return Preimage(Preimage(a,phi),psi); end;
58 tau.inv := sigma;
59 fi;
60 elif IsRec(phi) then
61 if "inv" in RecFields(phi) then
62 sigma := function(a) return Preimage(Preimage(a,phi),psi); end;
63 tau.inv := sigma;
64 fi;
65 else
66 if "inv" in RecFields(psi) then
67 sigma := function(a) return Preimage(Preimage(a,phi),psi); end;
68 tau.inv := sigma;
69 fi;
70 fi;
71 return tau;
72 end;
73
74 InstallMethod(
75 rec(
76 name := "Composition",
77 kind := "FUNCTION",
78 sin := [[map(),"phi"],[map(),"psi"]],
79 sou := [[map()]],
80 short:= "The composition 'phi*psi' of the maps 'phi' and 'psi'.",
81 ex := [
82 "x_add_with_inv := function(a)\n"+
83 "# this function returns a map that adds 'a'\n"+
84 "local phi, psi;\n"+
85 " phi := function(b) return b+a; end;\n"+
86 " psi := function(c) return c-a; end;\n"+
87 " return Map(Z,Z,phi,psi);\n"+
88 "end;\n\n"+
89 "x_f := x_add_with_inv(5);\n"+
90 "x_f(2);\n"+
91 "x_Z7 := Quotient(Z,7);\n"+
92 "x_g := Composition(x_Z7.ext1,x_f);\n"+
93 "x_g(1);\n"+
94 "Preimage(Coerce(x_Z7,8),x_g);\n"],
95 see := [
96 DocHash("map"),
97 DocHash("Map(any,any,func)"),
98 DocHash("Map(any,any,func,func)"),
99 DocHash("Domain(map())"),
100 DocHash("Codomain(map())"),
101 DocHash("Image(any,map())"),
102 DocHash("Preimage(any,map())")
103 ]
104 ),
105 _Composition_map_map
106 );
107
108
109 InstallMethod(
110 rec(
111 name := "Map",
112 kind := "FUNCTION",
113 sin := [[any,"domain"],[any,"codomain"],[func,"phi"],[func,"psi"]],
114 sou := [[map()]],
115 short := "Create a map with domain 'domain' and codomain 'codomain' "
116 +"from the function 'phi'. "
117 + "The function 'psi' is used for the computation of preimages.",
118 ex := [
119 "x_add_with_inv := function(a)\n"+
120 "# this function returns a map that adds 'a'\n"+
121 "local phi, psi;\n"+
122 " phi := function(b) return b+a; end;\n"+
123 " psi := function(c) return c-a; end;\n"+
124 " return Map(Z,Z,phi,psi);\n"+
125 "end;\n\n"+
126 "x_f := x_add_with_inv(5);\n"+
127 "x_f(2);\n"+
128 "Image(3,x_f);\n"+
129 "Preimage(8,x_f);\n"+
130 "Preimage(x_f(900),x_f);"],
131 see := [
132 DocHash("map"),
133 DocHash("Maps"),
134 DocHash("Map(any,any,func)"),
135 DocHash("Domain(map())"),
136 DocHash("Codomain(map())"),
137 DocHash("Image(any,map())"),
138 DocHash("Preimage(any,map())"),
139 DocHash("Composition(map(),map())")
140 ]
141 ),
142 function(domain,codomain,phi,psi)
143 return
144 rec(
145 base := phi,
146 inv := psi,
147 domain := domain,
148 codomain := codomain,
149 type := map(Type(domain),Type(codomain)),
150 operations :=
151 rec(Print:=__Print_map, \*:=_Composition_map_map
152 )
153 );
154 end
155 );
156
157 InstallMethod(
158 rec(
159 name := "Map",
160 kind := "FUNCTION",
161 sin := [[any,"domain"],[any,"codomain"],[func,"phi"]],
162 sou := [[map()]],
163 short := "Create a map with domain 'domain' and codomain 'codomain' "
164 +"from the function 'phi'. ",
165 ex := [
166 "x_mult := function(a)\n"+
167 "# this function returns a map that multiplies by 'I*a'\n"+
168 "local phi;\n"+
169 " phi := function(b) return b*a*I; end;\n"+
170 " return Map(R,C,phi);\n"+
171 "end;\n\n"+
172 "x_f := x_mult(5);\n"+
173 "x_f(2);\n"+
174 "Image(3.1,x_f);\n"+
175 "Domain(x_f);\n"+
176 "Codomain(x_f);"],
177 see := [
178 DocHash("map"),
179 DocHash("Maps"),
180 DocHash("Map(any,any,func,func)"),
181 DocHash("Domain(map())"),
182 DocHash("Codomain(map())"),
183 DocHash("Image(any,map())"),
184 DocHash("Preimage(any,map())"),
185 DocHash("Composition(map(),map())")
186 ]
187 ),
188 function(domain,codomain,phi)
189 return
190 rec(
191 base := phi,
192 domain := domain,
193 codomain := codomain,
194 type := map(Type(domain),Type(codomain)),
195 operations :=
196 rec(Print:= __Print_map, \*:=_Composition_map_map
197 )
198 );
199 end
200 );
201
202 ######################################################################
203 # replace the internal map functions by generalizations
204 ######################################################################
205
206 _Image := Image;
207 Unbind(Image);
208 _Preimage := Preimage;
209 Unbind(Preimage);
210 _Domain := Domain;
211 Unbind(Domain);
212 _Codomain := Codomain;
213 Unbind(Codomain);
214
215 Image := function(arg)
216 if Length(arg) = 2 then
217 if Is(Type(arg[1]),map()) then
218 return arg[1](arg[2]);
219 elif Is(Type(arg[2]),map()) then
220 return arg[2](arg[1]);
221 fi;
222 fi;
223 return _CallFunction(_Image,arg);
224 # Error("Image: second argument must be a map.");
225 end;
226
227 Preimage := function(a,phi)
228
229 if not IsRec(phi) then
230 return _Preimage(a,phi);
231 fi;
232 if Is(Type(phi),map()) then
233 if not "inv" in RecFields(phi) then
234 Error("Preimage: cannot compute preimages under this map.");
235 fi;
236 return phi.inv(a);
237 fi;
238 Error("Preimage: second argument must be a map.");
239 end;
240
241 Domain := function(phi)
242
243 if not IsRec(phi) then
244 return _Domain(phi);
245 fi;
246 if Is(Type(phi),map()) then
247 if not "domain" in RecFields(phi) then
248 Error("Domain: no domain has been assigned to this map.");
249 fi;
250 return phi.domain;
251 fi;
252 Error("Domain: argument must be a map.");
253 end;
254
255
256 Codomain := function(phi)
257
258 if not IsRec(phi) then
259 return _Codomain(phi);
260 fi;
261 if not "codomain" in RecFields(phi) then
262 Error("Codomain: no codomain has been assigned to this map.");
263 fi;
264 if Is(Type(phi),map()) then
265 return phi.codomain;
266 fi;
267 Error("Codomain: argument must be a map.");
268 end;
269
270