expand
¶
Distribute multiplication over addition (expand products).
Bottom-up traversal: expand children first, then distribute at the current node. Single pass — no has_nested_add predicate needed.
Distribution rules implemented
Mul over Add → Add (scalar) Dot over VAdd → Add (scalar from vectors) Cross over VAdd → VAdd (vector) SVMul over VAdd/Add → VAdd (vector, left=vector right=scalar) MVMul over MAdd/VAdd → VAdd (vector) SMMul over MAdd/Add → MAdd (matrix, left=matrix right=scalar) MMMul over MAdd → MAdd (matrix) Hat/Vee — recurse into child