Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello, @Cyrille! The problem here is that you misused the assume command. The assume command is used to establish restrictions on symbolic variables, and its use depends on the case you are solving. For example, consider the following integral:

$$ \int_1^a\frac{1}{x}\;dx $$

This will converge or diverge depending on the value of $a$, so no specific answer can be given in this case, without knowing more information about $a$. The assume command takes care of this. If you suppose (assume) that $a>1$, for example, you get

$$ \int_1^a\frac{1}{x}\;dx=\log(a) $$

The corresponding Sage code would be

var('a')
assume(a>1)
integrate(1/x, 1, a)

If you suppose (assume) $a<0$, the integral will diverge. The corresponding Sage code would be

var('a')
assume(a>1)
integrate(1/x, 1, a)

(Consider assume the equivalent of the hypotheses of a theorem, proposition, lemma, etc.: you can't prove or even apply the theorem without knowing the hypothesis are true.)

In the particular case of your question, it is of no help to know that $0\le a\le$. For example, $a=1/2$ satisfies the assumption, but $x^{1/2}$ can't be computed for every real value of $x$, so extra restrictions should apply in order to invert the function.

However, consider the restriction (hypothesis or assumption) that $a\in\mathbb{Z}$. In that case, the function $x^n$ is meaningful on the whole set $\mathbb{R}$, except maybe for $x=0$, which Sage can handle, and thus it can be inverted.

My suggestion: Don't worry about when to use the assume command; Sage will tell you when it needs it.

For example, continuing with your question, the code

var('x,y,a')
U(x) = x^a
V(x) = solve(x == U(y), y)[0].rhs()
show(V)

will print a very long traceback, most of which is useless for you, except for the last line, which says:

TypeError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(a>0)', see `assume?` for more details)
Is a an integer?

There you go, the Maxima part of Sage is asking whether the variable $a$ is an integer or not. Then you declare $a$ to be indeed integer with an assume:

var('x,y,a')
assume(a, 'integer')
U(x) = x^a
V(x) = solve(x == U(y), y)[0].rhs()
show(V)

In general, when you get a large traceback, ignore most of it, except the last line, or perhaps the last three lines.

Hello, @Cyrille! The problem here is that you misused the assume command. The assume command is used to establish restrictions on symbolic variables, and its use depends on the case you are solving. For example, consider the following integral:

$$ \int_1^a\frac{1}{x}\;dx $$

This will converge or diverge depending on the value of $a$, so no specific answer can be given in this case, without knowing more information about $a$. The assume command takes care of this. If you suppose (assume) that $a>1$, for example, you get

$$ \int_1^a\frac{1}{x}\;dx=\log(a) $$

The corresponding Sage code would be

var('a')
assume(a>1)
integrate(1/x, 1, a)

If you suppose (assume) $a<0$, the integral will diverge. The corresponding Sage code would be

var('a')
assume(a>1)
integrate(1/x, 1, a)

(Consider assume the equivalent of the hypotheses of a theorem, proposition, lemma, etc.: you can't prove or even apply the theorem without knowing the hypothesis are true.)

In the particular case of your question, it is of no help to know that $0\le a\le$. a\le1$. For example, $a=1/2$ satisfies the assumption, but $x^{1/2}$ can't be computed for every real value of $x$, so extra restrictions should apply in order to invert the function.

However, consider the restriction (hypothesis or assumption) that $a\in\mathbb{Z}$. In that case, the function $x^n$ is meaningful on the whole set $\mathbb{R}$, except maybe for $x=0$, which Sage can handle, and thus it can be inverted.

My suggestion: Don't worry about when to use the assume command; Sage will tell you when it needs it.

For example, continuing with your question, the code

var('x,y,a')
U(x) = x^a
V(x) = solve(x == U(y), y)[0].rhs()
show(V)

will print a very long traceback, most of which is useless for you, except for the last line, which says:

TypeError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(a>0)', see `assume?` for more details)
Is a an integer?

There you go, the Maxima part of Sage is asking whether the variable $a$ is an integer or not. Then you declare $a$ to be indeed integer with an assume:

var('x,y,a')
assume(a, 'integer')
U(x) = x^a
V(x) = solve(x == U(y), y)[0].rhs()
show(V)

In general, when you get a large traceback, ignore most of it, except the last line, or perhaps the last three lines.