ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 18 Oct 2019 14:30:12 -0500How to iterate over coefficientshttp://ask.sagemath.org/question/48391/how-to-iterate-over-coefficients/I am a relative newbie to Sage but not to algebraic manipulation in general.
I have a family of expressions with non-linear coefficients which I am not sure how best to represent. In the end it has to be an (infinite) ring of polynomials representing a Volterra space, but I have the same terms inside non-linear functions (which I need to evaluate to a known value) and as the polynomial variables.
Here is an example, where simple symbolic manipulation doesn't work:
f_m = a*x^b
ex = expand(f_m.subs({b : b_m + (b_s-b_m)^3})).derivative(b_m).full_simplify()
ex.subs({b_m + (b_s-b_m)^3 : b_m }).show()
Producing:
-(3*a*b_m^2 - 6*a*b_m*b_s + 3*a*b_s^2 - a)*x^(-b_m^3 + 3*b_m^2*b_s - 3*b_m*b_s^2 + b_s^3 + b_m)*log(x)
When what I want is:
-(3*a*b_m^2 - 6*a*b_m*b_s + 3*a*b_s^2 - a)*x^(-b_m)*log(x)
How can I iterate over non-linear elements (exponent and the arguments to any non-monomial terms) carrying out direct substitutions, while leaving monomials alone. I want the result to remain as a polynomial ring on b_s
----------
Clarification:
The intent is to use the code for a generic non-linear construct. It's intended to handle any general non-linear expression in L2, but these are manipulated to belong to a class of Volterra polynomials with non-linear coefficients. like the log(x) and x^bm on the above example. Those are the coefficients of the monomials.
Idealy whatever process I follow should be able to identify the non-monomial coefficients in the expression and remove the monomial terms from them by doing the substitution b_s = b_m. Basically:
x.subs(b_s = b_m) for x not a monomial term in expression.
Which would make the resulting expression strictly a polynomial ring on b_s with non-linear coefficients on x and b_m.Edgar BrownFri, 18 Oct 2019 03:29:04 -0500http://ask.sagemath.org/question/48391/possible invalid latex translation from fricas resulthttp://ask.sagemath.org/question/48409/possible-invalid-latex-translation-from-fricas-result/Using 8.9 sagemath on Linux. Where Fricas 1.5 is installed.
After calling fricas for integration from inside sagemath, and then translating the result to latex, the latex do not compile. I get syntax error compiling the latex with latest texlive TL 2019.
>sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.9, Release Date: 2019-09-29 │
│ Using Python 2.7.16. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: var('b c x n a e')
sage: anti=integrate((b*log(c*x^n) + a)*x^2*polylog(3, e*x),x, algorithm="fricas")
sage: anti_in_latex=latex(anti)
sage: anti_in_latex
sage: anti_in_latex
-\frac{4 \, {\left(4 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} + 9 \, {\left(3 \, b e^{2} n - 2 \, a e^{2}\right)} x^{2} + 36 \, {\left(2 \, b e n - a e\right)} x + 36 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(2 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} - b n\right)} {\rm %iint}\left(e, x, -\frac{\log\left(-e x + 1\right)}{e}, -\frac{\log\left(-e x + 1\right)}{x}\right) - 36 \, {\left({\left(b e^{3} n - a e^{3}\right)} x^{3} - b n + a\right)} \log\left(-e x + 1\right) - 6 \, {\left(2 \, b e^{3} x^{3} + 3 \, b e^{2} x^{2} + 6 \, b e x - 6 \, {\left(b e^{3} x^{3} - b\right)} \log\left(-e x + 1\right)\right)} \log\left(c\right) - 6 \, {\left(2 \, b e^{3} n x^{3} + 3 \, b e^{2} n x^{2} + 6 \, b e n x - 6 \, {\left(b e^{3} n x^{3} - b n\right)} \log\left(-e x + 1\right)\right)} \log\left(x\right) - 108 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(b e^{3} n - 3 \, a e^{3}\right)} x^{3}\right)} {\rm polylog}\left(3, e x\right)}{972 \, e^{3}}
sage:
Now when compiling the above, here is the error
>cat foo1.tex
\documentclass[12pt]{article}%
\usepackage{amsmath}
\begin{document}
\[
-\frac{4 \, {\left(4 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} + 9 \, {\left(3 \, b e^{2} n - 2 \, a e^{2}\right)} x^{2} + 36 \, {\left(2 \, b e n - a e\right)} x + 36 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(2 \, b e^{3} n - 3 \, a e^{3}\right)} x^{3} - b n\right)} {\rm %iint}\left(e, x, -\frac{\log\left(-e x + 1\right)}{e}, -\frac{\log\left(-e x + 1\right)}{x}\right) - 36 \, {\left({\left(b e^{3} n - a e^{3}\right)} x^{3} - b n + a\right)} \log\left(-e x + 1\right) - 6 \, {\left(2 \, b e^{3} x^{3} + 3 \, b e^{2} x^{2} + 6 \, b e x - 6 \, {\left(b e^{3} x^{3} - b\right)} \log\left(-e x + 1\right)\right)} \log\left(c\right) - 6 \, {\left(2 \, b e^{3} n x^{3} + 3 \, b e^{2} n x^{2} + 6 \, b e n x - 6 \, {\left(b e^{3} n x^{3} - b n\right)} \log\left(-e x + 1\right)\right)} \log\left(x\right) - 108 \, {\left(3 \, b e^{3} n x^{3} \log\left(x\right) + 3 \, b e^{3} x^{3} \log\left(c\right) - {\left(b e^{3} n - 3 \, a e^{3}\right)} x^{3}\right)} {\rm polylog}\left(3, e x\right)}{972 \, e^{3}}
\]
\end{document}
And
>lualatex foo1.tex
This is LuaTeX, Version 1.10.0 (TeX Live 2019)
restricted system commands enabled.
(./foo1.tex
LaTeX2e <2018-12-01>
luaotfload | main : initialization completed in 0.144 seconds
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size12.clo))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsopn.sty)) (./foo1.aux)
)
Runaway argument?
{4 \, {\left (4 \, b e^{3} n - 3 \, a e^{3}\right )} x^{3} + 9 \, {\left \ETC.
! File ended while scanning use of \frac .
<inserted text>
\par
<*> foo1.tex
?
This is the first time I see latex generated by sagemath not compile OK. I am usin
Any one knows what is going on and why this error is generated?
**Update**
Fyi, when running the above directly in Fricas, this is what I get
ii:=integrate((b*log(c*x^n) + a)*x^2*polylog(3, e*x),x);
unparse(ii::InputForm)
"(((-108)*b*e^3*n*x^3*log(x)+((-108)*b*e^3*x^3*log(c)+((72*b*e^3*n+(-108)*a*e
^3)*x^3+36*b*n)))*%iint(e,x,((-1)*log((-1)*e*x+1))/e,((-1)*log((-1)*e*x+1))/x
)+((324*b*e^3*n*x^3*log(x)+(324*b*e^3*x^3*log(c)+((-108)*b*e^3*n+324*a*e^3)*x
^3))*polylog(3,e*x)+((((-36)*b*e^3*n*x^3+36*b*n)*log((-1)*e*x+1)+(12*b*e^3*n*
x^3+18*b*e^2*n*x^2+36*b*e*n*x))*log(x)+((((-36)*b*e^3*x^3+36*b)*log((-1)*e*x+
1)+(12*b*e^3*x^3+18*b*e^2*x^2+36*b*e*x))*log(c)+(((36*b*e^3*n+(-36)*a*e^3)*x^
3+((-36)*b*n+36*a))*log((-1)*e*x+1)+(((-16)*b*e^3*n+12*a*e^3)*x^3+((-27)*b*e^
2*n+18*a*e^2)*x^2+((-72)*b*e*n+36*a*e)*x))))))/(972*e^3)"
But Fricas Latex is VALID, since it add `\` around `%`
(11) -> latex(ii)
(11)
"{{{\left( -{{108} \ b \ {{e} \sp {3}} \ n \ {{x} \sp {3}} \ {\log \left
( {x} \right)}} -{{108} \ b \ {{e} \sp {3}} \ {{x} \sp {3}} \ {\log \left
( {c} \right)}}+{{\left( {{72} \ b \ {{e} \sp {3}} \ n} -{{108} \ a \ {{
e} \sp {3}}} \right)} \ {{x} \sp {3}}}+{{36} \ b \ n} \right)} \ { \%iint
\left( {e, \: x, \: -{{\log \left( {{-{e \ x}+1}} \right)} \over e}, \: -{{
\log \left( {{-{e \ x}+1}} \right)} \over x}} \right)}}+{{\left( {{324} \ b
\ {{e} \sp {3}} \ n \ {{x} \sp {3}} \ {\log \left( {x} \right)}}+{{324}
\ b \ {{e} \sp {3}} \ {{x} \sp {3}} \ {\log \left( {c} \right)}}+{{\left(
-{{108} \ b \ {{e} \sp {3}} \ n}+{{324} \ a \ {{e} \sp {3}}} \right)} \
{{x} \sp {3}}} \right)} \ {polylog \left( {3, \: {e \ x}} \right)}}+{{\le
ft( {{\left( -{{36} \ b \ {{e} \sp {3}} \ n \ {{x} \sp {3}}}+{{36} \ b \
n} \right)} \ {\log \left( {{-{e \ x}+1}} \right)}}+{{12} \ b \ {{e} \s
p {3}} \ n \ {{x} \sp {3}}}+{{18} \ b \ {{e} \sp {2}} \ n \ {{x} \sp {2
}}}+{{36} \ b \ e \ n \ x} \right)} \ {\log \left( {x} \right)}}+{{\left
( {{\left( -{{36} \ b \ {{e} \sp {3}} \ {{x} \sp {3}}}+{{36} \ b} \right)
} \ {\log \left( {{-{e \ x}+1}} \right)}}+{{12} \ b \ {{e} \sp {3}} \ {{
x} \sp {3}}}+{{18} \ b \ {{e} \sp {2}} \ {{x} \sp {2}}}+{{36} \ b \ e \
x} \right)} \ {\log \left( {c} \right)}}+{{\left( {{\left( {{36} \ b \ {{
e} \sp {3}} \ n} -{{36} \ a \ {{e} \sp {3}}} \right)} \ {{x} \sp {3}}} -{
{36} \ b \ n}+{{36} \ a} \right)} \ {\log \left( {{-{e \ x}+1}} \right)}
}+{{\left( -{{16} \ b \ {{e} \sp {3}} \ n}+{{12} \ a \ {{e} \sp {3}}} \r
ight)} \ {{x} \sp {3}}}+{{\left( -{{27} \ b \ {{e} \sp {2}} \ n}+{{18} \
a \ {{e} \sp {2}}} \right)} \ {{x} \sp {2}}}+{{\left( -{{72} \ b \ e \
n}+{{36} \ a \ e} \right)} \ x}} \over {{972} \ {{e} \sp {3}}}"
So it looks like sagemath needs to do the same. Look into the result returned by Fricas, and replace `%iint` by ` \%iint` in the Latex?
Thanks
--NasserNasserFri, 18 Oct 2019 14:30:12 -0500http://ask.sagemath.org/question/48409/Solve failshttp://ask.sagemath.org/question/48390/solve-fails/I wonder why the Variable 'x_0' not found
gr=Polyhedron(ieqs=[(10,-1,0),(-12,0,1)])
p1=gr.plot()
x_0, x_1 = var('x_0 x_1')
lin=solve([70==6*x_0+18*x_1],x_1)
p2=plot(lin, (x,8,14))
p1+p2CyrilleThu, 17 Oct 2019 23:50:09 -0500http://ask.sagemath.org/question/48390/Sage GUI on Mac when building from sourcehttp://ask.sagemath.org/question/48385/sage-gui-on-mac-when-building-from-source/I normally use the official (pre-compiled) app version of Sage on macOS. When I start the app, it adds a new dropdown menu to the menu bar.
Now I switched to building Sage from source, as this gives access to features I could not otherwise have (e.g. install Coin MIP solver with `sage -i cbc`). How can I run the same GUI interface that is available in the app version? I can run the command line `sage` program or I can use `sage --notebook=jupyter`. But is there a way to run the same GUI available in the app version?SzabolcsThu, 17 Oct 2019 05:42:39 -0500http://ask.sagemath.org/question/48385/Printing from parallel processeshttp://ask.sagemath.org/question/48382/printing-from-parallel-processes/I am trying to use Sage's parallelization with `@parallel(p_iter='fork')` (I need `fork` specifically to work around the problems brought up [here](https://ask.sagemath.org/question/48270/sage-stalls-during-computation/).)
If I use `print` to show some messages, they only appear when the parallelized function has finished. Example:
@parallel(1, timeout=10)
def fun(x):
print('Starting %d' % x)
sleep(5)
print('Finished %d' % x)
return x*x
list(fun([2,3,4]))
The "Starting" and the "Finished" messages show up simultaneously, even though they are issued with a 5 second time difference.
How can I print a message so that it will show up immediately?
I need this when I am running a Sage script in a terminal. I am not using Sage interactively in this case and I am not using the notebook interface.SzabolcsThu, 17 Oct 2019 04:40:21 -0500http://ask.sagemath.org/question/48382/Sage is not preparsing Python 3 underscored integershttp://ask.sagemath.org/question/47908/sage-is-not-preparsing-python-3-underscored-integers/Hello, Sage community!
With the upcoming migration of Sage from Python 2 to Python 3 (really soon, let us hope!), there are some testings I have been trying, and I have noticed that the "underscored integer literals", like "1_000_000" are not preparsed by Sage. For example,
preparse('1_000_000 + 3')
results in
'1_000_000 + Integer(3)'
However,
preparse('1000000 + 3')
returns
'Integer(1000000) + Integer(3)'
On the other hand, if I write
type(1_000_000 + 3)
the result is
<class 'sage.rings.integer.Integer'>
which is great, but
type(1_000_000 + 3_000)
instead gives me
<class 'int'>
Finally,
type(1000000 + 3000)
gives us
<class 'sage.rings.integer.Integer'>
I know one of the reasons for the `Integer` type was to allow divisions like `3/2` to return the float `1.5` even with Python 2, which would return (very disturbingly) `1`, in other case. However, Python 3 integers already do this. Besides what I mentioned above and this, I haven't found any other difference in behavior.
So I was wondering: Is there any disadvantage in Sage not being preparsing this type of literals?dsejasFri, 13 Sep 2019 15:41:47 -0500http://ask.sagemath.org/question/47908/Looking for musical exercises using sagehttp://ask.sagemath.org/question/48377/looking-for-musical-exercises-using-sage/ Hi Folks,
Has anyone tried to do some harmonic or rythm analysis for musical instruments using sage?
Also - how easy is it under ubuntu to produce sounds of these harmonics?
Any links will be appreciated.
thanks
PatPatBWed, 16 Oct 2019 14:38:26 -0500http://ask.sagemath.org/question/48377/How to remove PID of defunct notebook server?http://ask.sagemath.org/question/48372/how-to-remove-pid-of-defunct-notebook-server/ Hi Sage users
It looks like a system crash left a lock file for a sage notebook server. I cannot run the notebook:
Another Sage Notebook server is running, PID 2128.
Opening web browser at http://localhost:8080/ ...
Does anyone know where this lock file is or what the procedure is to clear up this error?
I have no PID 2128 running at the time this error occurs. Hence I think it is some lock file or ressource that needs to be freed or deleted.
Thanks
PatPatBWed, 16 Oct 2019 11:31:47 -0500http://ask.sagemath.org/question/48372/Possible bug: GLPKError/assertion failedhttp://ask.sagemath.org/question/48375/possible-bug-glpkerrorassertion-failed/ Hello, Sage Community!
Recently, while trying to help one of the users of this forum, I wrote [this code](https://sagecell.sagemath.org/?z=eJyFkVFrwjAQx98L_Q6HvtRRiw5BGfRBHzZkOnzYWxFJ27TeaJOSpLYM9t130VZFGGsCzT_t_e5_d0sIoWRGYest_JkfTX27xtOZP6H3sz9ekDjfTbo1vhe3053ej2AI5sghkTzLMEEujHaduERB2aIrpgvad38XsuEKYlmLVEMmVYcQ2iiGHYG1PUHKh91j6qr6B1MRY4stT9fC8JyrDQrO1E7JXLHSoxxY4jczKEX4ygrNfdCyOBE0hMHbZvc-sPU1BFWcGX7mb9ebnetYc1UgeHM4MYUsLriHlxThp6qJgyLFhOswmgTB_NomCoA-ABosCog5tBE1JggCOsx_XGdF6CU8Qds36-wZslok1ugflQ7hQzbWalxjkT5-h1qjyM-3XbsK1DbMspDMgmIi595i9OI6QE8VsDQ93AjeKsK9DzTX0A73Ilgb2jmRGFGrA32UjXepFDXQ_qq1ASOtkQxVad2lmAIaUJgfzS_OfM4l&lang=sage&interacts=eJyLjgUAARUAuQ==). As you can see, the MILP is defined as expected.
That was a few weeks ago. Just now, I have noticed that adding `p.solve()` produces an error/exception:
> GLPKError: Assertion failed: j->lb < j->ub
> Error detected in file glpnpp03.c at line 2134
According to this, the problem seems to be in a C (maybe Cython) subroutine, which I am not able to modify. The strange thing is that defining this same MILP, manually, using the data showed there, does not produce any error! That what makes me think this is a bug.
Here is the complete traceback:
---------------------------------------------------------------------------
GLPKError Traceback (most recent call last)
<ipython-input-1-fbad4ef266dd> in <module>()
9 p.add_constraint(B[i], min=bmin[i], max=bmax[i])
10 p.show() # this is just to confirm we did it right
---> 11 p.solve()
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/numerical/mip.pyx in sage.numerical.mip.MixedIntegerLinearProgram.solve (build/cythonized/sage/numerical/mip.c:15815)()
2259 """
2260 if log is not None: self._backend.set_verbosity(log)
-> 2261 self._backend.solve()
2262 return self._backend.get_objective_value()
2263
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/numerical/backends/glpk_backend.pyx in sage.numerical.backends.glpk_backend.GLPKBackend.solve (build/cythonized/sage/numerical/backends/glpk_backend.c:9430)()
1060 if ((self.simplex_or_intopt == glp_intopt_only)
1061 or (self.simplex_or_intopt == glp_simplex_then_intopt) and (solution_status != GLP_UNDEF) and (solution_status != GLP_NOFEAS)):
-> 1062 sig_on()
1063 solve_status = glp_intopt(self.lp, self.iocp)
1064 solution_status = glp_mip_status(self.lp)
GLPKError: Assertion failed: j->lb < j->ub
Error detected in file glpnpp03.c at line 2134
Thanks in advance for your answers!dsejasWed, 16 Oct 2019 14:06:27 -0500http://ask.sagemath.org/question/48375/Displaying a text before a solution and a strange behaviourhttp://ask.sagemath.org/question/48359/displaying-a-text-before-a-solution-and-a-strange-behaviour/1) Under Windows10
A=matrix(m,n,(0,1,1,0,6,18))
show($A =$,A)
This does not display with A= in latex style. How can I code what I expect ?
2) on my computer
%display latex
m=3 #nombre de contraintes
n=2 # nombre de variables
A=matrix(m,n,(0,1,1,0,6,18))
bmin=matrix(m,1,(12,0,0))
bmax=matrix(m,1,(oo,10,70))
c=matrix(1,n,(4.1,8))
show(A,bmin,bmax,c)
show(bmax)
10 and 70 are not displayed but sage substitute "$Apositivefinitenumber$"CyrilleWed, 16 Oct 2019 02:51:49 -0500http://ask.sagemath.org/question/48359/Strange result with GLPKhttp://ask.sagemath.org/question/48360/strange-result-with-glpk/This program
%display latex
m=3
n=2
A=matrix(m,n,(0,1,1,0,6,18))
bmin=[12,0,70]
bmax=[oo,10,70]
c=matrix(1,n,(4.1,8))
show(A,bmin,bmax,c)
p = MixedIntegerLinearProgram(maximization=False, solver = "GLPK")
x = p.new_variable(integer=False, indices=[0..n-1]) # les nouvelles variables seront x[1]... x[7]}
B = A * x # m
for i in range(m):
p.add_constraint(B[i], min=bmin[i], max=bmax[i])
for i in range(n):
p.set_min(x[i],0)
p.set_objective(4.1*x[0]+8*x[1])
p.show()
p.set_min(x[i],0)
p.set_objective(4.1*x[0]+8*x[1]
p.show()
p.solve()
has obviously no solution as show by the result of
z=p.polyhedron()
zz=z.vertices()
zz
(There are no vertices)
but
p.solve()
gives 96 and
valeurs=p.get_values(x)
valeurs
gives
$\{0:0.0,1:12.0\}$
but $18 *12 =216 \geq 70$ wich shows the assertion
CyrilleWed, 16 Oct 2019 04:11:25 -0500http://ask.sagemath.org/question/48360/Finite field F_16=F_4[y]/(y**2+xy+1) (where F_4=F_2[x]/(x**2+x+1))http://ask.sagemath.org/question/48353/finite-field-f_16f_4yy2xy1-where-f_4f_2xx2x1/So SageMath is new for me and I'm trying to find the parent element of F_16. My code is simple, but I have no idea why it doesn't work. Here it is:
`F.<x> = GF(2)[]`
`K.<y> = GF(16, modulus=y^2 + x * y + 1)`
The result is *TypeError: not a constant polynomial*
Is it about y^2 + x * y + 1? Why should it be constant?
I'll appreciate any help.sashkent3Tue, 15 Oct 2019 05:41:50 -0500http://ask.sagemath.org/question/48353/Fx=a(b(x)) find out f(2)http://ask.sagemath.org/question/48369/fxabx-find-out-f2/Undergraduate question SaurabhWed, 16 Oct 2019 08:32:40 -0500http://ask.sagemath.org/question/48369/Create fx=a(b(x)) and find out for(2)http://ask.sagemath.org/question/48367/create-fxabx-and-find-out-for2/ This is question from undergraduate SaurabhWed, 16 Oct 2019 08:29:17 -0500http://ask.sagemath.org/question/48367/inverse binary string bit by bithttp://ask.sagemath.org/question/48314/inverse-binary-string-bit-by-bit/if i have a binary string for example x='0110101' and i need to inverse it's bits bit by bit.
for example : inverse 1st bit >> x='1110101'
inverse 2nd bit >> x='0010101'
3rd bit >> x='0100101'
and so on. how can i do that.Hassan MostafaSun, 13 Oct 2019 03:54:04 -0500http://ask.sagemath.org/question/48314/Sage stalls during computationhttp://ask.sagemath.org/question/48270/sage-stalls-during-computation/I was using SageMath 8.8's [feedback_edge_set](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/digraph.html#sage.graphs.digraph.DiGraph.feedback_edge_set) function on a large dataset. The calculation would take a couple of days to finish.
Unfortunately, Sage would keep stalling every few hours. The CPU usage of the process would simply drop to zero, and it would stop doing anything. I had to kill the process (a simple `kill` worked, no `kill -9` necessary).
Has anyone else experienced this? Is it a known problem? Is there a workaround? It is very frustrating to have to keep manually killing and restarting the process. This problem also prevents me from running a calculation overnight: in the morning I might find that it stopped merely an hour after I started it (if I'm unlucky).
----
More information:
- I was using Sage on Linux
- This function uses [MixedIntegerLinearProgram](http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html#sage.numerical.mip.MixedIntegerLinearProgram). I used the default GLPK (didn't change settings)
- I used `alarm()` to set a time limit on each computation.
- I always believed GLPK [not to be interruptible](https://lists.gnu.org/archive/html/help-glpk/2006-04/msg00059.html), so I am not even sure which interruption (either manual or alarm) work on Sage with this function. This may be relevant.
- The memory usage of the process stayed low. It did not stall because the memory got filled and the machine started swapping.
----
Minimal example:
Put this in a source file:
import datetime
i=1
while True:
alarm(60)
try:
dg=digraphs.RandomDirectedGNM(300,750);
fes = dg.feedback_edge_set()
print(len(fes))
except AlarmInterrupt:
print("timeout")
cancel_alarm()
print(i)
print(str(datetime.datetime.now()))
print("\n")
i = i+1
Run it as `sage sourcefile.sage`.
In my last test, it took 291 iterations and ~4-5 hours before it stalled.
It appears to stall only when GLPK is used as the MIP solver (i.e. `feedback_edge_set(solver='GLPK')`, which is also the default). If I use `solver='Coin'` (which needs to be installed first using `sage -i cbc`) then it does not stall. However, the calculation is several times slower with Coin than with GLPK.SzabolcsFri, 11 Oct 2019 02:27:37 -0500http://ask.sagemath.org/question/48270/Problems with AMS symbols in Sage, Jupyterhttp://ask.sagemath.org/question/48303/problems-with-ams-symbols-in-sage-jupyter/ How to display the square (\square) symbol in a graph (Jupyter, maybe not only). Why \boxtimes is too large?
plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()
plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()
I tried \box \square \emptybox etc. and
from sage.misc.latex import latex_extra_preamble
latex.add_to_preamble('\\usepackage{amssymb}')
I get:
ValueError:
F(G\,\square\,H)
^
Unknown symbol: \square (at char 5), (line:1, col:6)
SYLASat, 12 Oct 2019 09:42:12 -0500http://ask.sagemath.org/question/48303/Verma modules and accessing constants of proportionalityhttp://ask.sagemath.org/question/48346/verma-modules-and-accessing-constants-of-proportionality/**The Math Part:**
Let me first describe the math without going into the programming. Start with two vectors $v$ and $w$ in a vector space (just a regular vector space with no additional structure). Let's say we know that $w=\lambda\cdot v$ for some scalar $\lambda$. Given $w$ and $v$, can we figure out what $\lambda$ is?
**The Programming Part:** Now let me describe specifics of my calculation. I am working with a Verma Module over $\frak{sp}(4)$.
sage: L = lie_algebras.sp(QQ, 4)
sage: La = L.cartan_type().root_system().weight_lattice().fundamental_weights()
sage: M = L.verma_module(La[1] - 3*La[2])
sage: pbw = M.pbw_basis()
sage: x1,x2,y1,y2,h1,h2 = [pbw(g) for g in L.gens()]
We will call the highest weight vector $v$. In code,
sage: v = M.highest_weight_vector()
sage: v
sage: v[Lambda[1] - 3*Lambda[2]]
Now we have $x_2y_2\cdot v=-3\cdot v$ and $x_2^2y_2^2\cdot v= 24\cdot v$. So in code,
sage: x2*y2*v
sage: -3*v[Lambda[1] - 3*Lambda[2]]
sage: x2^2*y2^2*v
sage: 24*v[Lambda[1] - 3*Lambda[2]]
In general, we will have
$$x_2^ny_2^n\cdot v=c_n\cdot v$$
for some constant $c_n$ (with $c_1=-3$ and $c_2=24$).
My questions is the following.
How to access this constant $c_n$, given that we know $v$ and $c_n\cdot v$?slartibartfastMon, 14 Oct 2019 19:33:14 -0500http://ask.sagemath.org/question/48346/generate his own symbolic math functionhttp://ask.sagemath.org/question/48243/generate-his-own-symbolic-math-function/Hi
If I would like to generate my own symbolic math function : **general_falling_factorial(x, j, n)** .
What I should add and modify in the code below ? (I do not know what to do with the two lines below
I know it is ok for the first one, but what must I write for the second one ?)
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
[code on sageCell ](https://sagecell.sagemath.org/?q=iskopi)
j,n=var('j,n')
N=11
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)= \
\text{general_falling_factorial() is not the falling_factorial() SageMath Function} \
\, = \, "),falling_factorial(x, n))
print "https://math.stackexchange.com/questions/497616/is-there-an-explicit-formula-for-the-bernoulli-numbers-that-doesnt-implicitly-r"
print "http://youngp.people.cofc.edu/factbern.pdf"
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)"))
def general_falling_factorial_latex(self, x,j,n):
return '{' + '('+str(x) + ' | ' + str(j) + ')'+'}_{' + str(n) + '}'
general_falling_factorial = function('general_falling_factorial', nargs=3, print_latex_func=general_falling_factorial_latex)
def general_falling_factorial(x, j, n):
r""" to fill up """
from sage.symbolic.expression import Expression
from sage.structure.coerce import py_scalar_to_element
x = py_scalar_to_element(x)
j = py_scalar_to_element(j)
n = py_scalar_to_element(n)
if ((isinstance(j, Integer) or
(isinstance(j, Expression) and
j.is_integer())) and j >= 0) and \
((isinstance(n, Integer) or
(isinstance(n, Expression) and
n.is_integer())) and n >= 0) :
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
def bernoulliExplicit(N) :
bernoulliSL=[]
for n in range(0,N) :
bernoulliSLt=[]
for j in range (1,n+2):
#show("j : ",j)
bernoulliSLt.append((((-1)^(j-1)/j) *(factorial(n+1))/((factorial(j)*(factorial((n+1-j))))))* \
sum([general_falling_factorial(i,j,n) for i in range(0,j)]))
bernoulliSL.append(sum(bernoulliSLt))
return bernoulliSL
show("Explicit Bernoulli List : ",bernoulliExplicit(N))
bernoulliL=[]
for i in range(0,N) :
bernoulliL.append(bernoulli(i))
show("SageMath Bernoulli List : ",bernoulliL)ortolljWed, 09 Oct 2019 06:10:37 -0500http://ask.sagemath.org/question/48243/interact button reacting twicehttp://ask.sagemath.org/question/48338/interact-button-reacting-twice/I'm trying to update some old interact to the new Jupyter notebook. I'd like
to have an interact with buttons, something like the following:
act = []
@interact
def play(move=selector([None] + ["Auto", "Reset"], buttons=True)):
act.append(move)
print(act)
However when I press a new button, the applet receive it twice. For example,
if I press "Auto" and the "Reset" it prints
[None, 'Auto', 'Auto', 'Reset', 'Reset']
instead of
[None, 'Auto', 'Reset']
Is it expected ? HivertMon, 14 Oct 2019 14:16:47 -0500http://ask.sagemath.org/question/48338/how do I find kernel of a ring homomorphism?http://ask.sagemath.org/question/48336/how-do-i-find-kernel-of-a-ring-homomorphism/ I have tried f.kernel() but not working.anjuMon, 14 Oct 2019 13:39:18 -0500http://ask.sagemath.org/question/48336/Schwarz-Christoffel transformationshttp://ask.sagemath.org/question/48332/schwarz-christoffel-transformations/I would like to visualize the Schwarz-Christoffel transformations. Do you have an idea how to implement those? For example a polygon (as a domain) in the complex plane and subsequently also a map (decomposed into several steps) into the upper half-plane of the complex plane should be drawn. I am not quite sure how to do this. The formulas for these transformations are well-known.Tintin1Mon, 14 Oct 2019 08:27:31 -0500http://ask.sagemath.org/question/48332/multivariate polynomials, libsingular and polydicthttp://ask.sagemath.org/question/48329/multivariate-polynomials-libsingular-and-polydict/When defining mutlivariate polynomial in two different ways, I cannot compare them because they seem to have a different type. On the one hand I have
R = PolynomialRing(QQ,'x', 3); x = R.gens()
f = x[0] + x[1] + x[2]
type(f)
which gives <𝚝𝚢𝚙𝚎'𝚜𝚊𝚐𝚎.𝚛𝚒𝚗𝚐𝚜.𝚙𝚘𝚕𝚢𝚗𝚘𝚖𝚒𝚊𝚕.𝚖𝚞𝚕𝚝𝚒⎯𝚙𝚘𝚕𝚢𝚗𝚘𝚖𝚒𝚊𝚕⎯𝚕𝚒𝚋𝚜𝚒𝚗𝚐𝚞𝚕𝚊𝚛.𝙼𝙿𝚘𝚕𝚢𝚗𝚘𝚖𝚒𝚊𝚕⎯𝚕𝚒𝚋𝚜𝚒𝚗𝚐𝚞𝚕𝚊𝚛'>.
On the other hand I define what is (to me) the same polynomial:
SF = SymmetricFunctions(F); SF.inject_shorthands(verbose=False)
g = h[1].expand(3, alphabet = R.gens())
type(g)
which gives <𝚌𝚕𝚊𝚜𝚜'𝚜𝚊𝚐𝚎.𝚛𝚒𝚗𝚐𝚜.𝚙𝚘𝚕𝚢𝚗𝚘𝚖𝚒𝚊𝚕.𝚖𝚞𝚕𝚝𝚒⎯𝚙𝚘𝚕𝚢𝚗𝚘𝚖𝚒𝚊𝚕⎯𝚎𝚕𝚎𝚖𝚎𝚗𝚝.𝙼𝙿𝚘𝚕𝚢𝚗𝚘𝚖𝚒𝚊𝚕⎯𝚙𝚘𝚕𝚢𝚍𝚒𝚌𝚝'>
Thus when comparing `f == g` it gives false. How can get these two modules to talk to each other?
AnnavwMon, 14 Oct 2019 07:22:36 -0500http://ask.sagemath.org/question/48329/Hypergeometric Bug?http://ask.sagemath.org/question/48204/hypergeometric-bug/The following code shows a (typical ?) failure.
F([m,a,b;m,c;z) should and does for
positive m; cancel m.
but when m is negative "0" is declared prematurely
--Juptyter code
def pochhammer(x,a):
return rising_factorial(x,a)
def fn2ref(a,b,c,z,m): return hypergeometric([a,b],[c],z)
def fn2lm(a,b,c,z,m):
return hypergeometric([m,a,b],[c,m],z)
def fn2l(a,b,c,z,m):
return hypergeometric([-m,a,b],[c,-m],z)
def fn1l(a,b,c,z,m):
var('k')
return sum((pochhammer(a,k)*pochhammer(b,k)/pochhammer(c,k))*(z^k/factorial(k)),k,0,m)
print "2F1(a,b;c;z,5) = ", fn2ref(1,2,3,.5,5)
print "3F2(m,a,b;m,c;z) = ", fn2lm(1,2,3,.5,5)
print "3F2(-m,a,b;-m,c;z) = ", fn2l(1,2,3,.5,5)
print "m terms of 2F1(a,b;c;z) = ", fn1l(1,2,3,.5,5)
-- produces
2F1(a,b;c;z,5) = 1.54517744447956
3F2(m,a,b;m,c;z) = 1.54517744447956
3F2(-m,a,b;-m,c;z) = 1.53809523809524
m terms of 2F1(a,b;c;z) = 1.538095238095238
--Whereas Maxima code
fn2ref(a,b,c,z):=hypergeometric([a,b],[c],z);
fn2lm(a,b,c,z,m) :=hypergeometric([a,b,m],[c,m],z);
fn2l(a,b,c,z,m) :=hypergeometric([a,b,-m],[c,-m],z);
fn1l(a,b,c,z,m):=
sum((pochhammer(a,k)*pochhammer(b,k)/(pochhammer(c,k))*z^k/factorial(k)),k,0,m);
print ("2F1(a,b;c;z) = ",fn2ref(1,2,3,.5))$
print("3F2(m,a,b;m,c;z) = ",fn2lm(1,2,3,.5,5))$
print("3F2(-m,a,b;-m,c;z) = ",fn2l(1,2,3,.5,5))$
print("m terms of 2F1(a,b;c;z) = ",fn1l(1,2,3,.5,5))$
-- Produces
2F1(a,b;c;z) = 1.545177444479563
3F2(m,a,b;m,c;z) = 1.545177444479563
3F2(-m,a,b;-m,c;z) = 1.545177444479563
m terms of 2F1(a,b;c;z) = 1.538095238095238
--
Which accords with the definition and Luke "The Special Functions and their Approximations" which is a pretty standard.rrogersSun, 06 Oct 2019 09:16:19 -0500http://ask.sagemath.org/question/48204/Building Sage 8.9 from source failshttp://ask.sagemath.org/question/48276/building-sage-89-from-source-fails/I am trying to build Sage 8.9 from source on Linux (Ubuntu 16.04, gcc 6). It fails. I could build Sage 8.8 on the same machine without problems.
It says that python2 and python3 failed to build, and suggests to look at the log files. The log files contain:
ImportError: No module named readline
readline module failed to import
and
ModuleNotFoundError: No module named 'readline'
readline module failed to import
Has anyone experienced the same and is there a simple solution?
Unfortunately, I do not have root access myself, thus I can't quickly try to install the readline dev package.
SzabolcsFri, 11 Oct 2019 06:06:28 -0500http://ask.sagemath.org/question/48276/Problems with AMS symbols in Sage, Jupyterhttp://ask.sagemath.org/question/48302/problems-with-ams-symbols-in-sage-jupyter/ How to display the square (\square) symbol in a graph (Jupyter, maybe not only). Why \boxtimes is too large?
plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()
plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()
I tried \box \square \emptybox etc. and
from sage.misc.latex import latex_extra_preamble
latex.add_to_preamble('\\usepackage{amssymb}')
I get:
ValueError:
F(G\,\square\,H)
^
Unknown symbol: \square (at char 5), (line:1, col:6)
SYLASat, 12 Oct 2019 09:39:14 -0500http://ask.sagemath.org/question/48302/Converting expression into a number and evaluating functionhttp://ask.sagemath.org/question/48295/converting-expression-into-a-number-and-evaluating-function/I was trying to use a lagrange multiplier to find the local maxima of a simple function over the circle:
x,y,c = var('x y c')
f(x,y) = x**2 + y**2 - 1
g(x,y) = x+y
F = diff(f)
G = diff(g)
polys = [f]
for i in range(len(F)):
p = F[i] - c * G[i]
polys.append(p)
list_solutions = solve(polys,x,y,c)
for solution in list_solutions:
print solution
print f({x : solution[0] , y : solution[1]})
print '\n'
At 'print solution' i get the first extremum:
[x == 1/2*sqrt(2), y == 1/2*sqrt(2), c == sqrt(2)]
But at the 'print f({x : solution[0] , y : solution[1]})' line the following error occurs:
TypeError: no canonical coercion from <type 'dict'> to Callable function ring with arguments (x, y)
So i guess x == 1/2*sqrt(2) and the like can't be seem as numbers. I would like to be able to evaluate f(x,y) at the point, so what can i do? Also, the lagrange multiplier algorithm must be on Sage already, but Google gives me nothing. If you can show its command that would be a plus.JGCFri, 11 Oct 2019 21:18:44 -0500http://ask.sagemath.org/question/48295/how to unlock sagemath 8.8 on MacOS 10.15 Catalina?http://ask.sagemath.org/question/48293/how-to-unlock-sagemath-88-on-macos-1015-catalina/ Sagemath 8.8 won't run on MacOS 10.15 because of security locks. The system objects to software packages from "unknown" sources, like python and sage. It's possible to instruct the system to accept a package, but I've been able to do that only manually, one package at a time--a boring job withe sagemath's hundreds (?) of packages.
Help? Hints? Thanks!
gamFri, 11 Oct 2019 16:25:55 -0500http://ask.sagemath.org/question/48293/building from git unresolved symbols libgomphttp://ask.sagemath.org/question/48286/building-from-git-unresolved-symbols-libgomp/fresh git cloned repository. Compilation fails with the spurious error as in https://trac.sagemath.org/ticket/28513. Running `./sage` crashes with the error
<pre><code>ImportError: /home/user/sage/local/lib/liblinbox.so.0: undefined symbol: GOMP_loop_ull_maybe_nonmonotonic_runtime_next
</code></pre>
But the symbols are there:
<pre><code>$ nm /usr/lib/libgomp.so | grep GOMP_loop_ull_maybe_
0000000000010070 T GOMP_loop_ull_maybe_nonmonotonic_runtime_next
000000000000f210 T GOMP_loop_ull_maybe_nonmonotonic_runtime_start</code></pre>
This is on Arch
<code><pre>$uname -a
Linux host 5.3.5-arch1-1-ARCH #1 SMP PREEMPT Mon Oct 7 19:03:08 UTC 2019 x86_64 GNU/Linux
$ gcc --version
gcc (GCC) 9.2.0</code></pre>heluaniFri, 11 Oct 2019 12:14:14 -0500http://ask.sagemath.org/question/48286/Adapt the nauty_directg functionhttp://ask.sagemath.org/question/48275/adapt-the-nauty_directg-function/Dear reader,
For a research interest, I would like to generate the collection of non-isomorphic digraphs on a given graph, with a given subset of the edges fixed. Naturally, simply generating the full collection using digraphs.nauty_directg() and removing the undesirable members of the obtained collection would be functional, but it's quite the waste of computing time to take this approach. Hence, I was wondering whether I'd be able to get under the hood of the nauty_directg function to create my own adapted version, which simply skips over the orientation of the edges listed in some input argument. Would anyone be able to help me get started with this endeavor?
Best,
PepijnPepijnWissingFri, 11 Oct 2019 06:01:38 -0500http://ask.sagemath.org/question/48275/