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.Thu, 21 Jan 2021 10:40:11 +0100Solve returns bad resultshttps://ask.sagemath.org/question/55395/solve-returns-bad-results/ I'm trying to use Sage to determine if a collection of (polynomial) inequalities has a solution or not. Ideally, I think I should use qepcad but I am having problems getting it to install. I thought I would try to see if standalone Sage would do the trick and began working with the solve function to get familiar with it. Already I'm running into very weird results. For example I run the following code:
x,y = var('x,y')
circ = x**2 + y**2 == 1
line = y == x
badIneq = y > 1
Now, if I execute
solve([circ, line], x)
it returns [] instead of the two solutions I expect. Furthermore, the code
assume(x,'real')
assume(y,'real')
solve([circ, badIneq], x)
is expected to return no solutions but instead it returns [[y - 1 > 0, x^2 + y^2 - 1 == 0]].
I must be doing something wrong but I can't figure out what it is. Thanks.
Wed, 20 Jan 2021 19:04:12 +0100https://ask.sagemath.org/question/55395/solve-returns-bad-results/Comment by slelievre for <p>I'm trying to use Sage to determine if a collection of (polynomial) inequalities has a solution or not. Ideally, I think I should use qepcad but I am having problems getting it to install. I thought I would try to see if standalone Sage would do the trick and began working with the solve function to get familiar with it. Already I'm running into very weird results. For example I run the following code:</p>
<pre><code>x,y = var('x,y')
circ = x**2 + y**2 == 1
line = y == x
badIneq = y > 1
</code></pre>
<p>Now, if I execute </p>
<pre><code>solve([circ, line], x)
</code></pre>
<p>it returns [] instead of the two solutions I expect. Furthermore, the code</p>
<pre><code>assume(x,'real')
assume(y,'real')
solve([circ, badIneq], x)
</code></pre>
<p>is expected to return no solutions but instead it returns [[y - 1 > 0, x^2 + y^2 - 1 == 0]]. </p>
<p>I must be doing something wrong but I can't figure out what it is. Thanks. </p>
https://ask.sagemath.org/question/55395/solve-returns-bad-results/?comment=55397#post-id-55397Welcome to Ask Sage! Thank you for your question!Wed, 20 Jan 2021 19:18:55 +0100https://ask.sagemath.org/question/55395/solve-returns-bad-results/?comment=55397#post-id-55397Comment by tmonteil for <p>I'm trying to use Sage to determine if a collection of (polynomial) inequalities has a solution or not. Ideally, I think I should use qepcad but I am having problems getting it to install. I thought I would try to see if standalone Sage would do the trick and began working with the solve function to get familiar with it. Already I'm running into very weird results. For example I run the following code:</p>
<pre><code>x,y = var('x,y')
circ = x**2 + y**2 == 1
line = y == x
badIneq = y > 1
</code></pre>
<p>Now, if I execute </p>
<pre><code>solve([circ, line], x)
</code></pre>
<p>it returns [] instead of the two solutions I expect. Furthermore, the code</p>
<pre><code>assume(x,'real')
assume(y,'real')
solve([circ, badIneq], x)
</code></pre>
<p>is expected to return no solutions but instead it returns [[y - 1 > 0, x^2 + y^2 - 1 == 0]]. </p>
<p>I must be doing something wrong but I can't figure out what it is. Thanks. </p>
https://ask.sagemath.org/question/55395/solve-returns-bad-results/?comment=55399#post-id-55399Could you please tell us which problems you encountered in installing `qepcad` ?Wed, 20 Jan 2021 20:52:43 +0100https://ask.sagemath.org/question/55395/solve-returns-bad-results/?comment=55399#post-id-55399Answer by tmonteil for <p>I'm trying to use Sage to determine if a collection of (polynomial) inequalities has a solution or not. Ideally, I think I should use qepcad but I am having problems getting it to install. I thought I would try to see if standalone Sage would do the trick and began working with the solve function to get familiar with it. Already I'm running into very weird results. For example I run the following code:</p>
<pre><code>x,y = var('x,y')
circ = x**2 + y**2 == 1
line = y == x
badIneq = y > 1
</code></pre>
<p>Now, if I execute </p>
<pre><code>solve([circ, line], x)
</code></pre>
<p>it returns [] instead of the two solutions I expect. Furthermore, the code</p>
<pre><code>assume(x,'real')
assume(y,'real')
solve([circ, badIneq], x)
</code></pre>
<p>is expected to return no solutions but instead it returns [[y - 1 > 0, x^2 + y^2 - 1 == 0]]. </p>
<p>I must be doing something wrong but I can't figure out what it is. Thanks. </p>
https://ask.sagemath.org/question/55395/solve-returns-bad-results/?answer=55406#post-id-55406Regarding your first issue, you could try:
sage: solve([circ, line], [x,y])
[[x == -1/2*sqrt(2), y == -1/2*sqrt(2)], [x == 1/2*sqrt(2), y == 1/2*sqrt(2)]]
Regarding your second issue, Sage reports the inequations because it is not able to solve the simple system of inequalities. Indeed, `qepcad` is able to decide that there is no solution:
sage: qf = qepcad_formula
sage: F = qf.and_([circ, badIneq]) ; F
[x^2 + y^2 = 1 /\ y > 1]
sage: qepcad(F, solution='extended')
FALSE
sage: qepcad(F)
FALSE
You should be able to install `qepcad` with the command (in a terminal)
sage -i qepcad
If this does not work, you should provide some informations on your system.
You could also have a look at sympy, which is installed in Sage: https://docs.sympy.org/latest/modules/solvers/inequalities.htmlThu, 21 Jan 2021 10:40:11 +0100https://ask.sagemath.org/question/55395/solve-returns-bad-results/?answer=55406#post-id-55406