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.Wed, 02 Feb 2022 15:18:43 +0100Possible bug - specifying category messes up coercion?https://ask.sagemath.org/question/60903/possible-bug-specifying-category-messes-up-coercion/The snippet
D = CombinatorialFreeModule(ZZ, [1,2])
D(0)
works fine, however
C = CombinatorialFreeModule(ZZ, [1,2], category=AlgebrasWithBasis(ZZ))
C(0)
gets into an infinite loop:
File "/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/categories/magmas.py", line 488, in one
return self(1)
File "sage/structure/parent.pyx", line 900, in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9218)
return mor._call_(x)
File "sage/categories/map.pyx", line 1694, in sage.categories.map.FormalCompositeMap._call_ (build/cythonized/sage/categories/map.c:11607)
x = f._call_(x)
File "sage/categories/morphism.pyx", line 549, in sage.categories.morphism.SetMorphism._call_ (build/cythonized/sage/categories/morphism.c:8489)
cpdef Element _call_(self, x):
File "sage/categories/morphism.pyx", line 568, in sage.categories.morphism.SetMorphism._call_ (build/cythonized/sage/categories/morphism.c:8439)
return self._function(x)
File "/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/categories/unital_algebras.py", line 70, in from_base_ring
return self.one()._lmul_(r)
File "sage/misc/cachefunc.pyx", line 2310, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (build/cythonized/sage/misc/cachefunc.c:12712)
self.cache = f(self._instance)
Why is this? Is this expected behaviour?makosWed, 02 Feb 2022 15:18:43 +0100https://ask.sagemath.org/question/60903/Calling Sage from Javahttps://ask.sagemath.org/question/44853/calling-sage-from-java/Hello,
I am looking for a way to call Sage functions, such as constructing Polyhedra, from Java (on Windows).
In more detail, I want to do the following:
1. Input to Sage from Java: P1 = Polyhedron(vertices = [[0,2], [-1,0], [1,0], [0,0]])
2. Retrieve in Java the Sage output: P1.Hrepresentation()
It would be optimal if I could call Sage directly somehow, but if it's necessary, I think a python wrapper could also work. It would be very kind if somebody could point me in the right direction, maybe with code snippets, as I am very new to the Sage Environment.
Thank you.CupOfCoffeeThu, 03 Jan 2019 03:11:12 +0100https://ask.sagemath.org/question/44853/Substitute square in polynomialhttps://ask.sagemath.org/question/25452/substitute-square-in-polynomial/Suppose I have a univariate polynomial, say from `QQ['x']`, and for some reason I know that the odd coefficients will all be zero. So in fact this is a polynomial in `x^2`. What's the most elegant syntax to substitute some other value for `x^2`?
The best I could come up with so far is something like this:
sage: x = QQ['x'].0
sage: p = x^6 - 3*x^4 + 5*x^2 - 9
sage: assert not any(p[i] for i in range(1,p.degree()+1,2))
sage: p.parent([p[i] for i in range(0,p.degree()+1,2)])
x^3 - 3*x^2 + 5*x - 9
sage: _(7)
222
Of course, if the value I want to plug in comes from some field where I can compute square roots, I could simply plug one of those in, like `p(sqrt(7))` in the example above, but I'm more interested in substituting a multivariate polynomial or something like this.MvGFri, 09 Jan 2015 14:58:34 +0100https://ask.sagemath.org/question/25452/How do I correct this 3d Function plot error?https://ask.sagemath.org/question/10563/how-do-i-correct-this-3d-function-plot-error/In recent work trying to visualize the graph of a function from RP^1 to RP^1 on the torus, the code I used gave a DeprecationWarning that I have not been able to interpret.
/home/sageserver/sage/sagecell-main/interact_sagecell.py:422: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
See http://trac.sagemath.org/5930 for details.
returned = f(*args, **control_vals)
The graph also seemed to hang up-- though it now seems ok.
Any assistance would be appreciated, THANKS.
Here's the permalink:
https://sagecell.sagemath.org/?z=eJyNUd1qwyAYvS_0HQ6hUG0dTUyvSlJ2t9uxB-iwRkloGsUYu739lLZsgzImyPn8OD9-OjEEMI8aQTiynFhgfknns9afe4Kskmrwyu1RHeNu-R4vTtgWRmOhscPb66FYwBssrlW1iZxqc9xn0eO5S1ohPeazRmmchSU6Jn0cON3NZ4hLFzUIKbGGNCMJlK4STpT96o3dkHoJAgW9Scv6W8lXwkkvBqJjmTBgA04j-WYZp6QM_-NfcxgS_kG8X8TGGaxw4qy86-S77Y0vG5Jmi4ETQ87AV7ZL8eHnSZreuBrZp-p7c8nubrwWzplLsiA5y9nTNr5GKrb0TikfBurycULmVJMx33byNKhxjB9Q5KDJ6Go3tuZCbLG2fG1LGptfnWWK-w==&lang=sage
And here's the Code:
u, v ,t = var('u,v,t')
html( "<center> <b> <h2> Graph of $f : RP^1$ to $RP^1$ </h2></b>")
@interact
def map(f = x^2):
f1= ((3 + cos(v))*cos(u),(3 + cos(v))*sin(u),sin(v) )
f3=((3 + cos(2*arctan(f(2*tan(v / 2)) )))*cos( v ), (3 + cos(2*arctan(f(2*tan(v / 2)) )))*sin(v), sin(2*arctan(f(2*tan(v / 2)) )) )
p1= parametric_plot3d( f1, (u, 0, 2*pi), (v, 0, 2*pi), color= "yellow")
p2=arrow3d( (0,0,-4),(0,0,4))
p3= parametric_plot3d( f3, (v, 0, 2*pi), color="red",thickness = 10 )
show(p1+p2+p3)
Martin FlashmanTue, 24 Sep 2013 13:33:32 +0200https://ask.sagemath.org/question/10563/invoke external programhttps://ask.sagemath.org/question/9222/invoke-external-program/What is the proper way to call external applications in my programs? Specifically, pdfLaTeX compiler. When I invoke `os.system("pdflatex foo.tex")` in Sage's CLI console, the command executes as expected. However, when I embedded this into my code and run this code, TeX asks for another input:
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(/tmp/foo.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
)
* [blinking cursor here]
Am I missing something or why doesn't this work?
P. S. My original post may have been confusing. When I wrote:
> However, when I embedded this into my code and run this code,
I meant embedding into "my_code.sage" source code, which is consequently attached and run in Sage's CLI.
P. P. S. When use it in my "foo.sage" code as below:
os.system("pdflatex -interaction=batchmode foo.tex")
following log is produced:
(/tmp/foo.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
)
! Emergency stop.
<*> /tmp/foo.tex
*** (job aborted, no legal \end found)
However, written explicitly in Sage's console and even in bash console, everything compiles correctly. Does this mean something? Just FYI, I did end my source file with `\end{document}`MathemageFri, 10 Aug 2012 16:10:26 +0200https://ask.sagemath.org/question/9222/bool returns true to an incorrect function call?https://ask.sagemath.org/question/8173/bool-returns-true-to-an-incorrect-function-call/This happened to me by mistake.
sage: var('x1,t1,x2,t2,u,c',domain=RR);assume(u>0);assume(c>u);assume(x2>x1);assume(t2>t1);
(x1, t1, x2, t2, u, c)
sage: T1 = (t1-((u*x1)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: T2 = (t2-((u*x2)/(c^2)))/sqrt(1-((u^2)/(c^2)))
sage: dT = T2-T1
sage: bool(dT.full_simplify >= 0)
True
sage: bool(dT.full_simplify() >= 0)
False
When I made the incorrect function call dT.full_simplify , bool returned true. When I made the correct function call dT.full_simplify() , bool returned false. Is this a bug?
ThanksomoplataMon, 20 Jun 2011 20:18:07 +0200https://ask.sagemath.org/question/8173/