Question: nested mods -> possible with fold-operators?

Hello,

my problem is as follows. Given


g := [g1, g2, ... , g99];    # a list of polynomials,  high  in degree and with big coefficients

S := [1, 3, 14, 29];        # Set of indices, which polynomials we want to multiply

p := 11;   # the modulus

------------------------------------------------------------------------------------------------------------------------------


I want to calculate the product of the constant-terms of the indexed g, that means for example

cg1 * cg3 * cg14 * cg29  mod p         

where cgi means coeff(g[i], x, 0), and mod should be mods,  using symmetric representatives

 

Till now I'm using:

    mods(mul(coeff(g[i], x, 0), i in S), p)


It works, but the problem is, that the order is not optimal and costs too much time.

The order is for example:
(3  *  5 * 7 * 9) mod 11;

But I need for efficieny an order like:
(((3 * 5 mod 11) * 7 mod 11) * 9 mod 11

I read about the fold operators, but I've no idea how to combine these with mul and mods to get what I need.

 

Please Wait...