GNU.WIKI: The GNU/Linux Knowledge Base

[HOME] [PHP Manual] [HowTo] [ABS] [MAN1] [MAN2] [MAN3] [MAN4] [MAN5] [MAN6] [MAN7] [MAN8] [MAN9]

[0-9] [Aa] [Bb] [Cc] [Dd] [Ee] [Ff] [Gg] [Hh] [Ii] [Jj] [Kk] [Ll] [Mm] [Nn] [Oo] [Pp] [Qq] [Rr] [Ss] [Tt] [Uu] [Vv] [Ww] [Xx] [Yy] [Zz]

## NAMEMath::Symbolic::Compiler - Compile Math::Symbolic trees to Perl code ## SYNOPSISuse Math::Symbolic::Compiler; # A tree to compile my $tree = Math::Symbolic->parse_from_string('a^2 + b * c * 2'); # The Math::Symbolic::Variable 'a' will be evaluated to $_[1], etc. my $vars = [qw(b a c)]; my ($closure, $code, $trees) = Math::Symbolic::Compiler->compile($tree, $vars); print $closure->(2, 3, 5); # (b, a, c) # prints 29 (= 3^2 + 2 * 5 * 2) # or: ($closure, $trees) = Math::Symbolic::Compiler->compile_to_sub($tree, $vars); ($code, $trees) = Math::Symbolic::Compiler->compile_to_code($tree, $vars); ## DESCRIPTIONThis module allows one to compile Math::Symbolic trees to Perl code and/or anonymous subroutines whose arguments will be positionally mapped to the variables of the compiled Math::Symbolic tree. The reason you'd want to do this is that evaluating a Math::Symbolic tree to its numeric value is extremely slow. So is compiling, but once you've done all necessary symbolic calculations, you can take advantage of the speed gain of invoking a closure instead of evaluating a tree. UNCOMPILED LEFTOVER TREES Not all, however, is well in the land of compiled Math::Symbolic trees. There may occasionally be trees that cannot be compiled (such as a derivative) which need to be included into the code as trees. These trees will be returned in a referenced array by the compile*() methods. The closures will have access to the required trees as a special variable '@_TREES inside the closure's scope, so you need not worry about them in that case. But if you plan to use the generated code itself, you need to supply an array named @_TREES that contains the trees as returned by the compile*() methods in the scope of the ## SUBROUTINES($code, $trees) = compile_to_code($tree, $vars) The ## AUTHORPlease send feedback, bug reports, and support requests to the Math::Symbolic support mailing list: math-symbolic-support at lists dot sourceforge dot net. Please consider letting us know how you use Math::Symbolic. Thank you. 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 MXller, symbolic-module at steffen-mueller dot net Stray Toaster, mwk at users dot sourceforge dot net Oliver EbenhXh ## SEE ALSONew 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 |

** All copyrights belong to their respective owners. Other content (c) 2014-2018, GNU.WIKI. Please report site errors to webmaster@gnu.wiki.Page load time: 0.113 seconds. Last modified: November 04 2018 12:49:43.**