keisan 0.8.11 → 0.8.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 982db21218a4096daa15314fb7de88f1710e1a82be5b122c1b1c4a76323fb44a
4
- data.tar.gz: 4df1eec9b4afd5da69db4a6d40d6900dc4bd9bd249dd1b67646766ba8468fd36
3
+ metadata.gz: 39ac1f6356b788327b43e6819d18b136da5bbada5f410b64c3f6995b2877973b
4
+ data.tar.gz: 60522376948b4806c0e45cb4f8e09e5187d37448fae0831630fea1f07608485c
5
5
  SHA512:
6
- metadata.gz: bcc26f352e4f13139a9f0e2c0e1e97be8b3801ca6c2590349aad746fb1283776bf14d4f8ff4eb98049dfd624e7d1b71ce5be5770080f3187a4349c01a5fba4a6
7
- data.tar.gz: 70e240222845d98e231ceb577939a37020b03ba1e3a5b9b88165a3c62ce4ffb6d5aa16cff0d4d2eed3078746b4595d3e104a2545b09f55f6d5b784dba1307bf1
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
@@ -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
@@ -90,6 +90,10 @@ module Keisan
90
90
  ])
91
91
  AST::Cell.new(h)
92
92
  end
93
+
94
+ def is_constant?
95
+ @hash.all? {|k,v| v.is_constant?}
96
+ end
93
97
  end
94
98
  end
95
99
  end
@@ -202,6 +202,10 @@ module Keisan
202
202
  def or(other)
203
203
  LogicalOr.new([self, other.to_node])
204
204
  end
205
+
206
+ def is_constant?
207
+ false
208
+ end
205
209
  end
206
210
  end
207
211
  end
@@ -75,6 +75,10 @@ module Keisan
75
75
  @children = children.map {|child| child.replace(variable, replacement)}
76
76
  self
77
77
  end
78
+
79
+ def is_constant?
80
+ @children.all?(&:is_constant?)
81
+ end
78
82
  end
79
83
  end
80
84
  end
@@ -21,7 +21,7 @@ module Keisan
21
21
  context ||= Context.new
22
22
 
23
23
  operand, arguments, expression = operand_arguments_expression_for(ast_function, context)
24
-
24
+
25
25
  # Extract underlying operand for cells
26
26
  real_operand = operand.is_a?(AST::Cell) ? operand.node : operand
27
27
 
@@ -1,3 +1,3 @@
1
1
  module Keisan
2
- VERSION = "0.8.11"
2
+ VERSION = "0.8.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keisan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.11
4
+ version: 0.8.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Locke