-
-
23 Feb 2020 03:55:27 UTC
- Distribution: Math-NumSeq
- Module version: 74
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Issues (1)
- Testers (550 / 6 / 0)
- Kwalitee
Bus factor: 1- License: gpl_3
- Perl: v5.4.0
- Activity
24 month- Tools
- Download (819.92KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
NAME
Math::NumSeq::Expression -- mathematical expression values
SYNOPSIS
use Math::NumSeq::Expression; my $seq = Math::NumSeq::Expression->new (expression => '2*i+1'); my ($i, $value) = $seq->next;
DESCRIPTION
A string expression evaluated at i=0, 1, 2, etc, by Perl or a choice of evaluator modules.
This is designed to take expression strings from user input though could be used for something quick from program code too. The expression syntax in the evaluator modules varies in subtle ways.
Perl
The default
expression_evaluator => 'Perl'
evaluates with Perl itself. This is always available. Expressions are run with theSafe
module to restrict to arithmetic (see Safe).The i index is in a
$i
variable and ani()
function. Thei()
function is prototyped like a constant.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 theMath::Symbolic
module, if available.The expression is parsed with
Math::Symbolic->parse_from_string()
and should use a single variable for the i index in the sequence. 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 perhaps reduce the expression a bit, thento_sub()
for actual evaluation.Math-Expression-Evaluator
expression_evaluator => 'MEE'
selects theMath::Expression::Evaluator
module, if available.The expression should use a single input variable, which can be any name, and takes the i index in the sequence. Temporary variables can be used by assigning to them,
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 theLanguage::Expr
module, if available.The expression should use a single variable, of any name, which will be the i index in the sequence. See Language::Expr::Manual::Syntax for the expression syntax.
$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.
Random Access
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?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 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/>.
Module Install Instructions
To install Math::NumSeq, copy and paste the appropriate command in to your terminal.
cpanm Math::NumSeq
perl -MCPAN -e shell install Math::NumSeq
For more information on module installation, please visit the detailed CPAN module installation guide.