Class: SyMath::Definition
- Inherits:
-
Value
- Object
- Value
- SyMath::Definition
show all
- Defined in:
- lib/symath/definition.rb
Defined Under Namespace
Classes: Abs, Arccos, Arccot, Arccsc, Arcsec, Arcsin, Arctan, Bounds, CoDiff, Constant, Cos, Cot, Csc, Curl, D, Div, Exp, Fact, Flat, Function, Grad, Hodge, Int, Laplacian, Lmd, Ln, Number, Operator, Sec, Sharp, Sin, Sqrt, Tan, Trig, Variable, Xd
Constant Summary
collapse
- @@definitions =
{}
- @@skip_method_def =
{
:+ => true,
:- => true,
:* => true,
:/ => true,
:** => true,
:'=' => true,
:op => true,
:fn => true,
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Value
#*, #**, #+, #-, #-@, #/, #<, #<=, #>, #>=, #^, #add, #base, compose_with_simplify, create, #deep_clone, #div, #dump, #evaluate, #exponent, #factors, #inv, #is_divisor_factor?, #is_finite?, #is_nan?, #is_negative?, #is_negative_number?, #is_number?, #is_positive?, #is_prod_exp?, #is_sum_exp?, #is_unit_quaternion?, #is_zero?, #mul, #neg, #power, #reduce, #reduce_modulo_sign, #sign, #sub, #terms, #to_m, #type, #wedge
#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
Constructor Details
#initialize(name, define_symbol: true, description: nil) ⇒ Definition
Returns a new instance of Definition.
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/symath/definition.rb', line 98
def initialize(name, define_symbol: true, description: nil)
@name = name.to_sym
if define_symbol
self.class.define(name, self)
end
if description.nil?
@description = self.to_s
else
@description = description
end
end
|
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
18
19
20
|
# File 'lib/symath/definition.rb', line 18
def description
@description
end
|
#name ⇒ Object
Returns the value of attribute name.
17
18
19
|
# File 'lib/symath/definition.rb', line 17
def name
@name
end
|
Class Method Details
.define(name, s) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/symath/definition.rb', line 57
def self.define(name, s)
if @@definitions.has_key?(name.to_sym)
raise "#{name} is already defined."
end
@@definitions[name.to_sym] = s
if !SyMath::Definitions.private_method_defined?(name) and
!SyMath::Definitions.method_defined?(name) and
!@@skip_method_def[name.to_sym]
SyMath::Definitions.define_method :"#{name}" do |*args|
sym = s
if args.length > 0
return sym.call(*args)
else
return sym
end
end
end
end
|
.defined?(name) ⇒ Boolean
90
91
92
|
# File 'lib/symath/definition.rb', line 90
def self.defined?(name)
return @@definitions.has_key?(name.to_sym)
end
|
.definitions ⇒ Object
94
95
96
|
# File 'lib/symath/definition.rb', line 94
def self.definitions()
return @@definitions.values
end
|
.get(name) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/symath/definition.rb', line 49
def self.get(name)
if !@@definitions.has_key?(name.to_sym)
raise "#{name} is not defined."
end
return @@definitions[name.to_sym]
end
|
.init_builtin ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/symath/definition.rb', line 33
def self.init_builtin()
SyMath::Definition::Function.new(:+)
SyMath::Definition::Function.new(:-)
SyMath::Definition::Function.new(:*)
SyMath::Definition::Function.new(:/)
SyMath::Definition::Function.new(:**)
SyMath::Definition::Function.new(:^)
SyMath::Definition::Function.new(:'=')
SyMath::Definition::Constant.init_builtin
SyMath::Definition::Function.init_builtin
SyMath::Definition::Operator.init_builtin
end
|
.undefine(name) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/symath/definition.rb', line 82
def self.undefine(name)
if !@@definitions.has_key?(name.to_sym)
raise "#{name} is not undefined."
end
@@definitions.delete(name.to_sym)
end
|
Instance Method Details
#<=>(other) ⇒ Object
FIXME: Identical to operator comparison
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/symath/definition.rb', line 152
def <=>(other)
if self.class.name != other.class.name
return super(other)
end
if name != other.name
return name.to_s <=> other.name.to_s
end
return 0
end
|
#==(other) ⇒ Object
Also known as:
eql?
141
142
143
144
145
146
|
# File 'lib/symath/definition.rb', line 141
def ==(other)
o = other.to_m
return false if self.class.name != o.class.name
return false if @name.to_s != o.name.to_s
return true
end
|
#arity ⇒ Object
133
134
135
|
# File 'lib/symath/definition.rb', line 133
def arity()
return 0
end
|
#hash ⇒ Object
137
138
139
|
# File 'lib/symath/definition.rb', line 137
def hash()
return @name.hash
end
|
#inspect ⇒ Object
183
184
185
186
187
188
189
|
# File 'lib/symath/definition.rb', line 183
def inspect()
if SyMath.setting(:inspect_to_s)
return to_s
else
return super.inspect
end
end
|
#is_constant?(vars = nil) ⇒ Boolean
is_self_adjoint is_additive is_homogenous is_conjugate_homogenous is_linear (additive + homogenous) is_antilinear (additive + conjugate_homogenous)
171
172
173
|
# File 'lib/symath/definition.rb', line 171
def is_constant?(vars = nil)
return true
end
|
#is_function? ⇒ Boolean
125
126
127
|
# File 'lib/symath/definition.rb', line 125
def is_function?()
return false
end
|
#is_operator? ⇒ Boolean
129
130
131
|
# File 'lib/symath/definition.rb', line 129
def is_operator?()
return false
end
|
#reduce_call(c) ⇒ Object
113
114
115
|
# File 'lib/symath/definition.rb', line 113
def reduce_call(c)
return c
end
|
#replace(map) ⇒ Object
121
122
123
|
# File 'lib/symath/definition.rb', line 121
def replace(map)
return self
end
|
#to_latex ⇒ Object
179
180
181
|
# File 'lib/symath/definition.rb', line 179
def to_latex()
return "#{name}"
end
|
#to_s ⇒ Object
175
176
177
|
# File 'lib/symath/definition.rb', line 175
def to_s()
return @name.to_s
end
|
#variables ⇒ Object
117
118
119
|
# File 'lib/symath/definition.rb', line 117
def variables()
return []
end
|