Symbolic expressions in positive characteristic
Is there a way to work with symbolic expressions in positive characteristic? I know that the standard answer is to convert everything into polynomials ovef GF(p), however, this does not work when an expression features a custom function, say:
a, b = var('a, b')
foo = function('foo', nargs=1)
expr = 3 * a**3 + 5 * foo(b**2 + 2 * a)
What I really need is something similar to Maple's expr mod p;
, which reduces the expression expr
modulo p
. It cannot be implemented by a simple rewriting, because one cannot just replace every integer in an expression by its remainder mod p (mind the powers!).
I tried taking R = SR.quotient_ring(SR.ideal(2))
and using R(expr)
, but this does not seem to have any effect. Using RingConverter
was not a success either.
If this simplifies things, I do not need the reduction to work inside the function arguments, so simply reducing 3 * a**3 + 5 * foo(b**2 + 2 * a)
to a**3 + foo(b**2 + 2 * a)
would suffice.
What is the end goal here? This sounds like an XY problem. You might use an ExpressionTreeWalker to solve this problem Y.
@rburing The goal is to simplify expressions with an assumption of positive characteristic. Say, in char=2 one gets (3a+b)/(a+b) = 1, but without first reducing the numerator and the denominator modulo 2 one cannot apply simplify_rational().
Perhaps, the simplest approach would be splitting the expression into subexpressions - those outside the function and those that are function arguments.