Class: SyMath::Value

Inherits:
Object
  • Object
show all
Includes:
Operation::Differential, Operation::DistributiveLaw, Operation::Exterior, Operation::Integration, Operation::Match, Operation::Normalization
Defined in:
lib/symath/value.rb

Direct Known Subclasses

Definition, Matrix, Operator

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

Methods included from Operation::Exterior

#flat, #hodge, #sharp

Methods included from Operation::Integration

#anti_derivative, #get_linear_constants, initialize, #int_constant, #int_failure, #int_function, #int_inv, #int_pattern, #int_power, #int_product, #int_sum, #integral_bounds

Methods included from Operation::Differential

#_d_wedge, #d, #d_failure, #d_fraction, #d_function, #d_function_def, #d_power, #d_product, initialize

Methods included from Operation

#iterate, #recurse

Methods included from Operation::DistributiveLaw

#combfrac_add_term, #combfrac_sum, #combine_fractions, #expand, #expand_product, #expand_single_pass, #factorize, #factorize_integer_poly, #factorize_simple, #has_fractional_terms?

Methods included from Operation::Normalization

#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

Methods included from Operation::Match

#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



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/symath/value.rb', line 40

def self.create(definition, *args)
  if !definition.is_a?(SyMath::Value)
    definition = SyMath::Definition.get(definition)
  end
  
  if SyMath.setting(:compose_with_simplify)
    return self.compose_with_simplify(definition, *args)
  else
    return self.new(definition, *args)
  end
end

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)
  # Identical with *. We apply * or ^ depending on what
  # the arguments are.
  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

#baseObject

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_cloneObject



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

#evaluateObject

Evaluate expression. Defaults to no evaluation



132
133
134
# File 'lib/symath/value.rb', line 132

def evaluate()
  return self
end

#exponentObject

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

#factorsObject

Return factors in enumerator



239
240
241
# File 'lib/symath/value.rb', line 239

def factors()
  return [self].to_enum
end

#inspectObject



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

#invObject



191
192
193
# File 'lib/symath/value.rb', line 191

def inv()
  return 1/self
end

#is_divisor_factor?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/symath/value.rb', line 118

def is_divisor_factor?()
  return false
end

#is_finite?Boolean

Returns:

  • (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.

Returns:

  • (Boolean)


86
87
88
# File 'lib/symath/value.rb', line 86

def is_nan?()
  return
end

#is_negative?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


110
111
112
# File 'lib/symath/value.rb', line 110

def is_negative_number?()
  return false
end

#is_number?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/symath/value.rb', line 106

def is_number?()
  return false
end

#is_positive?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


211
212
213
# File 'lib/symath/value.rb', line 211

def is_sum_exp?()
  return false
end

#is_unit_quaternion?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/symath/value.rb', line 122

def is_unit_quaternion?()
  return false
end

#is_zero?Boolean

Returns:

  • (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

#negObject



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

#reduceObject

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_signObject

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

#signObject

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

#sub(other) ⇒ Object



143
144
145
# File 'lib/symath/value.rb', line 143

def sub(other)
  return SyMath::Sum.new(self, SyMath::Minus.new(other.to_m))
end

#termsObject

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_mObject



262
263
264
# File 'lib/symath/value.rb', line 262

def to_m()
  return self
end

#typeObject

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