I’ve to control enormous expressions which are rational capabilities of many (∼300) variables with integer coefficients. Storing them simply as a ratio of two polynomials can be impractical. However they are often represented as multi-level (∼140 ranges) nested sums of fractions. Storing them on this kind nonetheless can be impractical (billions of nodes), however, fortunately, they’ve plenty of repeated sub-expressions, so I retailer them as expressions with
Experimental`OptimizedExpression head, the place all repeated components are recursively extracted and denoted by auxiliary intermediate variables. On this kind my expressions solely have a number of 1000’s of nodes.
To transform expressions to this optimized kind I exploit
Experimental`OptimizeExpression perform, with some extra customized post-processing. Typically, I’ve an inventory of expressions, however as they normally have many shared repeated components, the record may be effectively represented as a single optimized expression the place all shared components are extracted.
Now, I must do some symbolic computations with optimized expressions: addition, multiplication, division and a substitution of 1 optimized expression for a variable in one other. In all these circumstances, I wish to get a single optimized expression because of this, the place every shared repeated half amongst operands is extracted and denoted by a single variable.
For smaller expressions, this may be achieved by a brute-force strategy: increase the operands first, carry out the operation as normal and, lastly, apply
Experimental`OptimizeExpression to the consequence to get an optimized kind. For bigger expressions, it turns into too sluggish. I used to be about to put in writing my customized algorithm for extracting shared components from a number of optimized expressions with out totally increasing them. However I assumed that different folks, possible, have already got confronted the same drawback. So, I’d recognize if anyone has an present resolution, and is prepared to share it. Or, possibly, there may be already a perform in Mathematica that may do it?