Math::...tTests(3pm)

πŸŽ€ Math::Symbolic::Custom::DefaultTests β€” the default vibe-check squad for Math::Symbolic trees ✨

okay so bestie, welcome to Math::Symbolic::Custom::DefaultTests, a whole class of default tests for Math::Symbolic trees. Same energy as Math::Symbolic::Custom::DefaultMods, except that one defines default tree transformation routines and this one is all about asking trees questions and getting 1 or 0 back πŸ’…

want the tea on how the custom method delegation model actually works? go peek at the Math::Symbolic::Custom and Math::Symbolic::Custom::Base classes, they spill everything πŸ«–


πŸ’– SYNOPSIS πŸ’–

use Math::Symbolic;

that's it. that's the whole ritual, no cap 🌸


🌈 DESCRIPTION 🌈

so Math::Symbolic::Custom::DefaultTests is literally the class that holds all the default tests for Math::Symbolic trees. meanwhile Math::Symbolic::Custom::DefaultMods is its sibling who handles the default tree transformation routines, because one icon can't do everything πŸ‘‘

and if you're curious about the custom method delegation model β€” the whole how-does-this-even-work of it all β€” the Math::Symbolic::Custom and Math::Symbolic::Custom::Base classes have the full lore. go read them, iykyk πŸ“š

πŸ¦‹ EXPORT πŸ¦‹

check the docs on Math::Symbolic::Custom::Base for the deets, but do NOT try to use the standard Exporter semantics with this class, okay? that's not the move, bestie. it will not slay πŸ™ˆ


✨ SUBROUTINES ✨

πŸ’… is_zero()

returns true (1) if the tree is a constant and '0'. returns false (0) otherwise. simple as πŸ“

πŸ’… is_one()

returns true (1) if the tree is a constant and '1'. returns false (0) otherwise. twin of the one above, honestly πŸ‘―

πŸ’… is_zero_or_one()

returns true if the tree is a constant and '1' or '0' β€” specifically '1' for 1 and '0E0' for 0. returns false (0) otherwise. two-for-one deal, we love to see it πŸŽ€

πŸ’… is_integer()

is_integer() returns a boolean.

it returns true (1) if the tree is a constant object representing an integer value. it does not compute the value of the tree. like, for eg. '5*10' is not considered an integer, but '50' is. no math happening here, it's just vibes-checking the shape πŸ”

it returns false (0) otherwise.

πŸ’… is_simple_constant()

is_simple_constant() returns a boolean.

it returns true if the tree consists of only constants and operators. and here's the tea: as opposed to is_constant(), is_simple_constant() does not apply derivatives if necessary. so it's the cheap, fast, no-drama version of the check πŸ’¨

it returns false (0) otherwise.

πŸ’… is_constant()

is_constant() returns a boolean.

it returns true (1) if the tree consists of only constants and operators, or if it becomes a tree of only constants and operators after application of derivatives. yes, it does the whole derivative thing 😭

it returns false (0) otherwise.

if you need not pay the price of applying derivatives, you should use the is_simple_constant() method instead. periodt. your CPU will thank you 🫢

πŸ’… is_identical()

is_identical() returns a boolean.

it compares the tree it is called on to its first argument. if the first argument is not a Math::Symbolic tree, it gets sent through the parser first, no worries 🌸

is_identical() returns true (1) if the trees are completely identical. and i mean completely β€” that includes operands of commutating operators having the same order, etc. this does not test of mathematical equivalence! like, do not come for this function expecting it to know that stuff. (which is much, much harder to test for. if you know how to, please let me know!) 😭

it returns false (0) otherwise.

πŸ‘‘ is_identical_base

is_identical_base() returns a boolean.

it compares the tree it is called on to its first argument. if the first argument is not a Math::Symbolic tree, it is sent through the parser. same as above, consistency is key πŸ’…

is_identical_base() returns true (1) if the trees are identical or if they are exponentiations with the same base. the same gotchas that apply to is_identical apply here, too β€” watch out for those 🚨

for example, 'x*y' and '(x*y)^e' result in a true return value because 'x*y' is equal to '(x*y)^1' and this has the same base as '(x*y)^e'. see? iconic. ate. πŸ”₯

it returns false (0) otherwise.

🌸 is_sum()

(beta) β€” yes bestie, it said beta, we're in the early-access era πŸ§ͺ

is_constant() returns a boolean. (yes, the doc literally says that, i'm just the messenger 🫣)

it returns true (1) if the tree contains no variables (because it can then be evaluated to a single constant which is a sum). it also returns true if it is a sum or difference of constants and variables. furthermore, it is true for products of integers and constants because those products are really sums of variables. and if none of the above cases match, it applies all derivatives and tries again. it's giving determined πŸ’ͺ

it returns false (0) otherwise.

please contact the author in case you encounter bugs in the specs or implementation. the heuristics aren't all that great. they said it, not me πŸ™ˆ

πŸŽ€ test_num_equiv()

takes another Math::Symbolic tree or a code ref as first argument. it tests the tree it is called on and the one passed in as first argument for equivalence by sampling random numbers for their parameters and evaluating them. random chaos, but make it science 🎲

this is no guarantee that the functions are actually similar. the computation required for this test may be very high for large numbers of tests. so like, don't go feral with it 🫠

in case of a subroutine reference passed in, the values of the parameters of the Math::Symbolic tree are passed to the sub ref sorted by the parameter names. alphabetical bestie behavior πŸ“–

following the test-tree, there may be various options as key/value pairs:

limits: A hash reference with parameter names as keys and code refs
        as arguments. A code ref for parameter 'x', will be executed
        for every number of 'x' that is generated. If the code
        returns false, the number is discarded and regenerated.
tests:  The number of tests to carry out. Default: 20
epsilon: The accuracy of the numeric comparison. Default: 1e-7
retries: The number of attempts to make if a function evaluation
         throws an error.
upper:   Upper limit of the random numbers. Default: 10
lower:   Lower limit of the random numbers. Default: -10

quick rundown of the options so you're not lost πŸ’–:

  • limits β€” a hash reference with parameter names as keys and code refs as arguments. a code ref for parameter 'x', will be executed for every number of 'x' that is generated. if the code returns false, the number is discarded and regenerated. it's giving bouncer at the club πŸšͺ
  • tests β€” the number of tests to carry out. Default: 20
  • epsilon β€” the accuracy of the numeric comparison. Default: 1e-7
  • retries β€” the number of attempts to make if a function evaluation throws an error.
  • upper β€” upper limit of the random numbers. Default: 10
  • lower β€” lower limit of the random numbers. Default: -10

πŸ’Œ 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 🫢 (they really do wanna know, this is a genuine ask)

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 literal icons who built this πŸ‘‘πŸ‘‘πŸ‘‘


πŸ”— 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::Custom Math::Symbolic::Custom::DefaultDumpers Math::Symbolic::Custom::DefaultMods Math::Symbolic

go read all of them, they're the friend group 🌈


and that's the whole page bestie! this one's running on perl v5.40.0, dated 2024-09-16, and it lives in the Math::...tTests(3pm) corner of the perl manverse. go write something symbolic, slay, and remember: trees are just math with main character energy πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from