Is multiplication cached?
I'm doing some fairly complicated computations in a quotient ring of the form Z[x_1,..x_n]/I. I've tried looking through the code myself to try to understand it, but unfortunately it is beyond me.
My question is this: Suppose in the process of some computation (say I have an element f and I'm trying to compute f^9), the program computes a product xy, then later in the same computation it must repeat the product xy it already did before - will it be able to just pick up what it already computed, or will it compute the whole thing again? If it stores the value, is there a way to keep it cached to use in a future computation?
Unfortunately my code is taking too long to run the computations I need, so I'm trying to find ways to improve it. Most of the computational time is just spend with polynomial expressions in the quotient ring, so I want to see if it's worth my time to make it store a multiplication table as it goes, if it's not already doing that.
I'm curious: might it be faster to compute everything in the polynomial ring, and then at the end convert the result to the quotient?
I have tried this and it seems to be faster, though not by a significant enough margin. As well for more complex terms the difference is smaller, as in the quotient ring terms become 0 and that reduces the operations needed.
You might also do some computations in the polynomial ring and use a pre-computed Gröbner basis
G = I.groebner_basis()
to perform reductionf.reduce(G)
at certain steps. That way you have control over when the reduction happens. And you can cache reduced results (manually).I'll give this a try, thanks for the tip!