Basic Expression Simplification


#1

I've added some new basic algebraic simplificaitons to the juce expression class as part of my sparse optimized matrix solver, so I thought I'd share the latest version. It only handles simplifications of + - * / , and it's no where near a full CAS, but it is useful to trim off the fat off expressions before generating code to compile (which is what my matrix solver does) or for evaluating them (eg if you support user entered expressions in your program). I've also added a few different output options, so you can auto generate infix / prefix code from them. 

​a+a*b --> a*(1+b)
a/a --> 1
a+a --> 2*a
(a+b)*c + (a+b)*d --> (a+b)*(c+d)
a/b/c --> a/(b*c)

https://dl.dropboxusercontent.com/u/14219031/Juce/BasicExpressionSimplification.zip


#2

Very interesting, thanks !


#3

You're welcome! In the future I hope to add more complicated simplifications, as these were pretty easy to get going.

I forgot to say that the SSE/SSE2 output of expressions also balances the intrinsics to make the calls as parallel as possible so the compiler can optimise them, so things like a+b+c+d get turned into: add (add (a, b), add (c, d))

One area I would also like to spend more time on is optimisations of multiple expressions, pulling out loop invarients, pulling out initialisation time invarients, and also common sub-expressions in a series of expressions, then outputing these optimisations as code to give the compiler as much help as possible. These simplifications and optimisations could be either run on automatically generated code from a solver (like I'm doing) or parse normal c code and optimise that.


#4

Perhaps this is naive, but this seems like something that would be beneficial if built into native JUCE.  Is that something that Roli is considering?


#5

I started juceifying Andrew's classes with the aim of adding them, but haven't finished yet, there's quite a bit involved!


#6

Ok.  Thank you for the effort Jules!