Math::...riable(3pm)

πŸ’– Math::Symbolic::Variable πŸ’–

okay so bestie, welcome to a page straight out of the User Contributed Perl Documentation (that's the 3pm energy right there, iykyk) and today's main character is Math::Symbolic::Variable. she's a whole vibe and she's here to explain herself. let's go πŸ¦‹


🌸 NAME 🌸

Math::Symbolic::Variable β€” the Variable in symbolic calculations, periodt.


✨ SYNOPSIS ✨

use Math::Symbolic::Variable;

my $var1 = Math::Symbolic::Variable->new('name');
$var1->value(5);

my $var2 = Math::Symbolic::Variable->new('x', 2);

my $var3 =
  Math::Symbolic::Variable->new(
    {
      name  => 'variable',
      value => 1,
    }
  );

that's it. that's the whole flex. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

so this class implements variables for Math::Symbolic trees. that's literally her job and she eats every time. πŸ”₯

and the cute part? the objects are overloaded in stringification context to return their names. so when you stringify one, you don't get some cursed memory address situation β€” you get her name back. iconic behavior fr fr.

🧁 EXPORT 🧁

None by default. not a single thing, bestie. zero. nada. you gotta ask for what you want. πŸ’€


πŸ”₯ METHODS πŸ”₯

⭐ Constructor new ⭐

the first argument is expected to be a hash reference of key-value pairs, and those pairs get used as the object's attributes. slay.

specifically: a variable is required to have a 'name'. optional arguments include a 'value', and a 'signature'. the value expected for the signature key is a reference to an array of identifiers.

special case alert!! if the first argument is not a hash reference, then the first argument gets treated as the variable name and the second as the value. but bestie listen β€” this special case disallows cloning of objects when it's used as an object method. so heads up. 🫢

returns a Math::Symbolic::Variable. cute!

🌈 Method value 🌈

value() evaluates the Math::Symbolic tree to its numeric representation.

value() with no arguments requires that every variable in the tree contains a defined value attribute. and please note β€” that means every variable object, not just every named variable. the way that's important. 😭

value() with one argument sets the object's value if you're dealing with Variables or Constants. and if it's operators we're talking about? a call with one argument will just assume that the argument is a hash reference. (see the next paragraph bb)

value() with named arguments (those key/value pairs) associates variables in the tree with the value-arguments if the corresponding key matches the variable name. (can one say this any more complicated? literally no, but we move.) since version 0.132, an equivalent and valid syntax is to pass a single hash reference instead of a list. so you've got options, queen. πŸ‘‘

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. yeah. she will simply hand you undef and walk away. πŸ™ˆ

πŸ¦‹ Method name πŸ¦‹

optional argument: sets the object's name. returns the object's name. simple, clean, no notes. ✨

πŸ’œ Method signature πŸ’œ

signature() returns a tree's signature.

in the context of Math::Symbolic, signatures are the list of variables any given tree depends on. meaning the tree "v*t+x" depends on the variables v, t, and x. so if you apply signature() on the tree that would be parsed from that example up there, you get the sorted list ('t', 'v', 'x'). sorted! she's organized like that. πŸŽ€

constants do not depend on any variables and therefore return the empty list. and obviously, operators' dependencies vary.

Math::Symbolic::Variable objects, however, may have a slightly more involved signature. by convention, Math::Symbolic variables depend on themselves. so 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 complicated 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'). she contains multitudes fr. 🌸

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. don't do extra work for no reason bestie.

🌟 Method explicit_signature 🌟

explicit_signature() returns a lexicographically sorted list of variable names in the tree.

see also: signature().

πŸ“ Method set_signature πŸ“

set_signature expects any number of variable identifiers as arguments. it sets a variable's signature to this list of identifiers. boom. done. served. πŸ’…

🧚 Method to_string 🧚

returns a string representation of the variable. yep, that's the whole thing. 🫢

πŸ‘‘ Method term_type πŸ‘‘

returns the type of the term. (T_VARIABLE)


πŸ’Œ AUTHOR πŸ’Œ

please send feedback, bug reports, and support requests to the Math::Symbolic support mailing list: math-symbolic-support at lists dot sourceforge dot net. and please consider letting us know how you use Math::Symbolic. thank you!! πŸ₯Ί

if you're interested in helping with the development or extending the module's functionality, please contact the developers' mailing list: math-symbolic-develop at lists dot sourceforge dot net.

list of contributors:

Steffen MοΏ½ller, symbolic-module at steffen-mueller dot net
Stray Toaster, mwk at users dot sourceforge dot net
Oliver EbenhοΏ½h

(the little οΏ½ situations are just an encoding oopsie from the original page, no cap β€” the names are still exactly as written there πŸ’œ)


πŸ”­ SEE ALSO πŸ”­

new versions of this module can be found on http://steffen-mueller.net or CPAN. the module development takes place on Sourceforge at http://sourceforge.net/projects/math-symbolic/

Math::Symbolic


and that's the whole page bestie!! πŸŽ‰ this was perl v5.40.0, dated 2024-09-16, brought to you by the User Contributed Perl Documentation β€” go forth and assign some values, you absolute icon πŸ‘‘πŸ’–

πŸ“¦ where this page comes from