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.Fri, 12 Mar 2021 11:46:23 +0100max_symbolic, polynomial expressions, assumptionshttps://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/ The following works as expected:
var('b')
with assuming(b>1):
v = max_symbolic(7*b-5,0).full_simplify()
print(v)
yields 7*b - 5
The following does not (maybe my expectations are unrealistic)
with assuming(b>1):
v = max_symbolic(b^2-b+1,0).full_simplify()
print(v)
yields max(0, b^2 - b + 1), even though the latter expression is always > 3/4
I have a bunch of expressions such as the one below, that I want to analyze, to get a piecewise-defined function:
print(myexpr,"\n\n")
print(myexpr.full_simplify(),"\n\n")
with assuming(a>2):
print(myexpr.full_simplify(),"\n\n")
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(5*a + 7, a^2 + 3*a + 3)
This is good, however:
with assuming(a>2000):
print(myexpr.full_simplify())
yields max(5*a + 7, a^2 + 3*a + 3)
Can such expressions, as above, in max_symbolic be converted into piecewise defined functions? (I would also be interested in having
more than one parameter, and having SAGE partition the parameter space appropriately and automatically).
Thu, 11 Mar 2021 13:39:33 +0100https://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/Answer by Emmanuel Charpentier for <p>The following works as expected:</p>
<pre><code>var('b')
with assuming(b>1):
v = max_symbolic(7*b-5,0).full_simplify()
print(v)
</code></pre>
<p>yields 7*b - 5</p>
<p>The following does not (maybe my expectations are unrealistic)</p>
<pre><code>with assuming(b>1):
v = max_symbolic(b^2-b+1,0).full_simplify()
print(v)
</code></pre>
<p>yields max(0, b^2 - b + 1), even though the latter expression is always > 3/4</p>
<p>I have a bunch of expressions such as the one below, that I want to analyze, to get a piecewise-defined function:</p>
<pre><code>print(myexpr,"\n\n")
print(myexpr.full_simplify(),"\n\n")
with assuming(a>2):
print(myexpr.full_simplify(),"\n\n")
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(max(3, a + 1) + 2*max(2*max(3, a + 1) + 1, a + max(3, a + 1)), a*max(3, a + 1) + max(2*max(3, a + 1) + 1, a + max(3, a + 1)))
max(5*a + 7, a^2 + 3*a + 3)
</code></pre>
<p>This is good, however:</p>
<pre><code>with assuming(a>2000):
print(myexpr.full_simplify())
</code></pre>
<p>yields max(5<em>a + 7, a^2 + 3</em>a + 3)</p>
<p>Can such expressions, as above, in max_symbolic be converted into piecewise defined functions? (I would also be interested in having
more than one parameter, and having SAGE partition the parameter space appropriately and automatically).</p>
https://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/?answer=56126#post-id-56126In short : not a chance...
A few counter-examples :
- `max_symbolic(0, sin(1/x))` (infinity of roots)
- `max_symbolic(0, a_5*x^5 + a_4*x^4 + a_3*x^3 + a_21*x^2 + a_1*x + a_0)` (no way to compute roots (if any real...)).
More generally, it has been proved that the problem of the nullity of an arbitrary expression has no solution(i. e. it has been proved that some expressions may be null but not provably so) ; in consequence, there is no guarantee that your expression can be processed to get the roots necessary to write the desired `piecewise` expression.
HTH,
Thu, 11 Mar 2021 21:03:11 +0100https://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/?answer=56126#post-id-56126Comment by JTS for <p>In short : not a chance...</p>
<p>A few counter-examples :</p>
<ul>
<li><p><code>max_symbolic(0, sin(1/x))</code> (infinity of roots)</p></li>
<li><p><code>max_symbolic(0, a_5*x^5 + a_4*x^4 + a_3*x^3 + a_21*x^2 + a_1*x + a_0)</code> (no way to compute roots (if any real...)).</p></li>
</ul>
<p>More generally, it has been proved that the problem of the nullity of an arbitrary expression has no solution(i. e. it has been proved that some expressions may be null but not provably so) ; in consequence, there is no guarantee that your expression can be processed to get the roots necessary to write the desired <code>piecewise</code> expression.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/?comment=56129#post-id-56129Thank you for your answer. I tried restricting the problem to simplifying max of two piecewise linear expressions (hoping to get to max of piecewise polynomial functions with breakpoints that are algebraic and lying in some convenient extension of Q) but I ran into a bug, I think:
a = piecewise([((0,1),x),((1,2),1-x)]).extension(3)
b = piecewise([((0,3/2),3*x-1),((3/2,7/2),7/2-7*(x-3/2))]).extension(4)
xrange = [x/100 for x in range(400)]
p = list_plot([(x,a(x)) for x in xrange])
p += list_plot([(x,b(x)) for x in xrange], color='black')
p += list_plot([(x,max(a(x),b(x))) for x in xrange], color='red')
show(p)
max_symbolic(a,b).full_simplify()
The plot show the max, again a piecewise linear function, but max_symbolic (or simplify?) throws an exception "RFri, 12 Mar 2021 11:46:23 +0100https://ask.sagemath.org/question/56120/max_symbolic-polynomial-expressions-assumptions/?comment=56129#post-id-56129