@@ -77,6 +77,16 @@ public boolean checkLessEqual(IExpr expr) {
77
77
}
78
78
79
79
public boolean checkLess (IExpr expr ) {
80
+ long counter = complexityFunction .apply (expr );
81
+ if (counter < this .minCounter ) {
82
+ this .minCounter = counter ;
83
+ this .result = expr ;
84
+ return true ;
85
+ }
86
+ return false ;
87
+ }
88
+
89
+ public boolean checkLessPlusTimesPower (IExpr expr ) {
80
90
long counter = complexityFunction .apply (expr );
81
91
if (counter < this .minCounter ) {
82
92
this .minCounter = counter ;
@@ -347,43 +357,6 @@ private IExpr tryTransformations(IExpr expr) {
347
357
if (temp .isPresent ()) {
348
358
simplifiedResult .checkLessEqual (temp );
349
359
}
350
-
351
- Optional <IExpr []> commonFactors =
352
- Algebra .InternalFindCommonFactorPlus .findCommonFactors ((IAST ) expr , true );
353
- if (commonFactors .isPresent ()) {
354
- temp = eval (F .Times (commonFactors .get ()[0 ], commonFactors .get ()[1 ]));
355
- simplifiedResult .checkLessEqual (temp );
356
- }
357
-
358
- if (simplifiedResult .result .isPlus ()) {
359
- temp = tryPlusLog ((IAST ) simplifiedResult .result );
360
- } else {
361
- temp = tryPlusLog ((IAST ) expr );
362
- }
363
- if (temp .isPresent ()) {
364
- temp = eval (temp );
365
- simplifiedResult .checkLessEqual (temp );
366
- }
367
- // } else if (expr.isExp() && expr.second().isTimes()) {
368
- // IAST times = (IAST) expr.second();
369
- // IExpr i = Times.of(times, F.CNI, F.Power(F.Pi, F.CN1));
370
- // if (i.isRational()) {
371
- // IRational rat = (IRational) i;
372
- // if (rat.isGT(F.C1) || rat.isLE(F.CN1)) {
373
- // IInteger t = rat.trunc();
374
- // t = t.add(t.mod(F.C2));
375
- // // exp(I*(i - t)*Pi)
376
- // return F.Exp.of(F.Times(F.CI, F.Pi, F.Subtract(i, t)));
377
- // } else {
378
- // IRational t1 = rat.multiply(F.C6).normalize();
379
- // IRational t2 = rat.multiply(F.C4).normalize();
380
- // if (t1.isInteger() || t2.isInteger()) {
381
- // // Cos(- I*times) + I*Sin(- I*times)
382
- // return F.Plus.of(F.Cos(F.Times(F.CNI, times)),
383
- // F.Times(F.CI, F.Sin(F.Times(F.CNI, times))));
384
- // }
385
- // }
386
- // }
387
360
}
388
361
389
362
if (simplifiedResult .result .isAST ()) {
@@ -393,7 +366,7 @@ private IExpr tryTransformations(IExpr expr) {
393
366
try {
394
367
temp = F .evalExpandAll (expr );
395
368
expandAllCounter = fComplexityFunction .apply (temp );
396
- simplifiedResult .checkLess (temp );
369
+ simplifiedResult .checkLessPlusTimesPower (temp );
397
370
} catch (RuntimeException rex ) {
398
371
Errors .rethrowsInterruptException (rex );
399
372
//
@@ -407,17 +380,17 @@ private IExpr tryTransformations(IExpr expr) {
407
380
408
381
try {
409
382
temp = eval (F .TrigExpand (expr ));
410
- simplifiedResult .checkLess (temp );
383
+ simplifiedResult .checkLessPlusTimesPower (temp );
411
384
} catch (ValidateException ve ) {
412
385
//
413
386
}
414
387
415
388
try {
416
389
temp = eval (F .TrigToExp (expr ));
417
- if (!simplifiedResult .checkLess (temp )) {
390
+ if (!simplifiedResult .checkLessPlusTimesPower (temp )) {
418
391
if (fFullSimplify ) {
419
392
temp = eval (F .Factor (temp ));
420
- simplifiedResult .checkLess (temp );
393
+ simplifiedResult .checkLessPlusTimesPower (temp );
421
394
}
422
395
}
423
396
} catch (ValidateException ve ) {
@@ -426,7 +399,7 @@ private IExpr tryTransformations(IExpr expr) {
426
399
427
400
try {
428
401
temp = eval (F .TrigReduce (expr ));
429
- simplifiedResult .checkLess (temp );
402
+ simplifiedResult .checkLessPlusTimesPower (temp );
430
403
} catch (ValidateException ve ) {
431
404
//
432
405
}
@@ -436,7 +409,7 @@ private IExpr tryTransformations(IExpr expr) {
436
409
IExpr together = expr ;
437
410
if (simplifiedResult .minCounter < Config .MAX_SIMPLIFY_TOGETHER_LEAFCOUNT ) {
438
411
together = eval (F .Together (expr ));
439
- simplifiedResult .checkLess (together );
412
+ simplifiedResult .checkLessPlusTimesPower (together );
440
413
}
441
414
442
415
if (fFullSimplify ) {
@@ -449,7 +422,7 @@ private IExpr tryTransformations(IExpr expr) {
449
422
// have
450
423
// a new minimal expression
451
424
IExpr divide = F .Divide (parts [0 ], parts [1 ]);
452
- simplifiedResult .checkLess (divide );
425
+ simplifiedResult .checkLessPlusTimesPower (divide );
453
426
454
427
if (!numerator .isOne () && //
455
428
!denominator .isOne ()) {
@@ -458,7 +431,7 @@ private IExpr tryTransformations(IExpr expr) {
458
431
}
459
432
460
433
temp = eval (F .ExpToTrig (expr ));
461
- simplifiedResult .checkLess (temp );
434
+ simplifiedResult .checkLessPlusTimesPower (temp );
462
435
463
436
}
464
437
@@ -472,7 +445,7 @@ private IExpr tryTransformations(IExpr expr) {
472
445
temp = F .NIL ;
473
446
if (fFullSimplify && expandAllCounter < 50 ) { // Config.MAX_SIMPLIFY_FACTOR_LEAFCOUNT) {
474
447
temp = eval (F .Factor (expr ));
475
- simplifiedResult .checkLess (temp );
448
+ simplifiedResult .checkLessPlusTimesPower (temp );
476
449
}
477
450
// if (fFullSimplify
478
451
// && (minCounter >= Config.MAX_SIMPLIFY_FACTOR_LEAFCOUNT || !temp.equals(expr))) {
@@ -487,7 +460,7 @@ private IExpr tryTransformations(IExpr expr) {
487
460
// } else
488
461
if (expandAllCounter < Config .MAX_SIMPLIFY_FACTOR_LEAFCOUNT ) {
489
462
temp = eval (F .FactorSquareFree (expr ));
490
- simplifiedResult .checkLess (temp );
463
+ simplifiedResult .checkLessPlusTimesPower (temp );
491
464
}
492
465
493
466
} catch (ValidateException ve ) {
@@ -498,11 +471,37 @@ private IExpr tryTransformations(IExpr expr) {
498
471
if (!fNoApart //
499
472
&& simplifiedResult .minCounter < Config .MAX_SIMPLIFY_APART_LEAFCOUNT ) {
500
473
temp = eval (F .Apart (expr ));
501
- simplifiedResult .checkLess (temp );
474
+ simplifiedResult .checkLessPlusTimesPower (temp );
502
475
}
503
476
} catch (ValidateException ve ) {
504
477
//
505
478
}
479
+
480
+ // expr = simplifiedResult.result;
481
+ if (expr .isPlus ()) {
482
+ temp = Algebra .factorTermsPlus ((IAST ) expr , EvalEngine .get ());
483
+ if (temp .isPresent ()) {
484
+ simplifiedResult .checkLessEqual (temp );
485
+ }
486
+
487
+ Optional <IExpr []> commonFactors =
488
+ Algebra .InternalFindCommonFactorPlus .findCommonFactors ((IAST ) expr , true );
489
+ if (commonFactors .isPresent ()) {
490
+ temp = eval (F .Times (commonFactors .get ()[0 ], commonFactors .get ()[1 ]));
491
+ simplifiedResult .checkLessEqual (temp );
492
+ }
493
+
494
+ if (simplifiedResult .result .isPlus ()) {
495
+ temp = tryPlusLog ((IAST ) simplifiedResult .result );
496
+ } else {
497
+ temp = tryPlusLog ((IAST ) expr );
498
+ }
499
+ if (temp .isPresent ()) {
500
+ temp = eval (temp );
501
+ simplifiedResult .checkLessEqual (temp );
502
+ }
503
+ }
504
+
506
505
return simplifiedResult .result ;
507
506
} catch (LimitException aele ) {
508
507
//
@@ -532,7 +531,7 @@ private void tryPolynomialQuotientRemainder(IExpr numerator, IExpr denominator,
532
531
temp .second ().isZero ()) {
533
532
// the remainder is 0 here:
534
533
IExpr arg1 = temp .first ();
535
- if (sResult .checkLess (arg1 )) {
534
+ if (sResult .checkLessPlusTimesPower (arg1 )) {
536
535
evaled = true ;
537
536
break ;
538
537
}
@@ -546,7 +545,7 @@ private void tryPolynomialQuotientRemainder(IExpr numerator, IExpr denominator,
546
545
temp .second ().isZero ()) {
547
546
// the remainder is 0 here:
548
547
IExpr arg1 = temp .first ().reciprocal ();
549
- if (sResult .checkLess (arg1 )) {
548
+ if (sResult .checkLessPlusTimesPower (arg1 )) {
550
549
break ;
551
550
}
552
551
}
@@ -605,8 +604,8 @@ public IExpr visit(IASTMutable ast) {
605
604
return temp ;
606
605
}
607
606
}
608
- temp = F .evalExpandAll (ast );
609
- sResult .checkLess (temp );
607
+ // temp = F.evalExpandAll(ast);
608
+ // sResult.checkLess(temp);
610
609
611
610
functionExpand (ast , sResult );
612
611
return sResult .result ;
@@ -623,7 +622,7 @@ private IExpr visitPower(IASTMutable powerAST, SimplifiedResult sResult) {
623
622
IExpr expr = eval (F .Expand (F .Times (plus1 , plus2 )));
624
623
if (expr .isNumber () && !expr .isZero ()) {
625
624
IExpr powerSimplified = S .Times .of (expr .inverse (), plus2 );
626
- if (sResult .checkLess (powerSimplified )) {
625
+ if (sResult .checkLessPlusTimesPower (powerSimplified )) {
627
626
return powerSimplified ;
628
627
}
629
628
}
@@ -861,14 +860,14 @@ private IExpr reduceConjugateFactors(IASTMutable timesAST, SimplifiedResult sRes
861
860
}
862
861
temp = eval (F .Expand (temp ));
863
862
temp = numberFactors .times (temp );
864
- if (sResult .checkLess (temp )) {
863
+ if (sResult .checkLessPlusTimesPower (temp )) {
865
864
if (temp .isAtom ()) {
866
865
return temp ;
867
866
}
868
867
}
869
868
if (temp .isTimes ()) {
870
869
temp = eval (F .Expand (temp ));
871
- if (sResult .checkLess (temp )) {
870
+ if (sResult .checkLessPlusTimesPower (temp )) {
872
871
if (temp .isAtom ()) {
873
872
return temp ;
874
873
}
@@ -911,7 +910,7 @@ private IExpr visitPlus(IASTMutable plusAST, SimplifiedResult sResult) {
911
910
if (!temp .isPlus ()) {
912
911
return temp ;
913
912
}
914
- if (sResult .checkLess (temp )) {
913
+ if (sResult .checkLessPlusTimesPower (temp )) {
915
914
temp = sResult .result ;
916
915
if (temp .isPlus ()) {
917
916
plusAST = (IASTMutable ) sResult .result ;
@@ -939,7 +938,7 @@ private IExpr visitPlus(IASTMutable plusAST, SimplifiedResult sResult) {
939
938
temp = hashRuleMap .evaluateRepeated (plusAST , fEngine );
940
939
if (temp .isPresent ()) {
941
940
temp = eval (temp );
942
- if (sResult .checkLess (temp )) {
941
+ if (sResult .checkLessPlusTimesPower (temp )) {
943
942
return temp ;
944
943
}
945
944
}
@@ -1130,7 +1129,7 @@ private IExpr tryArg1IsOnePlus(IASTMutable plusAST, SimplifiedResult sResult) {
1130
1129
}
1131
1130
IExpr temp = result .oneIdentity0 ();
1132
1131
if (temp .isPlus ()) {
1133
- sResult .checkLess (temp );
1132
+ sResult .checkLessPlusTimesPower (temp );
1134
1133
return F .NIL ;
1135
1134
}
1136
1135
return temp ;
@@ -1233,7 +1232,7 @@ private void functionExpand(IExpr expr, SimplifiedResult sResult) { // long minC
1233
1232
if (expr .isBooleanFunction ()) {
1234
1233
try {
1235
1234
expr = eval (F .BooleanMinimize (expr ));
1236
- sResult .checkLess (expr );
1235
+ sResult .checkLessPlusTimesPower (expr );
1237
1236
return ;
1238
1237
} catch (RuntimeException rex ) {
1239
1238
Errors .rethrowsInterruptException (rex );
@@ -1242,7 +1241,7 @@ private void functionExpand(IExpr expr, SimplifiedResult sResult) { // long minC
1242
1241
} else if (fFullSimplify ) {
1243
1242
try {
1244
1243
expr = eval (F .FunctionExpand (expr ));
1245
- sResult .checkLess (expr );
1244
+ sResult .checkLessPlusTimesPower (expr );
1246
1245
} catch (RuntimeException rex ) {
1247
1246
Errors .rethrowsInterruptException (rex );
1248
1247
//
@@ -1252,7 +1251,7 @@ private void functionExpand(IExpr expr, SimplifiedResult sResult) { // long minC
1252
1251
IExpr re = expr .first ().re ();
1253
1252
IExpr im = expr .first ().im ();
1254
1253
IExpr temp = argReXImY (re , im , fEngine );
1255
- sResult .checkLess (temp );
1254
+ sResult .checkLessPlusTimesPower (temp );
1256
1255
} catch (RuntimeException rex ) {
1257
1256
Errors .rethrowsInterruptException (rex );
1258
1257
//
@@ -1272,7 +1271,7 @@ private void functionExpand(IExpr expr, SimplifiedResult sResult) { // long minC
1272
1271
result .set (i , arg .first ());
1273
1272
}
1274
1273
}
1275
- sResult .checkLess (F .Mod (result , arg2Mod ));
1274
+ sResult .checkLessPlusTimesPower (F .Mod (result , arg2Mod ));
1276
1275
}
1277
1276
} else if (expr .isTimes ()) {
1278
1277
try {
@@ -1303,7 +1302,7 @@ private void functionExpand(IExpr expr, SimplifiedResult sResult) { // long minC
1303
1302
if (TIMES_ORDERLESS_MATCHER != null ) {
1304
1303
IAST temp = TIMES_ORDERLESS_MATCHER .evaluateRepeatedNoCache ((IAST ) expr , fEngine );
1305
1304
if (temp .isPresent ()) {
1306
- sResult .checkLess (temp );
1305
+ sResult .checkLessPlusTimesPower (temp );
1307
1306
}
1308
1307
}
1309
1308
} catch (RuntimeException rex ) {
0 commit comments