1Math::NumSeq::ExpressioUns(e3r)Contributed Perl DocumentMaattiho:n:NumSeq::Expression(3)
2
3
4

NAME

6       Math::NumSeq::Expression -- mathematical expression values
7

SYNOPSIS

9        use Math::NumSeq::Expression;
10        my $seq = Math::NumSeq::Expression->new (expression => '2*i+1');
11        my ($i, $value) = $seq->next;
12

DESCRIPTION

14       A string expression evaluated at i=0, 1, 2, etc, by Perl or a choice of
15       evaluator modules.
16
17       This is designed to take expression strings from user input though
18       could be used for something quick from program code too.  The
19       expression syntax in the evaluator modules varies in subtle ways.
20
21   Perl
22       The default "expression_evaluator => 'Perl'" evaluates with Perl
23       itself.  This is always available.  Expressions are run with the "Safe"
24       module to restrict to arithmetic (see Safe).
25
26       The i index is in a $i variable and an "i()" function.  The "i()"
27       function is prototyped like a constant.
28
29           i+1
30           2*$i - 2
31
32       The functions made available include
33
34           atan2 sin cos exp log                 \    Perl builtins
35             sqrt rand                           /
36           min max                               List::Util
37           floor ceil                            POSIX module
38           cbrt hypot erf erfc expm1             \
39             j0 j1 jn lgamma_r log10              |  Math::Libm
40             log1p pow rint y0 y1 yn             /
41           tan asin acos atan                    \
42             csc cosec sec cot cotan              |  Math::Trig
43             acsc acosec asec acot acotan         |
44             sinh cosh tanh                       |
45             csch cosech sech coth cotanh         |
46             asinh acosh atanh                    |
47             acsch acosech asech acoth acotanh   /
48
49   Math-Symbolic
50       "expression_evaluator => 'MS'" selects the "Math::Symbolic" module, if
51       available.
52
53       The expression is parsed with "Math::Symbolic->parse_from_string()" and
54       should use a single variable for the i index in the sequence.  The
55       variable can be any name, not just  "i"
56
57           2*i+1
58           x^2 + x + 1           # any single variable
59
60       The usual "$ms->simplify()" is applied to perhaps reduce the expression
61       a bit, then "to_sub()" for actual evaluation.
62
63   Math-Expression-Evaluator
64       "expression_evaluator => 'MEE'" selects the
65       "Math::Expression::Evaluator" module, if available.
66
67       The expression should use a single input variable, which can be any
68       name, and takes the i index in the sequence.  Temporary variables can
69       be used by assigning to them,
70
71           x^2 + x + 1      # any single variable
72           t=2*i; t^2       # temporary variables assigned
73
74       The expression is run with "$mee->compiled()".  It turns the expression
75       into a Perl subr for actual evaluation.
76
77   Language-Expr
78       "expression_evaluator => 'LE'" selects the "Language::Expr" module, if
79       available.
80
81       The expression should use a single variable, of any name, which will be
82       the i index in the sequence.  See Language::Expr::Manual::Syntax for
83       the expression syntax.
84
85           $x*$x + $x + 1
86
87       The expression is compiled with Language::Expr::Compiler::perl for
88       evaluation.
89

FUNCTIONS

91       See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
92       classes.
93
94       "$seq = Math::NumSeq::Expression->new (expression => $str)"
95           Create and return a new sequence object.
96
97   Random Access
98       "$value = $seq->ith($i)"
99           Return the "expression" evaluated at $i.
100

BUGS

102       "Safe.pm" seems a bit of a slowdown.  Is that right or is it supposed
103       to validate ops during the eval which compiles a subr?
104

SEE ALSO

106       Math::NumSeq, Safe Math::Symbolic, Math::Expression::Evaluator,
107       Language::Expr
108

HOME PAGE

110       <http://user42.tuxfamily.org/math-numseq/index.html>
111

LICENSE

113       Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019 Kevin Ryde
114
115       Math-NumSeq is free software; you can redistribute it and/or modify it
116       under the terms of the GNU General Public License as published by the
117       Free Software Foundation; either version 3, or (at your option) any
118       later version.
119
120       Math-NumSeq is distributed in the hope that it will be useful, but
121       WITHOUT ANY WARRANTY; without even the implied warranty of
122       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
123       General Public License for more details.
124
125       You should have received a copy of the GNU General Public License along
126       with Math-NumSeq.  If not, see <http://www.gnu.org/licenses/>.
127
128
129
130perl v5.32.1                      2021-01-27       Math::NumSeq::Expression(3)
Impressum