-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
executable file
·4745 lines (4616 loc) · 443 KB
/
test.py
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# python 3.6+
from functools import lru_cache
import unittest
import sympy as sp
from sast import AST
import spatch
import sym
import sparser as _sparser
import test_sym as _test_sym
SympifyError = sp.SympifyError
parser = _sparser.Parser ()
_USER_FUNCS = {'N', 'O', 'S', 'beta', 'Lambda', 'gamma', 'Gamma', 'zeta'}
_sparser.set_sp_user_funcs (_USER_FUNCS)
sym.set_sym_user_funcs (_USER_FUNCS)
sym.set_pyS (False)
sym.set_simplify (False)
sym.set_doit (False)
sym.set_strict (True)
@lru_cache (maxsize = None)
def sparser (text): return parser.parse (text) [0]
@lru_cache (maxsize = None)
def ast2tex (ast): return sym.ast2tex (ast)
@lru_cache (maxsize = None)
def ast2nat (ast): return sym.ast2nat (ast)
@lru_cache (maxsize = None)
def ast2py (ast): return sym.ast2py (ast)
# @lru_cache (maxsize = None)
# def ast2spt (ast): return sym.ast2spt (ast)
ast2spt = sym.ast2spt
spt2ast = sym.spt2ast
def ast2tex2ast (ast):
return sparser (ast2tex (ast))
def ast2nat2ast (ast):
return sparser (ast2nat (ast))
def ast2py2ast (ast):
return sparser (ast2py (ast))
def ast2spt2ast (ast):
return spt2ast (ast2spt (ast))
p = sparser
class Test (unittest.TestCase):
def test_sym (self):
self.assertEqual (_test_sym.test (['-c']), True)
#...............................................................................................
# BEGIN UPDATE BLOCK
def test_sparser (self):
self.assertEqual (p ('1'), ('#', '1'))
self.assertEqual (p ('1.'), ('#', '1.'))
self.assertEqual (p ('.1'), ('#', '0.1'))
self.assertEqual (p ('1e20'), ('#', '1e+20'))
self.assertEqual (p ('1E-20'), ('#', '1e-20'))
self.assertEqual (p ('1.e+20'), ('#', '1.e+20'))
self.assertEqual (p ('.1e-20'), ('#', '0.1e-20'))
self.assertEqual (p ('sin (-1.23456789012345678901234567890123456789012345678901234567890123456789012345678901)'), ('-func', 'sin', (('#', '-1.23456789012345678901234567890123456789012345678901234567890123456789012345678901'),)))
self.assertEqual (p ('x'), ('@', 'x'))
self.assertEqual (p ('xy'), ('@', 'xy'))
self.assertEqual (p ('dx'), ('@', 'dx'))
self.assertEqual (p ('partialx'), ('@', 'partialx'))
self.assertEqual (p ('\\partial x'), ('@', 'partialx'))
self.assertEqual (p ('x d y'), ('*', (('@', 'x'), ('@', 'd'), ('@', 'y'))))
self.assertEqual (p ('x partial y'), ('*', (('@', 'x'), ('@', 'partial'), ('@', 'y'))))
self.assertEqual (p ('x \\partial y'), ('*', (('@', 'x'), ('@', 'partial'), ('@', 'y'))))
self.assertEqual (p ('x dx dy y'), ('*', (('@', 'x'), ('@', 'dx'), ('@', 'dy'), ('@', 'y'))))
self.assertEqual (p ('x partialx partialy y'), ('*', (('@', 'x'), ('@', 'partialx'), ('@', 'partialy'), ('@', 'y'))))
self.assertEqual (p ('-1'), ('#', '-1'))
self.assertEqual (p ('-x'), ('-', ('@', 'x')))
self.assertEqual (p ('{x}'), ('@', 'x'))
self.assertEqual (p ('()'), ('(', (',', ())))
self.assertEqual (p ('(x)'), ('(', ('@', 'x')))
self.assertEqual (p ('(x,)'), ('(', (',', (('@', 'x'),))))
self.assertEqual (p ('(x,y)'), ('(', (',', (('@', 'x'), ('@', 'y')))))
self.assertEqual (p ('(x,y,)'), ('(', (',', (('@', 'x'), ('@', 'y')))))
self.assertEqual (p ('[]'), ('[', ()))
self.assertEqual (p ('[x]'), ('[', (('@', 'x'),)))
self.assertEqual (p ('[x,]'), ('[', (('@', 'x'),)))
self.assertEqual (p ('[x,y]'), ('[', (('@', 'x'), ('@', 'y'))))
self.assertEqual (p ('[x,y,]'), ('[', (('@', 'x'), ('@', 'y'))))
self.assertEqual (p ('"x\\x20\\n"'), ('"', 'x \n'))
self.assertEqual (p ("'x\\x20\\n'"), ('"', 'x \n'))
self.assertEqual (p ('|x|'), ('|', ('@', 'x')))
self.assertEqual (p ('x!'), ('!', ('@', 'x')))
self.assertEqual (p ('x+y'), ('+', (('@', 'x'), ('@', 'y'))))
self.assertEqual (p ('x-y'), ('+', (('@', 'x'), ('-', ('@', 'y')))))
self.assertEqual (p ('x*y'), ('*', (('@', 'x'), ('@', 'y')), {1}))
self.assertEqual (p ('x y'), ('*', (('@', 'x'), ('@', 'y'))))
self.assertEqual (p ('x(y)'), ('-ufunc', 'x', (('@', 'y'),)))
self.assertEqual (p ('x*(y)'), ('*', (('@', 'x'), ('(', ('@', 'y'))), {1}))
self.assertEqual (p ('x/y'), ('/', ('@', 'x'), ('@', 'y')))
self.assertEqual (p ('x^y'), ('^', ('@', 'x'), ('@', 'y')))
self.assertEqual (p ('log x'), ('-log', ('@', 'x')))
self.assertEqual (p ('log {x}'), ('-log', ('@', 'x')))
self.assertEqual (p ('log (x)'), ('-log', ('@', 'x')))
self.assertEqual (p ('\\log_2 x'), ('-log', ('@', 'x'), ('#', '2')))
self.assertEqual (p ('\\log_2 {x}'), ('-log', ('@', 'x'), ('#', '2')))
self.assertEqual (p ('\\log_2 (x)'), ('-log', ('@', 'x'), ('#', '2')))
self.assertEqual (p ('sqrt x'), ('-sqrt', ('@', 'x')))
self.assertEqual (p ('sqrt {x}'), ('-sqrt', ('@', 'x')))
self.assertEqual (p ('sqrt (x)'), ('-sqrt', ('@', 'x')))
self.assertEqual (p ('sqrt {(x)}'), ('-sqrt', ('@', 'x')))
self.assertEqual (p ('sqrt[3] x'), ('-sqrt', ('@', 'x'), ('#', '3')))
self.assertEqual (p ('sqrt[3] {x}'), ('-sqrt', ('@', 'x'), ('#', '3')))
self.assertEqual (p ('sqrt[3] {(x)}'), ('-sqrt', ('@', 'x'), ('#', '3')))
self.assertEqual (p ('sqrt[3] (x)'), ('-sqrt', ('@', 'x'), ('#', '3')))
self.assertEqual (p ('sin x'), ('-func', 'sin', (('@', 'x'),)))
self.assertEqual (p ('sin^2 x'), ('^', ('-func', 'sin', (('@', 'x'),)), ('#', '2')))
self.assertEqual (p ('sin (x)'), ('-func', 'sin', (('@', 'x'),)))
self.assertEqual (p ('sin (x)^2'), ('^', ('-func', 'sin', (('@', 'x'),)), ('#', '2')))
self.assertEqual (p ('sin {x}'), ('-func', 'sin', (('@', 'x'),)))
self.assertEqual (p ('sin {(x)}'), ('-func', 'sin', (('@', 'x'),)))
self.assertEqual (p ('{sin x}^2'), ('^', ('-func', 'sin', (('@', 'x'),)), ('#', '2')))
self.assertEqual (p ('sin**2 x'), ('^', ('-func', 'sin', (('@', 'x'),)), ('#', '2')))
self.assertEqual (p ('sin**-1 x'), ('-func', 'asin', (('@', 'x'),)))
self.assertEqual (p ('sin(x)**-1'), ('^', ('-func', 'sin', (('@', 'x'),)), ('#', '-1')))
self.assertEqual (p ('acos (x)'), ('-func', 'acos', (('@', 'x'),)))
self.assertEqual (p ('\\arccos (x)'), ('-func', 'acos', (('@', 'x'),)))
self.assertEqual (p ('sin(x**2)'), ('-func', 'sin', (('^', ('@', 'x'), ('#', '2')),)))
self.assertEqual (p ('sin(x**2)**2'), ('^', ('-func', 'sin', (('^', ('@', 'x'), ('#', '2')),)), ('#', '2')))
self.assertEqual (p ('(sin(x**2)**2)'), ('(', ('^', ('-func', 'sin', (('^', ('@', 'x'), ('#', '2')),)), ('#', '2'))))
self.assertEqual (p ('ln(x**2)'), ('-log', ('^', ('@', 'x'), ('#', '2'))))
self.assertEqual (p ('ln(x**2)**2'), ('^', ('-log', ('^', ('@', 'x'), ('#', '2'))), ('#', '2')))
self.assertEqual (p ('(ln(x**2)**2)'), ('(', ('^', ('-log', ('^', ('@', 'x'), ('#', '2'))), ('#', '2'))))
self.assertEqual (p ('gamma(x**2)'), ('-func', 'gamma', (('^', ('@', 'x'), ('#', '2')),)))
self.assertEqual (p ('gamma(x**2)**2'), ('^', ('-func', 'gamma', (('^', ('@', 'x'), ('#', '2')),)), ('#', '2')))
self.assertEqual (p ('(gamma(x**2)**2)'), ('(', ('^', ('-func', 'gamma', (('^', ('@', 'x'), ('#', '2')),)), ('#', '2'))))
self.assertEqual (p ('{gamma}[2]'), ('-idx', ('@', 'gamma'), (('#', '2'),)))
self.assertEqual (p ('{Gamma}[2]'), ('-idx', ('@', 'Gamma'), (('#', '2'),)))
self.assertEqual (p ('f{(x)}'), ('*', (('@', 'f'), ('(', ('@', 'x'), True))))
self.assertEqual (p ("f{(x)}'(0)"), ('*', (('@', 'f'), ('-diffp', ('(', ('@', 'x'), True), 1), ('(', ('#', '0')))))
self.assertEqual (p ("f{(x)}'{(0)}"), ('*', (('@', 'f'), ('-diffp', ('(', ('@', 'x'), True), 1), ('(', ('#', '0'), True))))
self.assertEqual (p ('\\operatorname{x_{1}}{\\left(x \\right)}'), ('-ufunc', 'x1', (('@', 'x'),)))
self.assertEqual (p ('\\lim_{x\\to0} 1/x'), ('-lim', ('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0')))
self.assertEqual (p ('\\lim_{x\\to0^+} 1/x'), ('-lim', ('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0'), '+'))
self.assertEqual (p ('\\lim_{x\\to0**-} 1/x'), ('-lim', ('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0'), '-'))
self.assertEqual (p ('Limit (1/x, x, 0)'), ('-lim', ('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0'), '+'))
self.assertEqual (p ('Limit (1/x, x, 0, "-")'), ('-lim', ('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0'), '-'))
self.assertEqual (p ('Limit (1/x, x, 0, dir="+-")'), ('-lim', ('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0')))
self.assertEqual (p ('limit (1/x, x, 0)'), ('-func', 'limit', (('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0'))))
self.assertEqual (p ('limit (1/x, x, 0, "-")'), ('-func', 'limit', (('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0'), ('"', '-'))))
self.assertEqual (p ('limit (1/x, x, 0, dir="+-")'), ('-func', 'limit', (('/', ('#', '1'), ('@', 'x')), ('@', 'x'), ('#', '0'), ('=', ('@', 'dir'), ('"', '+-')))))
self.assertEqual (p ('\\sum_{n=0}^\\infty x^n/n!'), ('-sum', ('/', ('^', ('@', 'x'), ('@', 'n')), ('!', ('@', 'n'))), ('@', 'n'), ('#', '0'), ('@', 'oo')))
self.assertEqual (p ('Sum (x^n/n!, (n, 0, oo))'), ('-sum', ('/', ('^', ('@', 'x'), ('@', 'n')), ('!', ('@', 'n'))), ('@', 'n'), ('#', '0'), ('@', 'oo')))
self.assertEqual (p ('summation (x^n/n!, (n, 0, oo))'), ('-func', 'summation', (('/', ('^', ('@', 'x'), ('@', 'n')), ('!', ('@', 'n'))), ('(', (',', (('@', 'n'), ('#', '0'), ('@', 'oo')))))))
self.assertEqual (p ('d/dx x**2y**2z'), ('-diff', ('*', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('@', 'z'))), 'd', (('x', 1),)))
self.assertEqual (p ('d^2/dx^2 x^2y**2z'), ('-diff', ('*', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('@', 'z'))), 'd', (('x', 2),)))
self.assertEqual (p ('d^3/dx^2dy x^2y**2z'), ('-diff', ('*', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('@', 'z'))), 'd', (('x', 2), ('y', 1))))
self.assertEqual (p ('\\partial^4 / \\partial x^2\\partial y\\partial z x^2 y**2 z'), ('-diff', ('*', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('@', 'z'))), 'partial', (('x', 2), ('y', 1), ('z', 1))))
self.assertEqual (p ('d**1.5 / dx dy x**2y**2'), ('/', ('^', ('@', 'd'), ('#', '1.5')), ('*', (('@', 'dx'), ('@', 'dy'), ('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2'))))))
self.assertEqual (p ('d**-2 / dx dy x**2y**2'), ('/', ('^', ('@', 'd'), ('#', '-2')), ('*', (('@', 'dx'), ('@', 'dy'), ('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2'))))))
self.assertEqual (p ('d**2 / dx**1.5 x**2y**2'), ('/', ('^', ('@', 'd'), ('#', '2')), ('*', (('^', ('@', 'dx'), ('#', '1.5')), ('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2'))))))
self.assertEqual (p ('Derivative (x^2y**2z, x, 2, y, z)'), ('-diff', ('*', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('@', 'z'))), 'd', (('x', 2), ('y', 1), ('z', 1))))
self.assertEqual (p ('diff (x^2y**2z, x, 2, y, z)'), ('-func', 'diff', (('*', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('@', 'z'))), ('@', 'x'), ('#', '2'), ('@', 'y'), ('@', 'z'))))
self.assertEqual (p ('\\int dx'), ('-intg', None, ('@', 'dx')))
self.assertEqual (p ('\\int x dx'), ('-intg', ('@', 'x'), ('@', 'dx')))
self.assertEqual (p ('\\int_0^1 x dx'), ('-intg', ('@', 'x'), ('@', 'dx'), ('#', '0'), ('#', '1')))
self.assertEqual (p ('\\int_0^1 \\int y dy dx'), ('-intg', ('-intg', ('@', 'y'), ('@', 'dy')), ('@', 'dx'), ('#', '0'), ('#', '1')))
self.assertEqual (p ('Integral (\\int y dy, (x, 0, 1))'), ('-intg', ('-intg', ('@', 'y'), ('@', 'dy')), ('@', 'dx'), ('#', '0'), ('#', '1')))
self.assertEqual (p ('integrate (\\int y dy, (x, 0, 1))'), ('-func', 'integrate', (('-intg', ('@', 'y'), ('@', 'dy')), ('(', (',', (('@', 'x'), ('#', '0'), ('#', '1')))))))
self.assertEqual (p ('\\[1,]'), ('-mat', ((('#', '1'),),)))
self.assertEqual (p ('\\[1,2]'), ('-mat', ((('#', '1'),), (('#', '2'),))))
self.assertEqual (p ('\\[1,2,]'), ('-mat', ((('#', '1'),), (('#', '2'),))))
self.assertEqual (p ('\\[[1,],]'), ('-mat', ((('#', '1'),),)))
self.assertEqual (p ('\\[[1,],[2,]]'), ('-mat', ((('#', '1'),), (('#', '2'),))))
self.assertEqual (p ('\\[[1,],[2,],]'), ('-mat', ((('#', '1'),), (('#', '2'),))))
self.assertEqual (p ('\\left[\\begin{matrix} 1 \\end{matrix}\\right]'), ('-mat', ((('#', '1'),),)))
self.assertEqual (p ('\\begin{bmatrix} 1 \\\\ \\end{bmatrix}'), ('-mat', ((('#', '1'),),)))
self.assertEqual (p ('\\begin{vmatrix} 1 & 2 \\\\ \\end{vmatrix}'), ('-mat', ((('#', '1'), ('#', '2')),)))
self.assertEqual (p ('\\begin{pmatrix} 1 & 2 \\\\ 3 & 4 \\end{pmatrix}'), ('-mat', ((('#', '1'), ('#', '2')), (('#', '3'), ('#', '4')))))
self.assertEqual (p ('\\begin{matrix} 1 & 2 \\\\ 3 & 4 \\\\ \\end{matrix}'), ('-mat', ((('#', '1'), ('#', '2')), (('#', '3'), ('#', '4')))))
self.assertEqual (p ('\\[1,2]!'), ('!', ('-mat', ((('#', '1'),), (('#', '2'),)))))
self.assertEqual (p ('\\[[0,1],[1,0]]**x'), ('^', ('-mat', ((('#', '0'), ('#', '1')), (('#', '1'), ('#', '0')))), ('@', 'x')))
self.assertEqual (p ('\\[[1,2],[3,4]]!'), ('!', ('-mat', ((('#', '1'), ('#', '2')), (('#', '3'), ('#', '4'))))))
self.assertEqual (p ('\\[[1,2,3],[4,5,6]].T'), ('.', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), 'T'))
self.assertEqual (p ('\\[[1,2,3],[4,5,6]].T.T'), ('.', ('.', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), 'T'), 'T'))
self.assertEqual (p ('\\[[1,2,3],[4,5,6]].T.T.T'), ('.', ('.', ('.', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), 'T'), 'T'), 'T'))
self.assertEqual (p ('\\[[1,2,3],[4,5,6]].transpose ()'), ('.', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), 'transpose', ()))
self.assertEqual (p ('\\[[1,2,3],[4,5,6]].transpose ().transpose ()'), ('.', ('.', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), 'transpose', ()), 'transpose', ()))
self.assertEqual (p ('\\[[1,2,3],[4,5,6]].transpose ().transpose ().transpose ()'), ('.', ('.', ('.', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), 'transpose', ()), 'transpose', ()), 'transpose', ()))
self.assertEqual (p ('\\[[1,2,3],[4,5,6]].transpose ().transpose ().T.T.transpose ().transpose ()'), ('.', ('.', ('.', ('.', ('.', ('.', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), 'transpose', ()), 'transpose', ()), 'T'), 'T'), 'transpose', ()), 'transpose', ()))
self.assertEqual (p ('\\begin{matrix} A & B \\\\ C & D \\end{matrix} * \\[x, y]'), ('*', (('-mat', ((('@', 'A'), ('@', 'B')), (('@', 'C'), ('@', 'D')))), ('-mat', ((('@', 'x'),), (('@', 'y'),)))), {1}))
self.assertEqual (p ('\\[[1, 2], [3'), ('-mat', ((('#', '1'), ('#', '2')), (('#', '3'), ('@', '')))))
self.assertEqual (p ('\\[[1, 2], [3]]'), ('-mat', ((('#', '1'), ('#', '2')), (('#', '3'), ('@', '')))))
self.assertEqual (p ('\\[[1], [2, 3]]'), ('-mat', ((('#', '1'), ('@', '')), (('#', '2'), ('#', '3')))))
self.assertEqual (p ('-1**x'), ('-', ('^', ('#', '1'), ('@', 'x'))))
self.assertEqual (p ('{-1}**x'), ('^', ('#', '-1'), ('@', 'x')))
self.assertEqual (p ('-{-1}**x'), ('-', ('^', ('#', '-1'), ('@', 'x'))))
self.assertEqual (p ('(-1)**x'), ('^', ('(', ('#', '-1')), ('@', 'x')))
self.assertEqual (p ('-(-1)**x'), ('-', ('^', ('(', ('#', '-1')), ('@', 'x'))))
self.assertEqual (p ('alpha, beta, gamma, delta, epsilon, zeta, eta, theta, iota, kappa, lambda, mu, nu, xi, pi, rho, sigma, tau, upsilon, phi, chi, psi, omega, Gamma, Delta, Theta, Lambda, Xi, Pi, Sigma, Upsilon, Phi, Psi, Omega'), (',', (('@', 'alpha'), ('@', 'beta'), ('@', 'gamma'), ('@', 'delta'), ('@', 'epsilon'), ('@', 'zeta'), ('@', 'eta'), ('@', 'theta'), ('@', 'iota'), ('@', 'kappa'), ('@', 'lambda'), ('@', 'mu'), ('@', 'nu'), ('@', 'xi'), ('@', 'pi'), ('@', 'rho'), ('@', 'sigma'), ('@', 'tau'), ('@', 'upsilon'), ('@', 'phi'), ('@', 'chi'), ('@', 'psi'), ('@', 'omega'), ('@', 'Gamma'), ('@', 'Delta'), ('@', 'Theta'), ('@', 'Lambda'), ('@', 'Xi'), ('@', 'Pi'), ('@', 'Sigma'), ('@', 'Upsilon'), ('@', 'Phi'), ('@', 'Psi'), ('@', 'Omega'))))
self.assertEqual (p ('\\alpha, \\beta, \\gamma, \\delta, \\epsilon, \\zeta, \\eta, \\theta, \\iota, \\kappa, \\lambda, \\mu, \\nu, \\xi, \\pi, \\rho, \\sigma, \\tau, \\upsilon, \\phi, \\chi, \\psi, \\omega, \\Gamma, \\Delta, \\Theta, \\Lambda, \\Xi, \\Pi, \\Sigma, \\Upsilon, \\Phi, \\Psi, \\Omega'), (',', (('@', 'alpha'), ('@', 'beta'), ('@', 'gamma'), ('@', 'delta'), ('@', 'epsilon'), ('@', 'zeta'), ('@', 'eta'), ('@', 'theta'), ('@', 'iota'), ('@', 'kappa'), ('@', 'lambda'), ('@', 'mu'), ('@', 'nu'), ('@', 'xi'), ('@', 'pi'), ('@', 'rho'), ('@', 'sigma'), ('@', 'tau'), ('@', 'upsilon'), ('@', 'phi'), ('@', 'chi'), ('@', 'psi'), ('@', 'omega'), ('@', 'Gamma'), ('@', 'Delta'), ('@', 'Theta'), ('@', 'Lambda'), ('@', 'Xi'), ('@', 'Pi'), ('@', 'Sigma'), ('@', 'Upsilon'), ('@', 'Phi'), ('@', 'Psi'), ('@', 'Omega'))))
self.assertEqual (p ('1 if x < y'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))),)))
self.assertEqual (p ('1 if x < y else 3'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))), (('#', '3'), True))))
self.assertEqual (p ('1 if x < y else 3 if x < z'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))), (('#', '3'), ('<>', ('@', 'x'), (('<', ('@', 'z')),))))))
self.assertEqual (p ('1 if x < y else 3 if x < z else 5'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))), (('#', '3'), ('<>', ('@', 'x'), (('<', ('@', 'z')),))), (('#', '5'), True))))
self.assertEqual (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & \\end{cases}'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))), (('#', '3'), ('<>', ('@', 'x'), (('<', ('@', 'z')),))), (('#', '5'), True))))
self.assertEqual (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & \\\\ \\end{cases}'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))), (('#', '3'), ('<>', ('@', 'x'), (('<', ('@', 'z')),))), (('#', '5'), True))))
self.assertEqual (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & x < w \\end{cases}'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))), (('#', '3'), ('<>', ('@', 'x'), (('<', ('@', 'z')),))), (('#', '5'), ('<>', ('@', 'x'), (('<', ('@', 'w')),))))))
self.assertEqual (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & x < w \\\\ \\end{cases}'), ('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('@', 'y')),))), (('#', '3'), ('<>', ('@', 'x'), (('<', ('@', 'z')),))), (('#', '5'), ('<>', ('@', 'x'), (('<', ('@', 'w')),))))))
self.assertEqual (p ('x**y.a'), ('^', ('@', 'x'), ('.', ('@', 'y'), 'a')))
self.assertEqual (p ('x**y.a ()'), ('^', ('@', 'x'), ('.', ('@', 'y'), 'a', ())))
self.assertEqual (p ('x**y.a.b'), ('^', ('@', 'x'), ('.', ('.', ('@', 'y'), 'a'), 'b')))
self.assertEqual (p ('x**y.a.b ()'), ('^', ('@', 'x'), ('.', ('.', ('@', 'y'), 'a'), 'b', ())))
self.assertEqual (p ('x**y.a ().b'), ('^', ('@', 'x'), ('.', ('.', ('@', 'y'), 'a', ()), 'b')))
self.assertEqual (p ('x**y.a ().b ()'), ('^', ('@', 'x'), ('.', ('.', ('@', 'y'), 'a', ()), 'b', ())))
self.assertEqual (p ('{1 if x < 0 else 3} if x < 1 else 5'), ('-piece', ((('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('#', '0')),))), (('#', '3'), True))), ('<>', ('@', 'x'), (('<', ('#', '1')),))), (('#', '5'), True))))
self.assertEqual (p ('1 if {True if x < 0 else False} else 5'), ('-piece', ((('#', '1'), ('-piece', ((('@', 'True'), ('<>', ('@', 'x'), (('<', ('#', '0')),))), (('@', 'False'), True)))), (('#', '5'), True))))
self.assertEqual (p ('1 if {True if x < 0 else False} else {7 if x < 1 else 5}'), ('-piece', ((('#', '1'), ('-piece', ((('@', 'True'), ('<>', ('@', 'x'), (('<', ('#', '0')),))), (('@', 'False'), True)))), (('-piece', ((('#', '7'), ('<>', ('@', 'x'), (('<', ('#', '1')),))), (('#', '5'), True))), True))))
self.assertEqual (p ('{1 if x < 0 else 9} if {True if x < 1 else False} else {7 if x < 2 else 5}'), ('-piece', ((('-piece', ((('#', '1'), ('<>', ('@', 'x'), (('<', ('#', '0')),))), (('#', '9'), True))), ('-piece', ((('@', 'True'), ('<>', ('@', 'x'), (('<', ('#', '1')),))), (('@', 'False'), True)))), (('-piece', ((('#', '7'), ('<>', ('@', 'x'), (('<', ('#', '2')),))), (('#', '5'), True))), True))))
self.assertEqual (p ('x.y!'), ('!', ('.', ('@', 'x'), 'y')))
self.assertEqual (p ('x.y**2'), ('^', ('.', ('@', 'x'), 'y'), ('#', '2')))
self.assertEqual (p ('x.y ()!'), ('!', ('.', ('@', 'x'), 'y', ())))
self.assertEqual (p ('x.y ()**2'), ('^', ('.', ('@', 'x'), 'y', ()), ('#', '2')))
self.assertEqual (p ('x**y.a!'), ('^', ('@', 'x'), ('!', ('.', ('@', 'y'), 'a'))))
self.assertEqual (p ('x**y.a**2'), ('^', ('@', 'x'), ('^', ('.', ('@', 'y'), 'a'), ('#', '2'))))
self.assertEqual (p ('x**y.a ()!'), ('^', ('@', 'x'), ('!', ('.', ('@', 'y'), 'a', ()))))
self.assertEqual (p ('x**y.a ()**2'), ('^', ('@', 'x'), ('^', ('.', ('@', 'y'), 'a', ()), ('#', '2'))))
self.assertEqual (p ('lambda: x'), ('-lamb', ('@', 'x'), ()))
self.assertEqual (p ('lambda x: x**2'), ('-lamb', ('^', ('@', 'x'), ('#', '2')), ('x',)))
self.assertEqual (p ('lambda x, y: x + y'), ('-lamb', ('+', (('@', 'x'), ('@', 'y'))), ('x', 'y')))
self.assertEqual (p ('lambda x, y, z: x + y + z'), ('-lamb', ('+', (('@', 'x'), ('@', 'y'), ('@', 'z'))), ('x', 'y', 'z')))
self.assertEqual (p ('1, lambda: x'), (',', (('#', '1'), ('-lamb', ('@', 'x'), ()))))
self.assertEqual (p ('1, lambda x: x**2'), (',', (('#', '1'), ('-lamb', ('^', ('@', 'x'), ('#', '2')), ('x',)))))
self.assertEqual (p ('1, lambda x, y: x + y'), (',', (('#', '1'), ('-lamb', ('+', (('@', 'x'), ('@', 'y'))), ('x', 'y')))))
self.assertEqual (p ('1, lambda x, y, z: x + y + z'), (',', (('#', '1'), ('-lamb', ('+', (('@', 'x'), ('@', 'y'), ('@', 'z'))), ('x', 'y', 'z')))))
self.assertEqual (p ('f = lambda: 0'), ('=', ('@', 'f'), ('-lamb', ('#', '0'), ())))
self.assertEqual (p ('f = lambda x: 0'), ('=', ('@', 'f'), ('-lamb', ('#', '0'), ('x',))))
self.assertEqual (p ('f = lambda x, y: 0'), ('=', ('@', 'f'), ('-lamb', ('#', '0'), ('x', 'y'))))
self.assertEqual (p ('f = lambda x, y, z: 0'), ('=', ('@', 'f'), ('-lamb', ('#', '0'), ('x', 'y', 'z'))))
self.assertEqual (p ('\\left(\\left(\\right) \\mapsto x \\right)'), ('-lamb', ('@', 'x'), ()))
self.assertEqual (p ('\\left(\\left(x \\right) \\mapsto x^2 \\right)'), ('-lamb', ('^', ('@', 'x'), ('#', '2')), ('x',)))
self.assertEqual (p ('\\left(\\left(x, y \\right) \\mapsto x + y \\right)'), ('-lamb', ('+', (('@', 'x'), ('@', 'y'))), ('x', 'y')))
self.assertEqual (p ('\\lambda: x'), ('-slice', ('@', 'lambda'), ('@', 'x'), None))
self.assertEqual (p ('\\lambda x: x'), ('-slice', ('*', (('@', 'lambda'), ('@', 'x'))), ('@', 'x'), None))
self.assertEqual (p ('\\lambda x, y: x'), (',', (('*', (('@', 'lambda'), ('@', 'x'))), ('-slice', ('@', 'y'), ('@', 'x'), None))))
self.assertEqual (p ('{lambda}: x'), ('-slice', ('@', 'lambda'), ('@', 'x'), None))
self.assertEqual (p ('{lambda} x: x'), ('-slice', ('*', (('@', 'lambda'), ('@', 'x'))), ('@', 'x'), None))
self.assertEqual (p ('{lambda} x, y: x'), (',', (('*', (('@', 'lambda'), ('@', 'x'))), ('-slice', ('@', 'y'), ('@', 'x'), None))))
self.assertEqual (p ('$'), ('-sym', ''))
self.assertEqual (p ('$s'), ('-sym', 's'))
self.assertEqual (p ('$ (real = True)'), ('-sym', '', (('real', ('@', 'True')),)))
self.assertEqual (p ('$s (real = True)'), ('-sym', 's', (('real', ('@', 'True')),)))
self.assertEqual (p ('eye (2).is_diagonal ()'), ('.', ('-func', 'eye', (('#', '2'),)), 'is_diagonal', ()))
self.assertEqual (p ('a [2]'), ('-idx', ('@', 'a'), (('#', '2'),)))
self.assertEqual (p ('a [2,3]'), ('-idx', ('@', 'a'), (('#', '2'), ('#', '3'))))
self.assertEqual (p ('a * [2]'), ('*', (('@', 'a'), ('[', (('#', '2'),))), {1}))
self.assertEqual (p ('a * {-1}[x]'), ('*', (('@', 'a'), ('-idx', ('#', '-1'), (('@', 'x'),))), {1}))
self.assertEqual (p ('a * [x][y][z]'), ('*', (('@', 'a'), ('-idx', ('-idx', ('[', (('@', 'x'),)), (('@', 'y'),)), (('@', 'z'),))), {1}))
self.assertEqual (p ('N (1/2)'), ('-func', 'N', (('/', ('#', '1'), ('#', '2')),)))
self.assertEqual (p ("S ('1/2')"), ('-func', 'S', (('"', '1/2'),)))
self.assertEqual (p ("N (S ('1/2'))"), ('-func', 'N', (('-func', 'S', (('"', '1/2'),)),)))
self.assertEqual (p ('S.Half'), ('.', ('@', 'S'), 'Half'))
self.assertEqual (p ('N S.Half'), ('-func', 'N', (('.', ('@', 'S'), 'Half'),)))
self.assertEqual (p ('o [i].t'), ('.', ('-idx', ('@', 'o'), (('@', 'i'),)), 't'))
self.assertEqual (p ('o [i]**2'), ('^', ('-idx', ('@', 'o'), (('@', 'i'),)), ('#', '2')))
self.assertEqual (p ('o [i]!'), ('!', ('-idx', ('@', 'o'), (('@', 'i'),))))
self.assertEqual (p ("'Hello' [::-1]"), ('-idx', ('"', 'Hello'), (('-slice', False, False, ('#', '-1')),)))
self.assertEqual (p ('\\[[1, 2, 3], [4, 5, 6]] [:,1]'), ('-idx', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), (('-slice', False, False, None), ('#', '1'))))
self.assertEqual (p ('\\binom96'), ('-func', 'binomial', (('#', '9'), ('#', '6'))))
self.assertEqual (p ('binomial (x, y)'), ('-func', 'binomial', (('@', 'x'), ('@', 'y'))))
self.assertEqual (p ('y - 1*x'), ('+', (('@', 'y'), ('-', ('*', (('#', '1'), ('@', 'x')), {1})))))
self.assertEqual (p ("Poly(x**2 + 2 x + 1, x, domain = 'ZZ')"), ('-func', 'Poly', (('+', (('^', ('@', 'x'), ('#', '2')), ('*', (('#', '2'), ('@', 'x'))), ('#', '1'))), ('@', 'x'), ('=', ('@', 'domain'), ('"', 'ZZ')))))
self.assertEqual (p ("Poly(x**2 + y**2 + 2 x y, x, y, domain = 'CC')"), ('-func', 'Poly', (('+', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('*', (('#', '2'), ('@', 'x'), ('@', 'y'))))), ('@', 'x'), ('@', 'y'), ('=', ('@', 'domain'), ('"', 'CC')))))
self.assertEqual (p ('oct(10)'), ('-func', 'oct', (('#', '10'),)))
self.assertEqual (p ('(1,) + (2,)'), ('+', (('(', (',', (('#', '1'),))), ('(', (',', (('#', '2'),))))))
self.assertEqual (p ('[1] + [2]'), ('+', (('[', (('#', '1'),)), ('[', (('#', '2'),)))))
self.assertEqual (p ("'a' + 'b'"), ('+', (('"', 'a'), ('"', 'b'))))
self.assertEqual (p ('(1,) * 2'), ('*', (('(', (',', (('#', '1'),))), ('#', '2')), {1}))
self.assertEqual (p ('[1] * 2'), ('*', (('[', (('#', '1'),)), ('#', '2')), {1}))
self.assertEqual (p ("'a' * 2"), ('*', (('"', 'a'), ('#', '2')), {1}))
self.assertEqual (p ('Lambda (x, x**2)'), ('-lamb', ('^', ('@', 'x'), ('#', '2')), ('x',)))
self.assertEqual (p ('beta (2, 3)'), ('-func', 'beta', (('#', '2'), ('#', '3'))))
self.assertEqual (p ('{x d} y'), ('*', (('@', 'x'), ('@', 'd'), ('@', 'y'))))
self.assertEqual (p ('d**2e0/dx**2e0 x**3'), ('/', ('^', ('@', 'd'), ('#', '2e+0')), ('*', (('^', ('@', 'dx'), ('#', '2e+0')), ('^', ('@', 'x'), ('#', '3'))))))
self.assertEqual (p ('ln((a)**b)'), ('-log', ('^', ('(', ('@', 'a')), ('@', 'b'))))
self.assertEqual (p ('a * \\int dx + {\\int dx dx}'), ('+', (('*', (('@', 'a'), ('-intg', None, ('@', 'dx'))), {1}), ('*', (('-intg', None, ('@', 'dx')), ('@', 'dx'))))))
self.assertEqual (p ('1 if {a = x if z} else 0 if y'), ('-piece', ((('#', '1'), ('=', ('@', 'a'), ('-piece', ((('@', 'x'), ('@', 'z')),)))), (('#', '0'), ('@', 'y')))))
self.assertEqual (p ('a, lambda: b = 1'), (',', (('@', 'a'), ('-lamb', ('=', ('@', 'b'), ('#', '1')), ()))))
self.assertEqual (p ('a * [2]'), ('*', (('@', 'a'), ('[', (('#', '2'),))), {1}))
self.assertEqual (p ('sqrt(1, 2)'), ('-sqrt', (',', (('#', '1'), ('#', '2')))))
self.assertEqual (p ('x*[][y]'), ('*', (('@', 'x'), ('-idx', ('[', ()), (('@', 'y'),))), {1}))
self.assertEqual (p ('lambda: x:'), ('-lamb', ('-slice', ('@', 'x'), False, None), ()))
self.assertEqual (p ('a*[x][y][z]'), ('*', (('@', 'a'), ('-idx', ('-idx', ('[', (('@', 'x'),)), (('@', 'y'),)), (('@', 'z'),))), {1}))
self.assertEqual (p ('a*()**2'), ('*', (('@', 'a'), ('^', ('(', (',', ())), ('#', '2'))), {1}))
self.assertEqual (p ('a*().t'), ('*', (('@', 'a'), ('.', ('(', (',', ())), 't')), {1}))
self.assertEqual (p ('a*()[2]'), ('*', (('@', 'a'), ('-idx', ('(', (',', ())), (('#', '2'),))), {1}))
self.assertEqual (p ('o.f*(a)'), ('*', (('.', ('@', 'o'), 'f'), ('(', ('@', 'a'))), {1}))
self.assertEqual (p ('o.f*{1+2}'), ('*', (('.', ('@', 'o'), 'f'), ('+', (('#', '1'), ('#', '2')))), {1}))
self.assertEqual (p ('d**2e0/dx**2e0 x**3'), ('/', ('^', ('@', 'd'), ('#', '2e+0')), ('*', (('^', ('@', 'dx'), ('#', '2e+0')), ('^', ('@', 'x'), ('#', '3'))))))
self.assertEqual (p ('y**z [w]'), ('^', ('@', 'y'), ('-idx', ('@', 'z'), (('@', 'w'),))))
self.assertEqual (p ('{y**z} [w]'), ('-idx', ('^', ('@', 'y'), ('@', 'z')), (('@', 'w'),)))
self.assertEqual (p ('x {y**z} [w]'), ('*', (('@', 'x'), ('-idx', ('^', ('@', 'y'), ('@', 'z')), (('@', 'w'),)))))
self.assertEqual (p ('{x y**z} [w]'), ('-idx', ('*', (('@', 'x'), ('^', ('@', 'y'), ('@', 'z')))), (('@', 'w'),)))
self.assertEqual (p ('Min (x, y, z)'), ('-func', 'Min', (('@', 'x'), ('@', 'y'), ('@', 'z'))))
self.assertEqual (p ('Max (x, y, z)'), ('-func', 'Max', (('@', 'x'), ('@', 'y'), ('@', 'z'))))
self.assertEqual (p ('\\Re (z)'), ('-func', 'Re', (('@', 'z'),)))
self.assertEqual (p ('\\Im (z)'), ('-func', 'Im', (('@', 'z'),)))
self.assertEqual (p ('re (z)'), ('-func', 're', (('@', 'z'),)))
self.assertEqual (p ('im (z)'), ('-func', 'im', (('@', 'z'),)))
self.assertEqual (p ('{}'), ('-dict', ()))
self.assertEqual (p ('{1: 2}'), ('-dict', ((('#', '1'), ('#', '2')),)))
self.assertEqual (p ('{1: 2,}'), ('-dict', ((('#', '1'), ('#', '2')),)))
self.assertEqual (p ('{1: 2, 3: 4}'), ('-dict', ((('#', '1'), ('#', '2')), (('#', '3'), ('#', '4')))))
self.assertEqual (p ('set ()'), ('-func', 'set', ()))
self.assertEqual (p ('\\{}'), ('-set', ()))
self.assertEqual (p ('\\{1}'), ('-set', (('#', '1'),)))
self.assertEqual (p ('\\{1,2}'), ('-set', (('#', '1'), ('#', '2'))))
self.assertEqual (p ('{1,2}'), ('-set', (('#', '1'), ('#', '2'))))
self.assertEqual (p ('1 in {1,2,3}'), ('<>', ('#', '1'), (('in', ('-set', (('#', '1'), ('#', '2'), ('#', '3')))),)))
self.assertEqual (p ('1 \\in {1,2,3}'), ('<>', ('#', '1'), (('in', ('-set', (('#', '1'), ('#', '2'), ('#', '3')))),)))
self.assertEqual (p ('4 in {1,2,3}'), ('<>', ('#', '4'), (('in', ('-set', (('#', '1'), ('#', '2'), ('#', '3')))),)))
self.assertEqual (p ('4 \\in {1,2,3}'), ('<>', ('#', '4'), (('in', ('-set', (('#', '1'), ('#', '2'), ('#', '3')))),)))
self.assertEqual (p ('4 not in {1,2,3}'), ('<>', ('#', '4'), (('notin', ('-set', (('#', '1'), ('#', '2'), ('#', '3')))),)))
self.assertEqual (p ('4 \\notin {1,2,3}'), ('<>', ('#', '4'), (('notin', ('-set', (('#', '1'), ('#', '2'), ('#', '3')))),)))
self.assertEqual (p ('{1,2} - {2,3}'), ('+', (('-set', (('#', '1'), ('#', '2'))), ('-', ('-set', (('#', '2'), ('#', '3')))))))
self.assertEqual (p ('{1,2} || {2,3}'), ('||', (('-set', (('#', '1'), ('#', '2'))), ('-set', (('#', '2'), ('#', '3'))))))
self.assertEqual (p ('{1,2} ^^ {2,3}'), ('^^', (('-set', (('#', '1'), ('#', '2'))), ('-set', (('#', '2'), ('#', '3'))))))
self.assertEqual (p ('{1,2} && {2,3}'), ('&&', (('-set', (('#', '1'), ('#', '2'))), ('-set', (('#', '2'), ('#', '3'))))))
self.assertEqual (p ('{1,2} || {2,3} || {3,4}'), ('||', (('-set', (('#', '1'), ('#', '2'))), ('-set', (('#', '2'), ('#', '3'))), ('-set', (('#', '3'), ('#', '4'))))))
self.assertEqual (p ('{1,2} ^^ {2,3} ^^ {3,4}'), ('^^', (('-set', (('#', '1'), ('#', '2'))), ('-set', (('#', '2'), ('#', '3'))), ('-set', (('#', '3'), ('#', '4'))))))
self.assertEqual (p ('{1,2} && {2,3} && {3,4}'), ('&&', (('-set', (('#', '1'), ('#', '2'))), ('-set', (('#', '2'), ('#', '3'))), ('-set', (('#', '3'), ('#', '4'))))))
self.assertEqual (p ('{1,2} || {2,3} ^^ {3,4} && {4,5}'), ('||', (('-set', (('#', '1'), ('#', '2'))), ('^^', (('-set', (('#', '2'), ('#', '3'))), ('&&', (('-set', (('#', '3'), ('#', '4'))), ('-set', (('#', '4'), ('#', '5'))))))))))
self.assertEqual (p ('solve (x**2 = 4)'), ('-func', 'solve', (('=', ('^', ('@', 'x'), ('#', '2')), ('#', '4')),)))
self.assertEqual (p ('Subs (x y, x, 2)'), ('-subs', ('*', (('@', 'x'), ('@', 'y'))), ((('@', 'x'), ('#', '2')),)))
self.assertEqual (p ('Subs (x y, (x, y), (2, 3))'), ('-subs', ('*', (('@', 'x'), ('@', 'y'))), ((('@', 'x'), ('#', '2')), (('@', 'y'), ('#', '3')))))
self.assertEqual (p ('(x y).subs (x, 2)'), ('.', ('(', ('*', (('@', 'x'), ('@', 'y')))), 'subs', (('@', 'x'), ('#', '2'))))
self.assertEqual (p ('(x y).subs (x, 2).subs (y, 3)'), ('.', ('.', ('(', ('*', (('@', 'x'), ('@', 'y')))), 'subs', (('@', 'x'), ('#', '2'))), 'subs', (('@', 'y'), ('#', '3'))))
self.assertEqual (p ('Subs ((x y z w).subs ({z: 4}), (x, y), (2, 3)).subs ([(w, 5)])'), ('.', ('-subs', ('.', ('(', ('*', (('@', 'x'), ('@', 'y'), ('@', 'z'), ('@', 'w')))), 'subs', (('-dict', ((('@', 'z'), ('#', '4')),)),)), ((('@', 'x'), ('#', '2')), (('@', 'y'), ('#', '3')))), 'subs', (('[', (('(', (',', (('@', 'w'), ('#', '5')))),)),)))
self.assertEqual (p ('x or y'), ('-or', (('@', 'x'), ('@', 'y'))))
self.assertEqual (p ('x or y or z'), ('-or', (('@', 'x'), ('@', 'y'), ('@', 'z'))))
self.assertEqual (p ('x and y'), ('-and', (('@', 'x'), ('@', 'y'))))
self.assertEqual (p ('x and y and z'), ('-and', (('@', 'x'), ('@', 'y'), ('@', 'z'))))
self.assertEqual (p ('x and y or z'), ('-or', (('-and', (('@', 'x'), ('@', 'y'))), ('@', 'z'))))
self.assertEqual (p ('x and {y or z}'), ('-and', (('@', 'x'), ('-or', (('@', 'y'), ('@', 'z'))))))
self.assertEqual (p ('not x or y'), ('-or', (('-not', ('@', 'x')), ('@', 'y'))))
self.assertEqual (p ('not {x or y}'), ('-not', ('-or', (('@', 'x'), ('@', 'y')))))
self.assertEqual (p ('not x and y'), ('-and', (('-not', ('@', 'x')), ('@', 'y'))))
self.assertEqual (p ('not {x and y}'), ('-not', ('-and', (('@', 'x'), ('@', 'y')))))
self.assertEqual (p ('x or not y'), ('-or', (('@', 'x'), ('-not', ('@', 'y')))))
self.assertEqual (p ('x and not y'), ('-and', (('@', 'x'), ('-not', ('@', 'y')))))
self.assertEqual (p ('not x'), ('-not', ('@', 'x')))
self.assertEqual (p ('not not x'), ('-not', ('-not', ('@', 'x'))))
self.assertEqual (p ('not not not x'), ('-not', ('-not', ('-not', ('@', 'x')))))
self.assertEqual (p ('0 or []'), ('-or', (('#', '0'), ('[', ()))))
self.assertEqual (p ('0 or [1]'), ('-or', (('#', '0'), ('[', (('#', '1'),)))))
self.assertEqual (p ('1 and []'), ('-and', (('#', '1'), ('[', ()))))
self.assertEqual (p ('1 and [1]'), ('-and', (('#', '1'), ('[', (('#', '1'),)))))
self.assertEqual (p ('not []'), ('-not', ('[', ())))
self.assertEqual (p ('not [1]'), ('-not', ('[', (('#', '1'),))))
self.assertEqual (p ('not None'), ('-not', ('@', 'None')))
self.assertEqual (p ('True + True'), ('+', (('@', 'True'), ('@', 'True'))))
self.assertEqual (p ('False - True'), ('+', (('@', 'False'), ('-', ('@', 'True')))))
self.assertEqual (p ('True * True'), ('*', (('@', 'True'), ('@', 'True')), {1}))
self.assertEqual (p ('(2 > 1) x'), ('*', (('(', ('<>', ('#', '2'), (('>', ('#', '1')),))), ('@', 'x'))))
self.assertEqual (p ('(2 > 1) + (1 < 2)'), ('+', (('(', ('<>', ('#', '2'), (('>', ('#', '1')),))), ('(', ('<>', ('#', '1'), (('<', ('#', '2')),))))))
self.assertEqual (p ('\\[{[a, b]},]'), ('-mat', ((('[', (('@', 'a'), ('@', 'b'))),),)))
self.assertEqual (p ('{{a:b:c}:d}'), ('-dict', ((('-slice', ('@', 'a'), ('@', 'b'), ('@', 'c')), ('@', 'd')),)))
self.assertEqual (p ('{a:{b:c:d}}'), ('-dict', ((('@', 'a'), ('-slice', ('@', 'b'), ('@', 'c'), ('@', 'd'))),)))
self.assertEqual (p ('{a:b:c} = {a:b:c}'), ('=', ('-slice', ('@', 'a'), ('@', 'b'), ('@', 'c')), ('-slice', ('@', 'a'), ('@', 'b'), ('@', 'c'))))
self.assertEqual (p ('\\[1:2:3]'), ('-mat', ((('-slice', ('#', '1'), ('#', '2'), ('#', '3')),),)))
self.assertEqual (p ('-{not x}'), ('-', ('-not', ('@', 'x'))))
self.assertEqual (p ('x < y in [y] in [[y]] != 2 > 1'), ('<>', ('@', 'x'), (('<', ('@', 'y')), ('in', ('[', (('@', 'y'),))), ('in', ('[', (('[', (('@', 'y'),)),))), ('!=', ('#', '2')), ('>', ('#', '1')))))
self.assertEqual (p ('x < y < z < w'), ('<>', ('@', 'x'), (('<', ('@', 'y')), ('<', ('@', 'z')), ('<', ('@', 'w')))))
self.assertEqual (p ('\\[]'), ('-mat', ()))
self.assertEqual (p ('\\[[]]'), ('-mat', ()))
self.assertEqual (p ('\\[[], []]'), ('-mat', ()))
self.assertEqual (p ('\\{a:b}'), ('-set', (('-slice', ('@', 'a'), ('@', 'b'), None),)))
self.assertEqual (p ('{-x} y / z'), ('/', ('*', (('-', ('@', 'x')), ('@', 'y'))), ('@', 'z')))
self.assertEqual (p ('d / dz {-1} a'), ('-diff', ('*', (('#', '-1'), ('@', 'a'))), 'd', (('z', 1),)))
self.assertEqual (p ('1 / {-2} x'), ('/', ('#', '1'), ('*', (('#', '-2'), ('@', 'x')))))
self.assertEqual (p ('\\sum_{x=0}^b {-x} y'), ('-sum', ('*', (('-', ('@', 'x')), ('@', 'y'))), ('@', 'x'), ('#', '0'), ('@', 'b')))
self.assertEqual (p ('\\lim_{x\\to0} {-x} y'), ('-lim', ('*', (('-', ('@', 'x')), ('@', 'y'))), ('@', 'x'), ('#', '0')))
self.assertEqual (p ('\\int a / -1 dx'), ('-intg', ('/', ('@', 'a'), ('#', '-1')), ('@', 'dx')))
self.assertEqual (p ('\\[[[x]]]'), ('-mat', ((('[', (('@', 'x'),)),),)))
self.assertEqual (p ('\\[[[1, 2]], [[3]]]'), ('-mat', ((('[', (('#', '1'), ('#', '2'))),), (('[', (('#', '3'),)),))))
self.assertEqual (p ('{1/x}.limit (x, 0, "-")'), ('.', ('/', ('#', '1'), ('@', 'x')), 'limit', (('@', 'x'), ('#', '0'), ('"', '-'))))
self.assertEqual (p ('{x^2y**2z}.diff (x, 2, y, z)'), ('.', ('*', (('^', ('@', 'x'), ('#', '2')), ('^', ('@', 'y'), ('#', '2')), ('@', 'z'))), 'diff', (('@', 'x'), ('#', '2'), ('@', 'y'), ('@', 'z'))))
self.assertEqual (p ('{x y}.integrate ((x, 0, 1))'), ('.', ('*', (('@', 'x'), ('@', 'y'))), 'integrate', (('(', (',', (('@', 'x'), ('#', '0'), ('#', '1')))),)))
self.assertEqual (p ('\\sqrt (a:b)'), ('-sqrt', ('-slice', ('@', 'a'), ('@', 'b'), None)))
self.assertEqual (p ('\\sqrt[3] (a:b)'), ('-sqrt', ('-slice', ('@', 'a'), ('@', 'b'), None), ('#', '3')))
self.assertEqual (p ('? ()'), ('-ufunc', '?', ()))
self.assertEqual (p ('? (x)'), ('-ufunc', '?', (('@', 'x'),)))
self.assertEqual (p ('? (x) (2)'), ('*', (('-ufunc', '?', (('@', 'x'),)), ('(', ('#', '2')))))
self.assertEqual (p ('? (2)'), ('-ufunc', '?', (('#', '2'),)))
self.assertEqual (p ('?f (x, y, real = True)'), ('-ufunc', '?f', (('@', 'x'), ('@', 'y')), (('real', ('@', 'True')),)))
self.assertEqual (p ('?\\alpha(x)'), ('-ufunc', '?alpha', (('@', 'x'),)))
self.assertEqual (p ('?beta(y)'), ('-ufunc', '?beta', (('@', 'y'),)))
self.assertEqual (p ("Function ('f', real = True) (x, y)"), ('-ufunc', '?f', (('@', 'x'), ('@', 'y')), (('real', ('@', 'True')),)))
self.assertEqual (p ("x'"), ('-diffp', ('@', 'x'), 1))
self.assertEqual (p ("x''"), ('-diffp', ('@', 'x'), 2))
self.assertEqual (p ("{x + y}'"), ('-diffp', ('+', (('@', 'x'), ('@', 'y'))), 1))
self.assertEqual (p ("a [b]'"), ('-diffp', ('-idx', ('@', 'a'), (('@', 'b'),)), 1))
self.assertEqual (p ("a.b ()'"), ('-diffp', ('.', ('@', 'a'), 'b', ()), 1))
self.assertEqual (p ("{x/y}'"), ('-diffp', ('/', ('@', 'x'), ('@', 'y')), 1))
self.assertEqual (p ("1'['ac']"), ('-idx', ('-diffp', ('#', '1'), 1), (('"', 'ac'),)))
self.assertEqual (p ("|x|'"), ('-diffp', ('|', ('@', 'x')), 1))
self.assertEqual (p ("| 'str'|'"), ('-diffp', ('|', ('"', 'str')), 1))
self.assertEqual (p ("{x**y}'"), ('-diffp', ('^', ('@', 'x'), ('@', 'y')), 1))
self.assertEqual (p ("{{-1}'}"), ('-diffp', ('#', '-1'), 1))
self.assertEqual (p ("{a [b]}''"), ('-diffp', ('-idx', ('@', 'a'), (('@', 'b'),)), 2))
self.assertEqual (p ("1.'''"), ('-diffp', ('#', '1.'), 3))
self.assertEqual (p ('x [1]'), ('-idx', ('@', 'x'), (('#', '1'),)))
self.assertEqual (p ('1 [x]'), ('-idx', ('#', '1'), (('@', 'x'),)))
self.assertEqual (p ('[1, 2] [x]'), ('-idx', ('[', (('#', '1'), ('#', '2'))), (('@', 'x'),)))
self.assertEqual (p ('{1, 2} [x]'), ('-idx', ('-set', (('#', '1'), ('#', '2'))), (('@', 'x'),)))
self.assertEqual (p ('{x: 2} [x]'), ('-idx', ('-dict', ((('@', 'x'), ('#', '2')),)), (('@', 'x'),)))
self.assertEqual (p ('{y: 2} [x]'), ('-idx', ('-dict', ((('@', 'y'), ('#', '2')),)), (('@', 'x'),)))
self.assertEqual (p ("'}'"), ('"', '}'))
self.assertEqual (p ('q w * e * {r * t} * y u {i * o} p {a {s * d} f}'), ('*', (('@', 'q'), ('@', 'w'), ('@', 'e'), ('@', 'r'), ('@', 't'), ('@', 'y'), ('@', 'u'), ('@', 'i'), ('@', 'o'), ('@', 'p'), ('@', 'a'), ('@', 's'), ('@', 'd'), ('@', 'f')), {2, 3, 4, 5, 8, 12}))
self.assertEqual (p ('x, y = 1, 2'), ('=', (',', (('@', 'x'), ('@', 'y'))), (',', (('#', '1'), ('#', '2')))))
self.assertEqual (p ('x, 2 = 1, 2'), (',', (('@', 'x'), ('=', ('#', '2'), ('#', '1')), ('#', '2'))))
self.assertEqual (p ('(x, y) = 1, 2'), (',', (('=', ('(', (',', (('@', 'x'), ('@', 'y')))), ('#', '1')), ('#', '2'))))
self.assertEqual (p ('1; x, y = 1, 2'), (';', (('#', '1'), ('=', (',', (('@', 'x'), ('@', 'y'))), (',', (('#', '1'), ('#', '2')))))))
self.assertEqual (p ('1; x, 2 = 1, 2'), (';', (('#', '1'), (',', (('@', 'x'), ('=', ('#', '2'), ('#', '1')), ('#', '2'))))))
self.assertEqual (p ('1; (x, y) = 1, 2'), (';', (('#', '1'), (',', (('=', ('(', (',', (('@', 'x'), ('@', 'y')))), ('#', '1')), ('#', '2'))))))
self.assertEqual (p ('f()()'), ('*', (('-ufunc', 'f', ()), ('(', (',', ())))))
self.assertEqual (p ('f()*()'), ('*', (('-ufunc', 'f', ()), ('(', (',', ()))), {1}))
self.assertEqual (p ('f*()*()'), ('*', (('@', 'f'), ('(', (',', ())), ('(', (',', ()))), {1, 2}))
self.assertEqual (p ('f*()()'), ('*', (('@', 'f'), ('(', (',', ())), ('(', (',', ()))), {1}))
self.assertEqual (p ('dy / dx'), ('-diff', ('@', 'y'), 'd', (('x', 1),)))
self.assertEqual (p ('dy / dx z'), ('*', (('-diff', ('@', 'y'), 'd', (('x', 1),)), ('@', 'z'))))
self.assertEqual (p ('d**2 y / dx**2'), ('-diff', ('@', 'y'), 'd', (('x', 2),)))
self.assertEqual (p ('d**2 y / dx**2 z'), ('*', (('-diff', ('@', 'y'), 'd', (('x', 2),)), ('@', 'z'))))
self.assertEqual (p ('d**2 y / dx dy'), ('-diff', ('@', 'y'), 'd', (('x', 1), ('y', 1))))
self.assertEqual (p ('d**2 y / dx dy z'), ('*', (('-diff', ('@', 'y'), 'd', (('x', 1), ('y', 1))), ('@', 'z'))))
self.assertEqual (p ('\\frac{dy}{dx}'), ('-diff', ('@', 'y'), 'd', (('x', 1),)))
self.assertEqual (p ('\\frac{dy}{dx} z'), ('*', (('-diff', ('@', 'y'), 'd', (('x', 1),)), ('@', 'z'))))
self.assertEqual (p ('\\frac{d**2}{dx**2}'), ('/', ('^', ('@', 'd'), ('#', '2')), ('^', ('@', 'dx'), ('#', '2'))))
self.assertEqual (p ('\\frac{d**2}{dx**2} z'), ('-diff', ('@', 'z'), 'd', (('x', 2),)))
self.assertEqual (p ('\\frac{d**2}{dx dy}'), ('/', ('^', ('@', 'd'), ('#', '2')), ('*', (('@', 'dx'), ('@', 'dy')))))
self.assertEqual (p ('\\frac{d**2}{dx dy} z'), ('-diff', ('@', 'z'), 'd', (('x', 1), ('y', 1))))
self.assertEqual (p ('\\frac{d**2 y}{dx dy}'), ('-diff', ('@', 'y'), 'd', (('x', 1), ('y', 1))))
self.assertEqual (p ('\\frac{d**2 y}{dx dy} z'), ('*', (('-diff', ('@', 'y'), 'd', (('x', 1), ('y', 1))), ('@', 'z'))))
self.assertEqual (p ('\\int dy / dx'), ('-intg', ('-diff', ('@', 'y'), 'd', (('x', 1),)), ('@', '')))
self.assertEqual (p ('\\int d/dx x**2 dx'), ('-intg', ('-diff', ('^', ('@', 'x'), ('#', '2')), 'd', (('x', 1),)), ('@', 'dx')))
self.assertEqual (p ('\\int d/dx y(x) dx'), ('-intg', ('-diff', ('-ufunc', 'y', (('@', 'x'),)), 'd', (('x', 1),)), ('@', 'dx')))
self.assertEqual (p ('\\int dx dx dx'), ('*', (('-intg', None, ('@', 'dx')), ('@', 'dx'), ('@', 'dx'))))
self.assertEqual (p ('\\int dx * dx dx'), ('*', (('-intg', None, ('@', 'dx')), ('@', 'dx'), ('@', 'dx')), {1}))
self.assertEqual (p ('dlambda / dx : x'), ('-slice', ('-diff', ('@', 'lambda'), 'd', (('x', 1),)), ('@', 'x'), None))
self.assertEqual (p ('d**2 lambda / dx**2 : x'), ('-slice', ('-diff', ('@', 'lambda'), 'd', (('x', 2),)), ('@', 'x'), None))
self.assertEqual (p ('ln1.or'), ('.', ('@', 'ln1'), 'or'))
self.assertEqual (p ('ln1. or'), None)
self.assertEqual (p ('ln1 . or'), None)
self.assertEqual (p ('a.b * c.d'), ('*', (('.', ('@', 'a'), 'b'), ('.', ('@', 'c'), 'd')), {1}))
self.assertEqual (p ('a.b c.d'), ('*', (('.', ('@', 'a'), 'b'), ('.', ('@', 'c'), 'd'))))
self.assertEqual (p ('lambda x, y, z: ln lambda x:'), (',', (('*', (('@', 'lambda'), ('@', 'x'))), ('@', 'y'), ('-slice', ('@', 'z'), ('*', (('-log', ('@', 'lambda')), ('@', 'x'))), False))))
self.assertEqual (p ('lambda x, y, z: ln lambda x: 1'), ('-lamb', ('-log', ('-lamb', ('#', '1'), ('x',))), ('x', 'y', 'z')))
self.assertEqual (p ('f (x) (0)'), ('*', (('-ufunc', 'f', (('@', 'x'),)), ('(', ('#', '0')))))
self.assertEqual (p ('f (x, y) (0, 0)'), ('*', (('-ufunc', 'f', (('@', 'x'), ('@', 'y'))), ('(', (',', (('#', '0'), ('#', '0')))))))
self.assertEqual (p ('f (x, y, z) (0, 0, 0)'), ('*', (('-ufunc', 'f', (('@', 'x'), ('@', 'y'), ('@', 'z'))), ('(', (',', (('#', '0'), ('#', '0'), ('#', '0')))))))
self.assertEqual (p ("f (x)' (0)"), ('-subs', ('-diffp', ('-ufunc', 'f', (('@', 'x'),)), 1), ((('@', 'x'), ('#', '0')),)))
self.assertEqual (p ('\\. x+y |_{x = 1}'), ('-subs', ('+', (('@', 'x'), ('@', 'y'))), ((('@', 'x'), ('#', '1')),)))
self.assertEqual (p ('\\. x+y |_{x = 1, y = 2}'), ('-subs', ('+', (('@', 'x'), ('@', 'y'))), ((('@', 'x'), ('#', '1')), (('@', 'y'), ('#', '2')))))
self.assertEqual (p ('\\. x+y |_{x, y = 1, 2}'), ('-subs', ('+', (('@', 'x'), ('@', 'y'))), ((('@', 'x'), ('#', '1')), (('@', 'y'), ('#', '2')))))
self.assertEqual (p ('\\. x+y |_{\\substack{x = 1}}'), ('-subs', ('+', (('@', 'x'), ('@', 'y'))), ((('@', 'x'), ('#', '1')),)))
self.assertEqual (p ('\\. x+y |_{\\substack{x = 1 \\\\ y = 2}}'), ('-subs', ('+', (('@', 'x'), ('@', 'y'))), ((('@', 'x'), ('#', '1')), (('@', 'y'), ('#', '2')))))
self.assertEqual (p ('\\. f(x) |_{f(x) = y}'), ('-subs', ('-ufunc', 'f', (('@', 'x'),)), ((('-ufunc', 'f', (('@', 'x'),)), ('@', 'y')),)))
self.assertEqual (p ('\\. f(x) f(y) |_{f(x), f(y) = y, z}'), ('-subs', ('*', (('-ufunc', 'f', (('@', 'x'),)), ('-ufunc', 'f', (('@', 'y'),)))), ((('-ufunc', 'f', (('@', 'x'),)), ('@', 'y')), (('-ufunc', 'f', (('@', 'y'),)), ('@', 'z')))))
self.assertEqual (p ('\\. f(x) f(y) |_{f(x) = y, f(y) = z}'), ('-subs', ('*', (('-ufunc', 'f', (('@', 'x'),)), ('-ufunc', 'f', (('@', 'y'),)))), ((('-ufunc', 'f', (('@', 'x'),)), ('@', 'y')), (('-ufunc', 'f', (('@', 'y'),)), ('@', 'z')))))
self.assertEqual (p ('\\. f(x) f(y) |_{\\substack{f(x) = y \\\\ f(y) = z}}'), ('-subs', ('*', (('-ufunc', 'f', (('@', 'x'),)), ('-ufunc', 'f', (('@', 'y'),)))), ((('-ufunc', 'f', (('@', 'x'),)), ('@', 'y')), (('-ufunc', 'f', (('@', 'y'),)), ('@', 'z')))))
self.assertEqual (p ('\\. ((1, 2) + (1, 2)) |_{(1,2,1,2) = (3,4)}'), ('-subs', ('(', ('+', (('(', (',', (('#', '1'), ('#', '2')))), ('(', (',', (('#', '1'), ('#', '2'))))))), ((('(', (',', (('#', '1'), ('#', '2'), ('#', '1'), ('#', '2')))), ('(', (',', (('#', '3'), ('#', '4'))))),)))
self.assertEqual (p ("f (x)' (0)"), ('-subs', ('-diffp', ('-ufunc', 'f', (('@', 'x'),)), 1), ((('@', 'x'), ('#', '0')),)))
self.assertEqual (p ('d / dx (f (x)) (0)'), ('-subs', ('-diff', ('-ufunc', 'f', (('@', 'x'),)), 'd', (('x', 1),)), ((('@', 'x'), ('#', '0')),)))
self.assertEqual (p ('d / dx (u (x, y)) (x, y)'), ('-diff', ('-ufunc', 'u', (('@', 'x'), ('@', 'y'))), 'd', (('x', 1),)))
self.assertEqual (p ('d / dx (u (x, y)) (0, y)'), ('-subs', ('-diff', ('-ufunc', 'u', (('@', 'x'), ('@', 'y'))), 'd', (('x', 1),)), ((('@', 'x'), ('#', '0')),)))
self.assertEqual (p ('d / dx (u (x, y)) (0, 0)'), ('-subs', ('-diff', ('-ufunc', 'u', (('@', 'x'), ('@', 'y'))), 'd', (('x', 1),)), ((('@', 'x'), ('#', '0')), (('@', 'y'), ('#', '0')))))
self.assertEqual (p ('d**2 / dx dy (u (x, y)) (x, y)'), ('-diff', ('-ufunc', 'u', (('@', 'x'), ('@', 'y'))), 'd', (('x', 1), ('y', 1))))
self.assertEqual (p ('d**2 / dx dy (u (x, y)) (0, y)'), ('-subs', ('-diff', ('-ufunc', 'u', (('@', 'x'), ('@', 'y'))), 'd', (('x', 1), ('y', 1))), ((('@', 'x'), ('#', '0')),)))
self.assertEqual (p ('d**2 / dx dy (u (x, y)) (0, 0)'), ('-subs', ('-diff', ('-ufunc', 'u', (('@', 'x'), ('@', 'y'))), 'd', (('x', 1), ('y', 1))), ((('@', 'x'), ('#', '0')), (('@', 'y'), ('#', '0')))))
self.assertEqual (p ("dsolve (y(x)'' + 11y(x)' + 24y(x), ics = {y(0): 0, y(x)'(0): -7})"), ('-func', 'dsolve', (('+', (('-diffp', ('-ufunc', 'y', (('@', 'x'),)), 2), ('*', (('#', '11'), ('-diffp', ('-ufunc', 'y', (('@', 'x'),)), 1))), ('*', (('#', '24'), ('-ufunc', 'y', (('@', 'x'),)))))), ('=', ('@', 'ics'), ('-dict', ((('-ufunc', 'y', (('#', '0'),)), ('#', '0')), (('-subs', ('-diffp', ('-ufunc', 'y', (('@', 'x'),)), 1), ((('@', 'x'), ('#', '0')),)), ('#', '-7'))))))))
self.assertEqual (p ("\\. [f(x)', g(y)'] |_{x = 0, y = 1}"), ('-subs', ('[', (('-diffp', ('-ufunc', 'f', (('@', 'x'),)), 1), ('-diffp', ('-ufunc', 'g', (('@', 'y'),)), 1))), ((('@', 'x'), ('#', '0')), (('@', 'y'), ('#', '1')))))
self.assertEqual (p ('\\. [d / dx (f(x, y)), d / dx (g(y, x))] |_{x = 0, y = 1}'), ('-subs', ('[', (('-diff', ('(', ('-ufunc', 'f', (('@', 'x'), ('@', 'y')))), 'd', (('x', 1),)), ('-diff', ('(', ('-ufunc', 'g', (('@', 'y'), ('@', 'x')))), 'd', (('x', 1),)))), ((('@', 'x'), ('#', '0')), (('@', 'y'), ('#', '1')))))
self.assertEqual (p ('\\. d**2 / dx dy (f(x, z)) |_{x = 1, y = 2, z = 3}'), ('-subs', ('-diff', ('(', ('-ufunc', 'f', (('@', 'x'), ('@', 'z')))), 'd', (('x', 1), ('y', 1))), ((('@', 'x'), ('#', '1')), (('@', 'y'), ('#', '2')), (('@', 'z'), ('#', '3')))))
self.assertEqual (p ('?() = 2'), ('=', ('-ufunc', '?', ()), ('#', '2')))
self.assertEqual (p ('?f() = 2'), ('=', ('-ufunc', '?f', ()), ('#', '2')))
self.assertEqual (p ('d / dx (a) b'), ('*', (('-diff', ('(', ('@', 'a')), 'd', (('x', 1),)), ('@', 'b'))))
self.assertEqual (p ('\\frac{d}{dx} (a) b'), ('*', (('-diff', ('(', ('@', 'a')), 'd', (('x', 1),)), ('@', 'b'))))
self.assertEqual (p ('sin (())'), ('-func', 'sin', (('(', (',', ())),)))
self.assertEqual (p ('sin (((a))'), ('-func', 'sin', (('(', ('(', ('@', 'a'))),)))
self.assertEqual (p ('a.b (())'), ('.', ('@', 'a'), 'b', (('(', (',', ())),)))
self.assertEqual (p ('a.b (((a))'), ('.', ('@', 'a'), 'b', (('(', ('(', ('@', 'a'))),)))
self.assertEqual (p ('@x'), ('-func', '@', (('@', 'x'),)))
self.assertEqual (p ('@(x + y)'), ('-func', '@', (('+', (('@', 'x'), ('@', 'y'))),)))
self.assertEqual (p ('@(x + y)'), ('-func', '@', (('+', (('@', 'x'), ('@', 'y'))),)))
self.assertEqual (p ('%x'), ('-func', '%', (('@', 'x'),)))
self.assertEqual (p ('%(x + y)'), ('-func', '%', (('+', (('@', 'x'), ('@', 'y'))),)))
self.assertEqual (p ('%%x'), ('-func', '%', (('-func', '%', (('@', 'x'),)),)))
self.assertEqual (p ('%%(x + y)'), ('-func', '%', (('-func', '%', (('+', (('@', 'x'), ('@', 'y'))),)),)))
self.assertEqual (p ('\\[[1, 2, 3], [4, 5, 6]] [:, 1:]'), ('-idx', ('-mat', ((('#', '1'), ('#', '2'), ('#', '3')), (('#', '4'), ('#', '5'), ('#', '6')))), (('-slice', False, False, None), ('-slice', ('#', '1'), False, None))))
self.assertEqual (p ('N - N N 2'), ('+', (('@', 'N'), ('-', ('-func', 'N', (('-func', 'N', (('#', '2'),)),))))))
self.assertEqual (p ('N N N 2'), ('-func', 'N', (('-func', 'N', (('-func', 'N', (('#', '2'),)),)),)))
self.assertEqual (p ('sin sin sin 2'), ('-func', 'sin', (('-func', 'sin', (('-func', 'sin', (('#', '2'),)),)),)))
self.assertEqual (p ('-N sin -N 2'), ('-', ('-func', 'N', (('-func', 'sin', (('-', ('-func', 'N', (('#', '2'),))),)),))))
self.assertEqual (p ('sin -N sin 2'), ('-func', 'sin', (('-', ('-func', 'N', (('-func', 'sin', (('#', '2'),)),))),)))
self.assertEqual (p ('N N sin -a [2]'), ('-func', 'N', (('-func', 'N', (('-func', 'sin', (('-', ('-idx', ('@', 'a'), (('#', '2'),))),)),)),)))
self.assertEqual (p ('N N sin -a.b [2]'), ('-func', 'N', (('-func', 'N', (('-func', 'sin', (('-', ('-idx', ('.', ('@', 'a'), 'b'), (('#', '2'),))),)),)),)))
self.assertEqual (p ('N N sin -a.b () [2]'), ('-func', 'N', (('-func', 'N', (('-func', 'sin', (('-', ('-idx', ('.', ('@', 'a'), 'b', ()), (('#', '2'),))),)),)),)))
self.assertEqual (p ('N N sin -a.b () [2] [3]'), ('-func', 'N', (('-func', 'N', (('-func', 'sin', (('-', ('-idx', ('-idx', ('.', ('@', 'a'), 'b', ()), (('#', '2'),)), (('#', '3'),))),)),)),)))
self.assertEqual (p ('sin -N () [2] [3].c [4].d () [5]'), ('-func', 'sin', (('-', ('-idx', ('.', ('-idx', ('.', ('-idx', ('-idx', ('-func', 'N', ()), (('#', '2'),)), (('#', '3'),)), 'c'), (('#', '4'),)), 'd', ()), (('#', '5'),))),)))
self.assertEqual (p ('sqrt -N () [2] [3].c [4].d () [5]'), ('-sqrt', ('-', ('-idx', ('.', ('-idx', ('.', ('-idx', ('-idx', ('-func', 'N', ()), (('#', '2'),)), (('#', '3'),)), 'c'), (('#', '4'),)), 'd', ()), (('#', '5'),)))))
self.assertEqual (p ('sqrt[3] -N () [2] [3].c [4].d () [5]'), ('-sqrt', ('-', ('-idx', ('.', ('-idx', ('.', ('-idx', ('-idx', ('-func', 'N', ()), (('#', '2'),)), (('#', '3'),)), 'c'), (('#', '4'),)), 'd', ()), (('#', '5'),))), ('#', '3')))
self.assertEqual (p ('log -N () [2] [3].c [4].d () [5]'), ('-log', ('-', ('-idx', ('.', ('-idx', ('.', ('-idx', ('-idx', ('-func', 'N', ()), (('#', '2'),)), (('#', '3'),)), 'c'), (('#', '4'),)), 'd', ()), (('#', '5'),)))))
self.assertEqual (p ('\\log_2 -N () [2] [3].c [4].d () [5]'), ('-log', ('-', ('-idx', ('.', ('-idx', ('.', ('-idx', ('-idx', ('-func', 'N', ()), (('#', '2'),)), (('#', '3'),)), 'c'), (('#', '4'),)), 'd', ()), (('#', '5'),))), ('#', '2')))
self.assertEqual (p ('N sin**2 ln**2 N x'), ('-func', 'N', (('^', ('-func', 'sin', (('^', ('-log', ('-func', 'N', (('@', 'x'),))), ('#', '2')),)), ('#', '2')),)))
self.assertEqual (p ('sin ln N x'), ('-func', 'sin', (('-log', ('-func', 'N', (('@', 'x'),))),)))
self.assertEqual (p ('sin(a)**[a][b].c'), ('^', ('-func', 'sin', (('@', 'a'),)), ('.', ('-idx', ('[', (('@', 'a'),)), (('@', 'b'),)), 'c')))
self.assertEqual (p ('N sin N sin x'), ('-func', 'N', (('-func', 'sin', (('-func', 'N', (('-func', 'sin', (('@', 'x'),)),)),)),)))
self.assertEqual (p ('cos**-1 0 \\log_2 8'), ('*', (('-func', 'acos', (('#', '0'),)), ('-log', ('#', '8'), ('#', '2')))))
self.assertEqual (p ('N sin sqrt[3] \\log_2 8'), ('-func', 'N', (('-func', 'sin', (('-sqrt', ('-log', ('#', '8'), ('#', '2')), ('#', '3')),)),)))
self.assertEqual (p ('sin(x)**-a[b][c].d'), ('^', ('-func', 'sin', (('@', 'x'),)), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd'))))
self.assertEqual (p ('sin sin x [2].w'), ('-func', 'sin', (('-func', 'sin', (('.', ('-idx', ('@', 'x'), (('#', '2'),)), 'w'),)),)))
self.assertEqual (p ('sin -sin x [2].w'), ('-func', 'sin', (('-', ('-func', 'sin', (('.', ('-idx', ('@', 'x'), (('#', '2'),)), 'w'),))),)))
self.assertEqual (p ('sin sin (x) [2].w'), ('-func', 'sin', (('.', ('-idx', ('-func', 'sin', (('@', 'x'),)), (('#', '2'),)), 'w'),)))
self.assertEqual (p ('sin -sin (x) [2].w'), ('-func', 'sin', (('-', ('.', ('-idx', ('-func', 'sin', (('@', 'x'),)), (('#', '2'),)), 'w')),)))
self.assertEqual (p ('sin sin x [2].w ()'), ('-func', 'sin', (('-func', 'sin', (('.', ('-idx', ('@', 'x'), (('#', '2'),)), 'w', ()),)),)))
self.assertEqual (p ('ln ln x [2].w'), ('-log', ('-log', ('.', ('-idx', ('@', 'x'), (('#', '2'),)), 'w'))))
self.assertEqual (p ('N N sin -a [2]'), ('-func', 'N', (('-func', 'N', (('-func', 'sin', (('-', ('-idx', ('@', 'a'), (('#', '2'),))),)),)),)))
self.assertEqual (p ('sin sin -x [2].w'), ('-func', 'sin', (('-func', 'sin', (('-', ('.', ('-idx', ('@', 'x'), (('#', '2'),)), 'w')),)),)))
self.assertEqual (p ('sin -sin x [2].w'), ('-func', 'sin', (('-', ('-func', 'sin', (('.', ('-idx', ('@', 'x'), (('#', '2'),)), 'w'),))),)))
self.assertEqual (p ('sin(a)**b[2]'), ('^', ('-func', 'sin', (('@', 'a'),)), ('-idx', ('@', 'b'), (('#', '2'),))))
self.assertEqual (p ('sin**-a[b][c].d x'), ('^', ('-func', 'sin', (('@', 'x'),)), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd'))))
self.assertEqual (p ('sin**-a[b][c].d (x)'), ('^', ('@', 'sin'), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd', (('@', 'x'),)))))
self.assertEqual (p ('sin**-a[b][c].d {(x)}'), ('^', ('-func', 'sin', (('@', 'x'),)), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd'))))
self.assertEqual (p ('sin**-a[b][c] (x)'), ('^', ('-func', 'sin', (('@', 'x'),)), ('-', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)))))
self.assertEqual (p ('\\int**-a[b][c] x'), ('-intg', ('@', 'x'), ('@', ''), ('#', '0'), ('-', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)))))
self.assertEqual (p ('\\int**-a[b][c].d (x)'), ('-intg', None, ('@', ''), ('#', '0'), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd', (('@', 'x'),)))))
self.assertEqual (p ('\\int**-a[b][c].d {(x)}'), ('-intg', ('(', ('@', 'x'), True), ('@', ''), ('#', '0'), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd'))))
self.assertEqual (p ('\\int**-a[b][c].d (x) y'), ('-intg', ('@', 'y'), ('@', ''), ('#', '0'), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd', (('@', 'x'),)))))
self.assertEqual (p ('\\int**-a[b][c].d {(x)} y'), ('-intg', ('*', (('(', ('@', 'x'), True), ('@', 'y'))), ('@', ''), ('#', '0'), ('-', ('.', ('-idx', ('-idx', ('@', 'a'), (('@', 'b'),)), (('@', 'c'),)), 'd'))))
self.assertEqual (p ('\\int**a.b[2] x dx'), ('-intg', ('@', 'x'), ('@', 'dx'), ('#', '0'), ('-idx', ('.', ('@', 'a'), 'b'), (('#', '2'),))))
self.assertEqual (p ('d/dx (real = True)'), ('-diff', ('(', ('=', ('@', 'real'), ('@', 'True'))), 'd', (('x', 1),)))
self.assertEqual (p ('f {\\left(x\\right)}'), ('-ufunc', 'f', (('@', 'x'),)))
self.assertEqual (p ('a.b {(x)}'), ('*', (('.', ('@', 'a'), 'b'), ('(', ('@', 'x'), True))))
self.assertEqual (p ('a.b {\\left(x\\right)}'), ('.', ('@', 'a'), 'b', (('@', 'x'),)))
self.assertEqual (p ('\\log_{|x|} y'), ('-log', ('@', 'y'), ('|', ('@', 'x'))))
self.assertEqual (p ('|\\int a + b dx|'), ('|', ('-intg', ('+', (('@', 'a'), ('@', 'b'))), ('@', 'dx'))))
self.assertEqual (p ('\\int deg N dx'), ('-intg', ('-func', 'deg', (('@', 'N'),)), ('@', 'dx')))
self.assertEqual (p ('a \\int x dx / c'), ('/', ('*', (('@', 'a'), ('-intg', ('@', 'x'), ('@', 'dx')))), ('@', 'c')))
self.assertEqual (p ('\\int x dx b / c'), ('/', ('*', (('-intg', ('@', 'x'), ('@', 'dx')), ('@', 'b'))), ('@', 'c')))
self.assertEqual (p ('a \\int x dx b / c'), ('/', ('*', (('@', 'a'), ('-intg', ('@', 'x'), ('@', 'dx')), ('@', 'b'))), ('@', 'c')))
self.assertEqual (p ('a {\\lim_{x\\to0} \\int x dx} / b'), ('/', ('*', (('@', 'a'), ('-lim', ('-intg', ('@', 'x'), ('@', 'dx')), ('@', 'x'), ('#', '0')))), ('@', 'b')))
self.assertEqual (p ('a {\\sum_{x=0}^1 \\int x dx} / b'), ('/', ('*', (('@', 'a'), ('-sum', ('-intg', ('@', 'x'), ('@', 'dx')), ('@', 'x'), ('#', '0'), ('#', '1')))), ('@', 'b')))
self.assertEqual (p ('a / \\int x dx * c'), ('*', (('/', ('@', 'a'), ('-intg', ('@', 'x'), ('@', 'dx'))), ('@', 'c')), {1}))
self.assertEqual (p ('a / b \\int x dx * c'), ('*', (('/', ('@', 'a'), ('*', (('@', 'b'), ('-intg', ('@', 'x'), ('@', 'dx'))))), ('@', 'c')), {1}))
self.assertEqual (p ('cos'), ('@', 'cos'))
self.assertEqual (p ('f = cos'), ('=', ('@', 'f'), ('@', 'cos')))
self.assertEqual (p ('\\[[0, pi], [-pi, 0]].applyfunc (cos)'), ('.', ('-mat', ((('#', '0'), ('@', 'pi')), (('-', ('@', 'pi')), ('#', '0')))), 'applyfunc', (('@', 'cos'),)))
self.assertEqual (p ('$sin (real = True)'), ('-sym', 'sin', (('real', ('@', 'True')),)))
self.assertEqual (p ('sin = $(real = True)'), ('=', ('@', 'sin'), ('-sym', '', (('real', ('@', 'True')),))))
def test_ast2tex (self):
self.assertEqual (ast2tex (p ('1')), '1')
self.assertEqual (ast2tex (p ('1.')), '1.')
self.assertEqual (ast2tex (p ('.1')), '0.1')
self.assertEqual (ast2tex (p ('1e20')), '1{e}{+20}')
self.assertEqual (ast2tex (p ('1E-20')), '1{e}{-20}')
self.assertEqual (ast2tex (p ('1.e+20')), '1.{e}{+20}')
self.assertEqual (ast2tex (p ('.1e-20')), '0.1{e}{-20}')
self.assertEqual (ast2tex (p ('sin (-1.23456789012345678901234567890123456789012345678901234567890123456789012345678901)')), '\\sin{\\left(-1.23456789012345678901234567890123456789012345678901234567890123456789012345678901 \\right)}')
self.assertEqual (ast2tex (p ('x')), 'x')
self.assertEqual (ast2tex (p ('xy')), 'xy')
self.assertEqual (ast2tex (p ('dx')), 'dx')
self.assertEqual (ast2tex (p ('partialx')), '\\partial x')
self.assertEqual (ast2tex (p ('\\partial x')), '\\partial x')
self.assertEqual (ast2tex (p ('x d y')), 'x\\ d\\ y')
self.assertEqual (ast2tex (p ('x partial y')), 'x\\ \\partial\\ y')
self.assertEqual (ast2tex (p ('x \\partial y')), 'x\\ \\partial\\ y')
self.assertEqual (ast2tex (p ('x dx dy y')), 'x\\ dx\\ dy\\ y')
self.assertEqual (ast2tex (p ('x partialx partialy y')), 'x\\ \\partial x\\ \\partial y\\ y')
self.assertEqual (ast2tex (p ('-1')), '-1')
self.assertEqual (ast2tex (p ('-x')), '-x')
self.assertEqual (ast2tex (p ('{x}')), 'x')
self.assertEqual (ast2tex (p ('()')), '\\left( \\right)')
self.assertEqual (ast2tex (p ('(x)')), '\\left(x \\right)')
self.assertEqual (ast2tex (p ('(x,)')), '\\left(x, \\right)')
self.assertEqual (ast2tex (p ('(x,y)')), '\\left(x, y \\right)')
self.assertEqual (ast2tex (p ('(x,y,)')), '\\left(x, y \\right)')
self.assertEqual (ast2tex (p ('[]')), '\\left[ \\right]')
self.assertEqual (ast2tex (p ('[x]')), '\\left[x \\right]')
self.assertEqual (ast2tex (p ('[x,]')), '\\left[x \\right]')
self.assertEqual (ast2tex (p ('[x,y]')), '\\left[x, y \\right]')
self.assertEqual (ast2tex (p ('[x,y,]')), '\\left[x, y \\right]')
self.assertEqual (ast2tex (p ('"x\\x20\\n"')), "\\text{'x \\n'}")
self.assertEqual (ast2tex (p ("'x\\x20\\n'")), "\\text{'x \\n'}")
self.assertEqual (ast2tex (p ('|x|')), '\\left|x \\right|')
self.assertEqual (ast2tex (p ('x!')), 'x!')
self.assertEqual (ast2tex (p ('x+y')), 'x + y')
self.assertEqual (ast2tex (p ('x-y')), 'x - y')
self.assertEqual (ast2tex (p ('x*y')), 'x\\ y')
self.assertEqual (ast2tex (p ('x y')), 'x\\ y')
self.assertEqual (ast2tex (p ('x(y)')), 'x\\left(y \\right)')
self.assertEqual (ast2tex (p ('x*(y)')), 'x \\cdot \\left(y \\right)')
self.assertEqual (ast2tex (p ('x/y')), '\\frac{x}{y}')
self.assertEqual (ast2tex (p ('x^y')), 'x^y')
self.assertEqual (ast2tex (p ('log x')), '\\ln{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('log {x}')), '\\ln{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('log (x)')), '\\ln{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('\\log_2 x')), '\\log_2{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('\\log_2 {x}')), '\\log_2{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('\\log_2 (x)')), '\\log_2{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sqrt x')), '\\sqrt{x}')
self.assertEqual (ast2tex (p ('sqrt {x}')), '\\sqrt{x}')
self.assertEqual (ast2tex (p ('sqrt (x)')), '\\sqrt{x}')
self.assertEqual (ast2tex (p ('sqrt {(x)}')), '\\sqrt{x}')
self.assertEqual (ast2tex (p ('sqrt[3] x')), '\\sqrt[3]{x}')
self.assertEqual (ast2tex (p ('sqrt[3] {x}')), '\\sqrt[3]{x}')
self.assertEqual (ast2tex (p ('sqrt[3] {(x)}')), '\\sqrt[3]{x}')
self.assertEqual (ast2tex (p ('sqrt[3] (x)')), '\\sqrt[3]{x}')
self.assertEqual (ast2tex (p ('sin x')), '\\sin{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin^2 x')), '\\sin^2{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin (x)')), '\\sin{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin (x)^2')), '\\sin^2{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin {x}')), '\\sin{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin {(x)}')), '\\sin{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('{sin x}^2')), '\\sin^2{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin**2 x')), '\\sin^2{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin**-1 x')), '\\sin^{-1}{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin(x)**-1')), '\\sin{\\left(x \\right)}^{-1}')
self.assertEqual (ast2tex (p ('acos (x)')), '\\cos^{-1}{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('\\arccos (x)')), '\\cos^{-1}{\\left(x \\right)}')
self.assertEqual (ast2tex (p ('sin(x**2)')), '\\sin{\\left(x^2 \\right)}')
self.assertEqual (ast2tex (p ('sin(x**2)**2')), '\\sin^2{\\left(x^2 \\right)}')
self.assertEqual (ast2tex (p ('(sin(x**2)**2)')), '\\left(\\sin^2{\\left(x^2 \\right)} \\right)')
self.assertEqual (ast2tex (p ('ln(x**2)')), '\\ln{\\left(x^2 \\right)}')
self.assertEqual (ast2tex (p ('ln(x**2)**2')), '\\ln{\\left(x^2 \\right)}^2')
self.assertEqual (ast2tex (p ('(ln(x**2)**2)')), '\\left(\\ln{\\left(x^2 \\right)}^2 \\right)')
self.assertEqual (ast2tex (p ('gamma(x**2)')), '\\Gamma{\\left(x^2 \\right)}')
self.assertEqual (ast2tex (p ('gamma(x**2)**2')), '\\Gamma{\\left(x^2 \\right)}^2')
self.assertEqual (ast2tex (p ('(gamma(x**2)**2)')), '\\left(\\Gamma{\\left(x^2 \\right)}^2 \\right)')
self.assertEqual (ast2tex (p ('{gamma}[2]')), '{\\gamma}\\left[2 \\right]')
self.assertEqual (ast2tex (p ('{Gamma}[2]')), '{\\Gamma}\\left[2 \\right]')
self.assertEqual (ast2tex (p ('f{(x)}')), 'f \\cdot \\left(x \\right)')
self.assertEqual (ast2tex (p ("f{(x)}'(0)")), "f \\cdot \\left(x \\right)' \\left(0 \\right)")
self.assertEqual (ast2tex (p ("f{(x)}'{(0)}")), "f \\cdot \\left(x \\right)' \\left(0 \\right)")
self.assertEqual (ast2tex (p ('\\operatorname{x_{1}}{\\left(x \\right)}')), 'x_{1}\\left(x \\right)')
self.assertEqual (ast2tex (p ('\\lim_{x\\to0} 1/x')), '\\lim_{x \\to 0} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('\\lim_{x\\to0^+} 1/x')), '\\lim_{x \\to 0^+} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('\\lim_{x\\to0**-} 1/x')), '\\lim_{x \\to 0^-} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('Limit (1/x, x, 0)')), '\\lim_{x \\to 0^+} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('Limit (1/x, x, 0, "-")')), '\\lim_{x \\to 0^-} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('Limit (1/x, x, 0, dir="+-")')), '\\lim_{x \\to 0} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('limit (1/x, x, 0)')), '\\lim_{x \\to 0^+} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('limit (1/x, x, 0, "-")')), '\\lim_{x \\to 0^-} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('limit (1/x, x, 0, dir="+-")')), '\\lim_{x \\to 0} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('\\sum_{n=0}^\\infty x^n/n!')), '\\sum_{n = 0}^\\infty \\frac{x^n}{n!}')
self.assertEqual (ast2tex (p ('Sum (x^n/n!, (n, 0, oo))')), '\\sum_{n = 0}^\\infty \\frac{x^n}{n!}')
self.assertEqual (ast2tex (p ('summation (x^n/n!, (n, 0, oo))')), '\\sum_{n = 0}^\\infty \\frac{x^n}{n!}')
self.assertEqual (ast2tex (p ('d/dx x**2y**2z')), '\\frac{\\partial}{\\partial x}\\left(x^2 y^2 z \\right)')
self.assertEqual (ast2tex (p ('d^2/dx^2 x^2y**2z')), '\\frac{\\partial^2}{\\partial x^2}\\left(x^2 y^2 z \\right)')
self.assertEqual (ast2tex (p ('d^3/dx^2dy x^2y**2z')), '\\frac{\\partial^3}{\\partial x^2 \\partial y}\\left(x^2 y^2 z \\right)')
self.assertEqual (ast2tex (p ('\\partial^4 / \\partial x^2\\partial y\\partial z x^2 y**2 z')), '\\frac{\\partial^4}{\\partial x^2 \\partial y \\partial z}\\left(x^2 y^2 z \\right)')
self.assertEqual (ast2tex (p ('d**1.5 / dx dy x**2y**2')), '\\frac{d^{1.5}}{dx\\ dy\\ x^2 y^2}')
self.assertEqual (ast2tex (p ('d**-2 / dx dy x**2y**2')), '\\frac{d^{-2}}{dx\\ dy\\ x^2 y^2}')
self.assertEqual (ast2tex (p ('d**2 / dx**1.5 x**2y**2')), '\\frac{\\left(d^2 \\right)}{dx^{1.5} x^2 y^2}')
self.assertEqual (ast2tex (p ('Derivative (x^2y**2z, x, 2, y, z)')), '\\frac{\\partial^4}{\\partial x^2 \\partial y \\partial z}\\left(x^2 y^2 z \\right)')
self.assertEqual (ast2tex (p ('diff (x^2y**2z, x, 2, y, z)')), '\\frac{\\partial^4}{\\partial x^2 \\partial y \\partial z}\\left(x^2 y^2 z \\right)')
self.assertEqual (ast2tex (p ('\\int dx')), '\\int \\ dx')
self.assertEqual (ast2tex (p ('\\int x dx')), '\\int x \\ dx')
self.assertEqual (ast2tex (p ('\\int_0^1 x dx')), '\\int_0^1 x \\ dx')
self.assertEqual (ast2tex (p ('\\int_0^1 \\int y dy dx')), '\\int_0^1 \\int y \\ dy \\ dx')
self.assertEqual (ast2tex (p ('Integral (\\int y dy, (x, 0, 1))')), '\\int_0^1 \\int y \\ dy \\ dx')
self.assertEqual (ast2tex (p ('integrate (\\int y dy, (x, 0, 1))')), '\\int_0^1 \\int y \\ dy \\ dx')
self.assertEqual (ast2tex (p ('\\[1,]')), '\\begin{bmatrix} 1 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[1,2]')), '\\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[1,2,]')), '\\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[1,],]')), '\\begin{bmatrix} 1 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[1,],[2,]]')), '\\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[1,],[2,],]')), '\\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\left[\\begin{matrix} 1 \\end{matrix}\\right]')), '\\begin{bmatrix} 1 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\begin{bmatrix} 1 \\\\ \\end{bmatrix}')), '\\begin{bmatrix} 1 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\begin{vmatrix} 1 & 2 \\\\ \\end{vmatrix}')), '\\begin{bmatrix} 1 & 2 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\begin{pmatrix} 1 & 2 \\\\ 3 & 4 \\end{pmatrix}')), '\\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\begin{matrix} 1 & 2 \\\\ 3 & 4 \\\\ \\end{matrix}')), '\\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[1,2]!')), '\\begin{bmatrix} 1 \\\\ 2 \\end{bmatrix}!')
self.assertEqual (ast2tex (p ('\\[[0,1],[1,0]]**x')), '{\\begin{bmatrix} 0 & 1 \\\\ 1 & 0 \\end{bmatrix}}^x')
self.assertEqual (ast2tex (p ('\\[[1,2],[3,4]]!')), '\\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix}!')
self.assertEqual (ast2tex (p ('\\[[1,2,3],[4,5,6]].T')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}.T')
self.assertEqual (ast2tex (p ('\\[[1,2,3],[4,5,6]].T.T')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}.T.T')
self.assertEqual (ast2tex (p ('\\[[1,2,3],[4,5,6]].T.T.T')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}.T.T.T')
self.assertEqual (ast2tex (p ('\\[[1,2,3],[4,5,6]].transpose ()')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}.\\operatorname{transpose}\\left( \\right)')
self.assertEqual (ast2tex (p ('\\[[1,2,3],[4,5,6]].transpose ().transpose ()')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}.\\operatorname{transpose}\\left( \\right).\\operatorname{transpose}\\left( \\right)')
self.assertEqual (ast2tex (p ('\\[[1,2,3],[4,5,6]].transpose ().transpose ().transpose ()')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}.\\operatorname{transpose}\\left( \\right).\\operatorname{transpose}\\left( \\right).\\operatorname{transpose}\\left( \\right)')
self.assertEqual (ast2tex (p ('\\[[1,2,3],[4,5,6]].transpose ().transpose ().T.T.transpose ().transpose ()')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}.\\operatorname{transpose}\\left( \\right).\\operatorname{transpose}\\left( \\right).T.T.\\operatorname{transpose}\\left( \\right).\\operatorname{transpose}\\left( \\right)')
self.assertEqual (ast2tex (p ('\\begin{matrix} A & B \\\\ C & D \\end{matrix} * \\[x, y]')), '\\begin{bmatrix} A & B \\\\ C & D \\end{bmatrix} \\cdot \\begin{bmatrix} x \\\\ y \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[1, 2], [3')), '\\begin{bmatrix} 1 & 2 \\\\ 3 & {} \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[1, 2], [3]]')), '\\begin{bmatrix} 1 & 2 \\\\ 3 & {} \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[1], [2, 3]]')), '\\begin{bmatrix} 1 & {} \\\\ 2 & 3 \\end{bmatrix}')
self.assertEqual (ast2tex (p ('-1**x')), '-1^x')
self.assertEqual (ast2tex (p ('{-1}**x')), '\\left(-1 \\right)^x')
self.assertEqual (ast2tex (p ('-{-1}**x')), '-\\left(-1 \\right)^x')
self.assertEqual (ast2tex (p ('(-1)**x')), '\\left(-1 \\right)^x')
self.assertEqual (ast2tex (p ('-(-1)**x')), '-\\left(-1 \\right)^x')
self.assertEqual (ast2tex (p ('alpha, beta, gamma, delta, epsilon, zeta, eta, theta, iota, kappa, lambda, mu, nu, xi, pi, rho, sigma, tau, upsilon, phi, chi, psi, omega, Gamma, Delta, Theta, Lambda, Xi, Pi, Sigma, Upsilon, Phi, Psi, Omega')), '\\alpha, \\beta, \\gamma, \\delta, \\epsilon, \\zeta, \\eta, \\theta, \\iota, \\kappa, \\lambda, \\mu, \\nu, \\xi, \\pi, \\rho, \\sigma, \\tau, \\upsilon, \\phi, \\chi, \\psi, \\omega, \\Gamma, \\Delta, \\Theta, \\Lambda, \\Xi, \\Pi, \\Sigma, \\Upsilon, \\Phi, \\Psi, \\Omega')
self.assertEqual (ast2tex (p ('\\alpha, \\beta, \\gamma, \\delta, \\epsilon, \\zeta, \\eta, \\theta, \\iota, \\kappa, \\lambda, \\mu, \\nu, \\xi, \\pi, \\rho, \\sigma, \\tau, \\upsilon, \\phi, \\chi, \\psi, \\omega, \\Gamma, \\Delta, \\Theta, \\Lambda, \\Xi, \\Pi, \\Sigma, \\Upsilon, \\Phi, \\Psi, \\Omega')), '\\alpha, \\beta, \\gamma, \\delta, \\epsilon, \\zeta, \\eta, \\theta, \\iota, \\kappa, \\lambda, \\mu, \\nu, \\xi, \\pi, \\rho, \\sigma, \\tau, \\upsilon, \\phi, \\chi, \\psi, \\omega, \\Gamma, \\Delta, \\Theta, \\Lambda, \\Xi, \\Pi, \\Sigma, \\Upsilon, \\Phi, \\Psi, \\Omega')
self.assertEqual (ast2tex (p ('1 if x < y')), '\\begin{cases} 1 & \\text{for}\\: x < y \\end{cases}')
self.assertEqual (ast2tex (p ('1 if x < y else 3')), '\\begin{cases} 1 & \\text{for}\\: x < y \\\\ 3 & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('1 if x < y else 3 if x < z')), '\\begin{cases} 1 & \\text{for}\\: x < y \\\\ 3 & \\text{for}\\: x < z \\end{cases}')
self.assertEqual (ast2tex (p ('1 if x < y else 3 if x < z else 5')), '\\begin{cases} 1 & \\text{for}\\: x < y \\\\ 3 & \\text{for}\\: x < z \\\\ 5 & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & \\end{cases}')), '\\begin{cases} 1 & \\text{for}\\: x < y \\\\ 3 & \\text{for}\\: x < z \\\\ 5 & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & \\\\ \\end{cases}')), '\\begin{cases} 1 & \\text{for}\\: x < y \\\\ 3 & \\text{for}\\: x < z \\\\ 5 & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & x < w \\end{cases}')), '\\begin{cases} 1 & \\text{for}\\: x < y \\\\ 3 & \\text{for}\\: x < z \\\\ 5 & \\text{for}\\: x < w \\end{cases}')
self.assertEqual (ast2tex (p ('\\begin{cases} 1 & x < y \\\\ 3 & x < z \\\\ 5 & x < w \\\\ \\end{cases}')), '\\begin{cases} 1 & \\text{for}\\: x < y \\\\ 3 & \\text{for}\\: x < z \\\\ 5 & \\text{for}\\: x < w \\end{cases}')
self.assertEqual (ast2tex (p ('x**y.a')), 'x^{y.a}')
self.assertEqual (ast2tex (p ('x**y.a ()')), 'x^{y.\\operatorname{a}\\left( \\right)}')
self.assertEqual (ast2tex (p ('x**y.a.b')), 'x^{y.a.b}')
self.assertEqual (ast2tex (p ('x**y.a.b ()')), 'x^{y.a.\\operatorname{b}\\left( \\right)}')
self.assertEqual (ast2tex (p ('x**y.a ().b')), 'x^{y.\\operatorname{a}\\left( \\right).b}')
self.assertEqual (ast2tex (p ('x**y.a ().b ()')), 'x^{y.\\operatorname{a}\\left( \\right).\\operatorname{b}\\left( \\right)}')
self.assertEqual (ast2tex (p ('{1 if x < 0 else 3} if x < 1 else 5')), '\\begin{cases} \\begin{cases} 1 & \\text{for}\\: x < 0 \\\\ 3 & \\text{otherwise} \\end{cases} & \\text{for}\\: x < 1 \\\\ 5 & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('1 if {True if x < 0 else False} else 5')), '\\begin{cases} 1 & \\text{for}\\: \\begin{cases} True & \\text{for}\\: x < 0 \\\\ False & \\text{otherwise} \\end{cases} \\\\ 5 & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('1 if {True if x < 0 else False} else {7 if x < 1 else 5}')), '\\begin{cases} 1 & \\text{for}\\: \\begin{cases} True & \\text{for}\\: x < 0 \\\\ False & \\text{otherwise} \\end{cases} \\\\ \\begin{cases} 7 & \\text{for}\\: x < 1 \\\\ 5 & \\text{otherwise} \\end{cases} & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('{1 if x < 0 else 9} if {True if x < 1 else False} else {7 if x < 2 else 5}')), '\\begin{cases} \\begin{cases} 1 & \\text{for}\\: x < 0 \\\\ 9 & \\text{otherwise} \\end{cases} & \\text{for}\\: \\begin{cases} True & \\text{for}\\: x < 1 \\\\ False & \\text{otherwise} \\end{cases} \\\\ \\begin{cases} 7 & \\text{for}\\: x < 2 \\\\ 5 & \\text{otherwise} \\end{cases} & \\text{otherwise} \\end{cases}')
self.assertEqual (ast2tex (p ('x.y!')), 'x.y!')
self.assertEqual (ast2tex (p ('x.y**2')), 'x.y^2')
self.assertEqual (ast2tex (p ('x.y ()!')), 'x.\\operatorname{y}\\left( \\right)!')
self.assertEqual (ast2tex (p ('x.y ()**2')), 'x.\\operatorname{y}\\left( \\right)^2')
self.assertEqual (ast2tex (p ('x**y.a!')), 'x^{y.a!}')
self.assertEqual (ast2tex (p ('x**y.a**2')), 'x^{y.a^2}')
self.assertEqual (ast2tex (p ('x**y.a ()!')), 'x^{y.\\operatorname{a}\\left( \\right)!}')
self.assertEqual (ast2tex (p ('x**y.a ()**2')), 'x^{y.\\operatorname{a}\\left( \\right)^2}')
self.assertEqual (ast2tex (p ('lambda: x')), '\\left(\\left( \\right) \\mapsto x \\right)')
self.assertEqual (ast2tex (p ('lambda x: x**2')), '\\left(x \\mapsto x^2 \\right)')
self.assertEqual (ast2tex (p ('lambda x, y: x + y')), '\\left(\\left(x, y \\right) \\mapsto x + y \\right)')
self.assertEqual (ast2tex (p ('lambda x, y, z: x + y + z')), '\\left(\\left(x, y, z \\right) \\mapsto x + y + z \\right)')
self.assertEqual (ast2tex (p ('1, lambda: x')), '1, \\left(\\left( \\right) \\mapsto x \\right)')
self.assertEqual (ast2tex (p ('1, lambda x: x**2')), '1, \\left(x \\mapsto x^2 \\right)')
self.assertEqual (ast2tex (p ('1, lambda x, y: x + y')), '1, \\left(\\left(x, y \\right) \\mapsto x + y \\right)')
self.assertEqual (ast2tex (p ('1, lambda x, y, z: x + y + z')), '1, \\left(\\left(x, y, z \\right) \\mapsto x + y + z \\right)')
self.assertEqual (ast2tex (p ('f = lambda: 0')), 'f = \\left(\\left( \\right) \\mapsto 0 \\right)')
self.assertEqual (ast2tex (p ('f = lambda x: 0')), 'f = \\left(x \\mapsto 0 \\right)')
self.assertEqual (ast2tex (p ('f = lambda x, y: 0')), 'f = \\left(\\left(x, y \\right) \\mapsto 0 \\right)')
self.assertEqual (ast2tex (p ('f = lambda x, y, z: 0')), 'f = \\left(\\left(x, y, z \\right) \\mapsto 0 \\right)')
self.assertEqual (ast2tex (p ('\\left(\\left(\\right) \\mapsto x \\right)')), '\\left(\\left( \\right) \\mapsto x \\right)')
self.assertEqual (ast2tex (p ('\\left(\\left(x \\right) \\mapsto x^2 \\right)')), '\\left(x \\mapsto x^2 \\right)')
self.assertEqual (ast2tex (p ('\\left(\\left(x, y \\right) \\mapsto x + y \\right)')), '\\left(\\left(x, y \\right) \\mapsto x + y \\right)')
self.assertEqual (ast2tex (p ('\\lambda: x')), '\\lambda{:}x')
self.assertEqual (ast2tex (p ('\\lambda x: x')), '\\lambda\\ x{:}x')
self.assertEqual (ast2tex (p ('\\lambda x, y: x')), '\\lambda\\ x, y{:}x')
self.assertEqual (ast2tex (p ('{lambda}: x')), '\\lambda{:}x')
self.assertEqual (ast2tex (p ('{lambda} x: x')), '\\lambda\\ x{:}x')
self.assertEqual (ast2tex (p ('{lambda} x, y: x')), '\\lambda\\ x, y{:}x')
self.assertEqual (ast2tex (p ('$')), '\\$')
self.assertEqual (ast2tex (p ('$s')), '\\$s')
self.assertEqual (ast2tex (p ('$ (real = True)')), '\\$\\left(real = True \\right)')
self.assertEqual (ast2tex (p ('$s (real = True)')), '\\$s\\left(real = True \\right)')
self.assertEqual (ast2tex (p ('eye (2).is_diagonal ()')), '\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}.\\operatorname{is\\_diagonal}\\left( \\right)')
self.assertEqual (ast2tex (p ('a [2]')), 'a\\left[2 \\right]')
self.assertEqual (ast2tex (p ('a [2,3]')), 'a\\left[2, 3 \\right]')
self.assertEqual (ast2tex (p ('a * [2]')), 'a \\cdot \\left[2 \\right]')
self.assertEqual (ast2tex (p ('a * {-1}[x]')), 'a \\cdot \\left(-1 \\right)\\left[x \\right]')
self.assertEqual (ast2tex (p ('a * [x][y][z]')), 'a \\cdot \\left[x \\right]\\left[y \\right]\\left[z \\right]')
self.assertEqual (ast2tex (p ('N (1/2)')), '\\operatorname{N}{\\left(\\frac{1}{2} \\right)}')
self.assertEqual (ast2tex (p ("S ('1/2')")), "\\operatorname{S}{\\left(\\text{'1/2'} \\right)}")
self.assertEqual (ast2tex (p ("N (S ('1/2'))")), "\\operatorname{N}{\\left(\\operatorname{S}{\\left(\\text{'1/2'} \\right)} \\right)}")
self.assertEqual (ast2tex (p ('S.Half')), 'S.Half')
self.assertEqual (ast2tex (p ('N S.Half')), '\\operatorname{N}{\\left(S.Half \\right)}')
self.assertEqual (ast2tex (p ('o [i].t')), 'o\\left[i \\right].t')
self.assertEqual (ast2tex (p ('o [i]**2')), 'o\\left[i \\right]^2')
self.assertEqual (ast2tex (p ('o [i]!')), 'o\\left[i \\right]!')
self.assertEqual (ast2tex (p ("'Hello' [::-1]")), "\\text{'Hello'}\\left[{:}{:}{-1} \\right]")
self.assertEqual (ast2tex (p ('\\[[1, 2, 3], [4, 5, 6]] [:,1]')), '\\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\end{bmatrix}\\left[{:}, 1 \\right]')
self.assertEqual (ast2tex (p ('\\binom96')), '\\binom{9}{6}')
self.assertEqual (ast2tex (p ('binomial (x, y)')), '\\binom{x}{y}')
self.assertEqual (ast2tex (p ('y - 1*x')), 'y - 1 x')
self.assertEqual (ast2tex (p ("Poly(x**2 + 2 x + 1, x, domain = 'ZZ')")), "\\operatorname{Poly}{\\left(x^2 + 2 x + 1, x, domain = \\text{'ZZ'} \\right)}")
self.assertEqual (ast2tex (p ("Poly(x**2 + y**2 + 2 x y, x, y, domain = 'CC')")), "\\operatorname{Poly}{\\left(x^2 + y^2 + 2 x\\ y, x, y, domain = \\text{'CC'} \\right)}")
self.assertEqual (ast2tex (p ('oct(10)')), '\\operatorname{oct}{\\left(10 \\right)}')
self.assertEqual (ast2tex (p ('(1,) + (2,)')), '\\left(1, \\right) + \\left(2, \\right)')
self.assertEqual (ast2tex (p ('[1] + [2]')), '\\left[1 \\right] + \\left[2 \\right]')
self.assertEqual (ast2tex (p ("'a' + 'b'")), "\\text{'a'} + \\text{'b'}")
self.assertEqual (ast2tex (p ('(1,) * 2')), '\\left(1, \\right) \\cdot 2')
self.assertEqual (ast2tex (p ('[1] * 2')), '\\left[1 \\right] \\cdot 2')
self.assertEqual (ast2tex (p ("'a' * 2")), "\\text{'a'} \\cdot 2")
self.assertEqual (ast2tex (p ('Lambda (x, x**2)')), '\\left(x \\mapsto x^2 \\right)')
self.assertEqual (ast2tex (p ('beta (2, 3)')), '\\beta{\\left(2, 3 \\right)}')
self.assertEqual (ast2tex (p ('{x d} y')), 'x\\ d\\ y')
self.assertEqual (ast2tex (p ('d**2e0/dx**2e0 x**3')), '\\frac{d^{2{e}{+0}}}{dx^{2{e}{+0}} x^3}')
self.assertEqual (ast2tex (p ('ln((a)**b)')), '\\ln{\\left(\\left(a \\right)^b \\right)}')
self.assertEqual (ast2tex (p ('a * \\int dx + {\\int dx dx}')), '{a \\int \\ dx} + {\\int \\ dx} \\cdot dx')
self.assertEqual (ast2tex (p ('1 if {a = x if z} else 0 if y')), '\\begin{cases} 1 & \\text{for}\\: a = \\begin{cases} x & \\text{for}\\: z \\end{cases} \\\\ 0 & \\text{for}\\: y \\end{cases}')
self.assertEqual (ast2tex (p ('a, lambda: b = 1')), 'a, \\left(\\left( \\right) \\mapsto b = 1 \\right)')
self.assertEqual (ast2tex (p ('a * [2]')), 'a \\cdot \\left[2 \\right]')
self.assertEqual (ast2tex (p ('sqrt(1, 2)')), '\\sqrt{\\left(1, 2 \\right)}')
self.assertEqual (ast2tex (p ('x*[][y]')), 'x \\cdot \\left[ \\right]\\left[y \\right]')
self.assertEqual (ast2tex (p ('lambda: x:')), '\\left(\\left( \\right) \\mapsto x{:} \\right)')
self.assertEqual (ast2tex (p ('a*[x][y][z]')), 'a \\cdot \\left[x \\right]\\left[y \\right]\\left[z \\right]')
self.assertEqual (ast2tex (p ('a*()**2')), 'a \\cdot \\left( \\right)^2')
self.assertEqual (ast2tex (p ('a*().t')), 'a \\cdot \\left( \\right).t')
self.assertEqual (ast2tex (p ('a*()[2]')), 'a \\cdot \\left( \\right)\\left[2 \\right]')
self.assertEqual (ast2tex (p ('o.f*(a)')), 'o.f \\cdot \\left(a \\right)')
self.assertEqual (ast2tex (p ('o.f*{1+2}')), 'o.f \\cdot \\left(1 + 2 \\right)')
self.assertEqual (ast2tex (p ('d**2e0/dx**2e0 x**3')), '\\frac{d^{2{e}{+0}}}{dx^{2{e}{+0}} x^3}')
self.assertEqual (ast2tex (p ('y**z [w]')), 'y^{z\\left[w \\right]}')
self.assertEqual (ast2tex (p ('{y**z} [w]')), '{y^z}\\left[w \\right]')
self.assertEqual (ast2tex (p ('x {y**z} [w]')), 'x {y^z}\\left[w \\right]')
self.assertEqual (ast2tex (p ('{x y**z} [w]')), '\\left(x\\ y^z \\right)\\left[w \\right]')
self.assertEqual (ast2tex (p ('Min (x, y, z)')), '\\operatorname{Min}{\\left(x, y, z \\right)}')
self.assertEqual (ast2tex (p ('Max (x, y, z)')), '\\operatorname{Max}{\\left(x, y, z \\right)}')
self.assertEqual (ast2tex (p ('\\Re (z)')), '\\Re{\\left(z \\right)}')
self.assertEqual (ast2tex (p ('\\Im (z)')), '\\Im{\\left(z \\right)}')
self.assertEqual (ast2tex (p ('re (z)')), '\\Re{\\left(z \\right)}')
self.assertEqual (ast2tex (p ('im (z)')), '\\Im{\\left(z \\right)}')
self.assertEqual (ast2tex (p ('{}')), '\\left\\{ \\right\\}')
self.assertEqual (ast2tex (p ('{1: 2}')), '\\left\\{1{:} 2 \\right\\}')
self.assertEqual (ast2tex (p ('{1: 2,}')), '\\left\\{1{:} 2 \\right\\}')
self.assertEqual (ast2tex (p ('{1: 2, 3: 4}')), '\\left\\{1{:} 2, 3{:} 4 \\right\\}')
self.assertEqual (ast2tex (p ('set ()')), '\\emptyset')
self.assertEqual (ast2tex (p ('\\{}')), '\\emptyset')
self.assertEqual (ast2tex (p ('\\{1}')), '\\left\\{1 \\right\\}')
self.assertEqual (ast2tex (p ('\\{1,2}')), '\\left\\{1, 2 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2}')), '\\left\\{1, 2 \\right\\}')
self.assertEqual (ast2tex (p ('1 in {1,2,3}')), '1 \\in \\left\\{1, 2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('1 \\in {1,2,3}')), '1 \\in \\left\\{1, 2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('4 in {1,2,3}')), '4 \\in \\left\\{1, 2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('4 \\in {1,2,3}')), '4 \\in \\left\\{1, 2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('4 not in {1,2,3}')), '4 \\notin \\left\\{1, 2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('4 \\notin {1,2,3}')), '4 \\notin \\left\\{1, 2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} - {2,3}')), '\\left\\{1, 2 \\right\\} - \\left\\{2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} || {2,3}')), '\\left\\{1, 2 \\right\\} \\cup \\left\\{2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} ^^ {2,3}')), '\\left\\{1, 2 \\right\\} \\ominus \\left\\{2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} && {2,3}')), '\\left\\{1, 2 \\right\\} \\cap \\left\\{2, 3 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} || {2,3} || {3,4}')), '\\left\\{1, 2 \\right\\} \\cup \\left\\{2, 3 \\right\\} \\cup \\left\\{3, 4 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} ^^ {2,3} ^^ {3,4}')), '\\left\\{1, 2 \\right\\} \\ominus \\left\\{2, 3 \\right\\} \\ominus \\left\\{3, 4 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} && {2,3} && {3,4}')), '\\left\\{1, 2 \\right\\} \\cap \\left\\{2, 3 \\right\\} \\cap \\left\\{3, 4 \\right\\}')
self.assertEqual (ast2tex (p ('{1,2} || {2,3} ^^ {3,4} && {4,5}')), '\\left\\{1, 2 \\right\\} \\cup \\left\\{2, 3 \\right\\} \\ominus \\left\\{3, 4 \\right\\} \\cap \\left\\{4, 5 \\right\\}')
self.assertEqual (ast2tex (p ('solve (x**2 = 4)')), '\\operatorname{solve}{\\left(x^2 = 4 \\right)}')
self.assertEqual (ast2tex (p ('Subs (x y, x, 2)')), '\\left. x\\ y \\right|_{x = 2}')
self.assertEqual (ast2tex (p ('Subs (x y, (x, y), (2, 3))')), '\\left. x\\ y \\right|_{\\substack{x = 2 \\\\ y = 3}}')
self.assertEqual (ast2tex (p ('(x y).subs (x, 2)')), '\\left. \\left(x\\ y \\right) \\right|_{x = 2}')
self.assertEqual (ast2tex (p ('(x y).subs (x, 2).subs (y, 3)')), '\\left. \\left(x\\ y \\right) \\right|_{\\substack{x = 2 \\\\ y = 3}}')
self.assertEqual (ast2tex (p ('Subs ((x y z w).subs ({z: 4}), (x, y), (2, 3)).subs ([(w, 5)])')), '\\left. \\left. \\left(x\\ y\\ z\\ w \\right) \\right|_{z = 4} \\right|_{\\substack{x = 2 \\\\ y = 3 \\\\ w = 5}}')
self.assertEqual (ast2tex (p ('x or y')), 'x \\vee y')
self.assertEqual (ast2tex (p ('x or y or z')), 'x \\vee y \\vee z')
self.assertEqual (ast2tex (p ('x and y')), 'x \\wedge y')
self.assertEqual (ast2tex (p ('x and y and z')), 'x \\wedge y \\wedge z')
self.assertEqual (ast2tex (p ('x and y or z')), 'x \\wedge y \\vee z')
self.assertEqual (ast2tex (p ('x and {y or z}')), 'x \\wedge \\left(y \\vee z \\right)')
self.assertEqual (ast2tex (p ('not x or y')), '\\neg\\ x \\vee y')
self.assertEqual (ast2tex (p ('not {x or y}')), '\\neg\\ \\left(x \\vee y \\right)')
self.assertEqual (ast2tex (p ('not x and y')), '\\neg\\ x \\wedge y')
self.assertEqual (ast2tex (p ('not {x and y}')), '\\neg\\ \\left(x \\wedge y \\right)')
self.assertEqual (ast2tex (p ('x or not y')), 'x \\vee \\neg\\ y')
self.assertEqual (ast2tex (p ('x and not y')), 'x \\wedge \\neg\\ y')
self.assertEqual (ast2tex (p ('not x')), '\\neg\\ x')
self.assertEqual (ast2tex (p ('not not x')), '\\neg\\ \\neg\\ x')
self.assertEqual (ast2tex (p ('not not not x')), '\\neg\\ \\neg\\ \\neg\\ x')
self.assertEqual (ast2tex (p ('0 or []')), '0 \\vee \\left[ \\right]')
self.assertEqual (ast2tex (p ('0 or [1]')), '0 \\vee \\left[1 \\right]')
self.assertEqual (ast2tex (p ('1 and []')), '1 \\wedge \\left[ \\right]')
self.assertEqual (ast2tex (p ('1 and [1]')), '1 \\wedge \\left[1 \\right]')
self.assertEqual (ast2tex (p ('not []')), '\\neg\\ \\left[ \\right]')
self.assertEqual (ast2tex (p ('not [1]')), '\\neg\\ \\left[1 \\right]')
self.assertEqual (ast2tex (p ('not None')), '\\neg\\ None')
self.assertEqual (ast2tex (p ('True + True')), 'True + True')
self.assertEqual (ast2tex (p ('False - True')), 'False - True')
self.assertEqual (ast2tex (p ('True * True')), 'True\\ True')
self.assertEqual (ast2tex (p ('(2 > 1) x')), '\\left(2 > 1 \\right) x')
self.assertEqual (ast2tex (p ('(2 > 1) + (1 < 2)')), '\\left(2 > 1 \\right) + \\left(1 < 2 \\right)')
self.assertEqual (ast2tex (p ('\\[{[a, b]},]')), '\\begin{bmatrix} \\left[a, b \\right] \\end{bmatrix}')
self.assertEqual (ast2tex (p ('{{a:b:c}:d}')), '\\left\\{\\left(a{:}b{:}c \\right){:} d \\right\\}')
self.assertEqual (ast2tex (p ('{a:{b:c:d}}')), '\\left\\{a{:} \\left(b{:}c{:}d \\right) \\right\\}')
self.assertEqual (ast2tex (p ('{a:b:c} = {a:b:c}')), '\\left(a{:}b{:}c \\right) = \\left(a{:}b{:}c \\right)')
self.assertEqual (ast2tex (p ('\\[1:2:3]')), '\\begin{bmatrix} \\left(1{:}2{:}3 \\right) \\end{bmatrix}')
self.assertEqual (ast2tex (p ('-{not x}')), '-\\left(\\neg\\ x \\right)')
self.assertEqual (ast2tex (p ('x < y in [y] in [[y]] != 2 > 1')), 'x < y \\in \\left[y \\right] \\in \\left[\\left[y \\right] \\right] \\ne 2 > 1')
self.assertEqual (ast2tex (p ('x < y < z < w')), 'x < y < z < w')
self.assertEqual (ast2tex (p ('\\[]')), '\\begin{bmatrix} \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[]]')), '\\begin{bmatrix} \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[], []]')), '\\begin{bmatrix} \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\{a:b}')), '\\left\\{\\left(a{:}b \\right) \\right\\}')
self.assertEqual (ast2tex (p ('{-x} y / z')), '\\frac{-x\\ y}{z}')
self.assertEqual (ast2tex (p ('d / dz {-1} a')), '\\frac{d}{dz}\\left(-1 a \\right)')
self.assertEqual (ast2tex (p ('1 / {-2} x')), '\\frac{1}{-2 x}')
self.assertEqual (ast2tex (p ('\\sum_{x=0}^b {-x} y')), '\\sum_{x = 0}^b -x\\ y')
self.assertEqual (ast2tex (p ('\\lim_{x\\to0} {-x} y')), '\\lim_{x \\to 0} -x\\ y')
self.assertEqual (ast2tex (p ('\\int a / -1 dx')), '\\int \\frac{a}{-1} \\ dx')
self.assertEqual (ast2tex (p ('\\[[[x]]]')), '\\begin{bmatrix} \\left[x \\right] \\end{bmatrix}')
self.assertEqual (ast2tex (p ('\\[[[1, 2]], [[3]]]')), '\\begin{bmatrix} \\left[1, 2 \\right] \\\\ \\left[3 \\right] \\end{bmatrix}')
self.assertEqual (ast2tex (p ('{1/x}.limit (x, 0, "-")')), '\\lim_{x \\to 0^-} \\frac{1}{x}')
self.assertEqual (ast2tex (p ('{x^2y**2z}.diff (x, 2, y, z)')), '\\frac{\\partial^4}{\\partial x^2 \\partial y \\partial z}\\left(x^2 y^2 z \\right)')
self.assertEqual (ast2tex (p ('{x y}.integrate ((x, 0, 1))')), '\\int_0^1 x\\ y \\ dx')
self.assertEqual (ast2tex (p ('\\sqrt (a:b)')), '\\sqrt{\\left(a{:}b \\right)}')
self.assertEqual (ast2tex (p ('\\sqrt[3] (a:b)')), '\\sqrt[3]{\\left(a{:}b \\right)}')
self.assertEqual (ast2tex (p ('? ()')), '?\\left( \\right)')
self.assertEqual (ast2tex (p ('? (x)')), '?\\left(x \\right)')
self.assertEqual (ast2tex (p ('? (x) (2)')), '?\\left(x \\right) \\cdot \\left(2 \\right)')
self.assertEqual (ast2tex (p ('? (2)')), '?\\left(2 \\right)')
self.assertEqual (ast2tex (p ('?f (x, y, real = True)')), 'f\\left(x, y, real = True \\right)')
self.assertEqual (ast2tex (p ('?\\alpha(x)')), '\\alpha\\left(x \\right)')
self.assertEqual (ast2tex (p ('?beta(y)')), '?\\beta\\left(y \\right)')
self.assertEqual (ast2tex (p ("Function ('f', real = True) (x, y)")), 'f\\left(x, y, real = True \\right)')
self.assertEqual (ast2tex (p ("x'")), "x'")
self.assertEqual (ast2tex (p ("x''")), "x''")
self.assertEqual (ast2tex (p ("{x + y}'")), "\\left(x + y \\right)'")
self.assertEqual (ast2tex (p ("a [b]'")), "a\\left[b \\right]'")
self.assertEqual (ast2tex (p ("a.b ()'")), "a.\\operatorname{b}\\left( \\right)'")
self.assertEqual (ast2tex (p ("{x/y}'")), "\\left(\\frac{x}{y} \\right)'")
self.assertEqual (ast2tex (p ("1'['ac']")), "1'\\left[\\text{'ac'} \\right]")
self.assertEqual (ast2tex (p ("|x|'")), "\\left|x \\right|'")
self.assertEqual (ast2tex (p ("| 'str'|'")), "\\left|\\text{'str'} \\right|'")
self.assertEqual (ast2tex (p ("{x**y}'")), "\\left(x^y \\right)'")
self.assertEqual (ast2tex (p ("{{-1}'}")), "\\left(-1 \\right)'")
self.assertEqual (ast2tex (p ("{a [b]}''")), "a\\left[b \\right]''")
self.assertEqual (ast2tex (p ("1.'''")), "1.'''")
self.assertEqual (ast2tex (p ('x [1]')), 'x\\left[1 \\right]')
self.assertEqual (ast2tex (p ('1 [x]')), '1\\left[x \\right]')
self.assertEqual (ast2tex (p ('[1, 2] [x]')), '\\left[1, 2 \\right]\\left[x \\right]')
self.assertEqual (ast2tex (p ('{1, 2} [x]')), '\\left\\{1, 2 \\right\\}\\left[x \\right]')
self.assertEqual (ast2tex (p ('{x: 2} [x]')), '\\left\\{x{:} 2 \\right\\}\\left[x \\right]')
self.assertEqual (ast2tex (p ('{y: 2} [x]')), '\\left\\{y{:} 2 \\right\\}\\left[x \\right]')
self.assertEqual (ast2tex (p ("'}'")), "\\text{'\\}'}")
self.assertEqual (ast2tex (p ('q w * e * {r * t} * y u {i * o} p {a {s * d} f}')), 'q\\ w\\ e\\ r\\ t\\ y\\ u\\ i\\ o\\ p\\ a\\ s\\ d\\ f')
self.assertEqual (ast2tex (p ('x, y = 1, 2')), 'x, y = 1, 2')
self.assertEqual (ast2tex (p ('x, 2 = 1, 2')), 'x, 2 = 1, 2')
self.assertEqual (ast2tex (p ('(x, y) = 1, 2')), '\\left(x, y \\right) = 1, 2')
self.assertEqual (ast2tex (p ('1; x, y = 1, 2')), '1;\\: x, y = 1, 2')
self.assertEqual (ast2tex (p ('1; x, 2 = 1, 2')), '1;\\: x, 2 = 1, 2')
self.assertEqual (ast2tex (p ('1; (x, y) = 1, 2')), '1;\\: \\left(x, y \\right) = 1, 2')
self.assertEqual (ast2tex (p ('f()()')), 'f\\left( \\right) \\cdot \\left( \\right)')
self.assertEqual (ast2tex (p ('f()*()')), 'f\\left( \\right) \\cdot \\left( \\right)')
self.assertEqual (ast2tex (p ('f*()*()')), 'f \\cdot \\left( \\right) \\cdot \\left( \\right)')
self.assertEqual (ast2tex (p ('f*()()')), 'f \\cdot \\left( \\right) \\left( \\right)')
self.assertEqual (ast2tex (p ('dy / dx')), '\\frac{dy}{dx}')
self.assertEqual (ast2tex (p ('dy / dx z')), '\\frac{dy}{dx} \\cdot z')
self.assertEqual (ast2tex (p ('d**2 y / dx**2')), '\\frac{d^2 y}{dx^2}')
self.assertEqual (ast2tex (p ('d**2 y / dx**2 z')), '\\frac{d^2 y}{dx^2} \\cdot z')
self.assertEqual (ast2tex (p ('d**2 y / dx dy')), '\\frac{\\partial^2 y}{\\partial x \\partial y}')
self.assertEqual (ast2tex (p ('d**2 y / dx dy z')), '\\frac{\\partial^2 y}{\\partial x \\partial y} \\cdot z')
self.assertEqual (ast2tex (p ('\\frac{dy}{dx}')), '\\frac{dy}{dx}')
self.assertEqual (ast2tex (p ('\\frac{dy}{dx} z')), '\\frac{dy}{dx} \\cdot z')
self.assertEqual (ast2tex (p ('\\frac{d**2}{dx**2}')), '\\frac{\\left(d^2 \\right)}{dx^2}')
self.assertEqual (ast2tex (p ('\\frac{d**2}{dx**2} z')), '\\frac{d^2 z}{dx^2}')
self.assertEqual (ast2tex (p ('\\frac{d**2}{dx dy}')), '\\frac{\\left(d^2 \\right)}{dx\\ dy}')
self.assertEqual (ast2tex (p ('\\frac{d**2}{dx dy} z')), '\\frac{\\partial^2 z}{\\partial x \\partial y}')
self.assertEqual (ast2tex (p ('\\frac{d**2 y}{dx dy}')), '\\frac{\\partial^2 y}{\\partial x \\partial y}')
self.assertEqual (ast2tex (p ('\\frac{d**2 y}{dx dy} z')), '\\frac{\\partial^2 y}{\\partial x \\partial y} \\cdot z')
self.assertEqual (ast2tex (p ('\\int dy / dx')), '\\int {\\frac{dy}{dx}} \\ {}')
self.assertEqual (ast2tex (p ('\\int d/dx x**2 dx')), '\\int {\\frac{d}{dx}\\left(x^2 \\right)} \\ dx')
self.assertEqual (ast2tex (p ('\\int d/dx y(x) dx')), '\\int {\\frac{d}{dx}\\left(y\\left(x \\right) \\right)} \\ dx')
self.assertEqual (ast2tex (p ('\\int dx dx dx')), '{\\int \\ dx} \\cdot dx\\ dx')
self.assertEqual (ast2tex (p ('\\int dx * dx dx')), '{\\int \\ dx} \\cdot dx\\ dx')
self.assertEqual (ast2tex (p ('dlambda / dx : x')), '\\frac{d\\lambda}{dx}{:}x')
self.assertEqual (ast2tex (p ('d**2 lambda / dx**2 : x')), '\\frac{d^2 \\lambda}{dx^2}{:}x')
self.assertEqual (ast2tex (p ('ln1.or')), 'ln_{1}.or')
self.assertRaises (AttributeError, ast2tex, p ('ln1. or'))
self.assertRaises (AttributeError, ast2tex, p ('ln1 . or'))
self.assertEqual (ast2tex (p ('a.b * c.d')), 'a.b\\ c.d')
self.assertEqual (ast2tex (p ('a.b c.d')), 'a.b\\ c.d')
self.assertEqual (ast2tex (p ('lambda x, y, z: ln lambda x:')), '\\lambda\\ x, y, z{:}\\ln{\\left(\\lambda \\right)} x{:}')
self.assertEqual (ast2tex (p ('lambda x, y, z: ln lambda x: 1')), '\\left(\\left(x, y, z \\right) \\mapsto \\ln{\\left(\\left(x \\mapsto 1 \\right) \\right)} \\right)')
self.assertEqual (ast2tex (p ('f (x) (0)')), 'f\\left(x \\right) \\cdot \\left(0 \\right)')
self.assertEqual (ast2tex (p ('f (x, y) (0, 0)')), 'f\\left(x, y \\right) \\cdot \\left(0, 0 \\right)')
self.assertEqual (ast2tex (p ('f (x, y, z) (0, 0, 0)')), 'f\\left(x, y, z \\right) \\cdot \\left(0, 0, 0 \\right)')
self.assertEqual (ast2tex (p ("f (x)' (0)")), "f\\left(x \\right)'\\left(0 \\right)")
self.assertEqual (ast2tex (p ('\\. x+y |_{x = 1}')), '\\left. x + y \\right|_{x = 1}')
self.assertEqual (ast2tex (p ('\\. x+y |_{x = 1, y = 2}')), '\\left. x + y \\right|_{\\substack{x = 1 \\\\ y = 2}}')
self.assertEqual (ast2tex (p ('\\. x+y |_{x, y = 1, 2}')), '\\left. x + y \\right|_{\\substack{x = 1 \\\\ y = 2}}')
self.assertEqual (ast2tex (p ('\\. x+y |_{\\substack{x = 1}}')), '\\left. x + y \\right|_{x = 1}')
self.assertEqual (ast2tex (p ('\\. x+y |_{\\substack{x = 1 \\\\ y = 2}}')), '\\left. x + y \\right|_{\\substack{x = 1 \\\\ y = 2}}')
self.assertEqual (ast2tex (p ('\\. f(x) |_{f(x) = y}')), '\\left. f\\left(x \\right) \\right|_{f\\left(x \\right) = y}')
self.assertEqual (ast2tex (p ('\\. f(x) f(y) |_{f(x), f(y) = y, z}')), '\\left. f\\left(x \\right) f\\left(y \\right) \\right|_{\\substack{f\\left(x \\right) = y \\\\ f\\left(y \\right) = z}}')
self.assertEqual (ast2tex (p ('\\. f(x) f(y) |_{f(x) = y, f(y) = z}')), '\\left. f\\left(x \\right) f\\left(y \\right) \\right|_{\\substack{f\\left(x \\right) = y \\\\ f\\left(y \\right) = z}}')
self.assertEqual (ast2tex (p ('\\. f(x) f(y) |_{\\substack{f(x) = y \\\\ f(y) = z}}')), '\\left. f\\left(x \\right) f\\left(y \\right) \\right|_{\\substack{f\\left(x \\right) = y \\\\ f\\left(y \\right) = z}}')
self.assertEqual (ast2tex (p ('\\. ((1, 2) + (1, 2)) |_{(1,2,1,2) = (3,4)}')), '\\left. \\left(\\left(1, 2 \\right) + \\left(1, 2 \\right) \\right) \\right|_{\\left(1, 2, 1, 2 \\right) = \\left(3, 4 \\right)}')
self.assertEqual (ast2tex (p ("f (x)' (0)")), "f\\left(x \\right)'\\left(0 \\right)")
self.assertEqual (ast2tex (p ('d / dx (f (x)) (0)')), '\\frac{d}{dx}\\left(f\\left(x \\right) \\right)\\left(0 \\right)')
self.assertEqual (ast2tex (p ('d / dx (u (x, y)) (x, y)')), '\\frac{\\partial}{\\partial x}\\left(u\\left(x, y \\right) \\right)')
self.assertEqual (ast2tex (p ('d / dx (u (x, y)) (0, y)')), '\\frac{\\partial}{\\partial x}\\left(u\\left(x, y \\right) \\right)\\left(0, y \\right)')