ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 16 Aug 2023 18:42:15 +0200Symbolic expressions in positive characteristichttps://ask.sagemath.org/question/72552/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.Tue, 15 Aug 2023 09:12:22 +0200https://ask.sagemath.org/question/72552/symbolic-expressions-in-positive-characteristic/Comment by Max Alekseyev for <p>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:</p>
<pre><code>a, b = var('a, b')
foo = function('foo', nargs=1)
expr = 3 * a**3 + 5 * foo(b**2 + 2 * a)
</code></pre>
<p>What I really need is something similar to Maple's <code>expr mod p;</code>, which reduces the expression <code>expr</code> modulo <code>p</code>. 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!).</p>
<p>I tried taking <code>R = SR.quotient_ring(SR.ideal(2))</code> and using <code>R(expr)</code>, but this does not seem to have any effect. Using <code>RingConverter</code> was not a success either.</p>
<p>If this simplifies things, I do not need the reduction to work inside the function arguments, so simply reducing <code>3 * a**3 + 5 * foo(b**2 + 2 * a)</code> to <code>a**3 + foo(b**2 + 2 * a)</code> would suffice.</p>
https://ask.sagemath.org/question/72552/symbolic-expressions-in-positive-characteristic/?comment=72605#post-id-72605Perhaps, the simplest approach would be splitting the expression into subexpressions - those outside the function and those that are function arguments.Wed, 16 Aug 2023 18:42:15 +0200https://ask.sagemath.org/question/72552/symbolic-expressions-in-positive-characteristic/?comment=72605#post-id-72605Comment by Andrei Smolensky for <p>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:</p>
<pre><code>a, b = var('a, b')
foo = function('foo', nargs=1)
expr = 3 * a**3 + 5 * foo(b**2 + 2 * a)
</code></pre>
<p>What I really need is something similar to Maple's <code>expr mod p;</code>, which reduces the expression <code>expr</code> modulo <code>p</code>. 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!).</p>
<p>I tried taking <code>R = SR.quotient_ring(SR.ideal(2))</code> and using <code>R(expr)</code>, but this does not seem to have any effect. Using <code>RingConverter</code> was not a success either.</p>
<p>If this simplifies things, I do not need the reduction to work inside the function arguments, so simply reducing <code>3 * a**3 + 5 * foo(b**2 + 2 * a)</code> to <code>a**3 + foo(b**2 + 2 * a)</code> would suffice.</p>
https://ask.sagemath.org/question/72552/symbolic-expressions-in-positive-characteristic/?comment=72556#post-id-72556@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().Tue, 15 Aug 2023 10:26:48 +0200https://ask.sagemath.org/question/72552/symbolic-expressions-in-positive-characteristic/?comment=72556#post-id-72556Comment by rburing for <p>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:</p>
<pre><code>a, b = var('a, b')
foo = function('foo', nargs=1)
expr = 3 * a**3 + 5 * foo(b**2 + 2 * a)
</code></pre>
<p>What I really need is something similar to Maple's <code>expr mod p;</code>, which reduces the expression <code>expr</code> modulo <code>p</code>. 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!).</p>
<p>I tried taking <code>R = SR.quotient_ring(SR.ideal(2))</code> and using <code>R(expr)</code>, but this does not seem to have any effect. Using <code>RingConverter</code> was not a success either.</p>
<p>If this simplifies things, I do not need the reduction to work inside the function arguments, so simply reducing <code>3 * a**3 + 5 * foo(b**2 + 2 * a)</code> to <code>a**3 + foo(b**2 + 2 * a)</code> would suffice.</p>
https://ask.sagemath.org/question/72552/symbolic-expressions-in-positive-characteristic/?comment=72554#post-id-72554What is the end goal here? This sounds like an [XY problem](https://en.wikipedia.org/wiki/XY_problem). You might [use an ExpressionTreeWalker](https://ask.sagemath.org/question/44136/substituting-a-differential-equation-into-an-expression/#44143) to solve this problem Y.Tue, 15 Aug 2023 09:36:28 +0200https://ask.sagemath.org/question/72552/symbolic-expressions-in-positive-characteristic/?comment=72554#post-id-72554