Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Sagemath formatting routine is somewhat asinine in radical-involving fraction handling. Contemplate :

sage: 1/sqrt(2)
1/2*sqrt(2)

It turns out that, in this case, Sage denotes a division by a multiplication :

sage: (1/sqrt(2)).operator()
<function mul_vararg at 0x7fd16a1949d0>
sage: (1/sqrt(2)).operands()
[sqrt(2), 1/2]

On the other hand, if :

sage: (sqrt(x+1)/(x+1)).operator()
<built-in function pow>
sage: (sqrt(x+1)/(x+1)).operands()
[x + 1, -1/2]

the internal representation is different in your initial case :

sage: (sqrt(1-x)/(1-x)).operator()
<function mul_vararg at 0x7fd16a1949d0>
sage: (sqrt(1-x)/(1-x)).operands()
[1/(x - 1), sqrt(-x + 1), -1]

And; BTW, Sympy's internal representation is different :

sage: (sqrt(1-x)/(1-x))._sympy_().simplify()
1/sqrt(1 - x)
sage: (sqrt(1-x)/(1-x))._sympy_().simplify().func
<class 'sympy.core.power.Pow'>
sage: (sqrt(1-x)/(1-x))._sympy_().simplify().args
(1 - x, -1/2)

but this internal representation is lost when reverting to Sage :

sage: (sqrt(1-x)/(1-x))._sympy_()._sage_()
-sqrt(-x + 1)/(x - 1)
sage: (sqrt(1-x)/(1-x))._sympy_()._sage_().operator()
<function mul_vararg at 0x7fd16a1949d0>
sage: (sqrt(1-x)/(1-x))._sympy_()._sage_().operands()
[1/(x - 1), sqrt(-x + 1), -1]

HTH,

Sagemath formatting routine is somewhat asinine in radical-involving fraction handling. handling, due to internal representation of expressions. Contemplate :

sage: 1/sqrt(2)
1/2*sqrt(2)

It turns out that, in this case, Sage denotes a division by a multiplication :

sage: (1/sqrt(2)).operator()
<function mul_vararg at 0x7fd16a1949d0>
sage: (1/sqrt(2)).operands()
[sqrt(2), 1/2]

On the other hand, if :

sage: (sqrt(x+1)/(x+1)).operator()
<built-in function pow>
sage: (sqrt(x+1)/(x+1)).operands()
[x + 1, -1/2]

the internal representation is different in your initial case :

sage: (sqrt(1-x)/(1-x)).operator()
<function mul_vararg at 0x7fd16a1949d0>
sage: (sqrt(1-x)/(1-x)).operands()
[1/(x - 1), sqrt(-x + 1), -1]

And; BTW, Sympy's internal representation is different :

sage: (sqrt(1-x)/(1-x))._sympy_().simplify()
1/sqrt(1 - x)
sage: (sqrt(1-x)/(1-x))._sympy_().simplify().func
<class 'sympy.core.power.Pow'>
sage: (sqrt(1-x)/(1-x))._sympy_().simplify().args
(1 - x, -1/2)

but this internal representation is lost when reverting to Sage :

sage: (sqrt(1-x)/(1-x))._sympy_()._sage_()
-sqrt(-x + 1)/(x - 1)
sage: (sqrt(1-x)/(1-x))._sympy_()._sage_().operator()
<function mul_vararg at 0x7fd16a1949d0>
sage: (sqrt(1-x)/(1-x))._sympy_()._sage_().operands()
[1/(x - 1), sqrt(-x + 1), -1]

EDIT : FWIW, the internal representation used by Mathematica is yet another :

sage: mathematica("M=Sqrt[1-x]/(1-x)")
1/Sqrt[1 - x]
sage: mathematica("Table[M[[u]], {u, Range[0,(Length[M])]}]")
{Power, 1 - x, -1/2}

HTH,