| 627 | } |
| 628 | |
| 629 | shared_ptr<Func1> newDiffFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2) |
| 630 | { |
| 631 | if (isZero(f2)) { |
| 632 | return f1; |
| 633 | } |
| 634 | if (isZero(f1)) { |
| 635 | return newTimesConstFunction(f2, -1.); |
| 636 | } |
| 637 | if (f1->isIdentical(f2)) { |
| 638 | return make_shared<Const1>(0.); |
| 639 | } |
| 640 | if (isConstant(f2)) { |
| 641 | return newPlusConstFunction(f1, -f2->c()); |
| 642 | } |
| 643 | auto [prop, c] = isProportional(f1, f2); |
| 644 | if (prop) { |
| 645 | if (c == 1.0) { |
| 646 | return make_shared<Const1>(0.); |
| 647 | } |
| 648 | return newTimesConstFunction(f1, 1. - c); |
| 649 | } |
| 650 | return make_shared<Diff1>(f1, f2); |
| 651 | } |
| 652 | |
| 653 | shared_ptr<Func1> newProdFunction(shared_ptr<Func1> f1, shared_ptr<Func1> f2) |
| 654 | { |