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:20epsilonβ the accuracy of the numeric comparison. Default:1e-7retriesβ the number of attempts to make if a function evaluation throws an error.upperβ upper limit of the random numbers. Default:10lowerβ 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
- ubuntu resolute: libmath-symbolic-perl 0.613-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmath-symbolic-perl 0.613-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms