dydx 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.pryrc +2 -0
 - data/.rubocop.yml +25 -0
 - data/Gemfile +3 -0
 - data/README.md +29 -64
 - data/Rakefile +5 -8
 - data/dydx.gemspec +13 -13
 - data/lib/dydx.rb +20 -29
 - data/lib/dydx/algebra.rb +8 -76
 - data/lib/dydx/algebra/formula.rb +67 -29
 - data/lib/dydx/algebra/inverse.rb +16 -2
 - data/lib/dydx/algebra/operator/formula.rb +0 -4
 - data/lib/dydx/algebra/operator/general.rb +0 -4
 - data/lib/dydx/algebra/operator/inverse.rb +0 -4
 - data/lib/dydx/algebra/operator/num.rb +0 -4
 - data/lib/dydx/algebra/operator/parts/base.rb +2 -2
 - data/lib/dydx/algebra/operator/parts/formula.rb +61 -40
 - data/lib/dydx/algebra/operator/parts/general.rb +83 -30
 - data/lib/dydx/algebra/operator/parts/inverse.rb +4 -4
 - data/lib/dydx/algebra/operator/parts/num.rb +16 -11
 - data/lib/dydx/algebra/operator/parts/symbol.rb +2 -2
 - data/lib/dydx/algebra/set.rb +271 -34
 - data/lib/dydx/delta.rb +1 -1
 - data/lib/dydx/function.rb +1 -1
 - data/lib/dydx/helper.rb +53 -67
 - data/lib/dydx/integrand.rb +22 -10
 - data/lib/dydx/version.rb +1 -1
 - data/spec/dydx_spec.rb +10 -29
 - data/spec/lib/algebra/formula_spec.rb +44 -38
 - data/spec/lib/algebra/operator/parts/base_spec.rb +5 -5
 - data/spec/lib/algebra/operator/parts/formula_spec.rb +57 -57
 - data/spec/lib/algebra/operator/parts/inverse_spec.rb +8 -8
 - data/spec/lib/algebra/set_spec.rb +263 -0
 - data/spec/lib/delta_spec.rb +32 -8
 - data/spec/lib/function_spec.rb +60 -34
 - data/spec/lib/helper_spec.rb +44 -51
 - data/spec/lib/integrand_spec.rb +13 -15
 - data/spec/spec_helper.rb +2 -1
 - metadata +20 -64
 - data/lib/dydx/algebra/operator/common_parts.rb +0 -3
 - data/lib/dydx/algebra/operator/parts/interface.rb +0 -22
 - data/lib/dydx/algebra/operator/symbol.rb +0 -15
 - data/lib/dydx/algebra/set/base.rb +0 -9
 - data/lib/dydx/algebra/set/cos.rb +0 -22
 - data/lib/dydx/algebra/set/e.rb +0 -16
 - data/lib/dydx/algebra/set/fixnum.rb +0 -14
 - data/lib/dydx/algebra/set/float.rb +0 -14
 - data/lib/dydx/algebra/set/log.rb +0 -22
 - data/lib/dydx/algebra/set/num.rb +0 -22
 - data/lib/dydx/algebra/set/pi.rb +0 -16
 - data/lib/dydx/algebra/set/sin.rb +0 -22
 - data/lib/dydx/algebra/set/symbol.rb +0 -14
 - data/lib/dydx/algebra/set/tan.rb +0 -17
 - data/spec/lib/algebra/set/cos_spec.rb +0 -18
 - data/spec/lib/algebra/set/e_spec.rb +0 -27
 - data/spec/lib/algebra/set/fixnum_spec.rb +0 -65
 - data/spec/lib/algebra/set/float_spec.rb +0 -65
 - data/spec/lib/algebra/set/log_spec.rb +0 -15
 - data/spec/lib/algebra/set/num_spec.rb +0 -23
 - data/spec/lib/algebra/set/pi_spec.rb +0 -25
 - data/spec/lib/algebra/set/sin_spec.rb +0 -14
 - data/spec/lib/algebra/set/symbol_spec.rb +0 -22
 - data/spec/lib/algebra/set/tan_spec.rb +0 -13
 
| 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe Dydx::Algebra::Operator::Parts::Inverse do
         
     | 
| 
       4 
     | 
    
         
            -
              it{ expect(inverse( 
     | 
| 
       5 
     | 
    
         
            -
              it{ expect(inverse( 
     | 
| 
      
 4 
     | 
    
         
            +
              it { expect(inverse(x, :+).to_s).to eq('( - x )') }
         
     | 
| 
      
 5 
     | 
    
         
            +
              it { expect(inverse(x, :*).to_s).to eq('( 1 / x )') }
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
              it{ expect(inverse( 
     | 
| 
       8 
     | 
    
         
            -
              it{ expect(inverse( 
     | 
| 
      
 7 
     | 
    
         
            +
              it { expect(inverse(x, :+)).to eq(inverse(x, :+)) }
         
     | 
| 
      
 8 
     | 
    
         
            +
              it { expect(inverse(x, :*)).to eq(inverse(x, :*)) }
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
              it{ expect( 
     | 
| 
       11 
     | 
    
         
            -
              it{ expect( 
     | 
| 
       12 
     | 
    
         
            -
              it{ expect(inverse( 
     | 
| 
       13 
     | 
    
         
            -
              it{ expect(inverse( 
     | 
| 
      
 10 
     | 
    
         
            +
              it { expect(x - x).to eq(0) }
         
     | 
| 
      
 11 
     | 
    
         
            +
              it { expect(x / x).to eq(1) }
         
     | 
| 
      
 12 
     | 
    
         
            +
              it { expect(inverse(x, :+) + x).to eq(0) }
         
     | 
| 
      
 13 
     | 
    
         
            +
              it { expect(inverse(x, :*) * x).to eq(1) }
         
     | 
| 
       14 
14 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,263 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            # HOTFIX: Refactor by using context or describe
         
     | 
| 
      
 3 
     | 
    
         
            +
            describe Dydx::Algebra::Set do
         
     | 
| 
      
 4 
     | 
    
         
            +
              it { expect(_(1)).to eq(_(1)) }
         
     | 
| 
      
 5 
     | 
    
         
            +
              it { expect(_(-1)).to eq(_(-1)) }
         
     | 
| 
      
 6 
     | 
    
         
            +
              it { expect(e0).to eq(e0) }
         
     | 
| 
      
 7 
     | 
    
         
            +
              it { expect(e1).to eq(e1) }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              it { expect(e).to eq(e) }
         
     | 
| 
      
 10 
     | 
    
         
            +
              it { expect(pi).to eq(pi) }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              it { expect(log10(1)).to eq(e0) }
         
     | 
| 
      
 13 
     | 
    
         
            +
              it { expect(log10(10)).to eq(e1) }
         
     | 
| 
      
 14 
     | 
    
         
            +
              it { expect(log10(10 ** n)).to eq(n) }
         
     | 
| 
      
 15 
     | 
    
         
            +
              it { expect(log10(3 ** n)).to eq(n * log10( 3 )) }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              it { expect(log2(1)).to eq(e0) }
         
     | 
| 
      
 18 
     | 
    
         
            +
              it { expect(log2(2)).to eq(e1) }
         
     | 
| 
      
 19 
     | 
    
         
            +
              it { expect(log2(2 ** n)).to eq(n) }
         
     | 
| 
      
 20 
     | 
    
         
            +
              it { expect(log2(3 ** n)).to eq(n * log2( 3 )) }
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              it { expect(log(1)).to eq(0) }
         
     | 
| 
      
 23 
     | 
    
         
            +
              it { expect(log(e)).to eq(1) }
         
     | 
| 
      
 24 
     | 
    
         
            +
              it { expect(log(e ** n)).to eq(n) }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              it { expect(sin(pi)).to eq(0) }
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              it { expect(cos(0)).to eq(1) }
         
     | 
| 
      
 29 
     | 
    
         
            +
              it { expect(cos(pi)).to eq(-1) }
         
     | 
| 
      
 30 
     | 
    
         
            +
              it { expect(cos(2 * pi)).to eq(1) }
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              describe '#to_s' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                it { expect(e.to_s).to eq('e') }
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                it { expect(1.to_s).to eq('1') }
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                it { expect(1.0.to_s).to eq('1.0') }
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                it { expect(e1.to_s).to eq('1') }
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                it { expect(pi.to_s).to eq('pi') }
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                it { expect(cos(x).to_s).to eq('cos( x )') }
         
     | 
| 
      
 44 
     | 
    
         
            +
                it { expect(sin(x).to_s).to eq('sin( x )') }
         
     | 
| 
      
 45 
     | 
    
         
            +
                it { expect(tan(x).to_s).to eq('tan( x )') }
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                it { expect(x.to_s).to eq('x') }
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              describe '#==' do
         
     | 
| 
      
 51 
     | 
    
         
            +
                it { expect(_(1) == _(1)).to be true }
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
              describe '#subst' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                it { expect(1.subst).to eq(1) }
         
     | 
| 
      
 56 
     | 
    
         
            +
                it { expect(1.0.subst).to eq(1.0) }
         
     | 
| 
      
 57 
     | 
    
         
            +
                it { expect(e.subst).to eq(e) }
         
     | 
| 
      
 58 
     | 
    
         
            +
                it { expect(pi.subst).to eq(pi) }
         
     | 
| 
      
 59 
     | 
    
         
            +
                it { expect(sin(x).subst(x: 3)).to eq(sin(3)) }
         
     | 
| 
      
 60 
     | 
    
         
            +
                it { expect(cos(x).subst(x: pi)).to eq(-1) }
         
     | 
| 
      
 61 
     | 
    
         
            +
                it { expect(tan(0).subst(x: pi)).to eq(0) }
         
     | 
| 
      
 62 
     | 
    
         
            +
                it { expect(log(x).subst(x: e)).to eq(1) }
         
     | 
| 
      
 63 
     | 
    
         
            +
                it { expect(log10(x).subst(x: 7)).to eq(log10(7)) }
         
     | 
| 
      
 64 
     | 
    
         
            +
                it { expect(log2(2).subst(x: 2)).to eq(1) }
         
     | 
| 
      
 65 
     | 
    
         
            +
                it { expect(x.subst(x: 2)).to eq(2) }
         
     | 
| 
      
 66 
     | 
    
         
            +
                it { expect(x.subst(y: 2)).to eq(x) }
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
              describe '#differentiate' do
         
     | 
| 
      
 70 
     | 
    
         
            +
                it { expect(e.d).to eq(0) }
         
     | 
| 
      
 71 
     | 
    
         
            +
                it { expect((e ** x).d).to eq(e ** x) }
         
     | 
| 
      
 72 
     | 
    
         
            +
                it { expect((e ** (x + y)).d).to eq(e ** ( x + y )) }
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                it { expect(pi.d(x)).to eq(0) }
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                it { expect(1.d).to eq(0) }
         
     | 
| 
      
 77 
     | 
    
         
            +
                it { expect(3.d).to eq(0) }
         
     | 
| 
      
 78 
     | 
    
         
            +
                it { expect(3.0.d).to eq(0) }
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                it { expect(sin(x).d).to eq(cos(x)) }
         
     | 
| 
      
 81 
     | 
    
         
            +
                it { expect(cos(x).d).to eq(- sin(x)) }
         
     | 
| 
      
 82 
     | 
    
         
            +
                it { expect(tan(x).d).to eq(1 / cos(x) ** 2) }
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                it { expect(log(x).d).to eq(1 / x) }
         
     | 
| 
      
 85 
     | 
    
         
            +
                it { expect(log10(x).d).to eq(1 / ( x * log( 10 ) )) }
         
     | 
| 
      
 86 
     | 
    
         
            +
                it { expect(log2(x).d).to eq(1 / ( x * log( 2 ) )) }
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                it { expect(x.d(x)).to eq(1) }
         
     | 
| 
      
 89 
     | 
    
         
            +
              end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
              describe 'Calculate' do
         
     | 
| 
      
 92 
     | 
    
         
            +
                context 'E with Fixnum' do
         
     | 
| 
      
 93 
     | 
    
         
            +
                  it { expect(e + 0).to eq(e) }
         
     | 
| 
      
 94 
     | 
    
         
            +
                  it { expect(e - 0).to eq(e) }
         
     | 
| 
      
 95 
     | 
    
         
            +
                  it { expect((e * 0).to_s).to eq('0') }
         
     | 
| 
      
 96 
     | 
    
         
            +
                  it { expect(e * 1).to eq(e) }
         
     | 
| 
      
 97 
     | 
    
         
            +
                  it { expect { (e / 0).to_s }.to raise_error(ZeroDivisionError) }
         
     | 
| 
      
 98 
     | 
    
         
            +
                  it { expect(e / 1).to eq(e) }
         
     | 
| 
      
 99 
     | 
    
         
            +
                  it { expect((e ** 0).to_s).to eq('1') }
         
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                context 'Fixnum with Formula' do
         
     | 
| 
      
 103 
     | 
    
         
            +
                  let(:formula) { (x + y) }
         
     | 
| 
      
 104 
     | 
    
         
            +
                  it { expect(0 + formula).to eq(formula) }
         
     | 
| 
      
 105 
     | 
    
         
            +
                  it { expect(0 - formula).to eq( - ( x + y ) ) }
         
     | 
| 
      
 106 
     | 
    
         
            +
                  it { expect(0 * formula).to eq(0) }
         
     | 
| 
      
 107 
     | 
    
         
            +
                  it { expect(1 * formula).to eq(formula) }
         
     | 
| 
      
 108 
     | 
    
         
            +
                  it { expect(0 / formula).to eq(0) }
         
     | 
| 
      
 109 
     | 
    
         
            +
                  it { expect(1 / formula).to eq( 1 / ( x + y ) ) }
         
     | 
| 
      
 110 
     | 
    
         
            +
                  it { expect(0 ** formula).to eq(0) }
         
     | 
| 
      
 111 
     | 
    
         
            +
                  it { expect(1 ** formula).to eq(1) }
         
     | 
| 
      
 112 
     | 
    
         
            +
                end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                context 'Fixnum with Symbol' do
         
     | 
| 
      
 115 
     | 
    
         
            +
                  it { expect(0 + x).to eq(x) }
         
     | 
| 
      
 116 
     | 
    
         
            +
                  it { expect(0 - x).to eq(- x) }
         
     | 
| 
      
 117 
     | 
    
         
            +
                  it { expect(0 * x).to eq(0) }
         
     | 
| 
      
 118 
     | 
    
         
            +
                  it { expect(1 * x).to eq(x) }
         
     | 
| 
      
 119 
     | 
    
         
            +
                  it { expect(0 / x).to eq(0) }
         
     | 
| 
      
 120 
     | 
    
         
            +
                  it { expect(1 / x).to eq( 1 / x ) }
         
     | 
| 
      
 121 
     | 
    
         
            +
                  it { expect(0 ** x).to eq(0) }
         
     | 
| 
      
 122 
     | 
    
         
            +
                  it { expect(1 ** x).to eq(1) }
         
     | 
| 
      
 123 
     | 
    
         
            +
                end
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                context 'Fixnum with Fixnum' do
         
     | 
| 
      
 126 
     | 
    
         
            +
                  it { expect(0 + 3).to eq(3) }
         
     | 
| 
      
 127 
     | 
    
         
            +
                  it { expect(3 + 0).to eq(3) }
         
     | 
| 
      
 128 
     | 
    
         
            +
                  it { expect(2 + 3).to eq(5) }
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                  it { expect(0 - 3).to eq(-3) }
         
     | 
| 
      
 131 
     | 
    
         
            +
                  it { expect(3 - 0).to eq(3) }
         
     | 
| 
      
 132 
     | 
    
         
            +
                  it { expect(2 - 3).to eq(-1) }
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                  it { expect(0 * 3).to eq(0) }
         
     | 
| 
      
 135 
     | 
    
         
            +
                  it { expect(3 * 0).to eq(0) }
         
     | 
| 
      
 136 
     | 
    
         
            +
                  it { expect(1 * 3).to eq(3) }
         
     | 
| 
      
 137 
     | 
    
         
            +
                  it { expect(3 * 1).to eq(3) }
         
     | 
| 
      
 138 
     | 
    
         
            +
                  it { expect(3 * 2).to eq(6) }
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                  it { expect((0 / 3).to_s).to eq('0') }
         
     | 
| 
      
 141 
     | 
    
         
            +
                  it { expect { (3 / 0).to_s }.to raise_error(ZeroDivisionError) }
         
     | 
| 
      
 142 
     | 
    
         
            +
                  it { expect((3 / 1).to_s).to eq('3') }
         
     | 
| 
      
 143 
     | 
    
         
            +
                  # TODO:
         
     | 
| 
      
 144 
     | 
    
         
            +
                  it { expect((2 / 3).to_s).to eq('0') }
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                  it { expect((0 ** 3).to_s).to eq('0') }
         
     | 
| 
      
 147 
     | 
    
         
            +
                  it { expect((3 ** 0).to_s).to eq('1') }
         
     | 
| 
      
 148 
     | 
    
         
            +
                  it { expect((1 ** 3).to_s).to eq('1') }
         
     | 
| 
      
 149 
     | 
    
         
            +
                  it { expect((3 ** 1).to_s).to eq('3') }
         
     | 
| 
      
 150 
     | 
    
         
            +
                  it { expect((3 ** 2).to_s).to eq('9') }
         
     | 
| 
      
 151 
     | 
    
         
            +
                end
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
                context 'Float with Formula' do
         
     | 
| 
      
 154 
     | 
    
         
            +
                  let(:formula) { (:x + :y) }
         
     | 
| 
      
 155 
     | 
    
         
            +
                  it { expect((0.0 + formula).to_s).to eq(formula.to_s) }
         
     | 
| 
      
 156 
     | 
    
         
            +
                  it { expect((0.0 - formula).to_s).to eq('( - ( x + y ) )') }
         
     | 
| 
      
 157 
     | 
    
         
            +
                  it { expect((0.0 * formula).to_s).to eq('0') }
         
     | 
| 
      
 158 
     | 
    
         
            +
                  it { expect((1.0 * formula).to_s).to eq(formula.to_s) }
         
     | 
| 
      
 159 
     | 
    
         
            +
                  it { expect((0.0 / formula).to_s).to eq('0') }
         
     | 
| 
      
 160 
     | 
    
         
            +
                  it { expect((1.0 / formula).to_s).to eq('( 1 / ( x + y ) )') }
         
     | 
| 
      
 161 
     | 
    
         
            +
                  it { expect((0.0 ** formula).to_s).to eq('0') }
         
     | 
| 
      
 162 
     | 
    
         
            +
                  it { expect((1.0 ** formula).to_s).to eq('1') }
         
     | 
| 
      
 163 
     | 
    
         
            +
                end
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
                context 'Float with Symbol' do
         
     | 
| 
      
 166 
     | 
    
         
            +
                  it { expect(0.0 + :x).to eq(:x) }
         
     | 
| 
      
 167 
     | 
    
         
            +
                  it { expect((0.0 - :x).to_s).to eq('( - x )') }
         
     | 
| 
      
 168 
     | 
    
         
            +
                  it { expect((0.0 * :x).to_s).to eq('0') }
         
     | 
| 
      
 169 
     | 
    
         
            +
                  it { expect(1.0 * :x).to eq(:x) }
         
     | 
| 
      
 170 
     | 
    
         
            +
                  it { expect((0.0 / :x).to_s).to eq('0') }
         
     | 
| 
      
 171 
     | 
    
         
            +
                  it { expect((1.0 / :x).to_s).to eq('( 1 / x )') }
         
     | 
| 
      
 172 
     | 
    
         
            +
                  it { expect((0.0 ** :x).to_s).to eq('0') }
         
     | 
| 
      
 173 
     | 
    
         
            +
                  it { expect((1.0 ** :x).to_s).to eq('1') }
         
     | 
| 
      
 174 
     | 
    
         
            +
                end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
                context 'Float with Float' do
         
     | 
| 
      
 177 
     | 
    
         
            +
                  it { expect(0.0 + 3.0).to eq(3.0) }
         
     | 
| 
      
 178 
     | 
    
         
            +
                  it { expect(3.0 + 0.0).to eq(3.0) }
         
     | 
| 
      
 179 
     | 
    
         
            +
                  it { expect(2.0 + 3.0).to eq(5.0) }
         
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
      
 181 
     | 
    
         
            +
                  it { expect(0.0 - 3.0).to eq(-3.0) }
         
     | 
| 
      
 182 
     | 
    
         
            +
                  it { expect(3.0 - 0.0).to eq(3.0) }
         
     | 
| 
      
 183 
     | 
    
         
            +
                  it { expect(2.0 - 3.0).to eq(-1.0) }
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
                  it { expect(0.0 * 3.0).to eq(0.0) }
         
     | 
| 
      
 186 
     | 
    
         
            +
                  it { expect(3.0 * 0.0).to eq(0.0) }
         
     | 
| 
      
 187 
     | 
    
         
            +
                  it { expect(1.0 * 3.0).to eq(3.0) }
         
     | 
| 
      
 188 
     | 
    
         
            +
                  it { expect(3.0 * 1.0).to eq(3.0) }
         
     | 
| 
      
 189 
     | 
    
         
            +
                  it { expect(3.0 * 2.0).to eq(6.0) }
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
                  it { expect(0.0 / 3.0).to eq(0.0) }
         
     | 
| 
      
 192 
     | 
    
         
            +
                  it { expect(3.0 / 0.0).to eq(oo) }
         
     | 
| 
      
 193 
     | 
    
         
            +
                  it { expect(3.0 / 1.0).to eq(3.0) }
         
     | 
| 
      
 194 
     | 
    
         
            +
                  # TODO:
         
     | 
| 
      
 195 
     | 
    
         
            +
                  it { expect(2.0 / 3.0).to eq(0.6666666666666666) }
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
                  it { expect(0.0 ** 3.0).to eq(0.0) }
         
     | 
| 
      
 198 
     | 
    
         
            +
                  it { expect(3.0 ** 0.0).to eq(1.0) }
         
     | 
| 
      
 199 
     | 
    
         
            +
                  it { expect(1.0 ** 3.0).to eq(1.0) }
         
     | 
| 
      
 200 
     | 
    
         
            +
                  it { expect(3.0 ** 1.0).to eq(3.0) }
         
     | 
| 
      
 201 
     | 
    
         
            +
                  it { expect(3.0 ** 2.0).to eq(9.0) }
         
     | 
| 
      
 202 
     | 
    
         
            +
                end
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
                context 'Pi with Fixnum' do
         
     | 
| 
      
 205 
     | 
    
         
            +
                  it { expect(pi + 0).to eq(pi) }
         
     | 
| 
      
 206 
     | 
    
         
            +
                  it { expect(pi - 0).to eq(pi) }
         
     | 
| 
      
 207 
     | 
    
         
            +
                  it { expect((pi * 0).to_s).to eq('0') }
         
     | 
| 
      
 208 
     | 
    
         
            +
                  it { expect(pi * 1).to eq(pi) }
         
     | 
| 
      
 209 
     | 
    
         
            +
                  it { expect { (pi / 0).to_s }.to raise_error(ZeroDivisionError) }
         
     | 
| 
      
 210 
     | 
    
         
            +
                  it { expect(pi / 1).to eq(pi) }
         
     | 
| 
      
 211 
     | 
    
         
            +
                  it { expect((pi ** 0).to_s).to eq('1') }
         
     | 
| 
      
 212 
     | 
    
         
            +
                end
         
     | 
| 
      
 213 
     | 
    
         
            +
             
     | 
| 
      
 214 
     | 
    
         
            +
                context 'Symbol with Fixnum' do
         
     | 
| 
      
 215 
     | 
    
         
            +
                  it { expect(x + 0).to eq(x) }
         
     | 
| 
      
 216 
     | 
    
         
            +
                  it { expect(x - 0).to eq(x) }
         
     | 
| 
      
 217 
     | 
    
         
            +
                  it { expect(x * 0).to eq(0) }
         
     | 
| 
      
 218 
     | 
    
         
            +
                  it { expect(x * 1).to eq(x) }
         
     | 
| 
      
 219 
     | 
    
         
            +
                  it { expect { x / 0 }.to raise_error(ZeroDivisionError) }
         
     | 
| 
      
 220 
     | 
    
         
            +
                  it { expect(x / 1).to eq(x) }
         
     | 
| 
      
 221 
     | 
    
         
            +
                  it { expect(x ** 0).to eq(1) }
         
     | 
| 
      
 222 
     | 
    
         
            +
                  it { expect(x ** 1).to eq(x) }
         
     | 
| 
      
 223 
     | 
    
         
            +
                end
         
     | 
| 
      
 224 
     | 
    
         
            +
             
     | 
| 
      
 225 
     | 
    
         
            +
                context 'Num with Num' do
         
     | 
| 
      
 226 
     | 
    
         
            +
                  it { expect(_(1) + _(2)).to eq(3) }
         
     | 
| 
      
 227 
     | 
    
         
            +
                  it { expect(_(1) - _(2)).to eq(-1) }
         
     | 
| 
      
 228 
     | 
    
         
            +
                  it { expect(_(1) * _(2)).to eq(2) }
         
     | 
| 
      
 229 
     | 
    
         
            +
                  it { expect((_(1) / _(2)).to_s).to eq('( 1 / 2 )') }
         
     | 
| 
      
 230 
     | 
    
         
            +
                  it { expect(_(1) % _(2)).to eq(1) }
         
     | 
| 
      
 231 
     | 
    
         
            +
                end
         
     | 
| 
      
 232 
     | 
    
         
            +
              end
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
              describe Dydx::Algebra::Set::Num do
         
     | 
| 
      
 235 
     | 
    
         
            +
                describe :< do
         
     | 
| 
      
 236 
     | 
    
         
            +
                  it { expect(_(1) < _(2)).to be(true) }
         
     | 
| 
      
 237 
     | 
    
         
            +
                  it { expect(_(1) < 2).to be(true) }
         
     | 
| 
      
 238 
     | 
    
         
            +
                  it { expect(_(2) < _(1)).to be(false) }
         
     | 
| 
      
 239 
     | 
    
         
            +
                  it { expect(_(2) < 1).to be(false) }
         
     | 
| 
      
 240 
     | 
    
         
            +
                end
         
     | 
| 
      
 241 
     | 
    
         
            +
             
     | 
| 
      
 242 
     | 
    
         
            +
                describe :<= do
         
     | 
| 
      
 243 
     | 
    
         
            +
                  it { expect(_(1) <= _(2)).to be(true) }
         
     | 
| 
      
 244 
     | 
    
         
            +
                  it { expect(_(1) <= 2).to be(true) }
         
     | 
| 
      
 245 
     | 
    
         
            +
                  it { expect(_(2) <= _(1)).to be(false) }
         
     | 
| 
      
 246 
     | 
    
         
            +
                  it { expect(_(2) <= 1).to be(false) }
         
     | 
| 
      
 247 
     | 
    
         
            +
                end
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
      
 249 
     | 
    
         
            +
                describe :> do
         
     | 
| 
      
 250 
     | 
    
         
            +
                  it { expect(_(1) > _(2)).to be(false) }
         
     | 
| 
      
 251 
     | 
    
         
            +
                  it { expect(_(1) > 2).to be(false) }
         
     | 
| 
      
 252 
     | 
    
         
            +
                  it { expect(_(2) > _(1)).to be(true) }
         
     | 
| 
      
 253 
     | 
    
         
            +
                  it { expect(_(2) > 1).to be(true) }
         
     | 
| 
      
 254 
     | 
    
         
            +
                end
         
     | 
| 
      
 255 
     | 
    
         
            +
             
     | 
| 
      
 256 
     | 
    
         
            +
                describe :>= do
         
     | 
| 
      
 257 
     | 
    
         
            +
                  it { expect(_(1) >= _(2)).to be(false) }
         
     | 
| 
      
 258 
     | 
    
         
            +
                  it { expect(_(1) >= 2).to be(false) }
         
     | 
| 
      
 259 
     | 
    
         
            +
                  it { expect(_(2) >= _(1)).to be(true) }
         
     | 
| 
      
 260 
     | 
    
         
            +
                  it { expect(_(2) >= 1).to be(true) }
         
     | 
| 
      
 261 
     | 
    
         
            +
                end
         
     | 
| 
      
 262 
     | 
    
         
            +
              end
         
     | 
| 
      
 263 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/lib/delta_spec.rb
    CHANGED
    
    | 
         @@ -1,11 +1,35 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            describe Dydx 
     | 
| 
       4 
     | 
    
         
            -
              it{ expect(d.class).to eq(Delta) }
         
     | 
| 
       5 
     | 
    
         
            -
              it{ expect(dx.class).to eq(Delta) }
         
     | 
| 
       6 
     | 
    
         
            -
              it{ expect(dx.var).to eq(:x) }
         
     | 
| 
       7 
     | 
    
         
            -
              it{ expect(dx(y).class).to eq(Delta) }
         
     | 
| 
       8 
     | 
    
         
            -
              it{ expect(dx(y).var).to eq(:x) }
         
     | 
| 
       9 
     | 
    
         
            -
              it{ expect(dx(y).function).to eq(:y) }
         
     | 
| 
       10 
     | 
    
         
            -
              it{ expect{dxy}.to raise_error(NameError) }
         
     | 
| 
      
 3 
     | 
    
         
            +
            describe Dydx::Delta do
         
     | 
| 
      
 4 
     | 
    
         
            +
              it { expect(d.class).to eq(Delta) }
         
     | 
| 
      
 5 
     | 
    
         
            +
              it { expect(dx.class).to eq(Delta) }
         
     | 
| 
      
 6 
     | 
    
         
            +
              it { expect(dx.var).to eq(:x) }
         
     | 
| 
      
 7 
     | 
    
         
            +
              it { expect(dx(y).class).to eq(Delta) }
         
     | 
| 
      
 8 
     | 
    
         
            +
              it { expect(dx(y).var).to eq(:x) }
         
     | 
| 
      
 9 
     | 
    
         
            +
              it { expect(dx(y).function).to eq(:y) }
         
     | 
| 
      
 10 
     | 
    
         
            +
              it { expect { dxy }.to raise_error(NameError) }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              before { reset }
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              it 'ex1' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                $y = x ** n
         
     | 
| 
      
 16 
     | 
    
         
            +
                expect(dy/dx).to eq( n * ( x ** ( n - 1 ) ) )
         
     | 
| 
      
 17 
     | 
    
         
            +
                expect(d/dx($y)).to eq( n * ( x ** ( n - 1 ) ) )
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              it 'ex2' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                $y = x ** (x * 2)
         
     | 
| 
      
 22 
     | 
    
         
            +
                expect(dy/dx).to eq(( 2 * x ) * ( x ** ( ( 2 * x ) - 1 ) ))
         
     | 
| 
      
 23 
     | 
    
         
            +
                expect(d/dx($y)).to eq(( 2 * x ) * ( x ** ( ( 2 * x ) - 1 ) ))
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              it 'ex3' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                $y = (t ** 2) / 2
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect(dy/dt).to eq(t)
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              it 'ex4' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                $y = 2 * (e ** (2 * z))
         
     | 
| 
      
 33 
     | 
    
         
            +
                expect(dy/dz).to eq(4 * ( e ** ( 2 * z ) ))
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
       11 
35 
     | 
    
         
             
            end
         
     | 
    
        data/spec/lib/function_spec.rb
    CHANGED
    
    | 
         @@ -1,39 +1,65 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            describe Dydx 
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
              it 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
               
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              it 
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
               
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              it 
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
      
 3 
     | 
    
         
            +
            describe Dydx::Function do
         
     | 
| 
      
 4 
     | 
    
         
            +
              before { reset }
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              it 'ex1' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                expect(f(x, y)).to eq(f(x, y))
         
     | 
| 
      
 8 
     | 
    
         
            +
                expect(f(x, y)).to eq($f)
         
     | 
| 
      
 9 
     | 
    
         
            +
                expect(f(x, y).algebra).to be_nil
         
     | 
| 
      
 10 
     | 
    
         
            +
                expect(f(x, y).vars).to eq([:x, :y])
         
     | 
| 
      
 11 
     | 
    
         
            +
                expect { f(x, y, z) }.to raise_error(ArgumentError)
         
     | 
| 
      
 12 
     | 
    
         
            +
                expect { f(x) }.to raise_error(ArgumentError)
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              it 'ex2' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                expect(f(x, y) <= x * y ).to eq(f(x, y))
         
     | 
| 
      
 17 
     | 
    
         
            +
                expect(f(x, y)).to eq(f(x, y))
         
     | 
| 
      
 18 
     | 
    
         
            +
                expect(f(x, y)).to eq($f)
         
     | 
| 
      
 19 
     | 
    
         
            +
                expect(f(x, y).algebra).to eq(x * y)
         
     | 
| 
      
 20 
     | 
    
         
            +
                expect(f(x, y)).to eq(x * y)
         
     | 
| 
      
 21 
     | 
    
         
            +
                expect(f(x, y)).to eq(eval(f(x, y).to_s))
         
     | 
| 
      
 22 
     | 
    
         
            +
                expect(f(a, b)).to eq(a * b)
         
     | 
| 
      
 23 
     | 
    
         
            +
                expect(f(2, x)).to eq(2 * x)
         
     | 
| 
      
 24 
     | 
    
         
            +
                expect(f(2, 3)).to eq(6)
         
     | 
| 
      
 25 
     | 
    
         
            +
                expect(f(a + b, c)).to eq((a + b) * c)
         
     | 
| 
      
 26 
     | 
    
         
            +
                expect(d/dx(f(x, y))).to eq(y)
         
     | 
| 
      
 27 
     | 
    
         
            +
                expect(d/dy(f(x, y))).to eq(x)
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect(d/dz(f(x, y))).to eq(0)
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              it 'ex3' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                f(x, y) <= x * y
         
     | 
| 
      
 33 
     | 
    
         
            +
                g(a, b) <= f(a + b, b)
         
     | 
| 
      
 34 
     | 
    
         
            +
                expect(g(a, b)).to eq((a + b) * b)
         
     | 
| 
      
 35 
     | 
    
         
            +
                expect(g(a, 3)).to eq(9 + 3 * a)
         
     | 
| 
      
 36 
     | 
    
         
            +
                expect(g(2, 3)).to eq(15)
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              it 'ex4' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                f(a, b) <= (a + b) * b
         
     | 
| 
      
 41 
     | 
    
         
            +
                h(a, b, c) <= d/db(f(a, b))
         
     | 
| 
      
 42 
     | 
    
         
            +
                expect(h(a, b, c)).to eq(( a + ( 2 * b ) ))
         
     | 
| 
      
 43 
     | 
    
         
            +
                expect(h(a, b, c).algebra).to eq(( a + ( 2 * b ) ))
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              it 'ex5' do
         
     | 
| 
       36 
47 
     | 
    
         
             
                f(x) <= log(x)
         
     | 
| 
       37 
     | 
    
         
            -
                expect(f( 
     | 
| 
      
 48 
     | 
    
         
            +
                expect(f(e)).to eq(1)
         
     | 
| 
      
 49 
     | 
    
         
            +
                expect(f(0)).to eq(-oo)
         
     | 
| 
      
 50 
     | 
    
         
            +
                expect(f(y)).to eq(log(y))
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                g(x) <= d/dx(f(x))
         
     | 
| 
      
 53 
     | 
    
         
            +
                expect(g(1)).to eq(1)
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              it 'ex6' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                f(x) <= sin(x)
         
     | 
| 
      
 58 
     | 
    
         
            +
                expect(f(pi)).to eq(0)
         
     | 
| 
      
 59 
     | 
    
         
            +
                expect(f(pi / 2)).to eq(1)
         
     | 
| 
      
 60 
     | 
    
         
            +
                expect(f(y)).to eq(sin(y))
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                g(x) <= d/dx(f(x))
         
     | 
| 
      
 63 
     | 
    
         
            +
                expect(g(pi)).to eq(-1)
         
     | 
| 
       38 
64 
     | 
    
         
             
              end
         
     | 
| 
       39 
65 
     | 
    
         
             
            end
         
     | 
    
        data/spec/lib/helper_spec.rb
    CHANGED
    
    | 
         @@ -3,70 +3,63 @@ require 'spec_helper' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            describe Helper do
         
     | 
| 
       4 
4 
     | 
    
         
             
              include Helper
         
     | 
| 
       5 
5 
     | 
    
         
             
              context '#is_n?' do
         
     | 
| 
       6 
     | 
    
         
            -
                it{ expect(0. 
     | 
| 
       7 
     | 
    
         
            -
                it{ expect(_(0). 
     | 
| 
       8 
     | 
    
         
            -
                it{ expect(inverse(0, :+). 
     | 
| 
       9 
     | 
    
         
            -
                it{ expect(1. 
     | 
| 
       10 
     | 
    
         
            -
                it{ expect(_(1). 
     | 
| 
       11 
     | 
    
         
            -
                it{ expect(inverse(1, :*). 
     | 
| 
       12 
     | 
    
         
            -
                it{ expect(-1. 
     | 
| 
       13 
     | 
    
         
            -
                it{ expect(_(-1). 
     | 
| 
      
 6 
     | 
    
         
            +
                it { expect(0.zero?).to be true }
         
     | 
| 
      
 7 
     | 
    
         
            +
                it { expect(_(0).zero?).to be true }
         
     | 
| 
      
 8 
     | 
    
         
            +
                it { expect(inverse(0, :+).zero?).to be true }
         
     | 
| 
      
 9 
     | 
    
         
            +
                it { expect(1.one?).to be true }
         
     | 
| 
      
 10 
     | 
    
         
            +
                it { expect(_(1).one?).to be true }
         
     | 
| 
      
 11 
     | 
    
         
            +
                it { expect(inverse(1, :*).one?).to be true }
         
     | 
| 
      
 12 
     | 
    
         
            +
                it { expect(-1.minus1?).to be true }
         
     | 
| 
      
 13 
     | 
    
         
            +
                it { expect(_(-1).minus1?).to be true }
         
     | 
| 
       14 
14 
     | 
    
         
             
              end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
              context '# 
     | 
| 
       17 
     | 
    
         
            -
                it{ expect(0. 
     | 
| 
       18 
     | 
    
         
            -
                it{ expect(_(0).is_multiple_of(:y).to_s).to eq('0')}
         
     | 
| 
      
 16 
     | 
    
         
            +
              context '#multiple_of?' do
         
     | 
| 
      
 17 
     | 
    
         
            +
                it { expect(0.multiple_of?(x)).to be(true) }
         
     | 
| 
       19 
18 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                it{ expect( 
     | 
| 
       21 
     | 
    
         
            -
                it{ expect( 
     | 
| 
      
 19 
     | 
    
         
            +
                it { expect(4.multiple_of?(_(2))).to be(true) }
         
     | 
| 
      
 20 
     | 
    
         
            +
                it { expect(_(4).multiple_of?(2)).to be(true) }
         
     | 
| 
      
 21 
     | 
    
         
            +
                it { expect(_(4).multiple_of?(_(2))).to be(true) }
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                it{ expect( 
     | 
| 
       24 
     | 
    
         
            -
                it{ expect( 
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 23 
     | 
    
         
            +
                it { expect(x.multiple_of?(x)).to be(true) }
         
     | 
| 
      
 24 
     | 
    
         
            +
                it { expect(x.multiple_of?(y)).to be(false) }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                it { expect((x * y).multiple_of?(x)).to be(true) }
         
     | 
| 
      
 27 
     | 
    
         
            +
                it { expect((x * y).multiple_of?(x)).to be(true) }
         
     | 
| 
      
 28 
     | 
    
         
            +
                it { expect((x * y).multiple_of?(z)).to be(false) }
         
     | 
| 
       26 
29 
     | 
    
         
             
              end
         
     | 
| 
       27 
30 
     | 
    
         | 
| 
       28 
31 
     | 
    
         
             
              context '#like_term?' do
         
     | 
| 
       29 
     | 
    
         
            -
                it{ expect(x.like_term?(x)).to  
     | 
| 
       30 
     | 
    
         
            -
                it{ expect((2 * x).like_term?((3 * x))).to  
     | 
| 
      
 32 
     | 
    
         
            +
                it { expect(x.like_term?(x)).to be true }
         
     | 
| 
      
 33 
     | 
    
         
            +
                it { expect((2 * x).like_term?((3 * x))).to be true }
         
     | 
| 
       31 
34 
     | 
    
         
             
              end
         
     | 
| 
       32 
35 
     | 
    
         | 
| 
       33 
36 
     | 
    
         
             
              context '#combinable?' do
         
     | 
| 
       34 
     | 
    
         
            -
                it{ expect(:x.combinable?(:x, :+)).to  
     | 
| 
       35 
     | 
    
         
            -
                it{ expect(:x.combinable?(2 * :x, :+)).to  
     | 
| 
       36 
     | 
    
         
            -
                it{ expect((2 * :x).combinable?(:x, :+)).to  
     | 
| 
       37 
     | 
    
         
            -
                it{ expect((2 * :x).combinable?(2 * :x, :+)).to  
     | 
| 
       38 
     | 
    
         
            -
                it{ expect(:x.combinable?(:y, :+)).to  
     | 
| 
       39 
     | 
    
         
            -
                it{ expect(1.combinable?(2, :+)).to  
     | 
| 
       40 
     | 
    
         
            -
                it{ expect(:x.combinable?(:x, :*)).to  
     | 
| 
       41 
     | 
    
         
            -
                it{ expect(:x.combinable?(:y, :*)).to  
     | 
| 
       42 
     | 
    
         
            -
                it{ expect(1.combinable?(2, :*)).to  
     | 
| 
       43 
     | 
    
         
            -
                it{ expect(0.combinable?(:x,  
     | 
| 
       44 
     | 
    
         
            -
                it{ expect(1.combinable?(:y,  
     | 
| 
      
 37 
     | 
    
         
            +
                it { expect(:x.combinable?(:x, :+)).to be true }
         
     | 
| 
      
 38 
     | 
    
         
            +
                it { expect(:x.combinable?(2 * :x, :+)).to be true }
         
     | 
| 
      
 39 
     | 
    
         
            +
                it { expect((2 * :x).combinable?(:x, :+)).to be true }
         
     | 
| 
      
 40 
     | 
    
         
            +
                it { expect((2 * :x).combinable?(2 * :x, :+)).to be true }
         
     | 
| 
      
 41 
     | 
    
         
            +
                it { expect(:x.combinable?(:y, :+)).to be false }
         
     | 
| 
      
 42 
     | 
    
         
            +
                it { expect(1.combinable?(2, :+)).to be true }
         
     | 
| 
      
 43 
     | 
    
         
            +
                it { expect(:x.combinable?(:x, :*)).to be true }
         
     | 
| 
      
 44 
     | 
    
         
            +
                it { expect(:x.combinable?(:y, :*)).to be false }
         
     | 
| 
      
 45 
     | 
    
         
            +
                it { expect(1.combinable?(2, :*)).to be true }
         
     | 
| 
      
 46 
     | 
    
         
            +
                it { expect(0.combinable?(:x, :**)).to be true }
         
     | 
| 
      
 47 
     | 
    
         
            +
                it { expect(1.combinable?(:y, :**)).to be true }
         
     | 
| 
       45 
48 
     | 
    
         
             
              end
         
     | 
| 
       46 
49 
     | 
    
         | 
| 
       47 
50 
     | 
    
         
             
              context '#distributive?' do
         
     | 
| 
       48 
     | 
    
         
            -
                it{ expect(distributive?(:+, :*)).to  
     | 
| 
       49 
     | 
    
         
            -
                it{ expect(distributive?(:+, :/)).to  
     | 
| 
       50 
     | 
    
         
            -
                it{ expect(distributive?(:-, :*)).to  
     | 
| 
       51 
     | 
    
         
            -
                it{ expect(distributive?(:-, :/)).to  
     | 
| 
       52 
     | 
    
         
            -
                it{ expect(distributive?(:*,  
     | 
| 
       53 
     | 
    
         
            -
                it{ expect(distributive?(:/,  
     | 
| 
       54 
     | 
    
         
            -
                it{ expect(distributive?(:*, :+)).to  
     | 
| 
       55 
     | 
    
         
            -
                it{ expect(distributive?( 
     | 
| 
      
 51 
     | 
    
         
            +
                it { expect(distributive?(:+, :*)).to be true }
         
     | 
| 
      
 52 
     | 
    
         
            +
                it { expect(distributive?(:+, :/)).to be true }
         
     | 
| 
      
 53 
     | 
    
         
            +
                it { expect(distributive?(:-, :*)).to be true }
         
     | 
| 
      
 54 
     | 
    
         
            +
                it { expect(distributive?(:-, :/)).to be true }
         
     | 
| 
      
 55 
     | 
    
         
            +
                it { expect(distributive?(:*, :**)).to be true }
         
     | 
| 
      
 56 
     | 
    
         
            +
                it { expect(distributive?(:/, :**)).to be true }
         
     | 
| 
      
 57 
     | 
    
         
            +
                it { expect(distributive?(:*, :+)).to be false }
         
     | 
| 
      
 58 
     | 
    
         
            +
                it { expect(distributive?(:**, :*)).to be false }
         
     | 
| 
       56 
59 
     | 
    
         
             
              end
         
     | 
| 
       57 
60 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
               
     | 
| 
       59 
     | 
    
         
            -
               
     | 
| 
       60 
     | 
    
         
            -
               
     | 
| 
       61 
     | 
    
         
            -
               
     | 
| 
       62 
     | 
    
         
            -
              let(:exponentiation){ (:x ^ :y) }
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
              it{ expect(addition.addition?).to be_true }
         
     | 
| 
       65 
     | 
    
         
            -
              it{ expect(multiplication.multiplication?).to be_true }
         
     | 
| 
       66 
     | 
    
         
            -
              it{ expect(exponentiation.exponentiation?).to be_true }
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
              it{ expect(inverse(:x, :+).inverse?(:+, :x)).to be_true }
         
     | 
| 
       69 
     | 
    
         
            -
              it{ expect(:x.inverse?(:+, inverse(:x, :+))).to be_true }
         
     | 
| 
       70 
     | 
    
         
            -
              it{ expect(inverse(:x, :*).inverse?(:*, :x)).to be_true }
         
     | 
| 
       71 
     | 
    
         
            -
              it{ expect(:x.inverse?(:*, inverse(:x, :*))).to be_true }
         
     | 
| 
      
 61 
     | 
    
         
            +
              it { expect(inverse(x, :+).inverse?(:+, x)).to be true }
         
     | 
| 
      
 62 
     | 
    
         
            +
              it { expect(x.inverse?(:+, inverse(x, :+))).to be true }
         
     | 
| 
      
 63 
     | 
    
         
            +
              it { expect(inverse(x, :*).inverse?(:*, x)).to be true }
         
     | 
| 
      
 64 
     | 
    
         
            +
              it { expect(x.inverse?(:*, inverse(x, :*))).to be true }
         
     | 
| 
       72 
65 
     | 
    
         
             
            end
         
     |