Math::Expression::Evaluator::Optimizer - Optimize Math::Expression::Evaluator ASTs


NAME

Math::Expression::Evaluator::Optimizer - Optimize Math::Expression::Evaluator ASTs


SYNOPSIS

    use Math::Expression::Evaluator;
    my $m = Math::Expression::Evaluator->new("2 + 4*f");
    $m->optimize();
    for (0..100){
        print $m->val({f => $_}), "\n";
    }


DESCRIPTION

Math::Expression::Evaluator::Optimizer performs simple optimizations on the abstract syntax tree from Math::Expression::Evaluator.

You should not use this module directly, but interface it via the Math::Expression::Evaluator manpage.

The following optimizations are implemented:


PERFORMANCE CONSIDERATIONS

optimize() currently takes two full loops through the AST, copying and recreating it. If you execute val() only once, calling optimize() is in fact a performance loss.

If the expression is optimizable, and you execute it $n times, you usually have a net gain over unoptimized execution if $n > 15.

Of course that value depends on the complexity of the expression, and how well it can be reduced by the implemented optimizations.

Your best is to always benchmark what you do. If you are really serious about performance, you can use the Math::Calculus::Expression manpage and its method simplify.