ragni-cas 0.1.7 → 0.1.8
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 +4 -4
- checksums.yaml.gz.sig +2 -2
- data/lib/fnc-base.rb +133 -12
- data/lib/fnc-branch.rb +198 -0
- data/lib/fnc-trig.rb +44 -8
- data/lib/fnc-trsc.rb +12 -0
- data/lib/numbers.rb +91 -15
- data/lib/op.rb +206 -9
- data/lib/ragni-cas.rb +50 -0
- data/lib/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
data/lib/fnc-trig.rb
CHANGED
@@ -14,14 +14,19 @@ module CAS
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
# Same as `CAS::Op`
|
17
18
|
def call(f)
|
19
|
+
CAS::Help.assert(f, Hash)
|
20
|
+
|
18
21
|
Math::sin @x.call(f)
|
19
22
|
end
|
20
23
|
|
24
|
+
# Same as `CAS::Op`
|
21
25
|
def to_s
|
22
26
|
"sin(#{@x})"
|
23
27
|
end
|
24
28
|
|
29
|
+
# Same as `CAS::Op`
|
25
30
|
def simplify
|
26
31
|
super
|
27
32
|
if @x == CAS::Zero
|
@@ -36,6 +41,7 @@ module CAS
|
|
36
41
|
return self
|
37
42
|
end
|
38
43
|
|
44
|
+
# Same as `CAS::Op`
|
39
45
|
def to_code
|
40
46
|
"Math::sin(#{@x.to_code})"
|
41
47
|
end
|
@@ -58,14 +64,19 @@ module CAS
|
|
58
64
|
end
|
59
65
|
end
|
60
66
|
|
67
|
+
# Same as `CAS::Op`
|
61
68
|
def call(f)
|
69
|
+
CAS::Help.assert(f, Hash)
|
70
|
+
|
62
71
|
Math::acos @x.call(f)
|
63
72
|
end
|
64
73
|
|
74
|
+
# Same as `CAS::Op`
|
65
75
|
def to_s
|
66
76
|
"asin(#{@x})"
|
67
77
|
end
|
68
78
|
|
79
|
+
# Same as `CAS::Op`
|
69
80
|
def simplify
|
70
81
|
super
|
71
82
|
if @x == CAS::Zero
|
@@ -80,6 +91,7 @@ module CAS
|
|
80
91
|
return self
|
81
92
|
end
|
82
93
|
|
94
|
+
# Same as `CAS::Op`
|
83
95
|
def to_code
|
84
96
|
"Math::asin(#{@x.to_code})"
|
85
97
|
end
|
@@ -102,14 +114,19 @@ module CAS
|
|
102
114
|
end
|
103
115
|
end
|
104
116
|
|
117
|
+
# Same as `CAS::Op`
|
105
118
|
def call(f)
|
106
|
-
|
119
|
+
CAS::Help.assert(f, Hash)
|
120
|
+
|
121
|
+
Math::cos @x.call(f)
|
107
122
|
end
|
108
123
|
|
124
|
+
# Same as `CAS::Op`
|
109
125
|
def to_s
|
110
|
-
"cos(#{
|
126
|
+
"cos(#{@x})"
|
111
127
|
end
|
112
128
|
|
129
|
+
# Same as `CAS::Op`
|
113
130
|
def simplify
|
114
131
|
super
|
115
132
|
if @x == CAS::Zero
|
@@ -124,6 +141,7 @@ module CAS
|
|
124
141
|
return self
|
125
142
|
end
|
126
143
|
|
144
|
+
# Same as `CAS::Op`
|
127
145
|
def to_code
|
128
146
|
"Math::cos(#{@x.to_code})"
|
129
147
|
end
|
@@ -146,14 +164,19 @@ module CAS
|
|
146
164
|
end
|
147
165
|
end
|
148
166
|
|
167
|
+
# Same as `CAS::Op`
|
149
168
|
def call(f)
|
169
|
+
CAS::Help.assert(f, Hash)
|
150
170
|
|
171
|
+
return Math::acos @x
|
151
172
|
end
|
152
173
|
|
174
|
+
# Same as `CAS::Op`
|
153
175
|
def to_s
|
154
|
-
"acos(#{
|
176
|
+
"acos(#{@x})"
|
155
177
|
end
|
156
178
|
|
179
|
+
# Same as `CAS::Op`
|
157
180
|
def simplify
|
158
181
|
super
|
159
182
|
if @x == CAS::Zero
|
@@ -168,6 +191,7 @@ module CAS
|
|
168
191
|
return self
|
169
192
|
end
|
170
193
|
|
194
|
+
# Same as `CAS::Op`
|
171
195
|
def to_code
|
172
196
|
"Math::acos(#{@x.to_code})"
|
173
197
|
end
|
@@ -190,14 +214,19 @@ module CAS
|
|
190
214
|
end
|
191
215
|
end
|
192
216
|
|
217
|
+
# Same as `CAS::Op`
|
193
218
|
def call(f)
|
194
|
-
|
219
|
+
CAS::Help.assert(f, Hash)
|
220
|
+
|
221
|
+
Math::tan @x.call
|
195
222
|
end
|
196
223
|
|
224
|
+
# Same as `CAS::Op`
|
197
225
|
def to_s
|
198
|
-
"tan(#{
|
226
|
+
"tan(#{@x})"
|
199
227
|
end
|
200
228
|
|
229
|
+
# Same as `CAS::Op`
|
201
230
|
def simplify
|
202
231
|
super
|
203
232
|
if @x == CAS::Zero
|
@@ -212,6 +241,7 @@ module CAS
|
|
212
241
|
return self
|
213
242
|
end
|
214
243
|
|
244
|
+
# Same as `CAS::Op`
|
215
245
|
def to_code
|
216
246
|
"Math::tan(#{@x.to_code})"
|
217
247
|
end
|
@@ -234,14 +264,19 @@ module CAS
|
|
234
264
|
end
|
235
265
|
end
|
236
266
|
|
237
|
-
|
238
|
-
|
267
|
+
# Same as `CAS::Op`
|
268
|
+
def call(f)
|
269
|
+
CAS::Help.assert(f, Hash)
|
270
|
+
|
271
|
+
Math::atan @x.call
|
239
272
|
end
|
240
273
|
|
274
|
+
# Same as `CAS::Op`
|
241
275
|
def to_s
|
242
|
-
"atan(#{
|
276
|
+
"atan(#{@x})"
|
243
277
|
end
|
244
278
|
|
279
|
+
# Same as `CAS::Op`
|
245
280
|
def simplify
|
246
281
|
super
|
247
282
|
if @x == CAS::Zero
|
@@ -259,6 +294,7 @@ module CAS
|
|
259
294
|
return self
|
260
295
|
end
|
261
296
|
|
297
|
+
# Same as `CAS::Op`
|
262
298
|
def to_code
|
263
299
|
"Math::atan(#{@x.to_code})"
|
264
300
|
end
|
data/lib/fnc-trsc.rb
CHANGED
@@ -15,14 +15,19 @@ module CAS
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
# Same as `CAS::Op`
|
18
19
|
def call(f)
|
20
|
+
CAS::Help.assert(f, Hash)
|
21
|
+
|
19
22
|
Math::exp @x.call(f)
|
20
23
|
end
|
21
24
|
|
25
|
+
# Same as `CAS::Op`
|
22
26
|
def to_s
|
23
27
|
"exp(#{@x})"
|
24
28
|
end
|
25
29
|
|
30
|
+
# Same as `CAS::Op`
|
26
31
|
def simplify
|
27
32
|
super
|
28
33
|
if @x == CAS::Zero
|
@@ -40,6 +45,7 @@ module CAS
|
|
40
45
|
return self
|
41
46
|
end
|
42
47
|
|
48
|
+
# Same as `CAS::Op`
|
43
49
|
def to_code
|
44
50
|
"Math::exp(#{@x.to_code})"
|
45
51
|
end
|
@@ -63,16 +69,21 @@ module CAS
|
|
63
69
|
end
|
64
70
|
end
|
65
71
|
|
72
|
+
# Same as `CAS::Op`
|
66
73
|
def call(f)
|
67
74
|
# I'm leaving to Math the honor
|
68
75
|
# of handling negative values...
|
76
|
+
CAS::Help.assert(f, Hash)
|
77
|
+
|
69
78
|
Math::log @x.call(f)
|
70
79
|
end
|
71
80
|
|
81
|
+
# Same as `CAS::Op`
|
72
82
|
def to_s
|
73
83
|
"log(#{@x})"
|
74
84
|
end
|
75
85
|
|
86
|
+
# Same as `CAS::Op`
|
76
87
|
def simplify
|
77
88
|
super
|
78
89
|
if @x == CAS::Zero
|
@@ -90,6 +101,7 @@ module CAS
|
|
90
101
|
return self
|
91
102
|
end
|
92
103
|
|
104
|
+
# Same as `CAS::Op`
|
93
105
|
def to_code
|
94
106
|
"Math::log(#{@x.to_code})"
|
95
107
|
end
|
data/lib/numbers.rb
CHANGED
@@ -10,16 +10,29 @@ module CAS
|
|
10
10
|
@x = x
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
# The derivative of a constant is always zero
|
14
|
+
def diff(v)
|
15
|
+
CAS::Zero
|
16
|
+
end
|
14
17
|
|
15
|
-
|
18
|
+
# Same as `CAS::Op`
|
19
|
+
def call(f)
|
20
|
+
@x
|
21
|
+
end
|
16
22
|
|
17
|
-
|
23
|
+
# Same as `CAS::Op`
|
24
|
+
def depend?(v)
|
25
|
+
false
|
26
|
+
end
|
18
27
|
|
19
|
-
|
28
|
+
# Same as `CAS::Op`
|
29
|
+
def to_s
|
30
|
+
"#{@x}"
|
31
|
+
end
|
20
32
|
|
33
|
+
# Same as `CAS::Op`
|
21
34
|
def simplify
|
22
|
-
case x
|
35
|
+
case @x
|
23
36
|
when 0
|
24
37
|
return CAS::Zero
|
25
38
|
when 1
|
@@ -35,31 +48,46 @@ module CAS
|
|
35
48
|
end
|
36
49
|
end
|
37
50
|
|
51
|
+
# Same as `CAS::Op`
|
38
52
|
def args
|
39
53
|
[]
|
40
54
|
end
|
41
55
|
|
56
|
+
# Same as `CAS::Op`
|
42
57
|
def ==(op)
|
43
|
-
|
58
|
+
CAS::Help.assert(op, CAS::Op)
|
59
|
+
|
60
|
+
if op.is_a? CAS::Constant
|
61
|
+
return @x == op.x
|
62
|
+
else
|
63
|
+
return false
|
64
|
+
end
|
44
65
|
end
|
45
66
|
|
67
|
+
# Same as `CAS::Op`
|
46
68
|
def inspect
|
47
69
|
"Const(#{@x})"
|
48
70
|
end
|
49
71
|
|
72
|
+
# Same as `CAS::Op`
|
50
73
|
def dot_graph(node)
|
51
74
|
"#{self.class.to_s.gsub("CAS::", "")}_#{self.object_id};"
|
52
75
|
end
|
53
76
|
end
|
54
77
|
|
55
|
-
|
56
|
-
|
57
|
-
|
78
|
+
# Allows to define a series of new constants.
|
79
|
+
#
|
80
|
+
# ``` ruby
|
81
|
+
# a, b = CAS::const 1.0, 100
|
82
|
+
# ```
|
83
|
+
#
|
84
|
+
# <- `Array` of Numeric
|
85
|
+
# -> `Array` of `CAS::Contant`
|
58
86
|
def self.const(*val)
|
59
87
|
(return CAS::Constant.new(val[0])) if val.size == 1
|
60
88
|
ret = []
|
61
89
|
val.each do |n|
|
62
|
-
ret << CAS::
|
90
|
+
ret << CAS::Constant.new(n)
|
63
91
|
end
|
64
92
|
return ret
|
65
93
|
end
|
@@ -69,59 +97,107 @@ module CAS
|
|
69
97
|
# \ V / _` | '_| / _` | '_ \ / -_)
|
70
98
|
# \_/\__,_|_| |_\__,_|_.__/_\___|
|
71
99
|
class Variable < CAS::Op
|
100
|
+
# Contains all define variable, in an hash. Variables are
|
101
|
+
# accessible through variable name.
|
72
102
|
@@vars = {}
|
73
|
-
@@counter = 0
|
74
103
|
|
75
|
-
|
76
|
-
|
104
|
+
# Returns the `Hash` that contains all the variable
|
105
|
+
#
|
106
|
+
# -> `Hash`
|
107
|
+
def self.list
|
108
|
+
@@vars
|
109
|
+
end
|
110
|
+
|
111
|
+
# Return the number of variable defined
|
112
|
+
#
|
113
|
+
# -> `Fixnum`
|
114
|
+
def self.size
|
115
|
+
@@vars.keys.size
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns `true` if a variable already exists
|
119
|
+
#
|
120
|
+
# <- `Object` that represent the variable
|
121
|
+
# -> `TrueClass` if variable exists, `FalseClass` if not
|
77
122
|
def self.exist?(name)
|
78
123
|
@@vars.keys.include? name
|
79
124
|
end
|
80
125
|
|
126
|
+
attr_reader :name
|
127
|
+
# Variable is a container for an atomic simbol that becomes a number
|
128
|
+
# when `CAS::Op#call` method is used.
|
129
|
+
#
|
130
|
+
# <- `Object` that is a identifier for the variable
|
131
|
+
# -> `CAS::Variable` instance
|
81
132
|
def initialize(name)
|
82
133
|
raise CASError, "Variable #{name} already exists" if CAS::Variable.exist? name
|
83
134
|
@name = name
|
84
135
|
@@vars[@name] = self
|
85
|
-
@@counter = @@counter + 1
|
86
136
|
end
|
87
137
|
|
138
|
+
# Returns the derivative of a variable
|
139
|
+
#
|
140
|
+
# ```
|
141
|
+
# dx dx
|
142
|
+
# -- = 1; -- = 0
|
143
|
+
# dx dy
|
144
|
+
# ```
|
145
|
+
#
|
146
|
+
# <- `CAS::Op` for the derivative denominator
|
147
|
+
# -> `CAS::Constant`, 0 if not depended, 1 if dependent
|
88
148
|
def diff(v)
|
89
149
|
CAS::One
|
90
150
|
end
|
91
151
|
|
152
|
+
# Same as `CAS::Op`
|
92
153
|
def depend?(v)
|
93
154
|
self == v
|
94
155
|
end
|
95
156
|
|
157
|
+
# Same as `CAS::Op`
|
96
158
|
def ==(op)
|
97
|
-
|
159
|
+
CAS::Help.assert(op, CAS::Op)
|
160
|
+
if op.is_a? CAS::Variable
|
161
|
+
return self.inspect == op.inspect
|
162
|
+
else
|
163
|
+
false
|
164
|
+
end
|
98
165
|
end
|
99
166
|
|
167
|
+
# Same as `CAS::Op`
|
100
168
|
def call(f)
|
169
|
+
CAS::Help.assert(f, Hash)
|
170
|
+
|
101
171
|
return f[self] if f[self]
|
102
172
|
return f[@name] if f[@name]
|
103
173
|
end
|
104
174
|
|
175
|
+
# Same as `CAS::Op`
|
105
176
|
def to_s
|
106
177
|
"#{@name}"
|
107
178
|
end
|
108
179
|
|
180
|
+
# Same as `CAS::Op`
|
109
181
|
def to_code
|
110
182
|
"#{@name}"
|
111
183
|
end
|
112
184
|
|
185
|
+
# Same as `CAS::Op`
|
113
186
|
def args
|
114
187
|
[self]
|
115
188
|
end
|
116
189
|
|
190
|
+
# Same as `CAS::Op`
|
117
191
|
def inspect
|
118
192
|
"Var(#{@name})"
|
119
193
|
end
|
120
194
|
|
195
|
+
# Same as `CAS::Op`
|
121
196
|
def simplify
|
122
197
|
self
|
123
198
|
end
|
124
199
|
|
200
|
+
# Same as `CAS::Op`
|
125
201
|
def dot_graph(node)
|
126
202
|
"#{@name};"
|
127
203
|
end
|