keisan 0.8.11 → 0.8.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/keisan/ast/constant_literal.rb +164 -0
- data/lib/keisan/ast/function.rb +7 -0
- data/lib/keisan/ast/hash.rb +4 -0
- data/lib/keisan/ast/node.rb +4 -0
- data/lib/keisan/ast/parent.rb +4 -0
- data/lib/keisan/functions/enumerable_function.rb +1 -1
- data/lib/keisan/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39ac1f6356b788327b43e6819d18b136da5bbada5f410b64c3f6995b2877973b
|
4
|
+
data.tar.gz: 60522376948b4806c0e45cb4f8e09e5187d37448fae0831630fea1f07608485c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 964905af3a5734456ea5e3f81ddb5183a7512e9cf81567c72586dbab813123160d4aaa085467f2626bd0e29df861f87e44425e216b8ccf174cb9f1251d578122
|
7
|
+
data.tar.gz: be653ccfd93f2fa6ce3a33e26be4e14db33e9ccea8d2273d491e8df0aaa16b400291b08e90d66cd48020efc691742bf49667b3547fcae57e8adeaab52bf18d5d
|
@@ -22,6 +22,170 @@ module Keisan
|
|
22
22
|
value.to_s
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
def is_constant?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def +(other)
|
31
|
+
if other.is_constant?
|
32
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot add #{self.class} to #{other.class}")
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def -(other)
|
39
|
+
if other.is_constant?
|
40
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot subtract #{self.class} from #{other.class}")
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def *(other)
|
47
|
+
if other.is_constant?
|
48
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot multiply #{self.class} and #{other.class}")
|
49
|
+
else
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def /(other)
|
55
|
+
if other.is_constant?
|
56
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot divide #{self.class} and #{other.class}")
|
57
|
+
else
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def %(other)
|
63
|
+
if other.is_constant?
|
64
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot modulo #{self.class} and #{other.class}")
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def !
|
71
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot take logical not of #{self.class}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def ~
|
75
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot take bitwise not of #{self.class}")
|
76
|
+
end
|
77
|
+
|
78
|
+
def +@
|
79
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot take unary plus of #{self.class}")
|
80
|
+
end
|
81
|
+
|
82
|
+
def -@
|
83
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot take unary minus of #{self.class}")
|
84
|
+
end
|
85
|
+
|
86
|
+
def **(other)
|
87
|
+
if other.is_constant?
|
88
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot exponentiate #{self.class} and #{other.class}")
|
89
|
+
else
|
90
|
+
super
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def &(other)
|
95
|
+
if other.is_constant?
|
96
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot bitwise and #{self.class} and #{other.class}")
|
97
|
+
else
|
98
|
+
super
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def ^(other)
|
103
|
+
if other.is_constant?
|
104
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot bitwise xor #{self.class} and #{other.class}")
|
105
|
+
else
|
106
|
+
super
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def |(other)
|
111
|
+
if other.is_constant?
|
112
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot bitwise or #{self.class} and #{other.class}")
|
113
|
+
else
|
114
|
+
super
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def <<(other)
|
119
|
+
if other.is_constant?
|
120
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot bitwise left shift #{self.class} and #{other.class}")
|
121
|
+
else
|
122
|
+
super
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def >>(other)
|
127
|
+
if other.is_constant?
|
128
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot bitwise right shift #{self.class} and #{other.class}")
|
129
|
+
else
|
130
|
+
super
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def >(other)
|
135
|
+
if other.is_constant?
|
136
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot compute #{self.class} > #{other.class}")
|
137
|
+
else
|
138
|
+
super
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def >=(other)
|
143
|
+
if other.is_constant?
|
144
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot compute #{self.class} >= #{other.class}")
|
145
|
+
else
|
146
|
+
super
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def <(other)
|
151
|
+
if other.is_constant?
|
152
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot compute #{self.class} < #{other.class}")
|
153
|
+
else
|
154
|
+
super
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def <=(other)
|
159
|
+
if other.is_constant?
|
160
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot compute #{self.class} <= #{other.class}")
|
161
|
+
else
|
162
|
+
super
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def equal(other)
|
167
|
+
other.is_constant? ? Boolean.new(false) : super
|
168
|
+
end
|
169
|
+
|
170
|
+
def not_equal(other)
|
171
|
+
other.is_constant? ? Boolean.new(true) : super
|
172
|
+
end
|
173
|
+
|
174
|
+
def and(other)
|
175
|
+
if other.is_constant?
|
176
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot logical and #{self.class} and #{other.class}")
|
177
|
+
else
|
178
|
+
super
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def or(other)
|
183
|
+
if other.is_constant?
|
184
|
+
raise Keisan::Exceptions::InvalidExpression.new("Cannot logical or #{self.class} and #{other.class}")
|
185
|
+
else
|
186
|
+
super
|
187
|
+
end
|
188
|
+
end
|
25
189
|
end
|
26
190
|
end
|
27
191
|
end
|
data/lib/keisan/ast/function.rb
CHANGED
@@ -91,6 +91,13 @@ module Keisan
|
|
91
91
|
|
92
92
|
self.class.new([self, variable], "diff")
|
93
93
|
end
|
94
|
+
|
95
|
+
# Functions cannot be guaranteed to be constant even if the arguments
|
96
|
+
# are constants, because there might be randomness involved in the
|
97
|
+
# outputs.
|
98
|
+
def is_constant?
|
99
|
+
false
|
100
|
+
end
|
94
101
|
end
|
95
102
|
end
|
96
103
|
end
|
data/lib/keisan/ast/hash.rb
CHANGED
data/lib/keisan/ast/node.rb
CHANGED
data/lib/keisan/ast/parent.rb
CHANGED
data/lib/keisan/version.rb
CHANGED