Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: minimizing simple linear equations

by shotgunefx (Parson)
on Mar 13, 2006 at 23:13 UTC ( #536413=note: print w/replies, xml ) Need Help??


in reply to minimizing simple linear equations

You might find this helpful.
Evaluate Expressions. This is one of my favorite things I've ever written. It parses expressions and evaluates them. It's the basis for a mini language that got put on hold for some time.

In the evaulate sub, right after  @$ops = grep { defined $_ } @$ops; You basically have a parse tree.

For your example, you'd have
(foo*2) + (foo*3) $ops = [ [ 'foo', '*', '2' ], '+', [ 'foo', '*', '3' ] ];
You could modify it there to optimize the tree the way you w ant.

-Lee
"To be civilized is to deny one's nature."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://536413]
help
Chatterbox?
[LanX]: Enemies_of_the_Peo ple
[LanX]: Enemies_of_the_Peo ple
[LanX]: and https://en. wikipedia.org/ wiki/Enemy_of_the_ people#Recent_usag e

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-03-27 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.