UNPKG

3.97 kBtext/coffeescriptView Raw
1test_power = ->
2 run_test [
3
4 # according to the notorious
5 # "PEMDAS" mnemonic, the power
6 # operator has the most precedence.
7 # Strangely, Mathematica parses
8 # a^1/2 as sqrt(a), not following PEMDAS,
9 # probably because of some fancy
10 # euristics, since, contrarily to the
11 # case above, it also parses
12 # a^b/2 as (a^b)/2.
13 # I think this more standard/uniform handling
14 # a-la-sympy is ok.
15 "a^1/2 + a^1/2",
16 "a",
17
18 "2^(1/2)",
19 "2^(1/2)",
20
21 "2^(3/2)",
22 "2*2^(1/2)",
23
24 "(-2)^(1/2)",
25 "i*2^(1/2)",
26
27 "3^(4/3)",
28 "3*3^(1/3)",
29
30 "3^(-4/3)",
31 "1/(3*3^(1/3))",
32
33 "3^(5/3)",
34 "3*3^(2/3)",
35
36 "3^(2/3)-9^(1/3)",
37 "0",
38
39 "3^(10/3)",
40 "27*3^(1/3)",
41
42 "3^(-10/3)",
43 "1/(27*3^(1/3))",
44
45 "(1/3)^(10/3)",
46 "1/(27*3^(1/3))",
47
48 "(1/3)^(-10/3)",
49 "27*3^(1/3)",
50
51 "27^(2/3)",
52 "9",
53
54 "27^(-2/3)",
55 "1/9",
56
57 "102^(1/2)",
58 "2^(1/2)*3^(1/2)*17^(1/2)",
59
60 "32^(1/3)",
61 "2*2^(2/3)",
62
63 "9999^(1/2)",
64 "3*11^(1/2)*101^(1/2)",
65
66 "8^(1/2)",
67 "2*2^(1/2)",
68
69 "10000^(1/3)",
70 "10*2^(1/3)*5^(1/3)",
71
72 # we could take out a "18" from the radix but
73 # we only handle this for small numbers in
74 # "quickfactor" routine. TODO
75 "8204861575751304355842204^(1/2)",
76 "8204861575751304355842204^(1/2)",
77
78 # see above
79 "simplify(8204861575751304355842204^(1/2))",
80 "8204861575751304355842204^(1/2)",
81
82 "sqrt(-1/2 -1/2 * x)",
83 "(-1/2*x-1/2)^(1/2)",
84
85 "sqrt(x*y)",
86 "(x*y)^(1/2)",
87
88 "sqrt(1/x)",
89 "(1/x)^(1/2)",
90
91 "sqrt(x^y)",
92 "(x^y)^(1/2)",
93
94 "sqrt(x)^2",
95 "x",
96
97 "sqrt(x^2)",
98 "abs(x)",
99
100 # always true, whether x is real or not
101 "sqrt(x^2)^2",
102 "x^2",
103
104 "3^(1/2)*i/9",
105 "1/9*i*3^(1/2)",
106
107 "(-4.0)^(1.5)",
108 "-8.0*i",
109
110 "(-4.0)^(3/2)",
111 "-8.0*i",
112
113 # usually the rectangular form is returned.
114 "(-1)^(1/3)",
115 #"(-1)^(1/3)",
116 "1/2+1/2*i*3^(1/2)",
117
118 # note how the "double" type
119 # is toxic i.e. it propagates through
120 # everything it touches.
121 "(-1.0)^(2/3)",
122 "-0.5+0.866025*i",
123
124 # this also has a nested radical
125 # form but we are not calculating
126 # that.
127 "(-1)^(1/3)*2^(1/4)",
128 #"(-1)^(1/3)*2^(1/4)",
129 "1/2*2^(1/4)+1/2*i*2^(1/4)*3^(1/2)",
130
131 "(-1)^(1/2)",
132 "i",
133
134 "sqrt(1000000)",
135 "1000",
136
137 "sqrt(-1000000)",
138 "1000*i",
139
140 "sqrt(2^60)",
141 "1073741824",
142
143 # this is why we factor irrationals
144
145 "6^(1/3) 3^(2/3)",
146 "3*2^(1/3)",
147
148 # inverse of complex numbers
149
150 "1/(2+3*i)",
151 "2/13-3/13*i",
152
153 "1/(2+3*i)^2",
154 "-5/169-12/169*i",
155
156 "(-1+3i)/(2-i)",
157 "-1+i",
158
159 # other
160
161 "(0.0)^(0.0)",
162 "1.0",
163
164 "(-4.0)^(0.5)",
165 "2.0*i",
166
167 "(-4.0)^(-0.5)",
168 "-0.5*i",
169
170 "(-4.0)^(-1.5)",
171 "0.125*i",
172
173 # more complex number cases
174
175 "(1+i)^2",
176 "2*i",
177
178 "(1+i)^(-2)",
179 "-1/2*i",
180
181 "(1+i)^(1/2)",
182 #"(-1)^(1/8)*2^(1/4)",
183 "i*2^(1/4)*sin(1/8*pi)+2^(1/4)*cos(1/8*pi)",
184
185 "(1+i)^(-1/2)",
186 "-(-1)^(7/8)/(2^(1/4))",
187
188 "(1+i)^(0.5)",
189 "1.09868+0.45509*i",
190
191 "(1+i)^(-0.5)",
192 "0.776887-0.321797*i",
193
194 # test cases for simplification of polar forms, counterclockwise
195
196 "exp(i*pi/2)",
197 "i",
198
199 "exp(i*pi)",
200 "-1",
201
202 "exp(i*3*pi/2)",
203 "-i",
204
205 "exp(i*2*pi)",
206 "1",
207
208 "exp(i*5*pi/2)",
209 "i",
210
211 "exp(i*3*pi)",
212 "-1",
213
214 "exp(i*7*pi/2)",
215 "-i",
216
217 "exp(i*4*pi)",
218 "1",
219
220 "exp(A+i*pi/2)",
221 "i*exp(A)",
222
223 "exp(A+i*pi)",
224 "-exp(A)",
225
226 "exp(A+i*3*pi/2)",
227 "-i*exp(A)",
228
229 "exp(A+i*2*pi)",
230 "exp(A)",
231
232 "exp(A+i*5*pi/2)",
233 "i*exp(A)",
234
235 "exp(A+i*3*pi)",
236 "-exp(A)",
237
238 "exp(A+i*7*pi/2)",
239 "-i*exp(A)",
240
241 "exp(A+i*4*pi)",
242 "exp(A)",
243
244 # test cases for simplification of polar forms, clockwise
245
246 "exp(-i*pi/2)",
247 "-i",
248
249 "exp(-i*pi)",
250 "-1",
251
252 "exp(-i*3*pi/2)",
253 "i",
254
255 "exp(-i*2*pi)",
256 "1",
257
258 "exp(-i*5*pi/2)",
259 "-i",
260
261 "exp(-i*3*pi)",
262 "-1",
263
264 "exp(-i*7*pi/2)",
265 "i",
266
267 "exp(-i*4*pi)",
268 "1",
269
270 "exp(A-i*pi/2)",
271 "-i*exp(A)",
272
273 "exp(A-i*pi)",
274 "-exp(A)",
275
276 "exp(A-i*3*pi/2)",
277 "i*exp(A)",
278
279 "exp(A-i*2*pi)",
280 "exp(A)",
281
282 "exp(A-i*5*pi/2)",
283 "-i*exp(A)",
284
285 "exp(A-i*3*pi)",
286 "-exp(A)",
287
288 "exp(A-i*7*pi/2)",
289 "i*exp(A)",
290
291 "exp(A-i*4*pi)",
292 "exp(A)",
293 ]