1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | version="version mathml.lib 4.0.2.0 Sep_2015"; // $Id$ |
---|
3 | category="Miscellaneous"; |
---|
4 | info=" |
---|
5 | LIBRARY: mathml.lib printing mathml code |
---|
6 | |
---|
7 | AUTHORS: J. Boehm, boehm @ mathematik.uni-kl.de |
---|
8 | M. Mueller, mkmuelle @ mathematik.uni-kl.de |
---|
9 | H. Rombach, HRombach @ gmx.de |
---|
10 | M. Stein, maxstein77 @ web.de |
---|
11 | |
---|
12 | OVERVIEW: |
---|
13 | |
---|
14 | mathml conversion |
---|
15 | |
---|
16 | KEYWORDS: |
---|
17 | mathml |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | PROCEDURES: |
---|
22 | mathml(def) general procedure to generate a mathml code from a Singular object |
---|
23 | viewMathml(string) view mathml code |
---|
24 | "; |
---|
25 | |
---|
26 | LIB "matrix.lib"; |
---|
27 | |
---|
28 | |
---|
29 | |
---|
30 | /********************************************************* |
---|
31 | ** ** |
---|
32 | ** TOOLs ** |
---|
33 | ** ** |
---|
34 | *********************************************************/ |
---|
35 | |
---|
36 | static proc mathmlStringReplace(string s,string dummy,string origin)"USAGE: texStringReplace(s); where s is a string |
---|
37 | ASSUME: s is a string |
---|
38 | RETURN: s including origin instead of dummy |
---|
39 | THEORY: if s contains dummy, these parts will be replaced by origin |
---|
40 | "{ |
---|
41 | int k,L; |
---|
42 | string S; |
---|
43 | S = s; |
---|
44 | while(find(S,dummy)>0){ |
---|
45 | k = find(S,dummy); |
---|
46 | L = size(dummy); |
---|
47 | if(k+L<=size(S)){ |
---|
48 | S = S[1,k-1] + origin + S[k+L..size(S)]; |
---|
49 | } |
---|
50 | else{S = S[1,k-1] + origin;} |
---|
51 | } |
---|
52 | |
---|
53 | return(S); |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | proc mathmlRingType(){ |
---|
58 | string S = charstr(basering); |
---|
59 | int i = find(S,","); |
---|
60 | int n; |
---|
61 | if(i>0){S = S[1,i-1];} |
---|
62 | if(S=="real" || S =="complex"){return(0)} |
---|
63 | else{ if (npars(basering)>0) { |
---|
64 | n=ringlist(basering)[1][1]; |
---|
65 | if (n!=0 && prime(n)!=n) {return(2);} |
---|
66 | else {return(1);}} |
---|
67 | else {return(1);} |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | /********************************************************* |
---|
73 | ** ** |
---|
74 | ** POLY ** |
---|
75 | ** ** |
---|
76 | *********************************************************/ |
---|
77 | |
---|
78 | |
---|
79 | proc mathmlLeadCoef(string s) { |
---|
80 | string t; |
---|
81 | int i=1; |
---|
82 | int u=0; |
---|
83 | if (s=="1"){return(t);} |
---|
84 | if (s=="-1"){return("<mo>-</mo>");} |
---|
85 | while (i<size(s)) { |
---|
86 | if (s[i]=="/") {u=1; |
---|
87 | i=size(s);} |
---|
88 | i=i+1; |
---|
89 | } |
---|
90 | i=1; |
---|
91 | if (u==1) { |
---|
92 | if (s[1]=="-") { |
---|
93 | t="<mo>-</mo>"; |
---|
94 | i=2;} |
---|
95 | t=t+"<mfrac> <mn>"; |
---|
96 | while (i<=size(s)) { |
---|
97 | if (s[i]=="/") {t=t+"</mn> <mn>";} |
---|
98 | else {t=t+s[i];} |
---|
99 | i=i+1; |
---|
100 | } |
---|
101 | t=t+"</mn> </mfrac>"; |
---|
102 | } |
---|
103 | if (u==0) { |
---|
104 | if (s[1]=="-") {t=t+"<mo>-</mo>";s=s[2,size(s)-1];} |
---|
105 | t=t+"<mn>"+s+"</mn>";} |
---|
106 | return(t); |
---|
107 | } |
---|
108 | |
---|
109 | proc mathmlVariablesEncoding(string s) { |
---|
110 | string S; |
---|
111 | int p; |
---|
112 | if(s[size(s)]==")"){ |
---|
113 | p = find(s,"("); |
---|
114 | S = S + "<msub><mi>"+s[1,p-1] + "</mi><mn>" + s[p+1,size(s)-p-1]+ "</mn></msub>"; |
---|
115 | } |
---|
116 | else{ |
---|
117 | if (size(s)>1) { |
---|
118 | S = S + "<msub><mi>"+s[1] + "</mi><mn>" + s[2,size(s)-1]+ "</mn></msub>";} |
---|
119 | else {S="<mi>"+s+"</mi>";} |
---|
120 | } |
---|
121 | return(S); |
---|
122 | } |
---|
123 | |
---|
124 | proc mathmlMonomial(poly a) { |
---|
125 | string g; |
---|
126 | intvec d=leadexp(a); |
---|
127 | list e; |
---|
128 | for(int q=1;q<=size(variables(a));q++) { |
---|
129 | e[q]=variables(a)[q]; |
---|
130 | } |
---|
131 | int k=1; |
---|
132 | for(int i=1;i<=size(d);i++) { |
---|
133 | if (d[i]>0) { |
---|
134 | g=g+"<msup><mrow>"+mathmlVariablesEncoding(string(e[k]))+"</mrow><mn>"; |
---|
135 | if (d[i]>1) {g=g+string(d[i]);} |
---|
136 | g=g+"</mn></msup>"; |
---|
137 | k=k+1;} |
---|
138 | } |
---|
139 | return(g); |
---|
140 | } |
---|
141 | |
---|
142 | proc mathmlHilf1(poly a,def r) { |
---|
143 | poly d=a; |
---|
144 | list l1=ringlist(r); |
---|
145 | list l12=ringlist(r); |
---|
146 | for(int i=1;i<=size(l12[1][2]);i++) { |
---|
147 | l12[2][i]=l12[1][2][i]+"1"; |
---|
148 | l12[1][2][i]=l12[1][2][i]+"0"; |
---|
149 | } |
---|
150 | def w=ring(l12); |
---|
151 | setring(w); |
---|
152 | poly f=fetch(r,d); |
---|
153 | list l12=ringlist(basering); |
---|
154 | for (i=1;i<=size(l12[1][2]);i++) { |
---|
155 | f=subst(f,par(i),var(i)); |
---|
156 | } |
---|
157 | while (size(l12[2])>size(l12[1][2])) { |
---|
158 | l12[2]=delete(l12[2],size(l12[1][2])+1); |
---|
159 | } |
---|
160 | for (i=1;i<=size(l12[2]);i++) { |
---|
161 | l12[2][i]=l12[2][i][1,size(l12[2][i])-1]; |
---|
162 | } |
---|
163 | l12[1]=l12[1][1]; |
---|
164 | def w2=ring(l12); |
---|
165 | setring(w2); |
---|
166 | keepring(w2); |
---|
167 | poly f=fetch(w,f); |
---|
168 | return(f); |
---|
169 | } |
---|
170 | |
---|
171 | proc mathmlHilf(poly a,def r) { |
---|
172 | string g; |
---|
173 | def f=mathmlHilf1(a,r); |
---|
174 | g=g+mathmlPoly(f,basering); |
---|
175 | return(g); |
---|
176 | } |
---|
177 | |
---|
178 | proc SignumLeadcoef(poly a) { |
---|
179 | int n=0; |
---|
180 | def f=mathmlHilf1(a,basering); |
---|
181 | if (string(leadcoef(f))[1,1]=="-") { |
---|
182 | n=1; |
---|
183 | } |
---|
184 | return(n); |
---|
185 | } |
---|
186 | |
---|
187 | proc mathmlPolyGAL(poly p){ |
---|
188 | string S; |
---|
189 | for(int i = 1;i<size(p);i++){ |
---|
190 | S = S + mathmlTermGAL(p[i]); |
---|
191 | if (string(leadcoef(p[i+1]))!="-1") {S=S+"<mo>+</mo>";} |
---|
192 | } |
---|
193 | S = S+ mathmlTermGAL(p[i]); |
---|
194 | return(S); |
---|
195 | } |
---|
196 | |
---|
197 | proc mathmlTermGAL(poly p){ |
---|
198 | int b = 0; |
---|
199 | int B = 0; |
---|
200 | string S,S1,C,Pname; |
---|
201 | Pname = ringlist(basering)[1][2][1]; |
---|
202 | C = string(leadcoef(p)); |
---|
203 | |
---|
204 | C = mathmlStringReplace(C,Pname,""); |
---|
205 | C = mathmlStringReplace(C,"^",""); |
---|
206 | if (p==-1 || p==1 || p==0) {return("<mn>"+string(p)+"</mn>");} |
---|
207 | else { |
---|
208 | if (C=="-1") {S=S+"<mo>-</mo>";} |
---|
209 | else { |
---|
210 | if (C!="1") {S =S+ "<msup><mi>"+Pname+"</mi><mn>"+C +"</mi></msup>";} |
---|
211 | } |
---|
212 | S=S+mathmlMonomial(leadmonom(p)); |
---|
213 | return(S); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | proc mathmlPolyR(poly a) { |
---|
221 | string S; |
---|
222 | |
---|
223 | def origin = basering; |
---|
224 | |
---|
225 | if(npars(origin) == 0){ |
---|
226 | list l = ringlist(basering); |
---|
227 | l[1][3] = "parTMP"; |
---|
228 | def ringCOMPLEX = ring(l); |
---|
229 | setring ringCOMPLEX; |
---|
230 | poly a = fetch(origin,a); |
---|
231 | } |
---|
232 | string S1; |
---|
233 | string S2; |
---|
234 | poly d; |
---|
235 | string s; |
---|
236 | |
---|
237 | for (int i=1;i<=size(a);i++) { |
---|
238 | S2=""; |
---|
239 | d=a[i]; |
---|
240 | s=string(leadcoef(d)); |
---|
241 | if (s[1]=="-" || s[2]=="-") {S=S+"<mo>-</mo>";d=-1*d;} |
---|
242 | else {S=S+"<mo>+</mo>";} |
---|
243 | S1=mathmlMonomial(leadmonom(d)); |
---|
244 | if (leadcoef(d)==1) { |
---|
245 | if (S1=="") {S=S+"<mn>1</mn>";} |
---|
246 | } |
---|
247 | else { |
---|
248 | s=string(leadcoef(d)); |
---|
249 | S2=mathmlStringReplace(s,"*1)",")"); |
---|
250 | S2=mathmlStringReplace(S2,"*",""); |
---|
251 | if (npars(basering)==1) { |
---|
252 | if (find(S2,string(par(1)))>0) { |
---|
253 | S2=mathmlStringReplace(S2,string(par(1)),""); |
---|
254 | if (size(S2)>0) {S2=S2[1,size(S2)-1]+string(par(1))+")";} |
---|
255 | else {S2=string(par(1));} |
---|
256 | } |
---|
257 | } |
---|
258 | } |
---|
259 | S=S+S2+S1; |
---|
260 | } |
---|
261 | if (S[1,10]=="<mo>+</mo>") {S=S[11..size(S)];} |
---|
262 | return(S); |
---|
263 | } |
---|
264 | |
---|
265 | proc mathmlPolyN(poly a,def r){ |
---|
266 | string g; |
---|
267 | number d=leadcoef(a); |
---|
268 | list l12=ringlist(r); |
---|
269 | int n=npars(basering); |
---|
270 | |
---|
271 | if (n>0) { |
---|
272 | if (SignumLeadcoef(numerator(d))) { |
---|
273 | g=g+"<mo>-</mo>"; |
---|
274 | d=-d; |
---|
275 | } |
---|
276 | if (d!=1) { |
---|
277 | if (denominator(d)==1) { |
---|
278 | def f=mathmlHilf1(d,r); |
---|
279 | if (leadexp(f)==0) {setring r; |
---|
280 | g=g+mathmlHilf(d,r);} |
---|
281 | else {setring r; |
---|
282 | g=g+"<mi>(</mi>"+mathmlHilf(d,r)+"<mi>)</mi>";} |
---|
283 | } |
---|
284 | else {g=g+"<mfrac><mrow>"+mathmlHilf(numerator(d),r)+"</mrow><mrow>"+mathmlHilf(denominator(d),r)+"</mrow></mfrac>";} |
---|
285 | } |
---|
286 | } |
---|
287 | else { |
---|
288 | g=g+mathmlLeadCoef(string(leadcoef(a))); |
---|
289 | } |
---|
290 | setring(r); |
---|
291 | if (a==1 || a==-1) {g=g+"<mn>1</mn>";} |
---|
292 | |
---|
293 | g=g+mathmlMonomial(leadmonom(a)); |
---|
294 | a=a-lead(a); |
---|
295 | if (a!=0) { |
---|
296 | if (n==0) {if (poly(leadcoef(a))>0) {g=g+"<mo>+</mo>";}} |
---|
297 | else {if (SignumLeadcoef(numerator(leadcoef(a)))==0) {g=g+"<mo>+</mo>";}} |
---|
298 | g=g+mathmlPolyN(a,r); |
---|
299 | } |
---|
300 | return(g); |
---|
301 | } |
---|
302 | |
---|
303 | proc mathmlPoly(poly d) { |
---|
304 | string g="<math xmlns=http://www.w3.org/1998/Math/MathML>"; |
---|
305 | if (mathmlRingType()==0) {g=g+mathmlPolyR(d);} |
---|
306 | if (mathmlRingType()==2) {g=g+mathmlPolyGAL(d);} |
---|
307 | if (mathmlRingType()==1) {g=g+mathmlPolyN(d,basering);} |
---|
308 | g=g+"</math>"; |
---|
309 | return(g); |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | |
---|
314 | |
---|
315 | |
---|
316 | example |
---|
317 | { "EXAMPLE:"; echo=2; |
---|
318 | string h; |
---|
319 | ring r = (0,a),(x1,x2),dp; |
---|
320 | h=h+mathmlPoly(x1+a2)+"<br>"; |
---|
321 | h=h+mathmlPoly(x1*x2^3)+"<br>"; |
---|
322 | ring r=(0,a,b),(x(1..2)),lp; |
---|
323 | poly z=(3*a^2-12*b)*x(1)^2*x(2)+(3*a^3-1)*x(2)+x(1)^2-3/5*x(1)+1; |
---|
324 | h=h+mathmlPoly(z)+"<br>"; |
---|
325 | ring r=(0,a),(x,y),lp; |
---|
326 | poly z=(15*a^3+11*a-2)/(7*a^2+2)*x^2*y^3+13/7*x; |
---|
327 | h=h+mathmlPoly(z)+"<br>"; |
---|
328 | ring r=(13,s(1..2)),(y(1..2)),lp; |
---|
329 | poly z=(2*s(1)^4)*y(1)^3*y(2)-s(1)*s(2)*y(2)^4+(11*s(1)^3-2*s(2)^2+11*s(1)*s(2))*y(1)^2-s(2)*y(2)-3*y(2)+4; |
---|
330 | h=h+mathmlPoly(z)+"<br>"; |
---|
331 | ring r=(11,y(1..2)),(x(1..3)),lp; |
---|
332 | poly z=2*x(1)^3*x(3)-(2/(y(1)^2*y(2)^2+3))*x(2)^2; |
---|
333 | h=h+mathmlPoly(z)+"<br>"; |
---|
334 | ring r=integer,(v,x,y),lp; |
---|
335 | poly z=15*v^2*x^2*y^2-11*x*y; |
---|
336 | h=h+mathmlPoly(z)+"<br>"; |
---|
337 | ring r=(3^4,a),x,lp; |
---|
338 | poly z=a59*x2+a41; |
---|
339 | h=h+mathmlPoly(z)+"<br>"; |
---|
340 | ring r=real,(x,y),lp; |
---|
341 | poly z=3.334*x^2*y^3-4*y^2; |
---|
342 | h=h+mathmlPoly(z)+"<br>"; |
---|
343 | ring r=(real,15,a),(x(1..4)),lp; |
---|
344 | poly z=(5.2+11.11*a)*x(1)*x(4)^4-(2.333+1.344*a)*x(2); |
---|
345 | h=h+mathmlPoly(z)+"<br>"; |
---|
346 | ring r=complex,x,dp; |
---|
347 | poly z=(3.4-3.5*i)*x^5+(11.4*i)*x^4-3.552*x^3+1; |
---|
348 | h=h+mathmlPoly(z)+"<br>"; |
---|
349 | ring r=(complex,a),(ba,bb,bc),dp; |
---|
350 | poly z=(3.4-11*a)*ba^2*bb^2+4.555*ba^3; |
---|
351 | h=h+mathmlPoly(z); |
---|
352 | viewMathml(h); |
---|
353 | |
---|
354 | } |
---|
355 | |
---|
356 | |
---|
357 | /********************************************************* |
---|
358 | ** ** |
---|
359 | ** ring ** |
---|
360 | ** ** |
---|
361 | *********************************************************/ |
---|
362 | |
---|
363 | proc mathmlRing(def r) |
---|
364 | "USAGE: texRing(r); where r is a ring |
---|
365 | ASSUME: r is a ring |
---|
366 | RETURN: lateX-code for the ring r |
---|
367 | THEORY: |
---|
368 | KEYWORDS: ring, lateX, teX, tex, latex |
---|
369 | EXAMPLE: example texRing; shows an example |
---|
370 | " |
---|
371 | { setring r; |
---|
372 | list l,l1,l2; |
---|
373 | l = ringlist(r); |
---|
374 | l2 = ringlist(r)[2]; |
---|
375 | |
---|
376 | string c,p,P,V,C,S,h; |
---|
377 | |
---|
378 | int i,b; |
---|
379 | int bchar; |
---|
380 | |
---|
381 | |
---|
382 | list l3=l; |
---|
383 | l3[4]=ideal(0); |
---|
384 | def w=ring(l3); |
---|
385 | setring w; |
---|
386 | list l=fetch(r,l); |
---|
387 | setring r; |
---|
388 | |
---|
389 | |
---|
390 | //characteristic |
---|
391 | c = charstr(r); |
---|
392 | bchar = 0; |
---|
393 | if(find(c,",") != 0){ |
---|
394 | c = c[1,find(c,",")-1]; |
---|
395 | b = 0; |
---|
396 | if(typeof(l[1][2][1]) != "string" && b==0&& c =="integer"){bchar= 1;b = 1;} |
---|
397 | if(typeof(l[1][2][1]) != "string" && b==0){bchar = 2;b=1;} |
---|
398 | if(b==0){ if (mathmlRingType()==2) {bchar = 4;} |
---|
399 | else {bchar=3;} |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | //minimalpolynom |
---|
404 | p = string(minpoly); |
---|
405 | |
---|
406 | |
---|
407 | |
---|
408 | |
---|
409 | //parameters |
---|
410 | if(bchar==3){ |
---|
411 | if(p != "0"){P=P+"[";} |
---|
412 | else{P=P+"(";} |
---|
413 | for(i=1;i<size(l[1][2]);i++){ |
---|
414 | P = P + mathmlVariablesEncoding(string(l[1][2][i])) +","; |
---|
415 | } |
---|
416 | P=P+mathmlVariablesEncoding(string(l[1][2][size(l[1][2])])); |
---|
417 | if(p != "0"){ |
---|
418 | l3[1][4]=ideal(0); |
---|
419 | w=ring(l3); |
---|
420 | setring(w); |
---|
421 | list l=fetch(r,l); |
---|
422 | poly h1=l[1][4][1]; |
---|
423 | if (SignumLeadcoef(h1)==1) {h1=-h1;} |
---|
424 | h=mathmlPoly(h1); |
---|
425 | h=h[48..size(h)-7]; |
---|
426 | if (h[1,10]=="<mi>(</mi>") {h=h[11..size(h)-10];} |
---|
427 | P=P + "]/{"+h+"}"; |
---|
428 | setring(r); |
---|
429 | } |
---|
430 | else{P=P+")";} |
---|
431 | } |
---|
432 | |
---|
433 | |
---|
434 | //variables |
---|
435 | V = V + "["; |
---|
436 | for(i = 1;i<size(l2);i++){ |
---|
437 | V = V + mathmlVariablesEncoding((string(l2[i]))) + ","; |
---|
438 | } |
---|
439 | V = V + mathmlVariablesEncoding((string(l2[size(l2)]))); |
---|
440 | V = V + "]"; |
---|
441 | |
---|
442 | b = 0; |
---|
443 | if(c == "integer" && b == 0){ |
---|
444 | if(bchar==1){ //Z/(p^k) |
---|
445 | if(string(l[1][2][2])!="1"){ |
---|
446 | C=C+"<msub><mrow><mn>ℤ</mn></mrow><mrow><msup><mrow>"+string(l[1][2][1])+"</mrow><mrow>"+string(l[1][2][2])+"<mrow></msup></mrow></msub>"; |
---|
447 | } |
---|
448 | else{C=C+"<msub><mn>ℤ</mn>"+"<mn>"+string(l[1][2][1])+"</mn></msub>";} |
---|
449 | b = 1; |
---|
450 | } |
---|
451 | else{C = C + "<mn>ℤ</mn>";b=1;} //Z |
---|
452 | } |
---|
453 | if(c == "0" && b == 0){C = C + "<mn>ℚ</mn>";b=1;} //Q |
---|
454 | if(c == "real" && b == 0){C = C + "<mn>ℝ</mn>";b=1;} //R |
---|
455 | if(c == "complex" && b == 0){ |
---|
456 | b=1; |
---|
457 | if(typeof(l[1][3]) != "none"){ |
---|
458 | if(l[1][3]!="i"){C = C + "<mn>ℝ</mn>("+l[1][3]+")";} //R(j) |
---|
459 | else{C = C + "<mn>ℂ</mn>";} |
---|
460 | } |
---|
461 | else{C = C + "<mn>ℂ</mn";} //C |
---|
462 | } |
---|
463 | if(b == 0){ if (bchar==4) {C = C + "<msub><mn>F</mn>"+c+"</msub>";} //F/p |
---|
464 | else {C = C + "<msub><mn>ℤ</mn>"+c+"</msub>";b=1;} //Z/p |
---|
465 | |
---|
466 | } |
---|
467 | //epic conclusion |
---|
468 | if(size(P)!=0){S = S + C+P+V;} |
---|
469 | else{S=S+C+V;} |
---|
470 | |
---|
471 | if (l[4]!=0) { |
---|
472 | setring w; |
---|
473 | |
---|
474 | S=S+"<mo>/</mo><mo>(</mo>"; |
---|
475 | for(int k=1;k<=size(l[4]);k++) { |
---|
476 | h=mathmlPoly(l[4][k]); |
---|
477 | h=h[48..size(h)-7]; |
---|
478 | S=S+h+"<mo>,</mo>"; |
---|
479 | } |
---|
480 | S=S[1,size(S)-10]+"<mo>)</mo>"; |
---|
481 | } |
---|
482 | |
---|
483 | S = "<math xmlns=http://www.w3.org/1998/Math/MathML>" + S + "</math>"; |
---|
484 | return(S); |
---|
485 | } |
---|
486 | |
---|
487 | |
---|
488 | example |
---|
489 | { "EXAMPLE:"; echo=2; |
---|
490 | string h; |
---|
491 | ring r = 32003,(x,y,z),dp; |
---|
492 | h=h+mathmlRing(r)+"<br>"; |
---|
493 | ring r = 32003,(x(1..10)),dp; |
---|
494 | h=h+mathmlRing(r)+"<br>"; |
---|
495 | ring r = 0,(a,b,c,d),lp; |
---|
496 | h=h+mathmlRing(r)+"<br>"; |
---|
497 | ring r =7,(x,y,z),ds; |
---|
498 | h=h+mathmlRing(r)+"<br>"; |
---|
499 | ring r = 7,(x(1..6)),(lp(3),dp); |
---|
500 | h=h+mathmlRing(r)+"<br>"; |
---|
501 | ring r =0,(x,y,z),(c,wp(2,1,3)); |
---|
502 | h=h+mathmlRing(r)+"<br>"; |
---|
503 | ring r =(7,a,b,c),(x,y,z),Dp; |
---|
504 | h=h+mathmlRing(r)+"<br>"; |
---|
505 | ring r =(7,a),(x,y,z),dp; minpoly = a^2+a+3; |
---|
506 | h=h+mathmlRing(r)+"<br>"; |
---|
507 | ring r =real,(x,y,z),dp; |
---|
508 | h=h+mathmlRing(r)+"<br>"; |
---|
509 | ring r =(real,50),(x,y,z),dp; |
---|
510 | h=h+mathmlRing(r)+"<br>"; |
---|
511 | ring r =(real,10,50),(x,y,z),dp; |
---|
512 | h=h+mathmlRing(r)+"<br>"; |
---|
513 | ring r = (complex,30,j),(x,y,z),dp; |
---|
514 | h=h+mathmlRing(r)+"<br>"; |
---|
515 | ring r =complex,(x,y,z),dp; |
---|
516 | h=h+mathmlRing(r)+"<br>"; |
---|
517 | ring r =7,(x,y,z), dp; |
---|
518 | h=h+mathmlRing(r)+"<br>"; |
---|
519 | ring r =integer,(x,y,z), dp; |
---|
520 | h=h+mathmlRing(r)+"<br>"; |
---|
521 | ring r =(integer, 6, 3),(x,y,z), dp; |
---|
522 | h=h+mathmlRing(r)+"<br>"; |
---|
523 | ring r =(integer, 100),(x,y,z), dp; |
---|
524 | h=h+mathmlRing(r)+"<br>"; |
---|
525 | ring r=(121,a),x,lp; |
---|
526 | h=h+mathmlRing(r); |
---|
527 | viewMathml(h); |
---|
528 | } |
---|
529 | |
---|
530 | |
---|
531 | |
---|
532 | /********************************************************* |
---|
533 | ** ** |
---|
534 | ** map ** |
---|
535 | ** ** |
---|
536 | *********************************************************/ |
---|
537 | |
---|
538 | |
---|
539 | proc mathmlMap(map f, list #)"USAGE: texMap(f, #); #[1] source XOR texMap(f),if source == target |
---|
540 | ASSUME: f is a map, #[1] ring or empty |
---|
541 | RETURN: lateX-code for the map f |
---|
542 | THEORY: |
---|
543 | KEYWORDS: map, lateX, teX, tex, latex |
---|
544 | EXAMPLE: example texMap; shows an example |
---|
545 | " |
---|
546 | { |
---|
547 | |
---|
548 | // f: s--->r (rings) || f:s1--->s2 (string) |
---|
549 | string s1,s2; |
---|
550 | string h1,h2; |
---|
551 | string T,S; //variables, output string |
---|
552 | s2 = mathmlRing(basering); |
---|
553 | s2 = s2[48,size(s2)-54]; |
---|
554 | int B = 0; |
---|
555 | int b = 0; |
---|
556 | if(nameof(basering)==nameof(preimage(f))){b=1;} |
---|
557 | |
---|
558 | def r = basering; |
---|
559 | if(size(#)!=0){ |
---|
560 | if(typeof(#[1]) != "ring"){return("ERROR - wrong input. check texMap documentation." );} |
---|
561 | def s; |
---|
562 | s = #[1]; |
---|
563 | setring s; |
---|
564 | s1 = mathmlRing(s); |
---|
565 | s1 = s1[48,size(s1)-54]; |
---|
566 | list l1; |
---|
567 | for(int k=1;k<=nvars(s);k++){ |
---|
568 | l1[k] = mathmlVariablesEncoding(string(var(k))); |
---|
569 | } |
---|
570 | |
---|
571 | setring r; |
---|
572 | for(int i = 1;i<=nvars(s);i++){ |
---|
573 | h1=mathmlPoly(f[i]); |
---|
574 | h2=h1[48,size(h1)-54]; |
---|
575 | T =T+ "<mtr><mtd>"+l1[i]+"</mtd><mtd>"+"<mo>↦</mo>"+"</mtd><mtd>"+h2+"</mtd></mtr>"; |
---|
576 | } |
---|
577 | } |
---|
578 | else{ |
---|
579 | if(b==1){ |
---|
580 | mathmlMap(f,basering); |
---|
581 | return(); |
---|
582 | } |
---|
583 | else{ |
---|
584 | s1 = "'"+nameof(preimage(f))+"'"; |
---|
585 | print("For detailed information we need the source"); |
---|
586 | B = 1; |
---|
587 | } |
---|
588 | |
---|
589 | } |
---|
590 | S = "<mtr><mtd>"+s1+"</mtd><mtd>" + "<mo>→</mo>" +"</mtd><mtd>"+ s2+"</mtd></mtr>"+T; |
---|
591 | S = "<math xmlns=http://www.w3.org/1998/Math/MathML><mtable>" + S + "</mtable></math>"; |
---|
592 | |
---|
593 | return(S); |
---|
594 | } |
---|
595 | example |
---|
596 | { "EXAMPLE:"; echo=2; |
---|
597 | string h; |
---|
598 | ring U = 0,(x,y,z),lp; |
---|
599 | ring M2 = real,(z(1..3)),lp; |
---|
600 | setring M2; |
---|
601 | map f = U,z(1)*z(2)^3,z(1),-z(2); |
---|
602 | h=h+mathmlMap(f)+"<br>"; |
---|
603 | //2nd |
---|
604 | h=h+mathmlMap(f,U)+"<br>"; |
---|
605 | //3rd |
---|
606 | ring R = real,(x,y,z),lp; |
---|
607 | map f2 = R,x2,y2,z-x; |
---|
608 | h=h+string(mathmlMap(f2)); |
---|
609 | viewMathml(h);} |
---|
610 | |
---|
611 | |
---|
612 | |
---|
613 | |
---|
614 | |
---|
615 | |
---|
616 | |
---|
617 | |
---|
618 | /********************************************************* |
---|
619 | ** ** |
---|
620 | ** IDEAL ** |
---|
621 | ** ** |
---|
622 | *********************************************************/ |
---|
623 | proc mathmlIdeal(ideal I)"USAGE: texIdeal(I), where I is an ideal |
---|
624 | ASSUME: I is an ideal |
---|
625 | RETURN: lateX-code for the ideal I |
---|
626 | THEORY: |
---|
627 | KEYWORDS: ideal, lateX, teX, tex, latex |
---|
628 | EXAMPLE: example texIdeal; shows an example |
---|
629 | "{ |
---|
630 | string S = ""; |
---|
631 | for(int i = 1;i<size(I);i++){ |
---|
632 | S = S + mathmlPoly(I[i],"no$") + ","; |
---|
633 | } |
---|
634 | S = S + mathmlPoly(I[size(I)],"no$"); |
---|
635 | S = "<math xmlns=http://www.w3.org/1998/Math/MathML><mo>⟨</mo>" + S + "<mo>⟩</mo></math>"; |
---|
636 | return(S); |
---|
637 | } |
---|
638 | example |
---|
639 | {"EXAMPLE: "; echo=2; |
---|
640 | ring r = 0,(x,y,z),dp; |
---|
641 | ideal I = x2,y3,z; |
---|
642 | viewMathml(mathmlIdeal(I)); |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | |
---|
647 | /********************************************************* |
---|
648 | ** ** |
---|
649 | ** LIST ** |
---|
650 | ** ** |
---|
651 | *********************************************************/ |
---|
652 | proc mathmlList(list l)"USAGE: texList(l), where l is a list |
---|
653 | ASSUME: l is a list |
---|
654 | RETURN: lateX-code for the list l |
---|
655 | THEORY: |
---|
656 | KEYWORDS: list, lateX, teX, tex, latex |
---|
657 | EXAMPLE: example texList; shows an example |
---|
658 | "{ |
---|
659 | string tmp; |
---|
660 | string S = ""; |
---|
661 | for(int i=1;i<size(l);i++){ |
---|
662 | tmp = mathml(l[i]); |
---|
663 | tmp = tmp[48,size(tmp)-54]; |
---|
664 | //S = S + tex(l[i]) + ";"; |
---|
665 | S = S + tmp + ";"; |
---|
666 | } |
---|
667 | //tmp = tex(l[size(l)]); |
---|
668 | tmp = mathml(l[size(l)]); |
---|
669 | tmp = tmp[48,size(tmp)-54]; |
---|
670 | //S = S + tex(l[size(l)]); |
---|
671 | S = S + tmp; |
---|
672 | S = "<math xmlns=http://www.w3.org/1998/Math/MathML><mo>{</mo>" + S + "<mo>}</mo></math>";; |
---|
673 | return(S); |
---|
674 | } |
---|
675 | example |
---|
676 | {"EXAMPLE:"; echo=2; |
---|
677 | string h; |
---|
678 | //int |
---|
679 | ring r = integer,(x,y,z),dp; |
---|
680 | list l = 1,2,3; |
---|
681 | h=h+mathmlList(l)+"<br>"; |
---|
682 | //ring |
---|
683 | ring r2 = real,(a,b,c),dp; |
---|
684 | ring r3 = complex,(x(1..3)),dp; |
---|
685 | list l2 = r,r2,r3; |
---|
686 | h=h+mathmlList(l2)+"<br>"; |
---|
687 | //matrix |
---|
688 | setring r; |
---|
689 | matrix m1[2][2]=x2y,-xz3,0,17x3z2; |
---|
690 | matrix m2[2][2]=1,2,3,4; |
---|
691 | list l3 = m1,m2; |
---|
692 | h=h+mathmlList(l3); |
---|
693 | //poly |
---|
694 | poly p = x2-1; |
---|
695 | poly p2 = x3-y+z; |
---|
696 | poly p3 = y3-z7; |
---|
697 | list l4 = p,p2,p3; |
---|
698 | //mathmlList(l4); |
---|
699 | viewMathml(h); |
---|
700 | } |
---|
701 | |
---|
702 | |
---|
703 | |
---|
704 | /********************************************************* |
---|
705 | ** ** |
---|
706 | ** BIGINT,INT ** |
---|
707 | ** ** |
---|
708 | *********************************************************/ |
---|
709 | proc mathmlBigInt (bigint I){ |
---|
710 | return("<math xmlns=http://www.w3.org/1998/Math/MathML>"+string(I)+"</math>"); |
---|
711 | } |
---|
712 | |
---|
713 | proc mathmlInt(int I){ |
---|
714 | return(mathmlBigInt(I)); |
---|
715 | } |
---|
716 | |
---|
717 | |
---|
718 | /********************************************************* |
---|
719 | ** ** |
---|
720 | ** STRING ** |
---|
721 | ** ** |
---|
722 | *********************************************************/ |
---|
723 | proc mathmlString(string m){ |
---|
724 | return(m); |
---|
725 | } |
---|
726 | |
---|
727 | |
---|
728 | /********************************************************* |
---|
729 | ** ** |
---|
730 | ** NUMBER ** |
---|
731 | ** ** |
---|
732 | **requires: mathmlPoly - since there might be a parameter ** |
---|
733 | *********************************************************/ |
---|
734 | |
---|
735 | proc mathmlNumber(number n){ |
---|
736 | string S; |
---|
737 | S = mathmlPoly(n); |
---|
738 | return(S); |
---|
739 | } |
---|
740 | |
---|
741 | /********************************************************* |
---|
742 | ** ** |
---|
743 | ** VECTOR, INTVEC ** |
---|
744 | ** INTMAT, BIGINTMAT, MATRIX ** |
---|
745 | ** ** |
---|
746 | *********************************************************/ |
---|
747 | |
---|
748 | proc mathmlVector(vector v){ |
---|
749 | int L = size(v); |
---|
750 | matrix m[L][1] = v; |
---|
751 | string S = mathmlMatrix(m); |
---|
752 | return(S); |
---|
753 | } |
---|
754 | |
---|
755 | proc mathmlIntvec(intvec v){ |
---|
756 | matrix m = v; |
---|
757 | string S = mathmlMatrix(m); |
---|
758 | return(S); |
---|
759 | } |
---|
760 | proc mathmlIntmat(intmat M){ |
---|
761 | matrix m = M; |
---|
762 | string S = mathmlMatrix(m); |
---|
763 | return(S); |
---|
764 | } |
---|
765 | proc mathmlBigintmat(bigintmat M){ |
---|
766 | matrix m = M; |
---|
767 | string S = mathmlMatrix(m); |
---|
768 | return(S); |
---|
769 | } |
---|
770 | |
---|
771 | |
---|
772 | proc mathmlMatrix(matrix m){ |
---|
773 | string s,h; |
---|
774 | int i=1; |
---|
775 | int j=1; |
---|
776 | s=s+"<math xmlns=http://www.w3.org/1998/Math/MathML><mrow><mo>(</mo><mtable>"; |
---|
777 | while (i<=nrows(m)) { |
---|
778 | j=1; |
---|
779 | s=s+"<mtr>"; |
---|
780 | while (j<=ncols(m)) { |
---|
781 | h=mathmlPoly(m[i,j]); |
---|
782 | s=s+"<mtd>"+h[48,size(h)-54]+"</mtd>"; |
---|
783 | j=j+1; |
---|
784 | } |
---|
785 | s=s+"</mtr>"; |
---|
786 | i=i+1; |
---|
787 | } |
---|
788 | s=s+"</mtable><mo>)</mo></mrow></math>"; |
---|
789 | return(s); |
---|
790 | } |
---|
791 | |
---|
792 | |
---|
793 | /********************************************************* |
---|
794 | ** ** |
---|
795 | ** View ** |
---|
796 | ** ** |
---|
797 | *********************************************************/ |
---|
798 | |
---|
799 | |
---|
800 | |
---|
801 | proc viewMathml(string s){ |
---|
802 | string p = "firefox"; |
---|
803 | string Sstart = "<!doctype html><html><head><meta charset=UTF-8><title>MathML Examples</title></head><body>"; |
---|
804 | string Send = "</body></html> "; |
---|
805 | string S = Sstart + s + Send; |
---|
806 | write(":w singular_mathml.html", S); |
---|
807 | |
---|
808 | system("sh",p+" singular_mathml.html"); |
---|
809 | } |
---|
810 | |
---|
811 | |
---|
812 | |
---|
813 | |
---|