dydx 0.1.31 → 0.1.314
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -59
- data/lib/dydx.rb +7 -4
- data/lib/dydx/algebra.rb +0 -66
- data/lib/dydx/algebra/formula.rb +15 -2
- data/lib/dydx/algebra/inverse.rb +14 -0
- data/lib/dydx/algebra/set.rb +253 -19
- data/lib/dydx/helper.rb +5 -0
- data/lib/dydx/integrand.rb +7 -2
- data/lib/dydx/version.rb +1 -1
- data/spec/dydx_spec.rb +10 -29
- data/spec/lib/algebra/formula_spec.rb +6 -0
- data/spec/lib/algebra/set_spec.rb +227 -0
- data/spec/lib/delta_spec.rb +26 -0
- data/spec/lib/function_spec.rb +61 -33
- data/spec/lib/integrand_spec.rb +2 -2
- metadata +4 -40
- data/lib/dydx/algebra/operator.rb +0 -5
- 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/log10.rb +0 -22
- data/lib/dydx/algebra/set/log2.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/log10_spec.rb +0 -16
- data/spec/lib/algebra/set/log2_spec.rb +0 -16
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3575108c38dd6f4c3e191dcada2dfcc03e11b10
|
4
|
+
data.tar.gz: 37dbeb379531178c52253e213f6b79b930b0d9b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 047b709dd5da3ec9b0058c86ced1755fbee7928279794c1f4d366c9f3e50c27a948e6feba092425073a3a3dc6781dfdacd4d5724aa947a41393ef6ae4e511c2f
|
7
|
+
data.tar.gz: 846c7e77de2aad86f4e65a8b7e6cac39f88c9427b00c39fe7297efc6aa2d34f260450233c09ecca108200e2f8eb1cec492f7d0af48815bf24d1e85c0f916b6f4
|
data/README.md
CHANGED
@@ -19,29 +19,31 @@ require 'dydx'
|
|
19
19
|
include Dydx
|
20
20
|
|
21
21
|
# Define the function. syntax is not good enough...
|
22
|
-
f(x) <= x
|
22
|
+
f(x, y) <= x + x*y + y
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# simplify
|
25
|
+
f(x, y) == x * (1 + y) + y
|
26
|
+
=> true
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
#part substitution
|
29
|
+
f(a, 2) == 3*a + 2
|
30
|
+
=> true
|
29
31
|
|
30
|
-
f(
|
32
|
+
f(1, a + b) == 1 + 2 * ( a + b )
|
31
33
|
=> true
|
32
34
|
|
35
|
+
|
33
36
|
# Differentiate
|
34
|
-
|
37
|
+
d/dx(f(x, y)) == 1 + y
|
38
|
+
=> true
|
35
39
|
|
36
|
-
g(
|
37
|
-
=> 6
|
40
|
+
g(x) <= sin(x)
|
38
41
|
|
39
|
-
g(x)
|
40
|
-
=> '2 * x'
|
42
|
+
d/dx(g(x)) == cos(x)
|
41
43
|
|
42
44
|
# Integrate
|
43
|
-
S(
|
44
|
-
=> 0
|
45
|
+
S(g(x), dx)[0, pi/2]
|
46
|
+
=> 1.0
|
45
47
|
```
|
46
48
|
|
47
49
|
|
@@ -52,18 +54,14 @@ f(z) <= log(z)
|
|
52
54
|
S(f(z), dz)[0,1]
|
53
55
|
=> -Infinity
|
54
56
|
|
55
|
-
|
56
|
-
=>
|
57
|
-
|
58
|
-
( d/dx(cos(x)) ).to_s
|
59
|
-
=> "( - sin( x ) )"
|
57
|
+
d/dx(log(x)) == 1 / x
|
58
|
+
=> true
|
60
59
|
|
61
|
-
|
62
|
-
=>
|
60
|
+
d/dx(cos(x)) == -cos(x)
|
61
|
+
=> true
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
=> 1.0
|
63
|
+
d/dx(e ^ x) == e ^ x
|
64
|
+
=> true
|
67
65
|
|
68
66
|
# standard normal distribution;
|
69
67
|
f(x) <= (1.0 / ( ( 2.0 * pi ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
|
@@ -71,38 +69,6 @@ S(f(x), dx)[-oo, oo]
|
|
71
69
|
=> 1.0
|
72
70
|
```
|
73
71
|
|
74
|
-
#### it's like a magic...
|
75
|
-
|
76
|
-
```ruby:
|
77
|
-
f(x) <= x ^ 2
|
78
|
-
|
79
|
-
f(a + b).to_s
|
80
|
-
=> "( ( a + b ) ^ 2 )"
|
81
|
-
|
82
|
-
#↓it's like a magic!!!
|
83
|
-
g(a, b) <= f(a + b)
|
84
|
-
|
85
|
-
g(a, b).to_s
|
86
|
-
=> "( ( a + b ) ^ 2 )"
|
87
|
-
|
88
|
-
g(2, 2)
|
89
|
-
=> 16
|
90
|
-
|
91
|
-
( d/da(g(a, b)) ).to_s
|
92
|
-
=> "( 2 * ( a + b ) )"
|
93
|
-
|
94
|
-
# simplify
|
95
|
-
((x * y) + (z * x)).to_s
|
96
|
-
=> "( x * ( y + z ) )"
|
97
|
-
|
98
|
-
((x ^ y) / (x ^ z)).to_s
|
99
|
-
=> "( x ^ ( y - z ) )"
|
100
|
-
|
101
|
-
(x + x).to_s
|
102
|
-
=> "( 2 * x )"
|
103
|
-
```
|
104
|
-
|
105
|
-
|
106
72
|
## Documents
|
107
73
|
I'm going to write now...cominng soon....
|
108
74
|
|
@@ -111,14 +77,11 @@ I'm going to write now...cominng soon....
|
|
111
77
|
```
|
112
78
|
Dydx
|
113
79
|
|- Algebra
|
114
|
-
| |- Set
|
115
|
-
| | |- Num
|
116
|
-
| | |- ....
|
117
|
-
| |
|
118
80
|
| |- Operator
|
119
81
|
| | |- Interface
|
120
82
|
| | |- ....
|
121
83
|
| |
|
84
|
+
| |- Set
|
122
85
|
| |- Formula
|
123
86
|
| |- inverse
|
124
87
|
|
|
data/lib/dydx.rb
CHANGED
@@ -6,7 +6,7 @@ require 'dydx/integrand'
|
|
6
6
|
|
7
7
|
module Dydx
|
8
8
|
include Algebra
|
9
|
-
%w(f g h).each do |functioner|
|
9
|
+
%w(f g h int_f).each do |functioner|
|
10
10
|
define_method(functioner) do |*vars|
|
11
11
|
function = eval("$#{functioner}")
|
12
12
|
return eval("$#{functioner} = Function.new(*vars)") unless function
|
@@ -15,9 +15,12 @@ module Dydx
|
|
15
15
|
return function if function.vars == vars
|
16
16
|
return function unless function.algebra
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
subst_hash = Hash[*[function.vars, vars].transpose.flatten]
|
19
|
+
begin
|
20
|
+
function.algebra.subst(subst_hash).to_f
|
21
|
+
rescue ArgumentError
|
22
|
+
eval(function.algebra.subst(subst_hash).to_s)
|
23
|
+
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
data/lib/dydx/algebra.rb
CHANGED
@@ -1,77 +1,11 @@
|
|
1
1
|
require 'dydx/algebra/set'
|
2
|
-
require 'dydx/algebra/operator'
|
3
2
|
require 'dydx/algebra/formula'
|
4
3
|
require 'dydx/algebra/inverse'
|
5
4
|
|
6
5
|
module Dydx
|
7
6
|
module Algebra
|
8
7
|
include Set
|
9
|
-
module Set
|
10
|
-
# TODO: Refactor
|
11
|
-
Fixnum.class_eval do
|
12
|
-
alias_method :addition, :+
|
13
|
-
alias_method :subtraction, :-
|
14
|
-
alias_method :multiplication, :*
|
15
|
-
alias_method :division, :/
|
16
|
-
alias_method :exponentiation, :**
|
17
|
-
ope_to_str = {
|
18
|
-
addition: :+,
|
19
|
-
subtraction: :-,
|
20
|
-
multiplication: :*,
|
21
|
-
division: :/,
|
22
|
-
exponentiation: :^
|
23
|
-
}
|
24
|
-
%w(+ - * / ^).each do |operator|
|
25
|
-
define_method(operator) do |g|
|
26
|
-
if g.is_a?(Symbol) ||
|
27
|
-
g.is_a?(Formula) ||
|
28
|
-
g.is_a?(Base)
|
29
8
|
|
30
|
-
Num.new(self).send(operator.to_sym, g)
|
31
|
-
else
|
32
|
-
send(ope_to_str.key(operator.to_sym), g)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
Float.class_eval do
|
39
|
-
alias_method :addition, :+
|
40
|
-
alias_method :subtraction, :-
|
41
|
-
alias_method :multiplication, :*
|
42
|
-
alias_method :division, :/
|
43
|
-
alias_method :exponentiation, :**
|
44
|
-
ope_to_str = {
|
45
|
-
addition: :+,
|
46
|
-
subtraction: :-,
|
47
|
-
multiplication: :*,
|
48
|
-
division: :/,
|
49
|
-
exponentiation: :^
|
50
|
-
}
|
51
|
-
%w(+ - * / ^).each do |operator|
|
52
|
-
define_method(operator) do |g|
|
53
|
-
if g.is_a?(Symbol) ||
|
54
|
-
g.is_a?(Formula) ||
|
55
|
-
g.is_a?(Base)
|
56
|
-
|
57
|
-
Num.new(self).send(operator.to_sym, g)
|
58
|
-
else
|
59
|
-
send(ope_to_str.key(operator.to_sym), g)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
Symbol.class_eval{ include Operator::General }
|
65
|
-
class Num; include Operator::Num; end
|
66
|
-
class E; include Operator::General; end
|
67
|
-
class Pi; include Operator::General; end
|
68
|
-
class Log; include Operator::General; end
|
69
|
-
class Log2; include Operator::General; end
|
70
|
-
class Log10; include Operator::General; end
|
71
|
-
class Sin; include Operator::General; end
|
72
|
-
class Cos; include Operator::General; end
|
73
|
-
class Tan; include Operator::General; end
|
74
|
-
end
|
75
9
|
class Formula; include Operator::Formula; end
|
76
10
|
class Inverse; include Operator::Inverse; end
|
77
11
|
|
data/lib/dydx/algebra/formula.rb
CHANGED
@@ -40,6 +40,14 @@ module Dydx
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
def subst(hash = {})
|
44
|
+
f.subst(hash).send(operator, g.subst(hash))
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_f
|
48
|
+
f.to_f.send(operator, g.to_f)
|
49
|
+
end
|
50
|
+
|
43
51
|
def include?(x)
|
44
52
|
f == x || g == x
|
45
53
|
end
|
@@ -49,9 +57,14 @@ module Dydx
|
|
49
57
|
(f.combinable?(x, operator) || g.combinable?(x, operator))
|
50
58
|
end
|
51
59
|
|
52
|
-
# TODO: interchangeable
|
53
60
|
def ==(x)
|
54
|
-
to_s == x.to_s
|
61
|
+
if to_s == x.to_s
|
62
|
+
true
|
63
|
+
else
|
64
|
+
result = commutate!.to_s == x.to_s
|
65
|
+
commutate!
|
66
|
+
result
|
67
|
+
end
|
55
68
|
end
|
56
69
|
|
57
70
|
def common_factors(formula)
|
data/lib/dydx/algebra/inverse.rb
CHANGED
@@ -15,6 +15,20 @@ module Dydx
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def subst(hash = {})
|
19
|
+
case operator
|
20
|
+
when :+ then x.subst(hash) * -1
|
21
|
+
when :* then x.subst(hash) ** -1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_f
|
26
|
+
case operator
|
27
|
+
when :+ then x.to_f * -1
|
28
|
+
when :* then x.to_f ** -1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
18
32
|
def differentiate(sym=:x)
|
19
33
|
case operator
|
20
34
|
when :+
|
data/lib/dydx/algebra/set.rb
CHANGED
@@ -1,20 +1,253 @@
|
|
1
|
-
require 'dydx/algebra/
|
2
|
-
require 'dydx/algebra/
|
3
|
-
require 'dydx/algebra/
|
4
|
-
require 'dydx/algebra/
|
5
|
-
require 'dydx/algebra/
|
6
|
-
require 'dydx/algebra/set/e'
|
7
|
-
require 'dydx/algebra/set/pi'
|
8
|
-
require 'dydx/algebra/set/log'
|
9
|
-
require 'dydx/algebra/set/log2'
|
10
|
-
require 'dydx/algebra/set/log10'
|
11
|
-
require 'dydx/algebra/set/sin'
|
12
|
-
require 'dydx/algebra/set/cos'
|
13
|
-
require 'dydx/algebra/set/tan'
|
1
|
+
require 'dydx/algebra/operator/parts'
|
2
|
+
require 'dydx/algebra/operator/inverse'
|
3
|
+
require 'dydx/algebra/operator/formula'
|
4
|
+
require 'dydx/algebra/operator/num'
|
5
|
+
require 'dydx/algebra/operator/general'
|
14
6
|
|
15
7
|
module Dydx
|
16
8
|
module Algebra
|
17
9
|
module Set
|
10
|
+
module Base
|
11
|
+
include Helper
|
12
|
+
|
13
|
+
# TODO: Pi should not have attr_accessor
|
14
|
+
def self.included(klass)
|
15
|
+
attr_accessor :n, :x
|
16
|
+
alias_method :d, :differentiate
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(x=nil)
|
20
|
+
case self
|
21
|
+
when Num
|
22
|
+
@n = x
|
23
|
+
when Sin, Cos, Tan, Log, Log10, Log2
|
24
|
+
@x = x
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
case self
|
30
|
+
when Num then n.to_s
|
31
|
+
when Pi then 'pi'
|
32
|
+
when E then 'e'
|
33
|
+
when Sin then "sin( #{x.to_s} )"
|
34
|
+
when Cos then "cos( #{x.to_s} )"
|
35
|
+
when Tan then "tan( #{x.to_s} )"
|
36
|
+
when Log then "log( #{x.to_s} )"
|
37
|
+
when Log10 then "log10( #{x.to_s} )"
|
38
|
+
when Log2 then "log2( #{x.to_s} )"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_f
|
43
|
+
case self
|
44
|
+
when Num then n.to_f
|
45
|
+
when Pi then Math::PI
|
46
|
+
when E then Math::E
|
47
|
+
when Symbol then raise ArgumentError
|
48
|
+
when Sin then Math.sin(x.to_f)
|
49
|
+
when Cos then Math.cos(x.to_f)
|
50
|
+
when Tan then Math.tan(x.to_f)
|
51
|
+
when Log then Math.log(x.to_f)
|
52
|
+
when Log10 then Math.log(x.to_f, 10)
|
53
|
+
when Log2 then Math.log(x.to_f, 2)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def subst(hash = {})
|
58
|
+
case self
|
59
|
+
when Num, Pi, E
|
60
|
+
self
|
61
|
+
when Symbol
|
62
|
+
hash[self] || self
|
63
|
+
when Sin then sin(x.subst(hash))
|
64
|
+
when Cos then cos(x.subst(hash))
|
65
|
+
when Tan then tan(x.subst(hash))
|
66
|
+
when Log then log(x.subst(hash))
|
67
|
+
when Log10 then log10(x.subst(hash))
|
68
|
+
when Log2 then log2(x.subst(hash))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def differentiate(sym = :x)
|
73
|
+
case self
|
74
|
+
when Num, Pi, E then e0
|
75
|
+
when Symbol then self == sym ? e1 : e0
|
76
|
+
when Sin then cos(x) * x.d(sym)
|
77
|
+
when Cos then -1 * sin(x) * x.d(sym)
|
78
|
+
when Tan then 1 / (cos(x) ** 2)
|
79
|
+
when Log then x.d(sym) / (x)
|
80
|
+
when Log10 then x.d(sym) / (x * log(10))
|
81
|
+
when Log2 then x.d(sym) / (x * log(2))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class Num
|
87
|
+
include Base
|
88
|
+
include Operator::Num
|
89
|
+
end
|
90
|
+
|
91
|
+
class Pi
|
92
|
+
include Base
|
93
|
+
include Operator::General
|
94
|
+
end
|
95
|
+
|
96
|
+
class E
|
97
|
+
include Base
|
98
|
+
include Operator::General
|
99
|
+
end
|
100
|
+
|
101
|
+
class Sin
|
102
|
+
include Base
|
103
|
+
include Operator::General
|
104
|
+
end
|
105
|
+
|
106
|
+
class Cos
|
107
|
+
include Base
|
108
|
+
include Operator::General
|
109
|
+
end
|
110
|
+
|
111
|
+
class Tan
|
112
|
+
include Base
|
113
|
+
include Operator::General
|
114
|
+
end
|
115
|
+
|
116
|
+
class Log
|
117
|
+
include Base
|
118
|
+
include Operator::General
|
119
|
+
end
|
120
|
+
|
121
|
+
class Log10
|
122
|
+
include Base
|
123
|
+
include Operator::General
|
124
|
+
end
|
125
|
+
|
126
|
+
class Log2
|
127
|
+
include Base
|
128
|
+
include Operator::General
|
129
|
+
end
|
130
|
+
|
131
|
+
Symbol.class_eval do
|
132
|
+
include Base
|
133
|
+
include Operator::General
|
134
|
+
end
|
135
|
+
|
136
|
+
# FIX: Numeric
|
137
|
+
Fixnum.class_eval do
|
138
|
+
include Helper
|
139
|
+
|
140
|
+
def subst(hash = {})
|
141
|
+
self
|
142
|
+
end
|
143
|
+
|
144
|
+
def differentiate(sym=:x)
|
145
|
+
e0
|
146
|
+
end
|
147
|
+
alias_method :d, :differentiate
|
148
|
+
|
149
|
+
alias_method :addition, :+
|
150
|
+
alias_method :subtraction, :-
|
151
|
+
alias_method :multiplication, :*
|
152
|
+
alias_method :division, :/
|
153
|
+
alias_method :exponentiation, :**
|
154
|
+
ope_to_str = {
|
155
|
+
addition: :+,
|
156
|
+
subtraction: :-,
|
157
|
+
multiplication: :*,
|
158
|
+
division: :/,
|
159
|
+
exponentiation: :^
|
160
|
+
}
|
161
|
+
%w(+ - * / ^).each do |operator|
|
162
|
+
define_method(operator) do |g|
|
163
|
+
if g.is_a?(Symbol) ||
|
164
|
+
g.is_a?(Formula) ||
|
165
|
+
g.is_a?(Base)
|
166
|
+
|
167
|
+
Num.new(self).send(operator.to_sym, g)
|
168
|
+
else
|
169
|
+
send(ope_to_str.key(operator.to_sym), g)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
Float.class_eval do
|
176
|
+
include Helper
|
177
|
+
|
178
|
+
def subst(hash = {})
|
179
|
+
self
|
180
|
+
end
|
181
|
+
|
182
|
+
def differentiate(sym=:x)
|
183
|
+
e0
|
184
|
+
end
|
185
|
+
alias_method :d, :differentiate
|
186
|
+
|
187
|
+
alias_method :addition, :+
|
188
|
+
alias_method :subtraction, :-
|
189
|
+
alias_method :multiplication, :*
|
190
|
+
alias_method :division, :/
|
191
|
+
alias_method :exponentiation, :**
|
192
|
+
ope_to_str = {
|
193
|
+
addition: :+,
|
194
|
+
subtraction: :-,
|
195
|
+
multiplication: :*,
|
196
|
+
division: :/,
|
197
|
+
exponentiation: :^
|
198
|
+
}
|
199
|
+
%w(+ - * / ^).each do |operator|
|
200
|
+
define_method(operator) do |g|
|
201
|
+
if g.is_a?(Symbol) ||
|
202
|
+
g.is_a?(Formula) ||
|
203
|
+
g.is_a?(Base)
|
204
|
+
|
205
|
+
Num.new(self).send(operator.to_sym, g)
|
206
|
+
else
|
207
|
+
send(ope_to_str.key(operator.to_sym), g)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
Rational.class_eval do
|
214
|
+
include Helper
|
215
|
+
|
216
|
+
def subst(hash = {})
|
217
|
+
self
|
218
|
+
end
|
219
|
+
|
220
|
+
def differentiate(sym=:x)
|
221
|
+
e0
|
222
|
+
end
|
223
|
+
alias_method :d, :differentiate
|
224
|
+
|
225
|
+
alias_method :addition, :+
|
226
|
+
alias_method :subtraction, :-
|
227
|
+
alias_method :multiplication, :*
|
228
|
+
alias_method :division, :/
|
229
|
+
alias_method :exponentiation, :**
|
230
|
+
ope_to_str = {
|
231
|
+
addition: :+,
|
232
|
+
subtraction: :-,
|
233
|
+
multiplication: :*,
|
234
|
+
division: :/,
|
235
|
+
exponentiation: :^
|
236
|
+
}
|
237
|
+
%w(+ - * / ^).each do |operator|
|
238
|
+
define_method(operator) do |g|
|
239
|
+
if g.is_a?(Symbol) ||
|
240
|
+
g.is_a?(Formula) ||
|
241
|
+
g.is_a?(Base)
|
242
|
+
|
243
|
+
Num.new(self).send(operator.to_sym, g)
|
244
|
+
else
|
245
|
+
send(ope_to_str.key(operator.to_sym), g)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
18
251
|
def e0
|
19
252
|
eval("$e0 ||= Num.new(0)")
|
20
253
|
end
|
@@ -22,12 +255,9 @@ module Dydx
|
|
22
255
|
def e1
|
23
256
|
eval("$e1 ||= Num.new(1)")
|
24
257
|
end
|
258
|
+
|
25
259
|
def _(num)
|
26
|
-
|
27
|
-
eval("$p#{num} ||= Num.new(num)")
|
28
|
-
else
|
29
|
-
eval("$n#{-1 * num} ||= Num.new(num)")
|
30
|
-
end
|
260
|
+
Num.new(num)
|
31
261
|
end
|
32
262
|
|
33
263
|
def pi
|
@@ -117,7 +347,11 @@ module Dydx
|
|
117
347
|
end
|
118
348
|
|
119
349
|
def tan(x)
|
120
|
-
|
350
|
+
if x == 0
|
351
|
+
0
|
352
|
+
else
|
353
|
+
Tan.new(x)
|
354
|
+
end
|
121
355
|
end
|
122
356
|
end
|
123
357
|
end
|