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, 16 Jul 2020 20:27:18 +0200Dealing with undefined exponents in SAGEhttps://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/I've been playing with sage a bit and have been running into a number of walls in terms of getting analytical solutions so I decided to check if my beliefs are true about SAGE's difficulty with trying to solve the following algebraic problem in sage.
$$x^a-c=0, c\geq0$$
on paper if we were to solve for this problem on paper we get
$$x^*=c^{\frac{1}{a}}$$
What is simply done on paper seems to be an issue to run in sage:
x,a,c = var('x a c')
solve(x^a - c== 0)
This code does not work and wont give me the simple pen and paper solution to this problem. why is this the case?Thu, 16 Jul 2020 18:06:03 +0200https://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/Answer by Emmanuel Charpentier for <p>I've been playing with sage a bit and have been running into a number of walls in terms of getting analytical solutions so I decided to check if my beliefs are true about SAGE's difficulty with trying to solve the following algebraic problem in sage.
$$x^a-c=0, c\geq0$$
on paper if we were to solve for this problem on paper we get
$$x^*=c^{\frac{1}{a}}$$ </p>
<p>What is simply done on paper seems to be an issue to run in sage:</p>
<pre><code>x,a,c = var('x a c')
solve(x^a - c== 0)
</code></pre>
<p>This code does not work and wont give me the simple pen and paper solution to this problem. why is this the case?</p>
https://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/?answer=52512#post-id-52512Your code doesn't work because you didn't specify what to solve *for*. If you try `solve(x^a==c,x)`, Sage becomes nosy (verging on indiscrete...;-). You have a couple of solutions :
- add assumptions about `a` and `c` (see `assume?`).
- add temporary assumptions (useful for testing different branches) :
For example:
sage: with assuming(a,"noninteger", c>0): solve(x^a==c,x)
[x == c^(1/a)]
sage: with assuming(a,"noninteger", c<0): solve(x^a==c,x)
[x^a == c]
sage: with assuming(a,"noninteger", c==0): solve(x^a==c,x)
[x == c^(1/a)]
(one notes that the latter is nonsens, while formally correct...).
Transform your equation yourself :
sage: (x^a==c).log().log_expand().solve(x)
[x == c^(1/a)]
(but beware of transformations introducing spurious roots...).
HTH,Thu, 16 Jul 2020 19:25:14 +0200https://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/?answer=52512#post-id-52512Comment by EconJohn for <p>Your code doesn't work because you didn't specify what to solve <em>for</em>. If you try <code>solve(x^a==c,x)</code>, Sage becomes nosy (verging on indiscrete...;-). You have a couple of solutions :</p>
<ul>
<li><p>add assumptions about <code>a</code> and <code>c</code> (see <code>assume?</code>).</p></li>
<li><p>add temporary assumptions (useful for testing different branches) :</p></li>
</ul>
<p>For example:</p>
<pre><code>sage: with assuming(a,"noninteger", c>0): solve(x^a==c,x)
[x == c^(1/a)]
sage: with assuming(a,"noninteger", c<0): solve(x^a==c,x)
[x^a == c]
sage: with assuming(a,"noninteger", c==0): solve(x^a==c,x)
[x == c^(1/a)]
</code></pre>
<p>(one notes that the latter is nonsens, while formally correct...).</p>
<p>Transform your equation yourself :</p>
<pre><code>sage: (x^a==c).log().log_expand().solve(x)
[x == c^(1/a)]
</code></pre>
<p>(but beware of transformations introducing spurious roots...).</p>
<p>HTH,</p>
https://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/?comment=52513#post-id-52513My man you are saving me alot of time today! Thank you!Thu, 16 Jul 2020 19:44:34 +0200https://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/?comment=52513#post-id-52513Answer by EconJohn for <p>I've been playing with sage a bit and have been running into a number of walls in terms of getting analytical solutions so I decided to check if my beliefs are true about SAGE's difficulty with trying to solve the following algebraic problem in sage.
$$x^a-c=0, c\geq0$$
on paper if we were to solve for this problem on paper we get
$$x^*=c^{\frac{1}{a}}$$ </p>
<p>What is simply done on paper seems to be an issue to run in sage:</p>
<pre><code>x,a,c = var('x a c')
solve(x^a - c== 0)
</code></pre>
<p>This code does not work and wont give me the simple pen and paper solution to this problem. why is this the case?</p>
https://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/?answer=52514#post-id-52514The quick and dirty code for this is:
x,a,c = var('x a c')
assume(x>0,a>0,c>0)
solve(x^a - c== 0,x)Thu, 16 Jul 2020 20:27:18 +0200https://ask.sagemath.org/question/52507/dealing-with-undefined-exponents-in-sage/?answer=52514#post-id-52514