Module: SyMath

Defined in:
lib/symath/definition.rb,
lib/symath.rb,
lib/symath/sum.rb,
lib/symath/poly.rb,
lib/symath/type.rb,
lib/symath/minus.rb,
lib/symath/power.rb,
lib/symath/value.rb,
lib/symath/wedge.rb,
lib/symath/matrix.rb,
lib/symath/parser.rb,
lib/symath/product.rb,
lib/symath/version.rb,
lib/symath/equation.rb,
lib/symath/fraction.rb,
lib/symath/operator.rb,
lib/symath/poly/dup.rb,
lib/symath/poly/galois.rb,
lib/symath/definition/d.rb,
lib/symath/definition/ln.rb,
lib/symath/definition/xd.rb,
lib/symath/definition/abs.rb,
lib/symath/definition/cos.rb,
lib/symath/definition/cot.rb,
lib/symath/definition/csc.rb,
lib/symath/definition/div.rb,
lib/symath/definition/exp.rb,
lib/symath/definition/int.rb,
lib/symath/definition/lmd.rb,
lib/symath/definition/sec.rb,
lib/symath/definition/sin.rb,
lib/symath/definition/tan.rb,
lib/symath/definition/curl.rb,
lib/symath/definition/fact.rb,
lib/symath/definition/flat.rb,
lib/symath/definition/grad.rb,
lib/symath/definition/sqrt.rb,
lib/symath/definition/trig.rb,
lib/symath/definition/hodge.rb,
lib/symath/definition/sharp.rb,
lib/symath/definition/arccos.rb,
lib/symath/definition/arccot.rb,
lib/symath/definition/arccsc.rb,
lib/symath/definition/arcsec.rb,
lib/symath/definition/arcsin.rb,
lib/symath/definition/arctan.rb,
lib/symath/definition/bounds.rb,
lib/symath/definition/codiff.rb,
lib/symath/definition/number.rb,
lib/symath/definition/constant.rb,
lib/symath/definition/function.rb,
lib/symath/definition/operator.rb,
lib/symath/definition/variable.rb,
lib/symath/definition/laplacian.rb

Overview

A special case of a definition is the lambda function, which is a function with no name but a number of arguments, and an expression.

Defined Under Namespace

Modules: Definitions, Operation Classes: Definition, Equation, Fraction, Matrix, Minus, Operator, Parser, Poly, Power, Product, Sum, Type, Value, Wedge

Constant Summary collapse

VERSION =
"0.1.1"
@@global_settings =
{
  # Symbol used to represent the differential operator
  # on variables
  :d_symbol => 'd',
  # Symbol used to represent vector variables
  :vector_symbol => '\'',
  # Symbol used to represent covector variables
  :covector_symbol => '.',
   # Show all parantheses on +, *, / and ^ operators.
  :expl_parentheses => false,
  # Represent square roots with the root symbol or as a fraction exponent
  :sq_exponent_form => false,
  # Represent fraction of scalars as a negative exponent
  :fraction_exponent_form => false,
  # Show the multiplication sign in LaTeX output
  :ltx_product_sign => false,
   # Simplify expression at the time they are composed
  :compose_with_simplify => true,
   # Use complex arithmetic. Negative square roots are reduced to i*square
  # root of the positive part. The complex infinity is used rather than the
  # positive and negative real infinities.
  :complex_arithmetic => true,
   # Override inspect for value objects. This makes expression dumps more
  # readable, but less precise.
  :inspect_to_s => true,
   # Biggest factorial that we calculate to a value
  :max_calculated_factorial => 100,
}
@@special_variables =
{
  :basis.to_m => 1,
  :g.to_m => 1,
}
@@variable_assignments =
{
  # Some variables with special meanings
   # Row matrix of variable names used as the coordinates in differential
  # geometry analyses. These define the dimension of the manifold, and
  # also as the default names of the basis vectors and co-vectors of the
  # tangent space.
  :basis.to_m => [:x1, :x2, :x3].to_m,
   # Metric tensor, relative to the chosen basis (subscript indexes)
  :g.to_m => [[1, 0, 0],
              [0, 1, 0],
              [0, 0, 1]].to_m,
}
@@parser =
SyMath::Parser.new

Class Method Summary collapse

Class Method Details

.assign_variable(var, value) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/symath.rb', line 107

def self.assign_variable(var, value)
  var = var.to_m
  value = value.to_m
  
  # Check that name is a variable
  if !var.is_a?(SyMath::Definition::Variable)
    raise "#{var} is not a variable"
  end

  if !value.is_a?(SyMath::Value)
    raise "#{value} is not a SyMath::Value"
  end
  
  @@variable_assignments[var] = value

  # Re-calculate basis vectors if the basis or the metric tensor
  # changes
  if var.name.to_sym == :g or var.name.to_sym == :basis
    SyMath::Definition::Variable.recalc_basis_vectors
  end
end

.clear_variable(var) ⇒ Object



138
139
140
# File 'lib/symath.rb', line 138

def self.clear_variable(var)
  @@variable_assignments.delete(var.to_m)
end

.define_equation(exp1, exp2) ⇒ Object



95
96
97
# File 'lib/symath.rb', line 95

def self.define_equation(exp1, exp2)
  return SyMath::Equation.new(exp1, exp2)
end

.get_variable(var) ⇒ Object



103
104
105
# File 'lib/symath.rb', line 103

def self.get_variable(var)
  return @@variable_assignments[var.to_m]
end

.get_variablesObject



99
100
101
# File 'lib/symath.rb', line 99

def self.get_variables()
  return @@variable_assignments
end

.parse(str) ⇒ Object



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

def self.parse(str)
  return @@parser.parse(str)
end

.set_metric(g, basis = nil) ⇒ Object



129
130
131
132
133
134
135
136
# File 'lib/symath.rb', line 129

def self.set_metric(g, basis = nil)
  @@variable_assignments[:g.to_m] = g
  if !basis.nil?
    @@variable_assignments[:basis.to_m] = basis
  end

  SyMath::Definition::Variable.recalc_basis_vectors
end

.setting(name, value = nil) ⇒ Object

Note: No type checking here, although the library code expects the various parameters to be of specific types (boolean, string, etc.). Failure and/or strange behaviour must be expected if they are set to different types.



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/symath.rb', line 58

def self.setting(name, value = nil)
  name = name.to_sym
  if !@@global_settings.key?(name)
    raise "Setting #{name} does not exist"
  end

  if !value.nil?
    @@global_settings[name] = value
  end

  return @@global_settings[name]
end

.settingsObject



71
72
73
# File 'lib/symath.rb', line 71

def self.settings()
  return @@global_settings
end