So, let's do some rewriting using the pattern matching filter=true mode. Again, the VecMath.g parser will build trees but we'll avoid building an entire tree grammar. We'll focus on some patterns we want to rewrite.
Here's the grammar to build trees.
And now, let's distribute scalar-vector multiplies.
Give it a shot:
Now for stuff that needs to repeatedly get applied to subtrees.
I'm replacing multiply with shift left by 1 and then combining shifts.