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 May 2023 10:05:24 +0200solving one inequality with assumptionhttps://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/I wonder why Sagemath is not able to solve this
var('x a b c')
U_1 = lambda x, a, b, c: c*x*x^1+b*x+a
show(LatexExpr(r'U(x) = '),U_1(x,a,b,c))
#first order x derivative which must be positive
δU_1(x,a,b,c) = diff(U_1(x,a,b,c),x)
assume(x>=0)
solve_ineq([δU_1(x,a,b,c)>0],[x])Tue, 09 May 2023 11:19:52 +0200https://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/Answer by Emmanuel Charpentier for <p>I wonder why Sagemath is not able to solve this </p>
<pre><code>var('x a b c')
U_1 = lambda x, a, b, c: c*x*x^1+b*x+a
show(LatexExpr(r'U(x) = '),U_1(x,a,b,c))
#first order x derivative which must be positive
δU_1(x,a,b,c) = diff(U_1(x,a,b,c),x)
assume(x>=0)
solve_ineq([δU_1(x,a,b,c)>0],[x])
</code></pre>
https://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/?answer=68307#post-id-68307Inequation solving is a (very) weak point of Sage. A peek at Mathematica's solution helps to understand why :
sage: reset()
sage: var('a b c', domain="real")
(a, b, c)
sage: var("x", domain="positive")
x
sage: U_1(x, a, b, c) = c*x*x^1+b*x+a
sage: ineq = U_1(x, a, b, c).diff(x)>0 ; ineq
2*c*x + b > 0
sage: mathematica.Reduce(ineq, x)
Element[x, Reals] && ((b <= 0 && ((c < 0 && x < -1/2*b/c) ||
(c > 0 && x > -1/2*b/c))) || (b > 0 && ((c < 0 && x < -1/2*b/c) ||
c == 0 || (c > 0 && x > -1/2*b/c))))
Sage currently does not have logical functions allowing for such an expression of this solution. However, Sage can help manipulating the inequation to get a solution of sorts :
sage: (ineq-b)/2
c*x > -1/2*b
sage: (ineq-b)/2/c ### ZAssuming c > 0 !
x > -1/2*b/c
sage: (ineq-b)/2/-c ### Assuming c < 0 !
-x > 1/2*b/c
The latter can be rewritten `x > -1/2*b/c`, leading to rewrite *manually !* :
sage: cases([(c>0, x>-b/(2*c)), (c<0, x>b/(2*c)), (c==0, None)])
cases(((c > 0, x > -1/2*b/c), (c < 0, x > 1/2*b/c), (c == 0, None)))
This is more or less consonant with the (intricate) Mathematica solution...
We note that neither Maxima, Sympy, Giac nor Fricas fare better (as far as I have been able to prod them...) ; in particular, the `ineq` Maxima package currently *does **not** load*.
One should note that the optional package `qepcad` is said to be able to express and solve systemof inequations. I have not (yet) explored it.
HTH,Wed, 10 May 2023 00:20:49 +0200https://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/?answer=68307#post-id-68307Comment by Emmanuel Charpentier for <p>Inequation solving is a (very) weak point of Sage. A peek at Mathematica's solution helps to understand why :</p>
<pre><code>sage: reset()
sage: var('a b c', domain="real")
(a, b, c)
sage: var("x", domain="positive")
x
sage: U_1(x, a, b, c) = c*x*x^1+b*x+a
sage: ineq = U_1(x, a, b, c).diff(x)>0 ; ineq
2*c*x + b > 0
sage: mathematica.Reduce(ineq, x)
Element[x, Reals] && ((b <= 0 && ((c < 0 && x < -1/2*b/c) ||
(c > 0 && x > -1/2*b/c))) || (b > 0 && ((c < 0 && x < -1/2*b/c) ||
c == 0 || (c > 0 && x > -1/2*b/c))))
</code></pre>
<p>Sage currently does not have logical functions allowing for such an expression of this solution. However, Sage can help manipulating the inequation to get a solution of sorts :</p>
<pre><code>sage: (ineq-b)/2
c*x > -1/2*b
sage: (ineq-b)/2/c ### ZAssuming c > 0 !
x > -1/2*b/c
sage: (ineq-b)/2/-c ### Assuming c < 0 !
-x > 1/2*b/c
</code></pre>
<p>The latter can be rewritten <code>x > -1/2*b/c</code>, leading to rewrite <em>manually !</em> :</p>
<pre><code>sage: cases([(c>0, x>-b/(2*c)), (c<0, x>b/(2*c)), (c==0, None)])
cases(((c > 0, x > -1/2*b/c), (c < 0, x > 1/2*b/c), (c == 0, None)))
</code></pre>
<p>This is more or less consonant with the (intricate) Mathematica solution...</p>
<p>We note that neither Maxima, Sympy, Giac nor Fricas fare better (as far as I have been able to prod them...) ; in particular, the <code>ineq</code> Maxima package currently <em>does <strong>not</strong> load</em>.</p>
<p>One should note that the optional package <code>qepcad</code> is said to be able to express and solve systemof inequations. I have not (yet) explored it.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/?comment=68370#post-id-68370@Cyrille,
`qepcad` is an optional package. As far as understand it, those are not installable in a binary installation, which lacks the tools necessary for such a task. In an installation from source, `make qepcad` works, and `sage -i qepcad` *should* work.
HTH,Fri, 12 May 2023 10:05:24 +0200https://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/?comment=68370#post-id-68370Comment by Cyrille for <p>Inequation solving is a (very) weak point of Sage. A peek at Mathematica's solution helps to understand why :</p>
<pre><code>sage: reset()
sage: var('a b c', domain="real")
(a, b, c)
sage: var("x", domain="positive")
x
sage: U_1(x, a, b, c) = c*x*x^1+b*x+a
sage: ineq = U_1(x, a, b, c).diff(x)>0 ; ineq
2*c*x + b > 0
sage: mathematica.Reduce(ineq, x)
Element[x, Reals] && ((b <= 0 && ((c < 0 && x < -1/2*b/c) ||
(c > 0 && x > -1/2*b/c))) || (b > 0 && ((c < 0 && x < -1/2*b/c) ||
c == 0 || (c > 0 && x > -1/2*b/c))))
</code></pre>
<p>Sage currently does not have logical functions allowing for such an expression of this solution. However, Sage can help manipulating the inequation to get a solution of sorts :</p>
<pre><code>sage: (ineq-b)/2
c*x > -1/2*b
sage: (ineq-b)/2/c ### ZAssuming c > 0 !
x > -1/2*b/c
sage: (ineq-b)/2/-c ### Assuming c < 0 !
-x > 1/2*b/c
</code></pre>
<p>The latter can be rewritten <code>x > -1/2*b/c</code>, leading to rewrite <em>manually !</em> :</p>
<pre><code>sage: cases([(c>0, x>-b/(2*c)), (c<0, x>b/(2*c)), (c==0, None)])
cases(((c > 0, x > -1/2*b/c), (c < 0, x > 1/2*b/c), (c == 0, None)))
</code></pre>
<p>This is more or less consonant with the (intricate) Mathematica solution...</p>
<p>We note that neither Maxima, Sympy, Giac nor Fricas fare better (as far as I have been able to prod them...) ; in particular, the <code>ineq</code> Maxima package currently <em>does <strong>not</strong> load</em>.</p>
<p>One should note that the optional package <code>qepcad</code> is said to be able to express and solve systemof inequations. I have not (yet) explored it.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/?comment=68339#post-id-68339Thanks Elmmanuel; I have tried to install `quepcad` with pip but It was not founded.Thu, 11 May 2023 10:17:43 +0200https://ask.sagemath.org/question/68290/solving-one-inequality-with-assumption/?comment=68339#post-id-68339