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, 05 Aug 2011 19:30:32 +0200Interactive maxima question on fraction value during solve()https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/# Context
I executed this code
var('x, k')
As(x) = (2*k/(k-1))^(-0.5) * (( x^(2/k) - x^((k+1)/k)) )^(-0.5)
dAs(x) = As.derivative(x)
ns = solve(dAs(x), x)
print ns
which results in
<pre>
[
(1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k)
]
</pre>
My goal is the have sage solve this equation for x, where the result should look something like
x == ( 2/(k+1) )^( k/(k-1) )
# The Problem
This code
myEqs = [ (1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k) ]
assume(k>1)
solve(myEqs, x)
results in
<pre>
Traceback (click to the left of this block for traceback)
...
TypeError: Computation failed since Maxima requested additional constraints (try the command 'assume(k-1)/k>0)' before integral or limit evaluation, for example):
Is (k-1)/k an integer?
</pre>
But the suggested `assume(k-1)/k>0)` isn't even valid syntax.
**My question**: How can I cover this question with `assume()` so that maxima doesn't have to ask (and hence fail because it doesn't support interactive communication with another process)? Thu, 04 Aug 2011 09:16:47 +0200https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/Answer by benjaminfjones for <h1>Context</h1>
<p>I executed this code</p>
<pre><code>var('x, k')
As(x) = (2*k/(k-1))^(-0.5) * (( x^(2/k) - x^((k+1)/k)) )^(-0.5)
dAs(x) = As.derivative(x)
ns = solve(dAs(x), x)
print ns
</code></pre>
<p>which results in</p>
<pre>[
(1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k)
]
</pre>
<p>My goal is the have sage solve this equation for x, where the result should look something like</p>
<pre><code>x == ( 2/(k+1) )^( k/(k-1) )
</code></pre>
<h1>The Problem</h1>
<p>This code</p>
<pre><code>myEqs = [ (1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k) ]
assume(k>1)
solve(myEqs, x)
</code></pre>
<p>results in</p>
<pre>
Traceback (click to the left of this block for traceback)
...
TypeError: Computation failed since Maxima requested additional constraints (try the command 'assume(k-1)/k>0)' before integral or limit evaluation, for example):
Is (k-1)/k an integer?
</pre>
<p>But the suggested <code>assume(k-1)/k>0)</code> isn't even valid syntax.</p>
<p><strong>My question</strong>: How can I cover this question with <code>assume()</code> so that maxima doesn't have to ask (and hence fail because it doesn't support interactive communication with another process)? </p>
https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?answer=12555#post-id-12555Looks like you found a typo in the Sage code that is raising that exception. I'll start a ticket for that. Thanks.
To your question:
---------------
It is probably the case that without changing some settings/assumptions in Maxima directly, it's not going to be able to solve your particular equation. The assumptions you need relating `x` and `k` are tricky.. you have fractional exponents depending on `k`, so you've got to assume `x` is real and positive. But doing that doesn't seem to help Maxima.
Here is a work around, though. If you know the form of the equation is going to be like the one you have, the human mathematician would probably take the `log` of both sides and solve for `log(x)`, then exponentiate. This kind of process is easy to automate:
sage: var('x,y,k')
sage: eq = (1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k)
sage: eq = log(eq)
sage: eq.full_simplify()
-(k - 2)*log(x)/k == -(k*log(2/(k + 1)) - log(x))/k
sage: eq = eq.full_simplify()
sage: eq = eq.subs(log(x) == y)
sage: solve(eq, y)
[y == k*log(2/(k + 1))/(k - 1)]
sage: S = solve(eq, y)
sage: soln = exp(S[0].rhs())
sage: soln
e^(k*log(2/(k + 1))/(k - 1))
Hopefully there is a better answer which involves telling Maxima to load a package for doing "logarithmic solving" or whatever the process I just described is called.
Thu, 04 Aug 2011 17:47:38 +0200https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?answer=12555#post-id-12555Comment by MaikB for <p>Looks like you found a typo in the Sage code that is raising that exception. I'll start a ticket for that. Thanks.</p>
<h2>To your question: </h2>
<p>It is probably the case that without changing some settings/assumptions in Maxima directly, it's not going to be able to solve your particular equation. The assumptions you need relating <code>x</code> and <code>k</code> are tricky.. you have fractional exponents depending on <code>k</code>, so you've got to assume <code>x</code> is real and positive. But doing that doesn't seem to help Maxima. </p>
<p>Here is a work around, though. If you know the form of the equation is going to be like the one you have, the human mathematician would probably take the <code>log</code> of both sides and solve for <code>log(x)</code>, then exponentiate. This kind of process is easy to automate:</p>
<pre><code>sage: var('x,y,k')
sage: eq = (1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k)
sage: eq = log(eq)
sage: eq.full_simplify()
-(k - 2)*log(x)/k == -(k*log(2/(k + 1)) - log(x))/k
sage: eq = eq.full_simplify()
sage: eq = eq.subs(log(x) == y)
sage: solve(eq, y)
[y == k*log(2/(k + 1))/(k - 1)]
sage: S = solve(eq, y)
sage: soln = exp(S[0].rhs())
sage: soln
e^(k*log(2/(k + 1))/(k - 1))
</code></pre>
<p>Hopefully there is a better answer which involves telling Maxima to load a package for doing "logarithmic solving" or whatever the process I just described is called.</p>
https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?comment=21414#post-id-21414For me .simplify_full() doesnt factor out the variables in exponents: eq.simplify_full() results in 2*log(x^(1/k)) - log(x) == log(1/2*(k + 1)*x^(1/k)). A simpler example log(x^(2*k)).full_simplify()
2*log(x^k) . I guess some option variable in maxima has to be altered.
Fri, 05 Aug 2011 03:49:02 +0200https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?comment=21414#post-id-21414Comment by MaikB for <p>Looks like you found a typo in the Sage code that is raising that exception. I'll start a ticket for that. Thanks.</p>
<h2>To your question: </h2>
<p>It is probably the case that without changing some settings/assumptions in Maxima directly, it's not going to be able to solve your particular equation. The assumptions you need relating <code>x</code> and <code>k</code> are tricky.. you have fractional exponents depending on <code>k</code>, so you've got to assume <code>x</code> is real and positive. But doing that doesn't seem to help Maxima. </p>
<p>Here is a work around, though. If you know the form of the equation is going to be like the one you have, the human mathematician would probably take the <code>log</code> of both sides and solve for <code>log(x)</code>, then exponentiate. This kind of process is easy to automate:</p>
<pre><code>sage: var('x,y,k')
sage: eq = (1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k)
sage: eq = log(eq)
sage: eq.full_simplify()
-(k - 2)*log(x)/k == -(k*log(2/(k + 1)) - log(x))/k
sage: eq = eq.full_simplify()
sage: eq = eq.subs(log(x) == y)
sage: solve(eq, y)
[y == k*log(2/(k + 1))/(k - 1)]
sage: S = solve(eq, y)
sage: soln = exp(S[0].rhs())
sage: soln
e^(k*log(2/(k + 1))/(k - 1))
</code></pre>
<p>Hopefully there is a better answer which involves telling Maxima to load a package for doing "logarithmic solving" or whatever the process I just described is called.</p>
https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?comment=21413#post-id-21413I found the variable in maxima: logexpand. Sage offers .expand_log(), which ".. uses the Maxima simplifier and sets logexpand option for this simplifier." log(eq).log_expand().full_simplify() now results in the desired -(k - 2)*log(x)/k == -(k*log(2/(k + 1)) - log(x))/k
Fri, 05 Aug 2011 04:07:40 +0200https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?comment=21413#post-id-21413Comment by benjaminfjones for <p>Looks like you found a typo in the Sage code that is raising that exception. I'll start a ticket for that. Thanks.</p>
<h2>To your question: </h2>
<p>It is probably the case that without changing some settings/assumptions in Maxima directly, it's not going to be able to solve your particular equation. The assumptions you need relating <code>x</code> and <code>k</code> are tricky.. you have fractional exponents depending on <code>k</code>, so you've got to assume <code>x</code> is real and positive. But doing that doesn't seem to help Maxima. </p>
<p>Here is a work around, though. If you know the form of the equation is going to be like the one you have, the human mathematician would probably take the <code>log</code> of both sides and solve for <code>log(x)</code>, then exponentiate. This kind of process is easy to automate:</p>
<pre><code>sage: var('x,y,k')
sage: eq = (1/(x^((k - 2)/k))) == 1/2*(k + 1)*x^(1/k)
sage: eq = log(eq)
sage: eq.full_simplify()
-(k - 2)*log(x)/k == -(k*log(2/(k + 1)) - log(x))/k
sage: eq = eq.full_simplify()
sage: eq = eq.subs(log(x) == y)
sage: solve(eq, y)
[y == k*log(2/(k + 1))/(k - 1)]
sage: S = solve(eq, y)
sage: soln = exp(S[0].rhs())
sage: soln
e^(k*log(2/(k + 1))/(k - 1))
</code></pre>
<p>Hopefully there is a better answer which involves telling Maxima to load a package for doing "logarithmic solving" or whatever the process I just described is called.</p>
https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?comment=21412#post-id-21412I see, that's probably my fault , when I was testing I was using a computer with an old version of Sage. `.full_simplify()` must have changed.. Fri, 05 Aug 2011 19:30:32 +0200https://ask.sagemath.org/question/8262/interactive-maxima-question-on-fraction-value-during-solve/?comment=21412#post-id-21412