Constructornew
Expects a hash reference as first argument. That hash's contents will be treated as key-value pairs of
object attributes. Important attributes are 'type' => OPERATORTYPE (use constants as exported by
Math::Symbolic::ExportConstants!) and 'operands=>[op1,op2,...]'. Where the operands themselves may
either be valid Math::Symbolic::* objects or strings that will be parsed as such.
Special case: if no hash reference was found, first argument is assumed to be the operator's symbol and
the operator is assumed to be binary. The following 2 arguments will be treated as operands. This special
case will ignore attempts to clone objects but if the operands are no valid Math::Symbolic::* objects,
they will be sent through a Math::Symbolic::Parser to construct Math::Symbolic trees.
Returns a Math::Symbolic::Operator.
Supported operator symbols: (number of operands and their function in parens)
+ => sum (2)
- => difference (2)
* => product (2)
/ => division (2)
log => logarithm (2: base, function)
^ => exponentiation (2: base, exponent)
neg => unary minus (1)
partial_derivative => partial derivative (2: function, var)
total_derivative => total derivative (2: function, var)
sin => sine (1)
cos => cosine (1)
tan => tangent (1)
cot => cotangent (1)
asin => arc sine (1)
acos => arc cosine (1)
atan => arc tangent (1)
atan2 => arc tangent of y/x (2: y, x)
acot => arc cotangent (1)
sinh => hyperbolic sine (1)
cosh => hyperbolic cosine (1)
asinh => hyperbolic area sine (1)
acosh => hyperbolic area cosine (1)
Methodarity
Returns the operator's arity as an integer.
Methodtype
Optional integer argument that sets the operator's type. Returns the operator's type as an integer.
Methodto_string
Returns a string representation of the operator and its operands. Optional argument: 'prefix' or
'infix'. Defaults to 'infix'.
Methodterm_type
Returns the type of the term. ( T_OPERATOR )
Methodsimplify
Term simpilification. First argument: Boolean indicating that the tree does not need to be cloned, but
can be restructured instead. While this is faster, you might not be able to use the old tree any more.
Example:
my $othertree = $tree->simplify();
# can use $othertree and $tree now.
my $yetanothertree = $tree->simplify(1);
# must not use $tree any more because its internal
# representation might have been destroyed.
If you want to optimize a routine and you're sure that you won't need the unsimplified tree any more, go
ahead and use the first parameter. In all other cases, you should go the safe route.
Methodsop1andop2
Returns first/second operand of the operator if it exists or undef.
Methodapply
Applies the operation to its operands' value() and returns the result as a constant (-object).
Without arguments, all variables in the tree are required to have a value. If any don't, the call to
apply() returns undef.
To (temorarily, for this single method call) assign values to variables in the tree, you may provide
key/value pairs of variable names and values. Instead of passing a list of key/value pairs, you may also
pass a single hash reference containing the variable mappings.
You usually want to call the value() instead of this.
Methodvaluevalue() evaluates the Math::Symbolic tree to its numeric representation.
value() without arguments requires that every variable in the tree contains a defined value attribute.
Please note that this refers to every variable object, not just every named variable.
value() with one argument sets the object's value if you're dealing with Variables or Constants. In case
of operators, a call with one argument will assume that the argument is a hash reference. (see next
paragraph)
value() with named arguments (key/value pairs) associates variables in the tree with the value-arguments
if the corresponging key matches the variable name. (Can one say this any more complicated?) Since
version 0.132, an equivalent and valid syntax is to pass a single hash reference instead of a list.
Example: $tree->value(x => 1, y => 2, z => 3, t => 0) assigns the value 1 to any occurrances of variables
of the name "x", aso.
If a variable in the tree has no value set (and no argument of value sets it temporarily), the call to
value() returns undef.
Methodsignaturesignature() returns a tree's signature.
In the context of Math::Symbolic, signatures are the list of variables any given tree depends on. That
means the tree "v*t+x" depends on the variables v, t, and x. Thus, applying signature() on the tree that
would be parsed from above example yields the sorted list ('t', 'v', 'x').
Constants do not depend on any variables and therefore return the empty list. Obviously, operators'
dependencies vary.
Math::Symbolic::Variable objects, however, may have a slightly more involved signature. By convention,
Math::Symbolic variables depend on themselves. That means their signature contains their own name. But
they can also depend on various other variables because variables themselves can be viewed as
placeholders for more compicated terms. For example in mechanics, the acceleration of a particle depends
on its mass and the sum of all forces acting on it. So the variable 'acceleration' would have the
signature ('acceleration', 'force1', 'force2',..., 'mass', 'time').
If you're just looking for a list of the names of all variables in the tree, you should use the
explicit_signature() method instead.
Methodexplicit_signatureexplicit_signature() returns a lexicographically sorted list of variable names in the tree.
See also: signature().