File: c_tex_form.mpt

package info (click to toggle)
mathpiper 0.81f%2Bsvn4469%2Bdfsg3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 36,552 kB
  • ctags: 8,348
  • sloc: java: 57,479; lisp: 13,721; objc: 1,300; xml: 988; makefile: 114; awk: 95; sh: 38
file content (143 lines) | stat: -rw-r--r-- 3,652 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*LoadScriptOnce("texform");*/

NextTest("TeXForm()...");

/* it worketh no more...
Testing("Realistic example");
f:=Exp(I*lambda*eta)*w(T*(k+k1+lambda));
g:=Simplify(Subst(lambda,0) f+(k+k1)*(Differentiate(lambda)f)+k*k1*Differentiate(lambda)Differentiate(lambda)f );
Verify(TeXForm(g), ...);
*/

Verify(
TeXForm(Hold(Cos(A-B)*Sqrt(C+D)-(a+b)*c^d+2*I+Complex(a+b,a-b)/Complex(0,1)))
,"$\\cos ( A - B)  \\cdot \\sqrt{C + D} - ( a + b)  \\cdot c ^{d} + 2 \\cdot \\imath  + \\frac{a + b + \\imath  \\cdot ( a - b) }{\\imath } $"
);

Verify(
TeXForm(Hold(Exp(A*B)/C/D/(E+F)*G-(-(a+b)-(c-d))-b^(c^d) -(a^b)^c))
,"$\\frac{\\frac{\\frac{\\exp ( A \\cdot B) }{C} }{D} }{E + F}  \\cdot G - (  - ( a + b)  - ( c - d) )  - b ^{c ^{d}} - ( a ^{b})  ^{c}$"
);

Verify(
TeXForm(Hold(Cos(A-B)*Sin(a)*f(b,c,d*(e+1))*Sqrt(C+D)-(g(a+b)^(c+d))^(c+d)))
,"$\\cos ( A - B)  \\cdot \\sin a \\cdot f( b, c, d \\cdot ( e + 1) )  \\cdot \\sqrt{C + D} - ( g( a + b)  ^{c + d})  ^{c + d}$"
);

// testing latest features: \\cdot, %, (a/b)^n, BinomialCoefficient(), BesselI, OrthoH
Verify(
TeXForm(3*2^n+Hold(x*10!) + (x/y)^2 + BinomialCoefficient(x,y) + BesselI(n,x) + Maximum(a,b) + OrthoH(n,x))
, "$3\\cdot 2 ^{n} + x\\cdot 10! + ( \\frac{x}{y} )  ^{2} + {x \\choose y} + I _{n}( x)  + \\max ( a, b)  + H _{n}( x) $"
);

/* this fails because of a bug that Differentiate(x) f(y) does not go to 0 */ /*
Verify(
TeXForm(3*Differentiate(x)f(x,y,z)*Cos(Omega)*Modulo(Sin(a)*4,5/a^b))
,"$3 ( \\frac{\\partial}{\\partial x}f( x, y, z) )  ( \\cos \\Omega )  ( 4 ( \\sin a) ) \\bmod \\frac{5}{a ^{b}} $"
);
*/

Verify(
TeXForm(Hold(Differentiate(x)f(x)))
,"$\\frac{d}{d x}f( x) $");

Verify(
TeXForm(Hold(Not (c<0) And (a+b)*c>= -d^e And (c<=0 Or b+1>0) Or a!=0 And Not (p=q)))
,"$ \\neg c < 0\\wedge ( a + b)  \\cdot c\\geq  - d ^{e}\\wedge ( c\\leq 0\\vee b + 1 > 0) \\vee a\\neq 0\\wedge  \\neg p = q$"
);


Verify(
TeXForm((Differentiate(x)f(x,y,z))*Cos(Omega)*Modulo(Sin(a)*4,5/a^b))
,"$( \\frac{\\partial}{\\partial x}f( x, y, z) )  \\cdot \\cos \\Omega  \\cdot ( 4 \\cdot \\sin a) \\bmod \\frac{5}{a ^{b}} $"
);


Verify(
TeXForm(Pi+Exp(1)-Theta-Integrate(x,x1,3/g(Pi))2*theta(x)*Exp(1/x))
,"$\\pi  + \\exp ( 1)  - \\Theta  - \\int _{x_{1}} ^{\\frac{3}{g( \\pi ) }  } 2 \\cdot \\theta ( x)  \\cdot \\exp ( \\frac{1}{x} )  dx$"
);

Verify(
TeXForm({a[3]*b[5]-c[1][2],{a,b,c,d}})
,"$( a _{3} \\cdot b _{5} - c _{( 1, 2) }, ( a, b, c, d) ) $"
);

Bodied("aa", 200);
Infix("bar", 100);

Verify(
TeXForm(aa(x,y) z + 1 bar y!)
,"$aa( x, y) z + 1\\mathrm{ bar }y!$"
);

Verify(
TeXForm(x^(1/3)+x^(1/2))
, "$\\sqrt[3]{x} + \\sqrt{x}$"
);

/*
Verify(
TeXForm()
,"" 
);
*/

Verify(
CForm(Hold(Cos(A-B)*Sin(a)*func(b,c,d*(e+Pi))*Sqrt(Abs(C)+D)-(g(a+b)^(c+d))^(c+d)))
,"cos(A - B) * sin(a) * func(b, c, d * ( e + Pi) ) * sqrt(fabs(C) + D) - pow(pow(g(a + b), c + d), c + d)" 
);

Verify(
CForm(Hold([i:=0;While(i<10)[i++; a:=a+Floor(i);];]))
, "{
  i = 0;
  while(i < 10)
    {
      ++(i);
      a = a + floor(i);
      }
    ;
    ;
  }
"
);

/* Check that we can still force numbers to be floats in stead of integers if we want to */
Verify(
CForm(Hold([i:=0.;While(i<10.)[i++; a:=a+Floor(i);];]))
, "{
  i = 0.;
  while(i < 10.)
    {
      ++(i);
      a = a + floor(i);
      }
    ;
    ;
  }
"
);


Testing("IsCFormable");
Verify(
IsCFormable(e+Pi*Cos(A-B)/3-Floor(3.14)*2)
, True
);
Verify(
IsCFormable(e+Pi*Cos(A-B)/3-Floor(3.14)*2+bad'func(x+y))
, False
);
Verify(
IsCFormable(e+Pi*Cos(A-B)/3-Floor(3.14)*2+bad'func(x+y), {bad'func})
, True
);
Verify(
IsCFormable([i:=0;While(i<10)[i++; a:=a+i;];])
, True
);
Verify(
IsCFormable([i:=0;While(i<10)[i++; a:=a+i; {};];])
, False
);