-
Notifications
You must be signed in to change notification settings - Fork 31
/
Tests.cs
6780 lines (4766 loc) · 217 KB
/
Tests.cs
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
/* Copyright 2013 Eduardo Cavazos
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Symbolism;
using Symbolism.Has;
using Symbolism.Substitute;
using Symbolism.SimplifyLogical;
using Symbolism.LogicalExpand;
using Symbolism.SimplifyEquation;
using Symbolism.DegreeGpe;
using Symbolism.CoefficientGpe;
using Symbolism.AlgebraicExpand;
using Symbolism.IsolateVariable;
using Symbolism.EliminateVariable;
using Symbolism.RationalExpand;
using Symbolism.LeadingCoefficientGpe;
using Symbolism.Trigonometric;
using Symbolism.DeepSelect;
using Symbolism.RationalizeExpression;
using static Symbolism.Constructors;
using static Symbolism.Trigonometric.Constructors;
using static Symbolism.PolynomialDivision.Extensions;
using static Symbolism.PolynomialGcd.Extensions;
namespace SymbolismTests
{
public static class Extensions
{
// public static void AssertEqTo(this MathObject a, MathObject b) => Assert.True(a == b);
public static MathObject AssertEqTo(this MathObject a, MathObject b)
{
Assert.True(a == b);
return a;
}
public static MathObject MultiplyBothSidesBy(this MathObject obj, MathObject item)
{
//if (obj is Equation)
// return (obj as Equation).a * item == (obj as Equation).b * item;
if (obj is Equation)
return new Equation(
(obj as Equation).a * item,
(obj as Equation).b * item,
(obj as Equation).Operator);
if (obj is And) return (obj as And).Map(elt => elt.MultiplyBothSidesBy(item));
throw new Exception();
}
public static MathObject AddToBothSides(this MathObject obj, MathObject item)
{
if (obj is Equation)
return (obj as Equation).a + item == (obj as Equation).b + item;
throw new Exception();
}
}
public class Obj2
{
public Symbol ΣFx;
public Symbol ΣFy;
public Symbol m;
public Symbol ax;
public Symbol ay;
public Symbol F1, F2;
public Symbol th1, th2;
public Symbol F1x, F2x;
public Symbol F1y, F2y;
public Obj2(string name)
{
ΣFx = new Symbol($"{name}.ΣFx");
ΣFy = new Symbol($"{name}.ΣFy");
m = new Symbol($"{name}.m");
ax = new Symbol($"{name}.ax");
ay = new Symbol($"{name}.ay");
F1 = new Symbol($"{name}.F1");
F2 = new Symbol($"{name}.F2");
th1 = new Symbol($"{name}.th1");
th2 = new Symbol($"{name}.th2");
F1x = new Symbol($"{name}.F1x");
F2x = new Symbol($"{name}.F2x");
F1y = new Symbol($"{name}.F1y");
F2y = new Symbol($"{name}.F2y");
}
public And Equations()
{
return new And(
F1x == F1 * cos(th1),
F1y == F1 * sin(th1),
F2x == F2 * cos(th2),
F2y == F2 * sin(th2),
ΣFx == F1x + F2x,
ΣFx == m * ax,
ΣFy == F1y + F2y,
ΣFy == m * ay
);
}
}
public class Obj3
{
public Symbol ΣFx;
public Symbol ΣFy;
public Symbol m;
public Symbol ax;
public Symbol ay;
public Symbol F1, F2, F3;
public Symbol th1, th2, th3;
public Symbol F1x, F2x, F3x;
public Symbol F1y, F2y, F3y;
public Obj3(string name)
{
ΣFx = new Symbol($"{name}.ΣFx");
ΣFy = new Symbol($"{name}.ΣFy");
m = new Symbol($"{name}.m");
ax = new Symbol($"{name}.ax");
ay = new Symbol($"{name}.ay");
F1 = new Symbol($"{name}.F1");
F2 = new Symbol($"{name}.F2");
F3 = new Symbol($"{name}.F3");
th1 = new Symbol($"{name}.th1");
th2 = new Symbol($"{name}.th2");
th3 = new Symbol($"{name}.th3");
F1x = new Symbol($"{name}.F1x");
F2x = new Symbol($"{name}.F2x");
F3x = new Symbol($"{name}.F3x");
F1y = new Symbol($"{name}.F1y");
F2y = new Symbol($"{name}.F2y");
F3y = new Symbol($"{name}.F3y");
}
public And Equations()
{
return new And(
F1x == F1 * cos(th1),
F1y == F1 * sin(th1),
F2x == F2 * cos(th2),
F2y == F2 * sin(th2),
F3x == F3 * cos(th3),
F3y == F3 * sin(th3),
ΣFx == F1x + F2x + F3x,
ΣFx == m * ax,
ΣFy == F1y + F2y + F3y,
ΣFy == m * ay
);
}
}
public class Obj5
{
public Symbol ΣFx;
public Symbol ΣFy;
public Symbol m;
public Symbol ax;
public Symbol ay;
public Symbol F1, F2, F3, F4, F5;
public Symbol th1, th2, th3, th4, th5;
public Symbol F1x, F2x, F3x, F4x, F5x;
public Symbol F1y, F2y, F3y, F4y, F5y;
public Obj5(string name)
{
ΣFx = new Symbol($"{name}.ΣFx");
ΣFy = new Symbol($"{name}.ΣFy");
m = new Symbol($"{name}.m");
ax = new Symbol($"{name}.ax");
ay = new Symbol($"{name}.ay");
F1 = new Symbol($"{name}.F1");
F2 = new Symbol($"{name}.F2");
F3 = new Symbol($"{name}.F3");
F4 = new Symbol($"{name}.F4");
F5 = new Symbol($"{name}.F5");
th1 = new Symbol($"{name}.th1");
th2 = new Symbol($"{name}.th2");
th3 = new Symbol($"{name}.th3");
th4 = new Symbol($"{name}.th4");
th5 = new Symbol($"{name}.th5");
F1x = new Symbol($"{name}.F1x");
F2x = new Symbol($"{name}.F2x");
F3x = new Symbol($"{name}.F3x");
F4x = new Symbol($"{name}.F4x");
F5x = new Symbol($"{name}.F5x");
F1y = new Symbol($"{name}.F1y");
F2y = new Symbol($"{name}.F2y");
F3y = new Symbol($"{name}.F3y");
F4y = new Symbol($"{name}.F4y");
F5y = new Symbol($"{name}.F5y");
}
public And Equations()
{
return new And(
F1x == F1 * cos(th1),
F1y == F1 * sin(th1),
F2x == F2 * cos(th2),
F2y == F2 * sin(th2),
F3x == F3 * cos(th3),
F3y == F3 * sin(th3),
F4x == F4 * cos(th4),
F4y == F4 * sin(th4),
F5x == F5 * cos(th5),
F5y == F5 * sin(th5),
ΣFx == F1x + F2x + F3x + F4x + F5x,
ΣFx == m * ax,
ΣFy == F1y + F2y + F3y + F4y + F5y,
ΣFy == m * ay
);
}
}
public class KinematicObjectABC
{
public Symbol xA, yA, vxA, vyA, vA, thA;
public Symbol xB, yB, vxB, vyB, vB, thB;
public Symbol xC, yC, vxC, vyC, vC, thC;
public Symbol tAB, tBC, tAC;
public Symbol ax, ay;
public KinematicObjectABC(string name)
{
xA = new Symbol($"{name}.xA");
yA = new Symbol($"{name}.yA");
vxA = new Symbol($"{name}.vxA");
vyA = new Symbol($"{name}.vyA");
vA = new Symbol($"{name}.vA");
thA = new Symbol($"{name}.thA");
xB = new Symbol($"{name}.xB");
yB = new Symbol($"{name}.yB");
vxB = new Symbol($"{name}.vxB");
vyB = new Symbol($"{name}.vyB");
vB = new Symbol($"{name}.vB");
thB = new Symbol($"{name}.thB");
xC = new Symbol($"{name}.xC");
yC = new Symbol($"{name}.yC");
vxC = new Symbol($"{name}.vxC");
vyC = new Symbol($"{name}.vyC");
vC = new Symbol($"{name}.vC");
thC = new Symbol($"{name}.thC");
tAB = new Symbol($"{name}.tAB");
tBC = new Symbol($"{name}.tBC");
tAC = new Symbol($"{name}.tAC");
ax = new Symbol($"{name}.ax");
ay = new Symbol($"{name}.ay");
}
public And EquationsAB() =>
new And(
vxB == vxA + ax * tAB,
vyB == vyA + ay * tAB,
xB == xA + vxA * tAB + ax * (tAB ^ 2) / 2,
yB == yA + vyA * tAB + ay * (tAB ^ 2) / 2
);
public And EquationsBC() =>
new And(
vxC == vxB + ax * tBC,
vyC == vyB + ay * tBC,
xC == xB + vxB * tBC + ax * (tBC ^ 2) / 2,
yC == yB + vyB * tBC + ay * (tBC ^ 2) / 2
);
public And EquationsAC() =>
new And(
vxC == vxA + ax * tAC,
vyC == vyA + ay * tAC,
xC == xA + vxA * tAC + ax * (tAC ^ 2) / 2,
yC == yA + vyA * tAC + ay * (tAC ^ 2) / 2
);
public And TrigEquationsA() =>
new And(
vxA == vA * cos(thA),
vyA == vA * sin(thA)
);
}
public class Tests
{
Symbol a = new Symbol("a");
Symbol b = new Symbol("b");
Symbol c = new Symbol("c");
Symbol d = new Symbol("d");
Symbol w = new Symbol("w");
Symbol x = new Symbol("x");
Symbol y = new Symbol("y");
Symbol z = new Symbol("z");
Integer Int(int n) => new Integer(n);
#region
[Fact] public void Test1() => Assert.True(new DoubleFloat(1.2).Equals(new DoubleFloat(1.2)));
[Fact] public void Test2() => Assert.False(new DoubleFloat(1.20000001).Equals(new DoubleFloat(1.20000002)));
[Fact]
public void Test3()
{
DoubleFloat.tolerance = 0.000000001;
Assert.True(new DoubleFloat(1.2000000000001).Equals(new DoubleFloat(1.200000000002)));
DoubleFloat.tolerance = null;
}
[Fact] public void Test4() => Assert.False(new DoubleFloat(1.2).Equals(new DoubleFloat(1.23)));
#endregion
#region Const
[Fact] public void Test5() => Assert.True((2 * x * y).Const() == 2);
[Fact] public void Test6() => Assert.True((x * y / 2).Const() == new Integer(1) / 2);
[Fact] public void Test7() => Assert.True((0.1 * x * y).Const() == 0.1);
[Fact] public void Test8() => Assert.True((x * y).Const() == 1);
#endregion
#region Simplify
[Fact] public void Test9() => Assert.True(x + x == 2 * x);
[Fact] public void Test10() => Assert.True(x + x + x == 3 * x);
[Fact] public void Test11() => Assert.True(5 + x + 2 == 7 + x);
[Fact] public void Test12() => Assert.True(3 + x + 5 + x == 8 + 2 * x);
[Fact] public void Test13() => Assert.True(4 * x + 3 * x == 7 * x);
[Fact] public void Test14() => Assert.True(x + y + z + x + y + z == 2 * x + 2 * y + 2 * z);
[Fact] public void Test15() => Assert.True(10 - x == 10 + x * -1);
[Fact] public void Test16() => Assert.True(x * y / 3 == Int(1) / 3 * x * y);
[Fact] public void Test17() => Assert.True(x / y == x * (y ^ -1));
[Fact] public void Test18() => Assert.True(x / 3 == x * (Int(1) / 3));
[Fact] public void Test19() => Assert.True(6 * x * y / 3 == 2 * x * y);
[Fact] public void Test20() => Assert.True((((x ^ Int(1) / 2) ^ Int(1) / 2) ^ 8) == (x ^ 2));
[Fact] public void Test21() => Assert.True(((((x * y) ^ (Int(1) / 2)) * (z ^ 2)) ^ 2) == (x * y * (z ^ 4)));
[Fact] public void Test22() => Assert.True(x / x == 1);
[Fact] public void Test23() => Assert.True(x / y * y / x == 1);
[Fact] public void Test24() => Assert.True((x ^ 2) * (x ^ 3) == (x ^ 5));
[Fact] public void Test25() => Assert.True(x + y + x + z + 5 + z == 5 + 2 * x + y + 2 * z);
[Fact] public void Test26() => Assert.True(((Int(1) / 2) * x + (Int(3) / 4) * x) == Int(5) / 4 * x);
[Fact] public void Test27() => Assert.True(1.2 * x + 3 * x == 4.2 * x);
[Fact] public void Test28() => Assert.True(3 * x + 1.2 * x == 4.2 * x);
[Fact] public void Test29() => Assert.True(1.2 * x * 3 * y == 3.5999999999999996 * x * y);
[Fact] public void Test30() => Assert.True(3 * x * 1.2 * y == 3.5999999999999996 * x * y);
[Fact] public void Test31() => Assert.True(3.4 * x * 1.2 * y == 4.08 * x * y);
[Fact] public void Test32() => Assert.True((a == b) == (a == b));
#endregion
#region Power.Simplify
[Fact] public void Test33() => Assert.True((0 ^ x) == 0);
[Fact] public void Test34() => Assert.True((1 ^ x) == 1);
[Fact] public void Test35() => Assert.True((x ^ 0) == 1);
[Fact] public void Test36() => Assert.True((x ^ 1) == x);
#endregion
// Product.Simplify
[Fact] public void Test37() => Assert.True(x * 0 == 0);
// Difference
[Fact] public void Test38() => Assert.True(-x == -1 * x);
[Fact] public void Test39() => Assert.True(x - y == x + -1 * y);
#region Substitute
[Fact] public void Test40() => Assert.True(Int(10).Substitute(Int(10), 20) == 20);
[Fact] public void Test41() => Assert.True(Int(10).Substitute(Int(15), 20) == 10);
[Fact] public void Test42() => Assert.True(new DoubleFloat(1.0).Substitute(new DoubleFloat(1.0), 2.0) == 2.0);
[Fact] public void Test43() => Assert.True(new DoubleFloat(1.0).Substitute(new DoubleFloat(1.5), 2.0) == 1.0);
[Fact] public void Test44() => Assert.True((Int(1) / 2).Substitute(Int(1) / 2, Int(3) / 4) == Int(3) / 4);
[Fact] public void Test45() => Assert.True((Int(1) / 2).Substitute(Int(1) / 3, Int(3) / 4) == Int(1) / 2);
[Fact] public void Test46() => Assert.True(x.Substitute(x, y) == y);
[Fact] public void Test47() => Assert.True(x.Substitute(y, y) == x);
[Fact] public void Test48() => Assert.True((x ^ y).Substitute(x, 10) == (10 ^ y));
[Fact] public void Test49() => Assert.True((x ^ y).Substitute(y, 10) == (x ^ 10));
[Fact] public void Test50() => Assert.True((x ^ y).Substitute(x ^ y, 10) == 10);
[Fact] public void Test51() => Assert.True((x * y * z).Substitute(x, y) == ((y ^ 2) * z));
[Fact] public void Test52() => Assert.True((x * y * z).Substitute(x * y * z, x) == x);
[Fact] public void Test53() => Assert.True((x + y + z).Substitute(x, y) == ((y * 2) + z));
[Fact] public void Test54() => Assert.True((x + y + z).Substitute(x + y + z, x) == x);
[Fact] public void Test55() => Assert.True(((((x * y) ^ (Int(1) / 2)) * (z ^ 2)) ^ 2).Substitute(x, 10).Substitute(y, 20).Substitute(z, 3) == 16200);
#region Equation.Substitute
[Fact] public void Test56() => Assert.True((x == y).Substitute(y, z) == (x == z));
[Fact] public void Test57() => Assert.True((x != y).Substitute(y, z) == (x != z));
[Fact] public void Test58() => (x == 0).Substitute(x, 0).AssertEqTo(true);
[Fact] public void Test59() => (x == 0).Substitute(x, 1).AssertEqTo(false);
[Fact] public void Test60() => (x != 0).Substitute(x, 0).AssertEqTo(false);
[Fact] public void Test61() => (x != 0).Substitute(x, 1).AssertEqTo(true);
#endregion
#endregion
[Fact] public void Test62() => Assert.True(sin(new DoubleFloat(3.14159 / 2)) == 0.99999999999911982);
[Fact] public void Test63() => Assert.True(sin(x + y) + sin(x + y) == 2 * sin(x + y));
[Fact] public void Test64() => Assert.True(sin(x + x) == sin(2 * x));
[Fact] public void Test65() => Assert.True(sin(x + x).Substitute(x, 1) == sin(Int(2)));
[Fact] public void Test66() => Assert.True(sin(x + x).Substitute(x, 1.0) == 0.90929742682568171);
[Fact] public void Test67() => Assert.True(sin(2 * x).Substitute(x, y) == sin(2 * y));
// Product.RecursiveSimplify
[Fact] public void Test68() => Assert.True(1 * x == x);
[Fact] public void Test69() => Assert.True(x * 1 == x);
[Fact] public void Test70() => Assert.True(x != y);
[Fact] public void Test71() => Assert.True(x != 10);
// ==(double a, MathObject b)
[Fact] public void Test72() => Assert.True(1.0 == new DoubleFloat(3.0) - 2.0);
[Fact] public void Test73() => Assert.True((a == b) != (a != b));
[Fact] public void Test74() => (sqrt(a * b) * (sqrt(a * b) / a) / c).AssertEqTo(b / c);
void AssertToStringMatch(MathObject obj, string str) => Assert.True(obj.ToString() == str);
[Fact]
public void Test75()
{
MathObject.ToStringForm = MathObject.ToStringForms.Full;
AssertToStringMatch(x + y + z, "x + y + z");
AssertToStringMatch(x + y * z, "x + y * z");
AssertToStringMatch((x + y) * z, "(x + y) * z");
Assert.True((sin(x) * cos(y)).ToString() == "cos(y) * sin(x)", "(sin(x) * cos(y)).ToString()");
AssertToStringMatch(and(x, y, z), "and(x, y, z)");
AssertToStringMatch(x ^ y, "x ^ y");
AssertToStringMatch((x * y) ^ (x + z), "(x * y) ^ (x + z)");
Assert.True((x - y).ToString() == "x + -1 * y", "(x - y).ToString()");
Assert.True((x - y - z).ToString() == "x + -1 * y + -1 * z", "(x - y - z).ToString()");
Assert.True((x / y).ToString() == "x * y ^ -1", "(x / y).ToString()");
Assert.True((x - (y - z)).ToString() == "x + -1 * (y + -1 * z)", "(x - (y - z)).ToString()");
}
[Fact]
public void Test76()
{
MathObject.ToStringForm = MathObject.ToStringForms.Standard;
Assert.True((x + y).ToString() == "x + y", "(x + y).ToString()");
Assert.True((x - y).ToString() == "x - y", "(x - y).ToString()");
Assert.True((x - y - z).ToString() == "x - y - z", "(x - y - z).ToString()");
Assert.True((-x - y - z).ToString() == "-x - y - z", "(x - y - z).ToString()");
Assert.True((2 * x - 3 * y - 4 * z).ToString() == "2 * x - 3 * y - 4 * z", "(2 * x - 3 * y - 4 * z).ToString()");
Assert.True((x - (y - z)).ToString() == "x - (y - z)", "(x - (y - z)).ToString()");
Assert.True((x - y + z).ToString() == "x - y + z", "(x - y + z).ToString()");
Assert.True((-x).ToString() == "-x", "(-x).ToString()");
Assert.True((x / y).ToString() == "x / y", "(x / y).ToString()");
Assert.True((x / (y + z)).ToString() == "x / (y + z)", "(x / (y + z)).ToString()");
Assert.True(((x + y) / (x + z)).ToString() == "(x + y) / (x + z)", "((x + y) / (x + z)).ToString()");
Assert.True((-x * y).ToString() == "-x * y", "(-x * y).ToString()");
Assert.True((x * -y).ToString() == "-x * y", "(x * -y).ToString()");
Assert.True(sin(x / y).ToString() == "sin(x / y)", "sin(x / y).ToString()");
Assert.True(
(x == -sqrt(2 * y * (-z * a + y * (b ^ 2) / 2 - c * y * d + c * y * z * sin(x))) / y).ToString() ==
"x == -sqrt(2 * y * ((b ^ 2) * y / 2 - c * d * y - a * z + c * sin(x) * y * z)) / y",
"(x == -sqrt(2 * y * (-z * a + y * (b ^ 2) / 2 - c * y * d + c * y * z * sin(x))) / y).ToString()");
Assert.True((x * (y ^ z)).ToString() == "x * (y ^ z)", "(x * (y ^ z)).ToString()");
Assert.True((x + (y ^ z)).ToString() == "x + (y ^ z)", "((x + (y ^ z)).ToString()");
Assert.True(sqrt(x).ToString() == "sqrt(x)", "sqrt(x).ToString()");
Assert.True(sqrt(x).FullForm().ToString() == "x ^ 1/2", "sqrt(x).FullForm()");
Assert.True((x ^ (new Integer(1) / 3)).ToString() == "x ^ 1/3", "(x ^ (new Integer(1) / 3)).ToString()");
Assert.True(and(and(x, y), and(x, z)).SimplifyLogical().ToString() == "and(x, y, z)",
"and(and(x, y), and(x, z)).SimplifyLogical().ToString()");
AssertToStringMatch(x == sqrt(2 * (y * z - cos(a) * y * z)), "x == sqrt(2 * (y * z - cos(a) * y * z))");
AssertToStringMatch(
a == (-c * cos(d) - b * c * sin(d) + x * y + b * x * z) / (-y - z),
"a == (-c * cos(d) - b * c * sin(d) + x * y + b * x * z) / (-y - z)");
AssertToStringMatch(
x == -(sin(y) / cos(y) + sqrt((sin(y) ^ 2) / (cos(y) ^ 2))) * (z ^ 2) / a,
"x == -(sin(y) / cos(y) + sqrt((sin(y) ^ 2) / (cos(y) ^ 2))) * (z ^ 2) / a");
AssertToStringMatch(x * sqrt(y), "x * sqrt(y)");
AssertToStringMatch(x / sqrt(y), "x / sqrt(y)");
AssertToStringMatch(sqrt(y) / x, "sqrt(y) / x");
AssertToStringMatch((x ^ 2) / (y ^ 3), "(x ^ 2) / (y ^ 3)");
AssertToStringMatch(
x == y * sqrt(-8 * a / (y * (z ^ 2))) * (z ^ 2) / (4 * a),
"x == y * sqrt(-8 * a / (y * (z ^ 2))) * (z ^ 2) / (4 * a)");
AssertToStringMatch(-(-1 + x), "-(-1 + x)");
}
#region Equation.ToString
[Fact] public void Test77() => Assert.True((x == y).ToString() == "x == y", "x == y");
[Fact] public void Test78() => Assert.True((x != y).ToString() == "x != y", "x != y");
#endregion
#region Function.ToString
[Fact] public void Test79() => Assert.True(new And().ToString() == "and()", "and()");
#endregion
#region Equation.Simplify
[Fact] public void Test80() => (new Integer(0) == new Integer(0)).Simplify().AssertEqTo(true);
[Fact] public void Test81() => (new Integer(0) == new Integer(1)).Simplify().AssertEqTo(false);
[Fact] public void Test82() => (new Integer(0) != new Integer(1)).Simplify().AssertEqTo(true);
[Fact] public void Test83() => (new Integer(0) != new Integer(0)).Simplify().AssertEqTo(false);
#endregion
#region And
[Fact] public void Test84() => and().AssertEqTo(true);
[Fact] public void Test85() => and(10).AssertEqTo(10);
[Fact] public void Test86() => and(true).AssertEqTo(true);
[Fact] public void Test87() => and(false).AssertEqTo(false);
[Fact] public void Test88() => and(10, 20, 30).AssertEqTo(and(10, 20, 30));
[Fact] public void Test89() => and(10, false, 20).AssertEqTo(false);
[Fact] public void Test90() => and(10, true, 20).AssertEqTo(and(10, 20));
[Fact] public void Test91() => and(10, and(20, 30), 40).AssertEqTo(and(10, 20, 30, 40));
#endregion
#region Or
[Fact] public void Test92() => or(10).AssertEqTo(10);
[Fact] public void Test93() => or(true).AssertEqTo(true);
[Fact] public void Test94() => or(false).AssertEqTo(false);
[Fact] public void Test95() => or(10, 20, false).AssertEqTo(or(10, 20));
[Fact] public void Test96() => or(false, false).AssertEqTo(false);
[Fact] public void Test97() => or(10, true, 20, false).AssertEqTo(true);
[Fact] public void Test98() => or(10, false, 20).AssertEqTo(or(10, 20));
[Fact] public void Test99() => or(10, or(20, 30), 40).AssertEqTo(or(10, 20, 30, 40));
#endregion
#region Function.Map
[Fact]
public void Test100() => new And(1, 2, 3, 4, 5, 6).Map(elt => elt * 2)
.AssertEqTo(and(2, 4, 6, 8, 10, 12));
[Fact]
public void Test101() => new And(1, 2, 3, 4, 5, 6).Map(elt => (elt is Integer) && (elt as Integer).val % 2 == 0 ? elt : false)
.AssertEqTo(false);
[Fact]
public void Test102() => new Or(1, 2, 3).Map(elt => elt * 2)
.AssertEqTo(or(2, 4, 6));
[Fact]
public void Test103() => new Or(1, 2, 3, 4, 5, 6).Map(elt => (elt is Integer) && (elt as Integer).val % 2 == 0 ? elt : false)
.AssertEqTo(or(2, 4, 6));
#endregion Function.Map
#region Sum
[Fact]
public void Test104() => Assert.True((x + y).Equals(x * y) == false, "(x + y).Equals(x * y)");
#endregion
[Fact]
public void Test105()
{
(x < y).Substitute(x, 10).Substitute(y, 20).AssertEqTo(true);
(x > y).Substitute(x, 10).Substitute(y, 20).AssertEqTo(false);
}
Symbol Pi = new Symbol("Pi");
MathObject half = new Integer(1) / 2;
#region Sin
[Fact] public void Test106() => sin(0).AssertEqTo(0);
[Fact] public void Test107() => sin(Pi).AssertEqTo(0);
[Fact] public void Test108() => sin(-10).AssertEqTo(-sin(10));
[Fact] public void Test109() => sin(-x).AssertEqTo(-sin(x));
[Fact] public void Test110() => sin(-5 * x).AssertEqTo(-sin(5 * x));
// sin(k/n pi) for n = 1 2 3 4 6
[Fact] public void Test111() => sin(-2 * Pi).AssertEqTo(0);
[Fact] public void Test112() => sin(-1 * Pi).AssertEqTo(0);
[Fact] public void Test113() => sin(2 * Pi).AssertEqTo(0);
[Fact] public void Test114() => sin(3 * Pi).AssertEqTo(0);
[Fact] public void Test115() => sin(-7 * Pi / 2).AssertEqTo(1);
[Fact] public void Test116() => sin(-5 * Pi / 2).AssertEqTo(-1);
[Fact] public void Test117() => sin(-3 * Pi / 2).AssertEqTo(1);
[Fact] public void Test118() => sin(-1 * Pi / 2).AssertEqTo(-1);
[Fact] public void Test119() => sin(1 * Pi / 2).AssertEqTo(1);
[Fact] public void Test120() => sin(3 * Pi / 2).AssertEqTo(-1);
[Fact] public void Test121() => sin(5 * Pi / 2).AssertEqTo(1);
[Fact] public void Test122() => sin(7 * Pi / 2).AssertEqTo(-1);
[Fact] public void Test123() => sin(-4 * Pi / 3).AssertEqTo(sqrt(3) / 2);
[Fact] public void Test124() => sin(-2 * Pi / 3).AssertEqTo(-sqrt(3) / 2);
[Fact] public void Test125() => sin(-1 * Pi / 3).AssertEqTo(-sqrt(3) / 2);
[Fact] public void Test126() => sin(1 * Pi / 3).AssertEqTo(sqrt(3) / 2);
[Fact] public void Test127() => sin(2 * Pi / 3).AssertEqTo(sqrt(3) / 2);
[Fact] public void Test128() => sin(4 * Pi / 3).AssertEqTo(-sqrt(3) / 2);
[Fact] public void Test129() => sin(5 * Pi / 3).AssertEqTo(-sqrt(3) / 2);
[Fact] public void Test130() => sin(7 * Pi / 3).AssertEqTo(sqrt(3) / 2);
[Fact] public void Test131() => sin(-3 * Pi / 4).AssertEqTo(-1 / sqrt(2));
[Fact] public void Test132() => sin(-1 * Pi / 4).AssertEqTo(-1 / sqrt(2));
[Fact] public void Test133() => sin(1 * Pi / 4).AssertEqTo(1 / sqrt(2));
[Fact] public void Test134() => sin(3 * Pi / 4).AssertEqTo(1 / sqrt(2));
[Fact] public void Test135() => sin(5 * Pi / 4).AssertEqTo(-1 / sqrt(2));
[Fact] public void Test136() => sin(7 * Pi / 4).AssertEqTo(-1 / sqrt(2));
[Fact] public void Test137() => sin(9 * Pi / 4).AssertEqTo(1 / sqrt(2));
[Fact] public void Test138() => sin(11 * Pi / 4).AssertEqTo(1 / sqrt(2));
[Fact] public void Test139() => sin(-5 * Pi / 6).AssertEqTo(-half);
[Fact] public void Test140() => sin(-1 * Pi / 6).AssertEqTo(-half);
[Fact] public void Test141() => sin(1 * Pi / 6).AssertEqTo(half);
[Fact] public void Test142() => sin(5 * Pi / 6).AssertEqTo(half);
[Fact] public void Test143() => sin(7 * Pi / 6).AssertEqTo(-half);
[Fact] public void Test144() => sin(11 * Pi / 6).AssertEqTo(-half);
[Fact] public void Test145() => sin(13 * Pi / 6).AssertEqTo(half);
[Fact] public void Test146() => sin(17 * Pi / 6).AssertEqTo(half);
// sin(a/b pi) where a/b > 1/2 (i.e. not in first quadrant)
[Fact] public void Test147() => sin(15 * Pi / 7).AssertEqTo(sin(1 * Pi / 7));
[Fact] public void Test148() => sin(8 * Pi / 7).AssertEqTo(-sin(1 * Pi / 7));
[Fact] public void Test149() => sin(4 * Pi / 7).AssertEqTo(sin(3 * Pi / 7));
// sin( a + b + ... + n * pi ) where abs(n) >= 2
[Fact] public void Test150() => sin(x - 3 * Pi).AssertEqTo(sin(x + Pi));
[Fact] public void Test151() => sin(x - 2 * Pi).AssertEqTo(sin(x));
[Fact] public void Test152() => sin(x + 2 * Pi).AssertEqTo(sin(x));
[Fact] public void Test153() => sin(x + 3 * Pi).AssertEqTo(sin(x + Pi));
[Fact] public void Test154() => sin(x + 7 * Pi / 2).AssertEqTo(sin(x + 3 * Pi / 2));
// sin( a + b + ... + n/2 * pi )
[Fact] public void Test155() => sin(x - 3 * Pi / 2).AssertEqTo(cos(x));
[Fact] public void Test156() => sin(x - 1 * Pi / 2).AssertEqTo(-cos(x));
[Fact] public void Test157() => sin(x + 1 * Pi / 2).AssertEqTo(cos(x));
[Fact] public void Test158() => sin(x + 3 * Pi / 2).AssertEqTo(-cos(x));
[Fact] public void Test159() => sin(Pi + x).AssertEqTo(-sin(x));
[Fact] public void Test160() => sin(Pi + x + y).AssertEqTo(-sin(x + y));
[Fact] public void Test161() => cos(Pi + x).AssertEqTo(-cos(x));
[Fact] public void Test162() => cos(Pi + x + y).AssertEqTo(-cos(x + y));
#endregion
#region Cos
[Fact] public void Test163() => cos(0).AssertEqTo(1);
[Fact] public void Test164() => cos(Pi).AssertEqTo(-1);
[Fact] public void Test165() => cos(-10).AssertEqTo(cos(10));
[Fact] public void Test166() => cos(-10 * x).AssertEqTo(cos(10 * x));
[Fact] public void Test167() => cos(3 * Pi).AssertEqTo(-1);
[Fact] public void Test168() => cos(2 * Pi * 3 / 4).AssertEqTo(0);
// cos( a + b + ... + n * pi ) where abs(n) >= 2
[Fact] public void Test169() => cos(x - 3 * Pi).AssertEqTo(cos(x + Pi));
[Fact] public void Test170() => cos(x + 3 * Pi).AssertEqTo(cos(x + Pi));
[Fact] public void Test171() => cos(x - 2 * Pi).AssertEqTo(cos(x));
[Fact] public void Test172() => cos(x + 2 * Pi).AssertEqTo(cos(x));
[Fact] public void Test173() => cos(x + Pi * 7 / 2).AssertEqTo(cos(x + Pi * 3 / 2));
// cos( a + b + ... + n/2 * pi )
[Fact] public void Test174() => cos(x - Pi * 3 / 2).AssertEqTo(-sin(x));
[Fact] public void Test175() => cos(x - Pi * 1 / 2).AssertEqTo(sin(x));
[Fact] public void Test176() => cos(x + Pi * 1 / 2).AssertEqTo(-sin(x));
[Fact] public void Test177() => cos(x + Pi * 3 / 2).AssertEqTo(sin(x));
#endregion
#region Has
[Fact] public void Test178() => Assert.True(a.Has(elt => elt == a), "a.Has(elt => elt == a)");
[Fact] public void Test179() => Assert.True(a.Has(elt => elt == b) == false, "a.Has(elt => elt == b) == false");
[Fact] public void Test180() => Assert.True((a == b).Has(elt => elt == a), "Has - 3");
[Fact] public void Test181() => Assert.True((a == b).Has(elt => elt == c) == false, "Has - 4");
[Fact] public void Test182() => Assert.True(((a + b) ^ c).Has(elt => elt == a + b), "Has - 5");
[Fact] public void Test183() => Assert.True(((a + b) ^ c).Has(elt => (elt is Power) && (elt as Power).exp == c), "Has - 6");
[Fact] public void Test184() => Assert.True((x * (a + b + c)).Has(elt => (elt is Sum) && (elt as Sum).Has(b)), "Has - 7");
[Fact] public void Test185() => Assert.True((x * (a + b + c)).Has(elt => (elt is Sum) && (elt as Sum).elts.Any(obj => obj == b)), "Has - 8");
[Fact] public void Test186() => Assert.True((x * (a + b + c)).Has(elt => (elt is Product) && (elt as Product).elts.Any(obj => obj == b)) == false, "Has - 9");
#endregion
#region FreeOf
[Fact] public void Test187() => Assert.True((a + b).FreeOf(b) == false, "(a + b).FreeOf(b)");
[Fact] public void Test188() => Assert.True((a + b).FreeOf(c) == true, "(a + b).FreeOf(c)");
[Fact] public void Test189() => Assert.True(((a + b) * c).FreeOf(a + b) == false, "((a + b) * c).FreeOf(a + b)");
[Fact] public void Test190() => Assert.True((sin(x) + 2 * x).FreeOf(sin(x)) == false, "(sin(x) + 2 * x).FreeOf(sin(x))");
[Fact] public void Test191() => Assert.True(((a + b + c) * d).FreeOf(a + b) == true, "((a + b + c) * d).FreeOf(a + b)");
[Fact] public void Test192() => Assert.True(((y + 2 * x - y) / x).FreeOf(x) == true, "((y + 2 * x - y) / x).FreeOf(x)");
[Fact] public void Test193() => Assert.True(((x * y) ^ 2).FreeOf(x * y) == true, "((x * y) ^ 2).FreeOf(x * y)");
#endregion
#region Numerator
[Fact] public void Test194() => Assert.True((x ^ -1).Numerator() == 1);
[Fact] public void Test195() => Assert.True((x ^ -half).Numerator() == 1);
#endregion
#region Denominator
[Fact]
public void Test196() =>
((new Integer(2) / 3) * ((x * (x + 1)) / (x + 2)) * (y ^ z)).Denominator().AssertEqTo(3 * (x + 2));
#endregion
#region LogicalExpand
[Fact]
public void Test197() =>
and(or(a, b), c).LogicalExpand()
.AssertEqTo(
or(
and(a, c),
and(b, c)));
[Fact]
public void Test198() =>
and(a, or(b, c))
.LogicalExpand()
.AssertEqTo(or(and(a, b), and(a, c)));
[Fact]
public void Test199() =>
and(a, or(b, c), d)
.LogicalExpand()
.AssertEqTo(
or(
and(a, b, d),
and(a, c, d)));
[Fact]
public void Test200() =>
and(or(a == b, b == c), x == y)
.LogicalExpand()
.AssertEqTo(
or(
and(a == b, x == y),
and(b == c, x == y)));
[Fact]
public void Test201() =>
and(
or(a == b, b == c),
or(c == d, d == a),
x == y)
.LogicalExpand()
.AssertEqTo(
or(
and(a == b, c == d, x == y),
and(a == b, d == a, x == y),
and(b == c, c == d, x == y),
and(b == c, d == a, x == y)));
#endregion
#region SimplifyEquation
[Fact]
public void Test202() =>
(2 * x == 0)
.SimplifyEquation()
.AssertEqTo(x == 0);
[Fact]
public void Test203() =>
(2 * x != 0)
.SimplifyEquation()
.AssertEqTo(x != 0);
[Fact]
public void Test204() =>
((x ^ 2) == 0)
.SimplifyEquation()
.AssertEqTo(x == 0);
#endregion
#region SimplifyLogical
[Fact]
public void Test205() =>
and(a, b, c, a)
.SimplifyLogical()
.AssertEqTo(and(a, b, c));
#endregion SimplifyLogical
#region DegreeGpe
[Fact]
public void Test206() => Assert.True(
((3 * w * x ^ 2) * (y ^ 3) * (z ^ 4)).DegreeGpe(new List<MathObject>() { x, z }) == 6,
"((3 * w * x ^ 2) * (y ^ 3) * (z ^ 4)).DegreeGpe(new List<MathObject>() { x, z })");
[Fact]
public void Test207() => Assert.True(
((a * x ^ 2) + b * x + c).DegreeGpe(new List<MathObject>() { x }) == 2,
"((a * x ^ 2) + b * x + c).DegreeGpe(new List<MathObject>() { x })");