Ask Your Question

Emmanuel Charpentier's profile - activity

2021-01-18 08:20:12 -0600 commented question How to use for loops and assign values to array

Still no indentation. We can't help you without it : In Python, whitespace (indentation, line feeds) is syntactic.

2021-01-15 12:37:58 -0600 answered a question find_root fails in for loop with type coercion error

The error you reported is attributable to your initial allocation, which, by default, creates vectors of Integers, in which one cannot store floats. Try :

Ptetx = zero_vector(RR, 101)
Ptety = zero_vector(RR, 101)
Ptetz = zero_vector(RR 101)

(you can also try RDF : look up this in previous questions...).

However, this is not sufficient : it happens that your functions have no root for some i values, and this is not caught by your code, which stops at the first occurrence. You should bracket your root findings in try: except constructs (or, alternatively, use utility functions wrapping find_root in such constructs).

An interesting problem is to record this "no solution" occurrence in your results vectors. A possibility is RR("NaN"), but this depends in a large part on what you plan to do with these results...

HTH,

2021-01-14 17:39:51 -0600 answered a question SImple Trigonometric Equation solving

This plot :

var('r,l,m')
ex = l/sin(m/2/r)-r
plot(ex.subs(l=36/6, m=10), (r, -5, 5), ymin=-5, ymax=5, detect_poles=True, plot_points=1000)

suggests that ex has no (real) roots around 0. Proving it may require a non-trivial analytical exploration, possibly requiring the non-trivial use of non-trivial tools...

However, trying the suggested numerical solution :

print("Value of ex at suggested root r=%f is %f"%(3.68357, ex.subs([l==36/5,m==10]).subs(r==3.68357)))
Value of ex at suggested root r=3.683570 is 3.683570

suggests a typo in the question : at this value, ex approximately equals r. Which suggests that this value is (ano approximation of) a root of ex-r, which can be found more elegantly by :

print("Root of ex-r : %f"%find_root(ex.subs(l=36/5, m=10)-r, 2, 5))
Root of ex-r : 3.683570

See plot and computations in Sagecell

2021-01-14 10:02:24 -0600 commented question SImple Trigonometric Equation solving

Due to mis-reading the question, I inadvertently left here a pile of manure...

My apologies to whomever I may have misled.

2021-01-13 10:56:54 -0600 commented answer split display of long function on few lines

Note :

show(LatexExpr("f(x)=\\begin{array}{l}%s\\end{array}."%"\\\\".join(["\\displaystyle%s"%str(latex(u)) for u in f(x).operands()])))

may be considered slightly less horrible.

2021-01-13 10:54:47 -0600 commented answer split display of long function on few lines

I would like to split display of f(x) to appear on more than one line of code

That's what I did. Now, if you want to write (i. e. input) f(x) on more than one line, you need to use a backslash (\) as a continuation character just before a newline :

sage: foo = 1/2*x^2*arcsin(x*sin(1/9*pi)/(sqrt(-x^2 + 1)*cos(1/9*pi))) \
....:     -1/2*x^2*arcsin(1/2*sqrt(-3*x^2 + 3)/sqrt(-x^2 + 1)) \
....:      -1/2*sqrt(-x^2 - x^2*sin(1/9*pi)^2/cos(1/9*pi)^2 + 1)*x*sin(1/9*pi)/cos(1/9*pi) \
....:      + 1/4*sqrt(-1/4*x^2 + 1/4)*sqrt(-3*x^2 + 3) \
....:      -1/2*arcsin(x*sin(1/9*pi)/(sqrt(-x^2 + 1)*cos(1/9*pi))) \
....:       + 1/2*arcsin(1 ...
(more)
2021-01-13 09:05:38 -0600 answered a question split display of long function on few lines

This horror is a start... which can be quite certainly enhanced. Unfortunately, it doesn't display in ask.sagemath.org's implementation of Mathjax ; follow the link.

show(LatexExpr("f(x)=\\displaystyle\\begin{array}{l}%s\\end{array}."%"\\\\".join([str(latex(u)) for u in f(x).operands()])))
2021-01-12 08:27:06 -0600 answered a question Trigonometric equation

FredericC's answer is valid ; it just express the results in terms of sympyobjects with (currently) no automatic sage translation. A solution can be obtained in sage terms by simple transformations :

var("x, t, k")
assume(k, "integer")
Ex=tan(x)+tan(2*x)+tan(3*x)

This expression is a rational fraction in $\tan x$, which we re-express as a rational fraction in $t$ :

sage: ExT
2*(2*t^2 - 1)*(t^2 - 3)*t/((3*t^2 - 1)*(t + 1)*(t - 1))
ExT=Ex.trig_expand().factor().subs(tan(x)==t)

The roots of this fraction are the roots of its numerator...

MR=[u[0].radical_expression()
    for u in ExT.numerator().roots(x==t, ring=QQbar)]

... provided that none of these roots nullifies the denominator :

sage: any([ExT.denominator().subs(t==u).is_zero() for u in MR])
False

The properties of $\tan$ ensure us that if $x$ is a solution, so is $x+k\pi,\, k\in\mathbb{Z}$. Similarly, it is easy to check that if $x$ is a solution, so is $\pi-x$.

Sol=union([k*pi+arctan(u) for u in MR],[k*pi-arctan(u) for u in MR])
sage: Sol
[-1/3*pi + pi*k,
 pi*k,
 pi*k - arctan(1/2*sqrt(2)),
 1/3*pi + pi*k,
 pi*k + arctan(1/2*sqrt(2))]

FWIW, Mathematica proposes (using only the $2\pi$ periodicity of $\tan$, not $\pi$...) :

sage: mathematica.Solve(Ex==0,x)
{{x -> ConditionalExpression[2*Pi*C[1], Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[(-2*Pi)/3 + 2*Pi*C[1], 
    Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[-Pi/3 + 2*Pi*C[1], Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[Pi/3 + 2*Pi*C[1], Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[(2*Pi)/3 + 2*Pi*C[1], Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[Pi + 2*Pi*C[1], Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[-ArcTan[1/Sqrt[2]] + 2*Pi*C[1], 
    Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[Pi - ArcTan[1/Sqrt[2]] + 2*Pi*C[1], 
    Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[ArcTan[1/Sqrt[2]] + 2*Pi*C[1], 
    Element[C[1], Integers]]}, 
 {x -> ConditionalExpression[-Pi + ArcTan[1/Sqrt[2]] + 2*Pi*C[1], 
    Element[C[1], Integers]]}}

HTH,

2021-01-08 16:50:35 -0600 answered a question Integral equation solver

Sagemath has currently no "canned" solution for this kind of integro-differential equations. However, such a problem can sometimes be transformed in (a system of) sagemath-solvable differential equations.

In the example given by Daniel Volinski in the second comment :

var("x, t")
y = function("y")
E1 = y(x) == integrate(e^(-t + x)*y(t), t, 0, x)
E1
y(x) == integrate(e^(-t + x)*y(t), t, 0, x)

[ Note : This does not seem to fullfill the definition of a [Volterra equation](https://en.wikipedia.org/wiki/Volterra_integral_equation)]

One can clean up the problem by noting that in the righ-hand size, $e^x$ is a constant not dependent of the integration variable $t$, hence expressed out of the integrand :

with assuming(x>0): E2=E1.subs(E1.rhs()==e^x*integrate(e^-t*y(t),t,0,x))
with assuming(x<0): E3=E1.subs(E1.rhs()==e^x*integrate(e^-t*y(t),t,0,x))

The identity of E2 and E3 is easily checked :

sage: E2
y(x) == e^x*integrate(e^(-t)*y(t), t, 0, x)
sage: E3
y(x) == -e^x*integrate(e^(-t)*y(t), t, x, 0)

Differentiating (the two sides of) this equation with respect to $x$ gives a differential equation solvable by Sagemath

with assuming(x>0): S2=desolve((E2/e^x).diff(x),y(x), ivar=x)
S2
_C*e^(2*x)
# Declare the integration constants :
[var(str(u)) for u in S2.variables()]
[_C, x]

However, this candidate solution satisfies the original equation only for the trivial case of the null function :

E1.substitute_function(y,S2.function(x)).unhold().solve(_C)
[_C == 0]

By the way :

sage: E1.substitute_function(y,S2.function(x)).unhold()
_C*e^(2*x) == _C*(e^(2*x) - e^x)
sage: E2.substitute_function(y,S2.function(x)).unhold()
_C*e^(2*x) == _C*(e^x - 1)*e^x

EDIT : As already told, there is, to the best of my knowledge", no pre-programmed function for this in Sagemath. Feel free to submit one...

For the hell of it, I verified that a similar procedure was able to solve the equation proposed in the Mathematica example :

var("x, t, lambda_")
assume(x>0)
y = function("y")
E1 = y(x) == x^3 + lambda_*integrate((t-x)*y(t), t, 0, x)`

One notes that Sagemath insists to reformat this equation "its way" :

$$ y\left(x\right) = x^{3} - \lambda {\left(\int_{0}^{x} -t y\left(t\right)\,{d t} + \int_{0}^{x} x y\left(t\right)\,{d t}\right)} $$

Isolating the integral terms and differentiating twice gives us a second-order differential equation :

((E1-x^3)/lambda_).diff(x,2)
-(6*x - diff(y(x), x, x))/lambda_ == -y(x)

Sagemath default ODE solver (i. eI Maxima's) depends on the sign of $\lambda$ :

with assuming(lambda_>0): Sp = desolve(((E1-x^3)/lambda_).diff(x, 2), y(x), ivar=x)
[var(str(u)) for u in Sp.variables()] # Declaring the integration constants...
[_K1, _K2, lambda_, x]
Sp
_K2*cos(sqrt(lambda_)*x) + _K1*sin(sqrt(lambda_)*x) + 6*x/lambda_

Determining the constants is done by substituting in the original equation, simplifying a bit and solving for them the resulting polynomial in $x$ :

Ep = E1.substitute_function(y,Sp.function(x)).unhold().expand()-_K1*sin(x*sqrt(lambda_))-_K2*cos(x*sqrt(lambda_))
Consp = solve((Ep.lhs()-Ep.rhs()).coefficients(x, sparse=False),[_K1, _K2], solution_dict=True)
Solp = [Sp.subs(u).function(x) for u in Consp]
sage: Ep
6*x/lambda_ == -_K1*sqrt(lambda_)*x - _K2
sage: Consp
[{_K1: -6/lambda_^(3/2), _K2: 0}]
sage: Solp
[x |--> 6*x/lambda_ - 6*sin(sqrt(lambda_)*x)/lambda_^(3/2)]

$$\left[x \ {\mapsto}\ \frac{6\,x}{\lambda} - \frac{6 \, \sin\left(\sqrt{\lambda} x\right)}{\lambda^{\frac{3}{2}}}\right]$$

This unique solution is identical to Mathematica's proposed solution.

Similarly, for $\lambda<0$, we get :

with assuming(lambda_<0): Sn = desolve(((E1-x^3)/lambda_).diff(x, 2), y(x), ivar=x)
En = E1.substitute_function(y,Sn.function(x)).unhold().expand()-_K1*e^(-sqrt(-lambda_)*x)-_K2*e^(sqrt(-lambda_)*x)
Consn = solve((En.lhs()-En.rhs()).coefficients(x, sparse=False),[_K1, _K2], solution_dict=True)
Soln = [Sn.subs(u).maxima_methods().demoivre().trig_reduce().function(x) for u in Consn]
sage: Soln
[x |--> 6*x/lambda_ - 6*sin(sqrt(lambda_)*x)/lambda_^(3/2)]

This solution is formally identical to the solution obtained for $\lambda>0$ ; however, its meaning is different, $\lambda$ being negative...

HTH,

2021-01-06 07:29:20 -0600 commented question Line break in latex output makes it read wrong

The automatic "LaTeXification" (more precisely "mathjaxification") works reasonably well ... in "reasonable" cases, but has its limits. which you seem to have reached.

You could manipulate your result to "break" it in manageable parts ; say the denominator and the numerator, the latter being a polynomial which can be broken up in reasonably-sized parts. latex() each of these parts and build a LatexExpr representing correctly your result, using, for example, Latex arraysor align* as needed. In your case, something like LatexExpr(\frac{\array[c]{<lines of the numerator)}{<denominator>}). (Typed from memory, exact syntax to be checked).

Not having your original result prevents me to be more precise or proposing a solution...

2021-01-04 10:12:47 -0600 commented answer Simplify expression with root

Nice and smart...

2021-01-04 01:52:55 -0600 received badge  Necromancer (source)
2021-01-04 01:52:31 -0600 received badge  Nice Answer (source)
2021-01-03 13:14:04 -0600 answered a question problem with giac integration

This works under Linux; First pass :

sage: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:var('x,y,z,')
:var('xLow,xUp')
:var('yLow,yUp')
:rNum=1
:
:#xLow=sqrt(4*y^2/(sqrt(2) - 2) + sqrt(2)/(sqrt(2) - 2) - 2/(sqrt(2) - 2))
:#xUp=y*sin(1/9*pi)/cos(1/9*pi)
:
:#yLow=0.379024477
:#yUp=0.921891033
:zLow=0
:zUp=sqrt(-x^2 - y^2 + 1)
:zInt=integrate(1,z,zLow,zUp)
:print(zInt)
:yIntegr=integrate(zInt,y,yLow,yUp,algorithm="giac")
:xIntegr=integrate(zInt,x,xLow,xUp,algorithm="giac")
:print("yIntegr : " , yIntegr)
:print("xIntegr : " , xIntegr)
:--
(x, y, z)
(xLow, xUp)
(yLow, yUp)
sqrt(-x^2 - y^2 + 1)
yIntegr :  1/2*x^2*arcsin(yLow/sqrt(-x^2 + 1)) - 1/2*x^2*arcsin(yUp/sqrt(-x^2 + 1)) - 1/2*sqrt(-x^2 - yLow^2 + 1)*yLow + 1/2*sqrt(-x^2 - yUp^2 + 1)*yUp - 1/2*arcsin(yLow/sqrt(-x^2 + 1)) + 1/2*arcsin(yUp/sqrt(-x^2 + 1))
xIntegr :  1/2*y^2*arcsin(xLow/sqrt(-y^2 + 1)) - 1/2*y^2*arcsin(xUp/sqrt(-y^2 + 1)) - 1/2*sqrt(-xLow^2 - y^2 + 1)*xLow + 1/2*sqrt(-xUp^2 - y^2 + 1)*xUp - 1/2*arcsin(xLow/sqrt(-y^2 + 1)) + 1/2*arcsin(xUp/sqrt(-y^2 + 1))

Second pass :

sage: reset()
sage: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:var('x,y,z,')
:var('xLow,xUp')
:var('yLow,yUp')
:rNum=1
:
:#xLow=sqrt(4*y^2/(sqrt(2) - 2) + sqrt(2)/(sqrt(2) - 2) - 2/(sqrt(2) - 2))
:#xUp=y*sin(1/9*pi)/cos(1/9*pi)
:
:#yLow=0.379024477
:#yUp=0.921891033
:zLow=0
:zUp=sqrt(-x^2 - y^2 + 1)
:zInt=integrate(1,z,zLow,zUp)
:print(zInt)
:yIntegr=integrate(zInt,y,yLow,yUp,algorithm="giac")
:xIntegr=integrate(zInt,x,xLow,xUp,algorithm="giac")
:print("yIntegr : " , yIntegr)
:print("xIntegr : " , xIntegr)
:--
(x, y, z)
(xLow, xUp)
(yLow, yUp)
sqrt(-x^2 - y^2 + 1)
yIntegr :  1/2*x^2*arcsin(yLow/sqrt(-x^2 + 1)) - 1/2*x^2*arcsin(yUp/sqrt(-x^2 + 1)) - 1/2*sqrt(-x^2 - yLow^2 + 1)*yLow + 1/2*sqrt(-x^2 - yUp^2 + 1)*yUp - 1/2*arcsin(yLow/sqrt(-x^2 + 1)) + 1/2*arcsin(yUp/sqrt(-x^2 + 1))
xIntegr :  1/2*y^2*arcsin(xLow/sqrt(-y^2 + 1)) - 1/2*y^2*arcsin(xUp/sqrt(-y^2 + 1)) - 1/2*sqrt(-xLow^2 - y^2 + 1)*xLow + 1/2*sqrt(-xUp^2 - y^2 + 1)*xUp - 1/2*arcsin(xLow/sqrt(-y^2 + 1)) + 1/2*arcsin(xUp/sqrt(-y^2 + 1))

This may be Windows (and Cygwin)-specific. You should open an issue on its Github page.

2021-01-03 12:58:39 -0600 commented question Interface problem, integrate with giac

In 9.3.beta5, giac doesn't solve it when used through integrate :

sage: integrate(exp(t)/(t+1)^2,t, algorithm="giac")
integrate(e^t/(t + 1)^2, t)
sage: integrate(exp(t)/(t+1)^2,t)
-e^(-1)*exp_integral_e(2, -t - 1)/(t + 1)
sage: integrate(exp(t)/(t+1)^2,t, algorithm="sympy")
integrate(e^t/(t + 1)^2, t)
sage: integrate(exp(t)/(t+1)^2,t, algorithm="fricas")
((t + 1)*Ei(t + 1) - e^(t + 1))*e^(-1)/(t + 1)
sage: mathematica.Integrate(exp(t)/(t+1)^2,t)
-(E^t/(1 + t)) + ExpIntegralEi[1 + t]/E

But does when used directly :

sage: %giac integrate(exp(t)/(t + 1)^2,t)
(t*Ei(t+1)+Ei(t+1)-exp(1)*exp(t))/(t*exp(1)+exp(1))

HTH,

2021-01-03 12:53:59 -0600 edited answer Possible bug in Sage-Giac integration interface needs confirmation

I can repoduce the problem. However, it seems it is not (as I thought initially) in the Giac/Sage interface, since the following workaround works:

sage: Ex=(1-2*x^(1/3))^(3/4)/x
sage: from giacpy_sage import *
sage: Ig=libgiac.integrate(Ex,x).sage();Ig
4*(-2*x^(1/3) + 1)^(3/4) + 6*arctan((-2*x^(1/3) + 1)^(1/4)) - 3*log((-2*x^(1/3) + 1)^(1/4) + 1) + 3*log(abs((-2*x^(1/3) + 1)^(1/4) - 1))

The presence of the timing information given by Giac in the expression to convert is highly unwelcome...

This is now Trac#28913.

EDIT : Trac#28913 is now fixed.

2021-01-03 12:51:57 -0600 answered a question Unable to parse Giac output error

This is now fixed thanks to Trac#28913.

2021-01-01 09:33:52 -0600 received badge  Nice Answer (source)
2021-01-01 05:20:22 -0600 answered a question bug? multiply symbolic exponents

Not necessarily true. See sympy's documentation for a nice abstract on the problems...

EDIT : This is the third case mentioned in the pointed documentation :

sage: bool((x^a)^b==x^(a*b))
False
sage: with assuming(b,"integer"): bool((x^a)^b==x^(a*b))
True
2021-01-01 03:32:37 -0600 commented question Lost %display latex

WorksForMe(TM) in 9.3.beta5.

Try in a fresh worksheet ?

2021-01-01 01:27:10 -0600 commented question Lost %display latex

Can someone tell me what I mis-set and how to reset it?

In order to do that, you should let us know what you did set. Post code...

2020-12-31 11:59:35 -0600 received badge  Nice Answer (source)
2020-12-31 08:38:06 -0600 received badge  Necromancer (source)
2020-12-31 04:28:32 -0600 answered a question reverse function of latex()

It turns out that sympy has an (experimental) LaTeX parser, which however does not seem to be up to the task you ask. You'll need to install the antlr4-python3-runtime library using Sage's pip.

sage: from sympy.parsing.latex import parse_latex
sage: parse_latex(r"\int_a^b f(x) dx")
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
Integral(f(x), (x, a, b))
sage: parse_latex(r"\int_a^b f(x) dx")._sage_()
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
integrate(f(x), x, a, b)

Some of the version mismatch warnings are explored further. Notwithstanding these warnings, the parser seems to be able to correctly parse simple LaTeX expression and generate the SymPy representation of the objects they represent (which can then be re-translated to Sage).

However, your LaTeX expression is to complex to be parsed:

sage: parse_latex(z_k)
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
2

Eliminating the "obvious suspects" (text at the end of the expression, implicit multiplications) is not enough:

sage: z_k1 = r"2*\sqrt{\frac{-p}3}*\cos{\left(\frac13\arccos{\left(\frac{-q}2\sqrt{\frac{27}{-p^3}}\right)}+ \frac{2*k\pi}3\right)}"
sage: parse_latex(z_k1)
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
2

Some exploration seems to be in order. Could you keep us posted if you decide to go further?

EDIT : I did a bit of exploring myself. The problem seems bound to the fact that the arguments of \frac must be surrounded by braces in order to be parsed:

parse_latex(r"\frac{1}{2}")
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
1/2
sage: parse_latex(r"\frac12")
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
---------------------------------------------------------------------------
LaTeXParsingError                         Traceback (most recent call last)

[  Snip... ]

LaTeXParsingError: missing '{' at '12'
\frac12
~~~~~^

And, indeed:

sage: parse_latex(r"2 \sqrt{\frac{-p}{3}} \cos{\left(\frac{1}{3}\arccos{\left(\frac{-q}{2}\sqrt{\frac{27}{-p^3}}\right)}+ \frac{2k\pi}{3}\right)}")
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9!=4.7.2
2*((sqrt(3)*sqrt(-p)/3)*cos((2*(k*pi))/3 + acos(((-q)/2)*(3*sqrt(3)*sqrt(1/(-p**3))))/3))

which is, indeed, (mathematically) equal to the typeset expression; however, SymPy and/or Sage refactored some parts of the expression (see the innumerable questions about the "right" way to format an expression, which point to the lack of an algorithmic definition of "well-typeset"...), and the expressions are cosmetically different.

TL;DR : parse_latex might help more with some LaTeX expressions if they were not too much "hand-optimized" (the frac in \frac12 has indeed two arguments (see the \TeX book...), but is too "hand-optimized" for parse_latex (or for my taste, BTW...)).

HTH,

2020-12-31 01:45:23 -0600 received badge  Nice Answer (source)
2020-12-31 01:39:38 -0600 received badge  Necromancer (source)
2020-12-30 13:53:51 -0600 answered a question Difference of comportment between notebook and Sagecell

Sage's interacts are a Sage-specific-customization of ipywidgets.interact. Their behavior is, as far as I know, documented only for the Jupyter notebook.

Ran in a 9.3.beta5 notebook, your code gives the expected result. Ran in sagecell, the presentation is cosmetically duifferent (you get number cells instead of sliders), but the result is the same (i. e. ABCD+ABDC+2*ACBD).

What did you expect exactly ?

Second question : an interact does not wait for input : it paints and activates controls, comutes the result as a functin of the (default) values of these inputs and returns it. Whenever one of the inputs changes as a result of an end-user action, the resulting value is recomputed and returned. Mos common case : the return value is a graphic, which is redisplayed.

All of this is documented and tutorialized.

sage: r.library("fortunes")                                                     
sage: r.fortune("'WTFM'")                                                       

This is all documented in TFM. Those who WTFM don't want to have to WTFM again
on the mailing list. RTFM.
   -- Barry Rowlingson
      R-help (October 2003)
2020-12-30 01:55:58 -0600 answered a question Kernel died when computing large matrix
sage: m=5;n=3
sage: ((m^n)^2+1)*((m^m)^2)
152597656250
sage: (((m^n)^2+1)*((m^m)^2)).log(10).n()
11.1835478633337

You are trying to allocate a matrix of 152 billions rationals (and some change...). Do you have enough memory for that ?

2020-12-30 01:43:04 -0600 commented answer Expression substitution fails: why?

Indeed , I oversaw the subs problem, which I could reproduce. Answer edited, ticket filed.

2020-12-29 12:30:45 -0600 answered a question Installing optional packages - infinite loop

The version installed by the Windows binary installer runs on top of Cygwin, which is a library providing Unix-like routines and (pseudo-)system calls to binaries resulting from compiling (possibly adapted) Unix sources against it.

This approach is quite different from WSL use, since it attempts to use the Windows kernel (and some Windows libraries). It has for a long time been the only alternative to the installation of a virtual machine and a Linux distribution in it in order to install and run Sagemath.

In this setup, adding optional packages is not absolutely obvious. As far as I know, this is not (yet) fully supported, notwithstanding the main developer's (Eric Madison Bray) gigantic efforts in that direction.

WSL installation, as described by sandy_scott, amounts to a kind of virtual machine installation, but in an environment where the Linux kernel can "talk" directly to the Windows kernel, possibly streamlining the process.

Would you mind reviewing the issues filed at the binary installer Github page (and possibly open a new one if necessary) ?

2020-12-29 12:17:59 -0600 commented answer Installing optional packages - infinite loop

Would you mind write this up for the Sagemath Installation Guide ? The process is described in the Sage develoiper's guide. Basically, you submit a patch against the Installation Guide source. It is not supe-steamlined, but it is tolerably easy, even for dummies of my kind...

2020-12-29 12:10:55 -0600 answered a question Expression substitution fails: why?

WorksForMe(TM) on Sagemath 9.3.beta5 :

sage: reset()
sage: version()
'SageMath version 9.3.beta5, Release Date: 2020-12-27'
sage: var('A, L, G, R, f, k, n, q, u, beta, gamma', domain="positive") # Shortcut
(A, L, G, R, f, k, n, q, u, beta, gamma)
sage: expr_complex = (I*R^2*f^3*k*q*A*u/ ((2*pi*L*R^2*G*f^4*k^2*q - 2*pi*L*R^2*G*f^4*q - 2*pi*L*R^2*beta^2*G*q + (2*I*pi*L*R^2*beta*gamma*q + 2*I*pi*L*R*(beta + q))*G*f^3 + 2*(pi*(beta^2 + 1)*L*R^2*q + pi*L*R*beta*gamma*q + pi*L*beta)*G*f^2+ (-2*I*pi*L*R^2*beta*gamma*q - 2*I*pi*(beta^2*q + beta)*L*R)*G*f)*n))
sage: R1=(expr_complex.real()^2+expr_complex.imag()^2).factor()
sage: R2=(sqrt(expr_complex.real()^2+expr_complex.imag()^2)^2).factor()
sage: bool(R1==R2)
True
sage: R3=((sqrt(expr_complex.real()^2+expr_complex.imag()^2).factor())^2).factor()
sage: bool(R1==R3)
True
sage: bool(R2==R3)
True

HTH,

EDIT : The expressins are correct, but indeed, Sage's default mechanism for substitutions faits to work on R3. Sympy's subs works :

sage: import sympy
sage: bool(sympy.sympify(R3).subs(f,2*beta)._sage_()==R1.subs(f=2*beta))
True

More troubling : mathematica seems to faile somehow :

sage: bool(mathematica.Replace(R3,mathematica.Rule(f,2*beta)).sage()==R1.subs(f=2*beta))
False

And, indeed,

sage: bool(R3.subs(f=2*beta)==R1.subs(f=2*beta))

never returns.

This is now Trac#31137.

2020-12-28 06:39:20 -0600 commented answer If I compile Sage from source, will it start up faster?

Reformatted a bit in order to be able to read the damn thing...

2020-12-28 06:38:49 -0600 edited answer If I compile Sage from source, will it start up faster?

@slelievre I compiled sagemath using march=native -O3 -fno-plt and unfortunatlely I have to say that sage is now slower (I think). The thing you have to know is, sagemath speeds up if I use schedutil as my scaling governor. Unfortunately I can't remember whether I was using schedutil or powersave when I was testing the binary version (probably powersave though). So I downloaded the binary version again (turns out out you can have both installed side-by-side)(it's kind of creepy that the binary version remembers my previous inputs). Here are results from old the binary version:

Running benchmark 0 Benchmark 0:
   Factor the following polynomial over
       the rational numbers: (x^97+19*x+1)*(x^103-19*x^97+14)*(x^100-1) Time: 0.2822810000000002 seconds
   Running benchmark 1 Find the
   Mordell-Weil group of the elliptic
   curve 5077A using mwrank Time:
   0.4469660000000002 seconds Running benchmark 2 Some basic arithmetic
   with very large Integer numbers:
   '3^1000001 * 19^100001 Time:
   0.01994899999999955 seconds Running benchmark 3 Some basic arithmetic
   with very large Rational numbers:
   '(2/3)^100001 * (17/19)^100001 Time:
   0.028340999999999728 seconds Running benchmark 4 Rational polynomial
   arithmetic using Sage. Compute
   (x^29+17*x-5)^200. Time:
   0.009201000000000015 seconds Running benchmark 5 Rational polynomial
   arithmetic using Sage. Compute (x^19
   - 18*x + 1)^50 one hundred times. Time: 0.10662800000000017 seconds
   Running benchmark 6 Compute the
   p-division polynomials of y^2 = x^3 +
   37*x - 997 for primes p < 40. Time:
   0.05905899999999997 seconds Running benchmark 7 Compute the Mordell-Weil
   group of y^2 = x^3 + 37*x - 997.
   Time: 0.37592800000000004 seconds
   Running benchmark 8 %time
   sum(1/(x^2), x,1,100000) CPU times:
   user 1min 11s, sys: 1.14 s, total:
   1min 12s

Wall time: 27.9 s

Here are results from the new binary version (powersave):

Running benchmark 0
Benchmark 0: Factor the following polynomial over
    the rational numbers: (x^97+19*x+1)*(x^103-19*x^97+14)*(x^100-1)
Time: 0.2790720000000002 seconds
Running benchmark 1
Find the Mordell-Weil group of the elliptic curve 5077A using mwrank
Time: 0.4314460000000002 seconds
Running benchmark 2
Some basic arithmetic with very large Integer numbers: '3^1000001 * 19^100001
Time: 0.019366999999999912 seconds
Running benchmark 3
Some basic arithmetic with very large Rational numbers: '(2/3)^100001 * (17/19)^100001
Time: 0.028370000000000672 seconds
Running benchmark 4
Rational polynomial arithmetic using Sage. Compute (x^29+17*x-5)^200.
Time: 0.008942000000000228 seconds
Running benchmark 5
Rational polynomial arithmetic using Sage. Compute (x^19 - 18*x + 1)^50 one hundred times.
Time: 0.106522 seconds
Running benchmark 6
Compute the p-division polynomials of y^2 = x^3 + 37*x - 997 for primes p < 40.
Time: 0.05832100000000029 seconds
Running benchmark 7
Compute the Mordell-Weil group of y^2 = x^3 + 37*x - 997.
Time: 0.3272319999999995 seconds
Running benchmark 8

From compiled version (powersave):

Running benchmark 0
Benchmark 0: Factor the following polynomial over
    the rational numbers: (x^97+19*x+1)*(x^103-19*x^97+14)*(x^100-1)
Time: 0.3547199999999995 seconds
Running benchmark 1
Find the Mordell-Weil group of the elliptic curve 5077A using mwrank
Time: 0.43139200000000066 seconds
Running benchmark 2
Some basic arithmetic with very large Integer numbers: '3^1000001 * 19^100001
Time: 0.019306000000000267 seconds
Running benchmark 3
Some basic arithmetic with very large Rational numbers: '(2/3)^100001 * (17/19)^100001
Time: 0.028086999999999307 seconds
Running benchmark 4
Rational polynomial arithmetic using Sage. Compute (x^29+17*x-5)^200.
Time: 0.008855999999999753 seconds
Running benchmark 5
Rational polynomial arithmetic using Sage. Compute (x^19 - 18*x + 1)^50 one hundred times.
Time: 0.10795900000000103 seconds
Running benchmark 6
Compute the p-division polynomials of y^2 = x^3 + 37*x - 997 for primes p < 40.
Time: 4.499999999918458e-05 seconds
Running benchmark 7
Compute the Mordell-Weil group of y^2 = x^3 + 37*x - 997.
Time: 2.1000000000270802e-05 seconds
Running benchmark 8

What's interesting is that the compiled version is slower in benchmark 0. Could this be due to a missing dependency or something? Also the compiled version is faster at benchmarks 7 and 8. Now for my own test: the time it takes to compute sum(1/(x^2), x,1,100000):

Binary version (powersave):
CPU times: user 1min 11s, sys: 1.1 s, total: 1min 12s
Wall time: 27.4 s

Compiled version (powersave):
CPU times: user 1min 23s, sys: 1.3 s, total: 1min 25s
Wall time: 28.5 s

So the compiled version is slower in this regard.

Binary version (schedutil):
Running benchmark 0
Benchmark 0: Factor the following polynomial over
    the rational numbers: (x^97+19*x+1)*(x^103-19*x^97+14)*(x^100-1)
Time: 0.14427600000000007 seconds
Running benchmark 1
Find the Mordell-Weil group of the elliptic curve 5077A using mwrank
Time: 0.1471680000000002 seconds
Running benchmark 2
Some basic arithmetic with very large Integer numbers: '3^1000001 * 19^100001
Time: 0.0064669999999997785 seconds
Running benchmark 3
Some basic arithmetic with very large Rational numbers: '(2/3)^100001 * (17/19)^100001
Time: 0.009400999999999993 seconds
Running benchmark 4
Rational polynomial arithmetic using Sage. Compute (x^29+17*x-5)^200.
Time: 0.00301399999999985 seconds
Running benchmark 5
Rational polynomial arithmetic using Sage. Compute (x^19 - 18*x + 1)^50 one hundred times.
Time: 0.03593299999999999 seconds
Running benchmark 6
Compute the p-division polynomials of y^2 = x^3 + 37*x - 997 for primes p < 40.
Time: 3.0999999999892225e-05 seconds
Running benchmark 7
Compute the Mordell-Weil group of y^2 = x^3 + 37*x - 997.
Time: 1.2999999999596668e-05 seconds
Running benchmark 8

Compiled version (schedutil):

Running benchmark 0
Benchmark 0: Factor the following polynomial over
    the rational numbers: (x^97+19*x+1)*(x^103-19*x^97+14)*(x^100-1)
Time: 0.17197400000000007 seconds
Running benchmark 1
Find the Mordell-Weil group of the elliptic curve 5077A using mwrank
Time: 0.14492799999999972 seconds
Running benchmark 2
Some basic arithmetic with very large Integer numbers: '3^1000001 * 19^100001
Time: 0.006648000000000209 seconds
Running benchmark 3
Some basic arithmetic with very large Rational numbers: '(2/3)^100001 * (17/19)^100001
Time: 0.009484000000000048 seconds
Running benchmark 4
Rational polynomial arithmetic using Sage. Compute (x^29+17*x-5)^200.
Time: 0.0030330000000002855 seconds
Running benchmark 5
Rational polynomial arithmetic using Sage. Compute (x^19 - 18*x + 1)^50 one hundred times.
Time: 0.0348070000000007 seconds
Running benchmark 6
Compute the p-division polynomials of y^2 = x^3 + 37*x - 997 for primes p < 40.
Time: 5.2999999999858716e-05 seconds
Running benchmark 7
Compute the Mordell-Weil group of y^2 = x^3 + 37*x - 997.
Time: 1.1999999999900979e-05 seconds
Running benchmark 8

My own tests:

Binary version (schedutil):
CPU times: user 40.2 s, sys: 547 ms, total: 40.8 s
Wall time: 12.1 s

Compiled version (schedutil):
CPU times: user 46.3 s, sys: 621 ms, total: 46.9 s
Wall time: 12.6 s

P.S. I didn't delete the .sage directory before compiling.

2020-12-27 02:46:10 -0600 commented answer Finding absolute values of roots of polynomials with Sage

Why work with approximate rather than exact coefficients ?

2020-12-26 05:03:09 -0600 commented answer sage-shell-mode positions cursor incorrectly

And, BTW :

I just pulled latest git master

My patch is in the simple prompt branch of my forked tree ; master is untouched (necessary to submit a PR through Github's baroque mechanisms...).

Again, this has now been merged in the master branch of the version distributed by MELPA.

HTH,

2020-12-26 02:36:00 -0600 commented answer sage-shell-mode positions cursor incorrectly

Sage version 9.0 does not seem to support "simple-prompt"

This is, IIRC cared for in the initialization code

Anyway, upgrading to Sage > 9.1 is recommended, for much stronger reasons (Python 3....).

2020-12-25 04:30:28 -0600 edited answer sage-shell-mode positions cursor incorrectly

Sage 9.2.beta8 broke sage-shell-mode compatibility with emacs by upgrading Ipython. A patch was created and proposed on a pull request on Aug 125, 2020. It has not yet been reviewed as of Dec 25, 2020.

In the interim, feel free to try my fork, source of the pull request.

EDIT : The patch just got merged in the main tree, and should diffuse to normal channels (i. e. MELPA) in due time.

Re-EDIT : The patched version has diffused to MELPA. My fork is no longer necessary.

HTH,