UNPKG

8.41 kBtext/coffeescriptView Raw
1test_simplify = ->
2 run_test [
3
4 "simplify(A)",
5 "A",
6
7 "simplify(A+B)",
8 "A+B",
9
10 "simplify(A B)",
11 "A*B",
12
13 "simplify(A^B)",
14 "A^B",
15
16 "simplify(A/(A+B)+B/(A+B))",
17 "1",
18
19 "simplify((A-B)/(B-A))",
20 "-1",
21
22 "A=[[A11,A12],[A21,A22]]",
23 "",
24
25 "simplify(det(A) inv(A) - adj(A))",
26 "0",
27
28 "A=quote(A)",
29 "",
30
31 # this shows need for <= in try_factoring
32
33 # "x*(1+a)",
34 # "x+a*x",
35
36 # "simplify(last)",
37 # "x*(1+a)",
38
39 "simplify(-3 exp(-1/3 r + i phi) cos(theta) / sin(theta)\
40 + 3 exp(-1/3 r + i phi) cos(theta) sin(theta)\
41 + 3 exp(-1/3 r + i phi) cos(theta)^3 / sin(theta))",
42 "0",
43
44 "simplify((A^2 C^2 + A^2 D^2 + B^2 C^2 + B^2 D^2)/(A^2+B^2)/(C^2+D^2))",
45 "1",
46
47 "simplify(d(arctan(y/x),y))",
48 "x/(x^2+y^2)",
49
50 "simplify(d(arctan(y/x),x))",
51 "-y/(x^2+y^2)",
52
53 "simplify(1-sin(x)^2)",
54 "cos(x)^2",
55
56 "simplify(1-cos(x)^2)",
57 "sin(x)^2",
58
59 "simplify(sin(x)^2-1)",
60 "-cos(x)^2",
61
62 "simplify(cos(x)^2-1)",
63 "-sin(x)^2",
64
65 # tries to get rid of sin and cos if there are more
66 # compact clockforms or exponential forms
67 "simplify(-cos(2/5*pi)*(k/a)^(1/5)-i*(k/a)^(1/5)*sin(2/5*pi))",
68 "((k/a)^(2/5))^(1/2)/((-1)^(3/5))",
69
70 #"simfac(n!/n)-(n-1)!",
71 #"0",
72
73 #"simfac(n/n!)-1/(n-1)!",
74 #"0",
75
76 #"simfac(rationalize((n+k+1)/(n+k+1)!))-1/(n+k)!",
77 #"0",
78
79 #"simfac(condense((n+1)*n!))-(n+1)!",
80 #"0",
81
82 #"simfac(1/((n+1)*n!))-1/(n+1)!",
83 #"0",
84
85 #"simfac((n+1)!/n!)-n-1",
86 #"0",
87
88 #"simfac(n!/(n+1)!)-1/(n+1)",
89 #"0",
90
91 #"simfac(binomial(n+1,k)/binomial(n,k))",
92 #"(1+n)/(1-k+n)",
93
94 #"simfac(binomial(n,k)/binomial(n+1,k))",
95 #"(1-k+n)/(1+n)",
96
97 #"F(nn,kk)=kk*binomial(nn,kk)",
98 #"",
99
100 #"simplify(simfac((F(n,k)+F(n,k-1))/F(n+1,k))-n/(n+1))",
101 #"0",
102
103 #"F=quote(F)",
104 #"",
105
106 "simplify(n!/n)-(n-1)!",
107 "0",
108
109 "simplify(n/n!)-1/(n-1)!",
110 "0",
111
112 "simplify(rationalize((n+k+1)/(n+k+1)!))-1/(n+k)!",
113 "0",
114
115 "simplify(condense((n+1)*n!))-(n+1)!",
116 "0",
117
118 "simplify(1/((n+1)*n!))-1/(n+1)!",
119 "0",
120
121 "simplify((n+1)!/n!)-n-1",
122 "0",
123
124 "simplify(n!/(n+1)!)-1/(n+1)",
125 "0",
126
127 "simplify(binomial(n+1,k)/binomial(n,k))",
128 "(1+n)/(1-k+n)",
129
130 "simplify(binomial(n,k)/binomial(n+1,k))",
131 "(1-k+n)/(1+n)",
132
133 "F(nn,kk)=kk*binomial(nn,kk)",
134 "",
135
136 "simplify((F(n,k)+F(n,k-1))/F(n+1,k))-n/(n+1)",
137 "0",
138
139 "F=quote(F)",
140 "",
141
142 "simplify((n+1)/(n+1)!)-1/n!",
143 "0",
144
145 "simplify(a*b+a*c)",
146 "a*(b+c)",
147
148 # Symbol's binding is evaluated, undoing simplify
149
150 "x=simplify(a*b+a*c)",
151 "",
152
153 "x",
154 "a*b+a*c",
155
156 "x=quote(x)",
157 "",
158
159 "simplify((6 - 4*2^(1/2))^(1/2))",
160 "2-2^(1/2)",
161
162 "4-4*(-1)^(1/3)+4*(-1)^(2/3)",
163 "0",
164
165 "simplify(4-4*(-1)^(1/3)+4*(-1)^(2/3))",
166 "0",
167
168 # this requires some simplification to be
169 # further done after the de-nesting
170 "simplify(14^(1/2) - (16 - 4*7^(1/2))^(1/2))",
171 "2^(1/2)",
172
173
174 "simplify(-(2^(1/2)*(-1+7^(1/2)))+2^(1/2)*7^(1/2))",
175 "2^(1/2)",
176
177
178 "simplify((9 + 6*2^(1/2))^(1/2))",
179 "3^(1/2)*(1+2^(1/2))",
180
181
182 "simplify((7 + 13^(1/2))^(1/2))",
183 "(1+13^(1/2))/(2^(1/2))",
184
185 # two nested radicals at the same time
186 "simplify((17 + 12*2^(1/2))^(1/2) + (17 - 12*2^(1/2))^(1/2))",
187 "6",
188
189 "simplify((2 + 3^(1/2))^(1/2))",
190 "(1+3^(1/2))/(2^(1/2))",
191
192 "simplify((1/2 + (39^(1/2)/16))^(1/2))",
193 "(3^(1/2)+13^(1/2))/(4*2^(1/2))",
194
195 # there would be a slightly better presentation for this,
196 # where 108 is factored and some parts get out of the
197 # radical but there is no way to de-nest this.
198 "simplify((-108+108*(-1)^(1/2)*3^(1/2))^(1/3))",
199 "6*(-1)^(2/9)",
200 # also: "(-108+108*i*3^(1/2))^(1/3)" is a possible result
201
202 # you can take that 4 out of the radical
203 # but other than that there is no
204 # "sum or radicals" form of this
205 "simplify((-4+4*(-1)^(1/2)*3^(1/2))^(1/3))",
206 "2*(-1)^(2/9)",
207 # also: "(-4+4*i*3^(1/2))^(1/3)" is a possible result
208
209
210 # scrambling the order of things a little
211 # and checking whether the nested radical
212 # still gets simplified.
213 "simplify((((-3)^(1/2) + 1)/2)^(1/2))",
214 #"(-1)^(1/6)",
215 "1/2*(i+3^(1/2))",
216
217 "simplify((1/2 + (-3)^(1/2)/2)^(1/2))",
218 #"(-1)^(1/6)",
219 "1/2*(i+3^(1/2))",
220
221 # no possible de-nesting, should
222 # leave unchanged.
223 "simplify((2 +2^(1/2))^(1/2))",
224 "(2+2^(1/2))^(1/2)",
225
226 "simplify((1 +3^(1/2)/2)^(1/2) + (1 -3^(1/2)/2)^(1/2))",
227 "3^(1/2)",
228
229 "simplify((1 +3^(1/2)/2)^(1/2))",
230 "1/2*(1+3^(1/2))",
231
232 # not quite perfect as there is a radical at the
233 # denominator, but the de-nesting happens.
234 "simplify(((1 +39^(1/2)/8)/2)^(1/2))",
235 "(3^(1/2)+13^(1/2))/(4*2^(1/2))",
236
237 "simplify((5 +24^(1/2))^(1/2))",
238 "2^(1/2)+3^(1/2)",
239
240 "simplify((3 +4*i)^(1/2))",
241 "2+i",
242
243 "simplify((3 -4*i)^(1/2))",
244 "2-i",
245
246 "simplify((-2 +2*3^(1/2)*i)^(1/2))",
247 #"2*(-1)^(1/3)",
248 "1+i*3^(1/2)",
249
250 "simplify((9 - 4*5^(1/2))^(1/2))",
251 "-2+5^(1/2)",
252
253 "simplify((61 - 24*5^(1/2))^(1/2))",
254 "-4+3*5^(1/2)",
255
256 "simplify((-352+936*(-1)^(1/2))^(1/3))",
257 "2*(4+3*i)",
258
259
260 "simplify((3 - 2*2^(1/2))^(1/2))",
261 "-1+2^(1/2)",
262
263 "simplify((27/2+27/2*(-1)^(1/2)*3^(1/2))^(1/3))",
264 "3*(-1)^(1/9)",
265 # also good: (27/2+27/2*i*3^(1/2))^(1/3)
266
267 # this nested radical is also equal to
268 # (-1)^(1/9)
269 # but there is no "sum of radicals" form
270 # for this.
271 "simplify((1/2+1/2*(-1)^(1/2)*3^(1/2))^(1/3))",
272 "(-1)^(1/9)",
273 # also good: (1/2+1/2*i*3^(1/2))^(1/3)
274
275 "simplify((2 + 5^(1/2))^(1/3))",
276 "1/2*(1+5^(1/2))",
277
278 "simplify((-3 + 10*3^(1/2)*i/9)^(1/3))",
279 "1+2/3*i*3^(1/2)",
280
281 "simplify((1-3*x^2+3*x^4-x^6)^(1/2))",
282 "(-x^6+3*x^4-3*x^2+1)^(1/2)",
283
284 "simplify(subst((-1)^(1/2),i,(-3 + 10*3^(1/2)*i/9)^(1/3)))",
285 "1+2/3*i*3^(1/2)",
286
287 "simplify(rationalize(-3 + 10*3^(1/2)*i/9)^(1/3))",
288 "1+2/3*i*3^(1/2)",
289
290 # note that sympy doesn't give a straight symbolic answer to
291 # this one, the result to this is numeric instead, and with
292 # a near-zero imaginary part.
293 # In Sympy one can get to the answer obliquely with minpoly instead,
294 # as minpoly((-1)^(1/6) - (-1)^(5/6)) -> x^2−3
295 "simplify((-1)^(1/6) - (-1)^(5/6))",
296 "3^(1/2)",
297
298 "simplify((7208+2736*5^(1/2))^(1/3))",
299 "17+3*5^(1/2)",
300
301 "simplify((901+342*5^(1/2))^(1/3))",
302 "1/2*(17+3*5^(1/2))",
303
304 "-i*(-2*(-1)^(1/6)/(3^(1/2))+2*(-1)^(5/6)/(3^(1/2)))^(1/4)*(2*(-1)^(1/6)/(3^(1/2))-2*(-1)^(5/6)/(3^(1/2)))^(1/4)/(2^(1/2))",
305 "1/2^(1/2)-i/(2^(1/2))",
306
307 "simplify(-i*(-2*(-1)^(1/6)/(3^(1/2))+2*(-1)^(5/6)/(3^(1/2)))^(1/4)*(2*(-1)^(1/6)/(3^(1/2))-2*(-1)^(5/6)/(3^(1/2)))^(1/4)/(2^(1/2)))",
308 # this one simplifies to any of these two, these are all the same:
309 "(1-i)/(2^(1/2))",
310 # -(-1)^(3/4)
311 #"-(-1)^(3/4)",
312
313 "(-1)^(-5/a)",
314 #"(-1)^(-5/a)",
315 "1/(-1)^(5/a)",
316
317
318 # -----------------------
319 "simplify((-1)^(-5))",
320 "-1",
321
322 "simplify((-1)^(5))",
323 "-1",
324
325 "simplify((1)^(-5))",
326 "1",
327
328 "simplify((1)^(5))",
329 "1",
330
331 # seems here that the simplification
332 # has more nodes than the result but
333 # it's not the case: the 1/... inversion
334 # is just done at the print level for
335 # legibility
336 "simplify((-1)^(-5/a))",
337 #"(-1)^(-5/a)",
338 "1/(-1)^(5/a)",
339
340 "simplify((-1)^(5/a))",
341 "(-1)^(5/a)",
342
343 "simplify((1)^(-5/a))",
344 "1",
345
346 "simplify((1)^(5/a))",
347 "1",
348
349 # -----------------------
350 "simplify((-1)^(-6))",
351 "1",
352
353 "simplify((-1)^(6))",
354 "1",
355
356 "simplify((1)^(-6))",
357 "1",
358
359 "simplify((1)^(6))",
360 "1",
361
362 # clockform can be much more compact than the
363 # rectangular format so we return that one,
364 # the user can always do a rect or a circexp on
365 # the result if she desires other forms
366 "simplify(i*2^(1/4)*sin(1/8*pi)+2^(1/4)*cos(1/8*pi))",
367 "(-1)^(1/8)*2^(1/4)",
368 # the circexp of the above is
369 # 2^(1/4) exp(1/8 i pi), which is less compact
370
371
372 # seems here that the simplification
373 # has more nodes than the result but
374 # it's not the case: the 1/... inversion
375 # is just done at the print level for
376 "simplify((-1)^(-6/a))",
377 #"(-1)^(-6/a)",
378 "1/(-1)^(6/a)",
379
380 "simplify((-1)^(6/a))",
381 "(-1)^(6/a)",
382
383 "simplify((1)^(-6/a))",
384 "1",
385
386 "simplify((1)^(6/a))",
387 "1",
388
389 "simplify(transpose(A)*transpose(x))",
390 "transpose(A*x)",
391
392 "simplify(inner(transpose(A),transpose(x)))",
393 "transpose(inner(x,A))",
394
395 # ---------------------------------------------
396 # checking that simplify doesn't make incorrect
397 # simplifications
398
399 "simplify(sqrt(-1/2 -1/2 * x))",
400 "(-1/2*x-1/2)^(1/2)",
401
402 "simplify(sqrt(x*y))",
403 "(x*y)^(1/2)",
404
405 "simplify(sqrt(1/x))",
406 "(1/x)^(1/2)",
407
408 "simplify(sqrt(x^y))",
409 "(x^y)^(1/2)",
410
411 "simplify(sqrt(x)^2)",
412 "x",
413
414 "simplify(sqrt(x^2))",
415 "abs(x)",
416
417
418 ]