Class: SyMath::Definition::Constant
Constant Summary
collapse
- @@ltx_symbol =
{
:pi => '\pi',
:e => '\mathrm{e}',
:phi => '\varphi',
:nan => '\mathrm{NaN}',
:oo => '\infty',
}
- @@descriptions =
{
:pi => 'ratio of cirle cirumference/diameter (3.14159265...)',
:e => 'eulers number (2.71828182...)',
:phi => 'golden ratio (1.61803398...)',
:nan => "'not a number', i.e. an invalid value",
:oo => 'positive infinity',
:i => 'imaginary unit, first basic quaternion',
:j => 'second basic quaternion',
:k => 'third basic quaternion',
}
- @@unit_quaternions =
[:i, :j, :k].to_set
Instance Attribute Summary
#name
Class Method Summary
collapse
Instance Method Summary
collapse
#<=>, #==, #arity, define, defined?, definitions, get, #hash, #initialize, #inspect, #is_constant?, #is_function?, #is_operator?, #reduce_call, #replace, #to_s, undefine, #variables
Methods inherited from Value
#*, #**, #+, #-, #-@, #/, #<, #<=, #<=>, #>, #>=, #^, #add, #base, compose_with_simplify, create, #deep_clone, #div, #dump, #evaluate, #exponent, #factors, #inspect, #inv, #is_divisor_factor?, #is_negative?, #is_negative_number?, #is_number?, #is_prod_exp?, #is_sum_exp?, #mul, #neg, #power, #reduce, #reduce_modulo_sign, #sign, #sub, #terms, #to_m, #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
Class Method Details
.init_builtin ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/symath/definition/constant.rb', line 27
def self.init_builtin()
self.new(:pi)
self.new(:e)
self.new(:phi)
self.new(:nan)
self.new(:oo)
self.new(:i)
self.new(:j)
self.new(:k)
end
|
Instance Method Details
#calc_unit_quaternions(q) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/symath/definition/constant.rb', line 67
def calc_unit_quaternions(q)
qmap = {
:i => {
:i => -1.to_m,
:j => :k.to_m,
:k => -:j.to_m,
},
:j => {
:i => -:k.to_m,
:j => -1.to_m,
:k => :i.to_m,
},
:k => {
:i => :j.to_m,
:j => -:i.to_m,
:k => -1.to_m,
},
}
return qmap[@name][q.name]
end
|
#description ⇒ Object
43
44
45
|
# File 'lib/symath/definition/constant.rb', line 43
def description()
return "#{@name} - #{@@descriptions[@name]}"
end
|
#is_finite? ⇒ Boolean
51
52
53
|
# File 'lib/symath/definition/constant.rb', line 51
def is_finite?()
return (@name != :oo and @name != :nan)
end
|
#is_nan? ⇒ Boolean
47
48
49
|
# File 'lib/symath/definition/constant.rb', line 47
def is_nan?()
return @name == :nan
end
|
#is_positive? ⇒ Boolean
55
56
57
|
# File 'lib/symath/definition/constant.rb', line 55
def is_positive?()
return (!is_zero? and !is_nan?)
end
|
#is_unit_quaternion? ⇒ Boolean
63
64
65
|
# File 'lib/symath/definition/constant.rb', line 63
def is_unit_quaternion?()
return @@unit_quaternions.member?(@name)
end
|
#is_zero? ⇒ Boolean
59
60
61
|
# File 'lib/symath/definition/constant.rb', line 59
def is_zero?()
return false
end
|
#to_latex ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/symath/definition/constant.rb', line 103
def to_latex()
if @@ltx_symbol.key?(@name)
return @@ltx_symbol[@name]
else
return @name.to_s
end
end
|
#type ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/symath/definition/constant.rb', line 90
def type()
n = @name
if n == :e or n == :pi or n == :phi
return 'real'.to_t
elsif n == :i
return 'imaginary'.to_t
elsif is_unit_quaternion?
return 'quaternion'.to_t
else
return 'nonfinite'.to_t
end
end
|