Class: SyMath::Value
Constant Summary
collapse
- @@class_order =
[
'SyMath::Definition::Number',
'SyMath::Definition::Constant',
'SyMath::Definition::Variable',
'SyMath::Definition::Function',
'SyMath::Definition::Operator',
'SyMath::Definition',
'SyMath::Minus',
'SyMath::Power',
'SyMath::Wedge',
'SyMath::Fraction',
'SyMath::Product',
'SyMath::Sum',
'SyMath::Operator',
]
- @@class_order_hash =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
#flat, #hodge, #sharp
#anti_derivative, #get_linear_constants, initialize, #int_constant, #int_failure, #int_function, #int_inv, #int_pattern, #int_power, #int_product, #int_sum, #integral_bounds
#_d_wedge, #d, #d_failure, #d_fraction, #d_function, #d_function_def, #d_power, #d_product, initialize
Methods included from Operation
#iterate, #recurse
#combfrac_add_term, #combfrac_sum, #combine_fractions, #expand, #expand_product, #expand_single_pass, #factorize, #factorize_integer_poly, #factorize_simple, #has_fractional_terms?
#combine_factors, #compare_factors_and_swap, #normalize, #normalize_matrix, #normalize_power, #normalize_product, #normalize_single_pass, #normalize_sum, #order_product, #product_on_fraction_form, #reduce_constant_factors, #replace_combined_factors, #swap_factors
#build_assoc_op, #match, #match_assoc, #match_replace
Class Method Details
.compose_with_simplify(*args) ⇒ Object
Compose with simplify. Defaults to composition with no reductions
53
54
55
|
# File 'lib/symath/value.rb', line 53
def self.compose_with_simplify(*args)
return self.new(*args)
end
|
.create(definition, *args) ⇒ Object
Instance Method Details
#*(other) ⇒ Object
183
184
185
|
# File 'lib/symath/value.rb', line 183
def *(other)
return SyMath::Product.create(self, other)
end
|
#**(other) ⇒ Object
195
196
197
|
# File 'lib/symath/value.rb', line 195
def **(other)
return SyMath::Power.create(self, other)
end
|
#+(other) ⇒ Object
Overridden object operators. These operations do some simple reductions.
171
172
173
|
# File 'lib/symath/value.rb', line 171
def +(other)
return SyMath::Sum.create(self, other)
end
|
#-(other) ⇒ Object
175
176
177
|
# File 'lib/symath/value.rb', line 175
def -(other)
return self + (- other)
end
|
#-@ ⇒ Object
179
180
181
|
# File 'lib/symath/value.rb', line 179
def -@()
return SyMath::Minus.create(self)
end
|
#/(other) ⇒ Object
187
188
189
|
# File 'lib/symath/value.rb', line 187
def /(other)
return SyMath::Fraction.create(self, other)
end
|
#<(other) ⇒ Object
68
69
70
|
# File 'lib/symath/value.rb', line 68
def <(other)
return (self <=> other) < 0
end
|
#<=(other) ⇒ Object
76
77
78
|
# File 'lib/symath/value.rb', line 76
def <=(other)
return (self <=> other) <= 0
end
|
#<=>(other) ⇒ Object
Sorting/ordering operator. The ordering is used by the normalization to order the parts of a sum, product etc.
63
64
65
66
|
# File 'lib/symath/value.rb', line 63
def <=>(other)
return @@class_order_hash[self.class.name] <=>
@@class_order_hash[other.class.name]
end
|
#>(other) ⇒ Object
72
73
74
|
# File 'lib/symath/value.rb', line 72
def >(other)
return (self <=> other) > 0
end
|
#>=(other) ⇒ Object
80
81
82
|
# File 'lib/symath/value.rb', line 80
def >=(other)
return (self <=> other) >= 0
end
|
#^(other) ⇒ Object
199
200
201
202
203
|
# File 'lib/symath/value.rb', line 199
def ^(other)
return self*other
end
|
#add(other) ⇒ Object
Compositional math operator methods. No reductions are performed.
139
140
141
|
# File 'lib/symath/value.rb', line 139
def add(other)
return SyMath::Sum.new(self, other.to_m)
end
|
#base ⇒ Object
Returns the base of a power expression. Defaults to self for non-powers.
228
229
230
|
# File 'lib/symath/value.rb', line 228
def base()
return self
end
|
#deep_clone ⇒ Object
57
58
59
|
# File 'lib/symath/value.rb', line 57
def deep_clone()
return Marshal.load(Marshal.dump(self))
end
|
#div(other) ⇒ Object
155
156
157
|
# File 'lib/symath/value.rb', line 155
def div(other)
return SyMath::Fraction.new(self, other.to_m)
end
|
#dump(indent = 0) ⇒ Object
274
275
276
277
|
# File 'lib/symath/value.rb', line 274
def dump(indent = 0)
i = ' '*indent
return "#{i}#{self.class}: #{self}"
end
|
#evaluate ⇒ Object
Evaluate expression. Defaults to no evaluation
132
133
134
|
# File 'lib/symath/value.rb', line 132
def evaluate()
return self
end
|
#exponent ⇒ Object
Returns the exponent of a power expression. Defaults to self for non-powers.
234
235
236
|
# File 'lib/symath/value.rb', line 234
def exponent()
return 1.to_m
end
|
#factors ⇒ Object
Return factors in enumerator
239
240
241
|
# File 'lib/symath/value.rb', line 239
def factors()
return [self].to_enum
end
|
#inspect ⇒ Object
266
267
268
269
270
271
272
|
# File 'lib/symath/value.rb', line 266
def inspect()
if SyMath.setting(:inspect_to_s)
return self.to_s
else
return super.inspect
end
end
|
#inv ⇒ Object
191
192
193
|
# File 'lib/symath/value.rb', line 191
def inv()
return 1/self
end
|
#is_divisor_factor? ⇒ Boolean
118
119
120
|
# File 'lib/symath/value.rb', line 118
def is_divisor_factor?()
return false
end
|
#is_finite? ⇒ Boolean
90
91
92
|
# File 'lib/symath/value.rb', line 90
def is_finite?()
return
end
|
#is_nan? ⇒ Boolean
Default properties for operators Note: Returning nil here means neither true or false, but unknown.
86
87
88
|
# File 'lib/symath/value.rb', line 86
def is_nan?()
return
end
|
#is_negative? ⇒ Boolean
98
99
100
101
102
103
104
|
# File 'lib/symath/value.rb', line 98
def is_negative?()
if is_nan?
return false
end
return (is_positive? == false and is_zero? == false)
end
|
#is_negative_number? ⇒ Boolean
110
111
112
|
# File 'lib/symath/value.rb', line 110
def is_negative_number?()
return false
end
|
#is_number? ⇒ Boolean
106
107
108
|
# File 'lib/symath/value.rb', line 106
def is_number?()
return false
end
|
#is_positive? ⇒ Boolean
94
95
96
|
# File 'lib/symath/value.rb', line 94
def is_positive?()
return
end
|
#is_prod_exp? ⇒ Boolean
Value is a product, fraction or unitary minus
216
217
218
|
# File 'lib/symath/value.rb', line 216
def is_prod_exp?()
return false
end
|
#is_sum_exp? ⇒ Boolean
Value is a sum or unitary minus
211
212
213
|
# File 'lib/symath/value.rb', line 211
def is_sum_exp?()
return false
end
|
#is_unit_quaternion? ⇒ Boolean
122
123
124
|
# File 'lib/symath/value.rb', line 122
def is_unit_quaternion?()
return false
end
|
#is_zero? ⇒ Boolean
114
115
116
|
# File 'lib/symath/value.rb', line 114
def is_zero?()
return
end
|
#mul(other) ⇒ Object
151
152
153
|
# File 'lib/symath/value.rb', line 151
def mul(other)
return SyMath::Product.new(self, other.to_m)
end
|
#neg ⇒ Object
147
148
149
|
# File 'lib/symath/value.rb', line 147
def neg()
return SyMath::Minus.new(self)
end
|
#power(other) ⇒ Object
159
160
161
|
# File 'lib/symath/value.rb', line 159
def power(other)
return SyMath::Power.new(self, other.to_m)
end
|
#reduce ⇒ Object
Reduce expression if possible. Defaults to no reduction
127
128
129
|
# File 'lib/symath/value.rb', line 127
def reduce()
return self
end
|
#reduce_modulo_sign ⇒ Object
Simple reduction rules, allows sign to change. Returns (reduced exp, sign, changed). Defaults to no change
251
252
253
|
# File 'lib/symath/value.rb', line 251
def reduce_modulo_sign
return self, 1, false
end
|
#sign ⇒ Object
Returns the accumulated sign of a product. Defaults to 1 for positive non-sum expressions.
245
246
247
|
# File 'lib/symath/value.rb', line 245
def sign()
return 1
end
|
#terms ⇒ Object
Returns the terms of a sum in an array. Defaults to self for non-sums.
222
223
224
|
# File 'lib/symath/value.rb', line 222
def terms()
return [self]
end
|
#to_m ⇒ Object
262
263
264
|
# File 'lib/symath/value.rb', line 262
def to_m()
return self
end
|
#type ⇒ Object
By default, assume an unknown expression to be scalar
256
257
258
|
# File 'lib/symath/value.rb', line 256
def type()
return 'scalar'.to_t
end
|
#wedge(other) ⇒ Object
163
164
165
|
# File 'lib/symath/value.rb', line 163
def wedge(other)
return SyMath::Wedge.new(self, other.to_m)
end
|