ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 17 Mar 2015 18:07:48 -0500max_symbolic and distributive law with multiplicationhttp://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/Minimum and maximum are distributive over multiplication of non-negative numbers, i.e., if a,b,c >= 0 then
a * max{ b, c } = max { ab, ac }
and the same works for min{}. How can I exploit this in sagemath? Consider the followiing:
n=5
x=var(['x_'+str(i+1) for i in range(n)])
# (x_1, x_2, x_3, x_4, x_5)
assume([x[i] >= 0 for i in range(n)])
assumptions()
# [x_1 >= 0, x_2 >= 0, x_3 >= 0, x_4 >= 0, x_5 >= 0]
This does **not** work as expected:
y = max_symbolic( x[4] * max_symbolic(x[0],x[1]), x[0] * max_symbolic(x[2],x[3]) )
# y == max(x_5*max(x_1, x_2), x_1*max(x_3, x_4))
simplify(y)
# max(x_1*max(x_3, x_4), x_5*max(x_1, x_2))
Simplify does not do the simplification I want it to do, which should yield
## max(max(x_1*x_3, x_1*x_4), max(x_5*x_1, x_5*x_2))
or even better
## max(x_1*x_3, x_1*x_4, x_5*x_1, x_5*x_2)
Needless to say, I have also tried `expand` and `full_simplify`. None of them does the trick.
So, I wonder, am I missing out on some other fancy function here, or is there a (hopefully easy) way to add a distributive law-feature to the max_symbolic function?Tue, 17 Mar 2015 00:12:56 -0500http://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/Comment by nbruin for <p>Minimum and maximum are distributive over multiplication of non-negative numbers, i.e., if a,b,c >= 0 then </p>
<p>a * max{ b, c } = max { ab, ac }</p>
<p>and the same works for min{}. How can I exploit this in sagemath? Consider the followiing:</p>
<pre><code>n=5
x=var(['x_'+str(i+1) for i in range(n)])
# (x_1, x_2, x_3, x_4, x_5)
assume([x[i] >= 0 for i in range(n)])
assumptions()
# [x_1 >= 0, x_2 >= 0, x_3 >= 0, x_4 >= 0, x_5 >= 0]
</code></pre>
<p>This does <strong>not</strong> work as expected:</p>
<pre><code>y = max_symbolic( x[4] * max_symbolic(x[0],x[1]), x[0] * max_symbolic(x[2],x[3]) )
# y == max(x_5*max(x_1, x_2), x_1*max(x_3, x_4))
simplify(y)
# max(x_1*max(x_3, x_4), x_5*max(x_1, x_2))
</code></pre>
<p>Simplify does not do the simplification I want it to do, which should yield </p>
<pre><code>## max(max(x_1*x_3, x_1*x_4), max(x_5*x_1, x_5*x_2))
</code></pre>
<p>or even better</p>
<pre><code>## max(x_1*x_3, x_1*x_4, x_5*x_1, x_5*x_2)
</code></pre>
<p>Needless to say, I have also tried <code>expand</code> and <code>full_simplify</code>. None of them does the trick.</p>
<p>So, I wonder, am I missing out on some other fancy function here, or is there a (hopefully easy) way to add a distributive law-feature to the max_symbolic function?</p>
http://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/?comment=26216#post-id-26216your simplification requires that x_1>0 and x_5>0 , so sage is right in not performing them. In principle you could use "assume(x_1>0)" but I expect that that will not make a difference. It's a tricky thing you're asking.Tue, 17 Mar 2015 02:18:41 -0500http://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/?comment=26216#post-id-26216Comment by Bjorn for <p>Minimum and maximum are distributive over multiplication of non-negative numbers, i.e., if a,b,c >= 0 then </p>
<p>a * max{ b, c } = max { ab, ac }</p>
<p>and the same works for min{}. How can I exploit this in sagemath? Consider the followiing:</p>
<pre><code>n=5
x=var(['x_'+str(i+1) for i in range(n)])
# (x_1, x_2, x_3, x_4, x_5)
assume([x[i] >= 0 for i in range(n)])
assumptions()
# [x_1 >= 0, x_2 >= 0, x_3 >= 0, x_4 >= 0, x_5 >= 0]
</code></pre>
<p>This does <strong>not</strong> work as expected:</p>
<pre><code>y = max_symbolic( x[4] * max_symbolic(x[0],x[1]), x[0] * max_symbolic(x[2],x[3]) )
# y == max(x_5*max(x_1, x_2), x_1*max(x_3, x_4))
simplify(y)
# max(x_1*max(x_3, x_4), x_5*max(x_1, x_2))
</code></pre>
<p>Simplify does not do the simplification I want it to do, which should yield </p>
<pre><code>## max(max(x_1*x_3, x_1*x_4), max(x_5*x_1, x_5*x_2))
</code></pre>
<p>or even better</p>
<pre><code>## max(x_1*x_3, x_1*x_4, x_5*x_1, x_5*x_2)
</code></pre>
<p>Needless to say, I have also tried <code>expand</code> and <code>full_simplify</code>. None of them does the trick.</p>
<p>So, I wonder, am I missing out on some other fancy function here, or is there a (hopefully easy) way to add a distributive law-feature to the max_symbolic function?</p>
http://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/?comment=26234#post-id-26234You are of course right, and I simply forgot to copy the corresponding lines from my worksheet. They are included now.Tue, 17 Mar 2015 18:07:48 -0500http://ask.sagemath.org/question/26214/max_symbolic-and-distributive-law-with-multiplication/?comment=26234#post-id-26234