Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://536413]
[james28909]: oh ok, i gotcha
[shmem]: "talking of facts, it is irrelevant what you or I think about them." --Georg C. Lichtenberg
[james28909]: is reference the same as aliasing?
[shmem]: no
[shmem]: aliasing means "accessing the same thing by another name"
[james28909]: this makes sense to me. https://stackoverf 14224831/meaning- of-referencing-and -dereferencing
[james28909]: stack overflow
[james28909]: i think im going to ditch perl and learn C
[shmem]: for instance: for (@array) { $_ += 1 }; - here $_ inside the loop is an alias for the current element of @array
[james28909]: having to juggle between machines and perl versions and guis and compiling to a portable binary is slightly redundant when i could just use c or something

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2018-05-20 15:46 GMT
Find Nodes?
    Voting Booth?