Math::N...ression(3)
โจ NAME โจ
Math::NumSeq::Expression โ mathematical expression values ๐
(ngl bestie, this is a User Contributed Perl Documentation page, and the manual name is literally squished down to Math::N...ression because the column budget said no ๐ญ)
๐ธ SYNOPSIS ๐ธ
use Math::NumSeq::Expression;
my $seq = Math::NumSeq::Expression->new (expression => '2*i+1');
my ($i, $value) = $seq->next;
๐ฆ DESCRIPTION ๐ฆ
So the whole vibe is: it's a string expression, and it gets evaluated at i=0, 1, 2, etc โ by Perl or by whichever evaluator module you pick. โจ
It's literally designed to take expression strings straight from user input, though you could also use it for something quick from program code. Just know that the expression syntax across the evaluator modules varies in subtle ways โ so like, pick one and stay loyal to it fr fr. ๐
๐ช Perl
The default expression_evaluator => 'Perl' evaluates with Perl itself. This one is always available โ it's the ride-or-die default. Expressions are run with the Safe module to restrict to arithmetic (see Safe).
The i index lives in a $i variable and also in an i() function. And the i() function is prototyped like a constant, which is very iconic of it.
i+1
2*$i - 2
The functions made available include:
atan2 sin cos exp log \ Perl builtins
sqrt rand /
min max List::Util
floor ceil POSIX module
cbrt hypot erf erfc expm1 \
j0 j1 jn lgamma_r log10 | Math::Libm
log1p pow rint y0 y1 yn /
tan asin acos atan \
csc cosec sec cot cotan | Math::Trig
acsc acosec asec acot acotan |
sinh cosh tanh |
csch cosech sech coth cotanh |
asinh acosh atanh |
acsch acosech asech acoth acotanh /
๐ฎ Math-Symbolic
expression_evaluator => 'MS' selects the Math::Symbolic module โ if it's available, bestie, that's the catch. ๐
The expression gets parsed with Math::Symbolic->parse_from_string() and should use a single variable for the i index in the sequence. And plot twist: the variable can be any name, not just i. ๐
2*i+1
x^2 + x + 1 # any single variable
The usual $ms->simplify() is applied to maybe reduce the expression a bit, then to_sub() for the actual evaluation. Slay.
๐งฎ Math-Expression-Evaluator
expression_evaluator => 'MEE' selects the Math::Expression::Evaluator module โ again, if available. ๐ซถ
The expression should use a single input variable, which can be any name, and it takes the i index in the sequence. Temporary variables can be used by assigning to them, which is lowkey so fun:
x^2 + x + 1 # any single variable
t=2*i; t^2 # temporary variables assigned
The expression is run with $mee->compiled(). It turns the expression into a Perl subr for actual evaluation. โจ
๐ Language-Expr
expression_evaluator => 'LE' selects the Language::Expr module โ yep, if available. ๐
The expression should use a single variable, of any name, which will be the i index in the sequence. Peep Language::Expr::Manual::Syntax for the expression syntax, iykyk.
$x*$x + $x + 1
The expression is compiled with Language::Expr::Compiler::perl for evaluation.
๐ FUNCTIONS ๐
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::Expression->new (expression => $str)โ Create and return a new sequence object. Brand new, fresh out the box. ๐
๐ฒ Random Access
$value = $seq->ith($i)โ Return theexpressionevaluated at$i. That's it, that's the whole job. ๐
๐ BUGS ๐
Safe.pm seems a bit of a slowdown. Is that right, or is it supposed to validate ops during the eval which compiles a subr? Genuinely asking, bestie, nobody knows. ๐ญ
๐ SEE ALSO ๐
Math::NumSeq, Safe Math::Symbolic, Math::Expression::Evaluator, Language::Expr
๐ HOME PAGE ๐
<http://user42.tuxfamily.org/math-numseq/index.html>
๐ LICENSE ๐
Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
okay that's the whole page, you ate that ๐
โจ this masterpiece is brought to you by perl v5.42.0, dated 2025-07-25 โ periodt, no cap, go forth and evaluate some expressions bestie ๐ฆ๐
๐ฆ where this page comes from
- fedora 43: perl-Math-NumSeq 75-11.fc43 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms