1Math::Symbolic::VariablUes(e3r)Contributed Perl DocumentMaattiho:n:Symbolic::Variable(3)
2
3
4

NAME

6       Math::Symbolic::Variable - Variable in symbolic calculations
7

SYNOPSIS

9         use Math::Symbolic::Variable;
10
11         my $var1 = Math::Symbolic::Variable->new('name');
12         $var1->value(5);
13
14         my $var2 = Math::Symbolic::Variable->new('x', 2);
15
16         my $var3 =
17           Math::Symbolic::Variable->new(
18             {
19               name  => 'variable',
20               value => 1,
21             }
22           );
23

DESCRIPTION

25       This class implements variables for Math::Symbolic trees.  The objects
26       are overloaded in stringification context to return their names.
27
28   EXPORT
29       None by default.
30

METHODS

32   Constructor new
33       First argument is expected to be a hash reference of key-value pairs
34       which will be used as object attributes.
35
36       In particular, a variable is required to have a 'name'. Optional
37       arguments include a 'value', and a 'signature'. The value expected for
38       the signature key is a reference to an array of identifiers.
39
40       Special case: First argument is not a hash reference. In this case,
41       first argument is treated as variable name, second as value.  This
42       special case disallows cloning of objects (when used as object method).
43
44       Returns a Math::Symbolic::Variable.
45
46   Method value
47       value() evaluates the Math::Symbolic tree to its numeric
48       representation.
49
50       value() without arguments requires that every variable in the tree
51       contains a defined value attribute. Please note that this refers to
52       every variable object, not just every named variable.
53
54       value() with one argument sets the object's value if you're dealing
55       with Variables or Constants. In case of operators, a call with one
56       argument will assume that the argument is a hash reference. (see next
57       paragraph)
58
59       value() with named arguments (key/value pairs) associates variables in
60       the tree with the value-arguments if the corresponging key matches the
61       variable name.  (Can one say this any more complicated?) Since version
62       0.132, an equivalent and valid syntax is to pass a single hash
63       reference instead of a list.
64
65       Example: $tree->value(x => 1, y => 2, z => 3, t => 0) assigns the value
66       1 to any occurrances of variables of the name "x", aso.
67
68       If a variable in the tree has no value set (and no argument of value
69       sets it temporarily), the call to value() returns undef.
70
71   Method name
72       Optional argument: sets the object's name.  Returns the object's name.
73
74   Method signature
75       signature() returns a tree's signature.
76
77       In the context of Math::Symbolic, signatures are the list of variables
78       any given tree depends on. That means the tree "v*t+x" depends on the
79       variables v, t, and x. Thus, applying signature() on the tree that
80       would be parsed from above example yields the sorted list ('t', 'v',
81       'x').
82
83       Constants do not depend on any variables and therefore return the empty
84       list.  Obviously, operators' dependencies vary.
85
86       Math::Symbolic::Variable objects, however, may have a slightly more
87       involved signature. By convention, Math::Symbolic variables depend on
88       themselves. That means their signature contains their own name. But
89       they can also depend on various other variables because variables
90       themselves can be viewed as placeholders for more compicated terms. For
91       example in mechanics, the acceleration of a particle depends on its
92       mass and the sum of all forces acting on it. So the variable
93       'acceleration' would have the signature ('acceleration', 'force1',
94       'force2',..., 'mass', 'time').
95
96       If you're just looking for a list of the names of all variables in the
97       tree, you should use the explicit_signature() method instead.
98
99   Method explicit_signature
100       explicit_signature() returns a lexicographically sorted list of
101       variable names in the tree.
102
103       See also: signature().
104
105   Method set_signature
106       set_signature expects any number of variable identifiers as arguments.
107       It sets a variable's signature to this list of identifiers.
108
109   Method to_string
110       Returns a string representation of the variable.
111
112   Method term_type
113       Returns the type of the term. (T_VARIABLE)
114

AUTHOR

116       Please send feedback, bug reports, and support requests to the
117       Math::Symbolic support mailing list: math-symbolic-support at lists dot
118       sourceforge dot net. Please consider letting us know how you use
119       Math::Symbolic. Thank you.
120
121       If you're interested in helping with the development or extending the
122       module's functionality, please contact the developers' mailing list:
123       math-symbolic-develop at lists dot sourceforge dot net.
124
125       List of contributors:
126
127         Steffen Mueller, symbolic-module at steffen-mueller dot net
128         Stray Toaster, mwk at users dot sourceforge dot net
129         Oliver Ebenhoeh
130

SEE ALSO

132       New versions of this module can be found on http://steffen-mueller.net
133       or CPAN. The module development takes place on Sourceforge at
134       http://sourceforge.net/projects/math-symbolic/
135
136       Math::Symbolic
137
138
139
140perl v5.30.1                      2020-01-30       Math::Symbolic::Variable(3)
Impressum