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.Tue, 16 Oct 2018 08:54:43 -0500How to implement "positional-only parameter" in a user defined function?http://ask.sagemath.org/question/43959/how-to-implement-positional-only-parameter-in-a-user-defined-function/def fun( a, b, /):
print(a,b)
o/p:
File "<ipython-input-36-1fceb840aeb9>", line 1
def fun( a, b, /):
^
SyntaxError: invalid syntaxdamodarTue, 16 Oct 2018 04:23:40 -0500http://ask.sagemath.org/question/43959/How to attach a simple Sage script in a Sage Jupyter notebookhttp://ask.sagemath.org/question/43964/how-to-attach-a-simple-sage-script-in-a-sage-jupyter-notebook/**My two PCs' configurations:** Windows 8.1, Windows 10
**Sage version:** SageMath 8.3, windows installer 0.4
github.com/sagemath/sage-windows/releases
I want to use a Sage script in a Sage Jupyter Notebook (Jupyter with Sage as a kernel).
I have tried the following procedure:
1. I put a Sage code (definition of a function) in text file named Script.sage.
2. In a Jupyter notebook I tried command attach('Script.Sage')
3. I got a usage error:
UsageError: Invalid GUI request 'sage', valid ones are:[None, 'widget', 'qt5', 'qt', 'nbagg', 'osx', 'gtk', 'qt4', 'gtk3', 'notebook', 'tk', 'ipympl', 'inline', 'asyncio', 'wx']
Some advice about where is a problem? What to do?
Or is there another procedure how to use a Sage code written in separate files in a Jupyter notebook?
JozefTue, 16 Oct 2018 07:31:13 -0500http://ask.sagemath.org/question/43964/Is there any difference between the variables b and *b in these two statements? If so, what is it?http://ask.sagemath.org/question/43966/is-there-any-difference-between-the-variables-b-and-b-in-these-two-statements-if-so-what-is-it/
(a, b, c) = 1, 2, 3
(a, *b, c) = 1, 2, 3damodarTue, 16 Oct 2018 08:54:43 -0500http://ask.sagemath.org/question/43966/Reducing a polynomial over a function field modulo a valuationhttp://ask.sagemath.org/question/43965/reducing-a-polynomial-over-a-function-field-modulo-a-valuation/ In my situation, I have the following elliptic curve:
K.<t> = FunctionField(QQ)
E = EllipticCurve([t,t])
I want to be able to go modulo t to get the curve
z*y^2 - x^3 = 0
I cannot figure out how to do this. I would like to work with valuations if possible (like going mod K.valuation(0)), but any way to make this work would be great. In general, I'd like to be able to go modulo any irreducible polynomial.trbillinTue, 16 Oct 2018 08:22:31 -0500http://ask.sagemath.org/question/43965/Change binary Operation in Monoid/Semigroup Ringshttp://ask.sagemath.org/question/43958/change-binary-operation-in-monoidsemigroup-rings/I have been experimenting in Semigroup rings and what I’m wondering is whether Sage allows me to define a Set, it’s binary operation, and take its Semigroup Ring via the Set.algebra constructor.
Example would be
S=Set([0,1,2]) #generators
A=S.algebra(RR,Semigroups())
A.product=lambda x,y: x+y
But this does work on the basis elements of A.
I want to modify the way basis elements multiply.ChernoxylMon, 15 Oct 2018 20:36:38 -0500http://ask.sagemath.org/question/43958/Install optional packages (eg extra Jupyter kernels) on top of conda-installed SageMathhttp://ask.sagemath.org/question/43952/install-optional-packages-eg-extra-jupyter-kernels-on-top-of-conda-installed-sagemath/Suppose one has installed SageMath using the conda package.
How does one then install optional packages?
It seems `sage -i` is not active there.
For example, what would be the replacement for
$ sage -i gap_jupyter # install Jupyter kernel for GAP 4.8
$ sage -i pari_jupyter # install Jupyter kernel for PARI/GP
$ sage -i r_jupyter # install Jupyter kernel for R
$ sage -i singular_jupyter # install Jupyter kernel for Singular
if one is using a conda-installed Jupyter and SageMath?
slelievreMon, 15 Oct 2018 05:22:56 -0500http://ask.sagemath.org/question/43952/desolve initial condition involving e gives strange answerhttp://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/I'm trying to do some basic differential equations in Sage. When I run the following:
var('t')
y = function('y')(t)
de1 = t^3*diff(y, t) + 4*t^2*y == e^(t^2)
desolve(de1, y, ics = [1,e])
The output is
1/2*(e^(t^2) + y(t))/t^4
My expectation is that there shouldn't by any y(t) term in the output. If I make a seemingly meaningless tweak to my initial conditions:
desolve(de1, y, ics = [1,e*1])
I get the expected output of
1/2*(e + e^(t^2))/t^4
If I change the initial conditions to [1, e/2], I again get the output I expect. I haven't been able to reproduce this issue with any other example. Maybe the issue just comes in converting Sage's version of e into Maxima? Does anyone know what is going on here?PWSun, 14 Oct 2018 16:20:07 -0500http://ask.sagemath.org/question/43946/compile error building sagemath 8.4 beta7 on Linux Manjarohttp://ask.sagemath.org/question/43941/compile-error-building-sagemath-84-beta7-on-linux-manjaro/I've run Arch Linux package manager to install sagemath many times before on Linux Manjaro and it never failed to compile before. This is the first time I've seen a compile error. This seems like a packaging issue?
Using
>uname -a
Linux me-pc 4.14.74-1-MANJARO
>cat /etc/*release
Manjaro Linux
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=18.0.0-rc
DISTRIB_CODENAME=Illyria
I select sagemath from AUR using the package manager, click install. I fail with this error
Building sagemath-git...
Cloning into 'sagemath-git'...
==> Making package: sagemath-git 8.4.beta7.r0.ga1bfef8cf3-1 (Sat 13 Oct 2018 08:04:38 PM CDT)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
-> Cloning sage git repo...
....
gcc -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2 -fPIC -I/usr/lib/python2.7/site-packages/cysignals -I/usr/include -I/usr/include/python2.7 -I/usr/lib/python2.7/site-packages/numpy/core/include -I/home/me/TMP/sagemath-git/src/sage/src -I/home/me/TMP/sagemath-git/src/sage/src/sage/ext -Ibuild/cythonized -I/usr/include/python2.7 -c build/cythonized/sage/calculus/integration.c -o build/temp.linux-x86_64-2.7/build/cythonized/sage/calculus/integration.o -fno-strict-aliasing -DCYTHON_CLINE_IN_TRACEBACK=1 -DGSL_DISABLE_DEPRECATED -std=c99
build/cythonized/sage/calculus/integration.c:609:10: fatal error: gsl/gsl_cblas.h: No such file or directory
#include "gsl/gsl_cblas.h"
^~~~~~~~~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
[ 15/499] gcc -DNDEBUG -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2 -fPIC -I/usr/lib/python2.7/site-packages/cysignals -I/usr/include -I/usr/include/python2.7 -I/usr/lib/python2.7/site-packages/numpy/core/include -I/home/me/TMP/sagemath-git/src/sage/src -I/home/me/TMP/sagemath-git/src/sage/src/sage/ext -Ibuild/cythonized -I/usr/include/python2.7 -c build/cythonized/sage/calculus/interpolation.c -o build/temp.linux-x86_64-2.7/build/cythonized/sage/calculus/interpolation.o -fno-strict-aliasing -DCYTHON_CLINE_IN_TRACEBACK=1 -std=c99
build/cythonized/sage/calculus/interpolation.c:603:10: fatal error: gsl/gsl_interp.h: No such file or directory
#include "gsl/gsl_interp.h"
^~~~~~~~~~~~~~~~~~
compilation terminated.
I've put the complete build log file here [https://www.12000.org/tmp/10132018/sage_build_log.txt](https://www.12000.org/tmp/10132018/sage_build_log.txt) (this form will not let me attach a plain text file).
I install the Linux system new, and was trying to install sagemath on it.
Posting this here in case someone wants to have a look to see why it failed to compile. It seems to be missing some prerequisites.NasserSat, 13 Oct 2018 21:57:29 -0500http://ask.sagemath.org/question/43941/list as a function parameter.http://ask.sagemath.org/question/43939/list-as-a-function-parameter/.
>>> def fun(x, b= []):
... b.append(x)
... print(x,' ',b)
...
>>> fun(7)
7 [7]
>>> fun([9, 7])
[9, 7] [7, [9, 7]]
>>> fun([9, 8])
[9, 8] [7, [9, 7], [9, 8]]
>>>damodarSat, 13 Oct 2018 17:25:51 -0500http://ask.sagemath.org/question/43939/How to call nested tuple and nested set or dictionary using variable argument and variable keyword argument methods ?http://ask.sagemath.org/question/43921/how-to-call-nested-tuple-and-nested-set-or-dictionary-using-variable-argument-and-variable-keyword-argument-methods/.
def arithmetic_mean(first, *values):
""" This function calculates the arithmetic mean of a non-empty
arbitrary number of numerical values """
return (first + sum(values)) / (1 + len(values))
x= [('a', 232), ('b', 343), ('c', 543), ('d', 23)]
y= [[('a', 232), ('b', 343), ('c', 543), ('d', 23)]]
how to pass x and y inside arithmetic_mean.
can it be possible through zip method?damodarThu, 11 Oct 2018 13:16:34 -0500http://ask.sagemath.org/question/43921/Polynomial interpolation given a mathematic function f(x), an interval [a,b] and a natural number nhttp://ask.sagemath.org/question/43927/polynomial-interpolation-given-a-mathematic-function-fx-an-interval-ab-and-a-natural-number-n/Hi, i'm a computer science bachelor 's student and i'm having some trouble with this exercice, i'd like to get some help since it's my first course using sagemath, thanks, the exercice:
Write a function that takes as input a mathematical function f, an interval [a, b] and a natural n and return the interpolative polynomial of the function in the n + 1 points resulting from dividing the interval into subinterval n of equal length. That is to say, a polynomial p (x) of degree ≤ n such p (xi) = f (xi), where xi = a + i * ((b-a)/n) for all i = 0, ... n.
I'm stuck in the way of transforming a list into a matrix. This is what i've tried so far:
def list1(a,b,n):
r=(b-a)/n
return [a+i*r for i in range(n+1)]
def list2(a,b,n):
r=(b-a)/n
l=[]
for i in range(n+1):
l.append(a+i*r)
return l
def functionlist(f,llista):
return[f(i) for i in llista]
px=matrix(7, 1,list2(1, 5, 6))
show(px)
py=matrix(7, 1, functionlist(sin, list1(1, 5, 6)))
show(py)
points= zip(px,py); points
A=matrix(RDF,[[1,px[0],px[0]^2,px[0]^3],[1,px[1],px[1]^2,px[1]^3],[1,px[2],px[2]^2,px[2]^3],[1,px[3],px[3]^2,px[3]^3]]); A
And gives me this error:
NotImplementedError Traceback (most recent call last)
<ipython-input-112-a1670df9c827> in <module>()
19 points= zip(px,py); points
20
---> 21 A=matrix(RDF,[[Integer(1),px[Integer(0)],px[Integer(0)]**Integer(2),px[Integer(0)]**Integer(3)],[Integer(1),px[Integer(1)],px[Integer(1)]**Integer(2),px[Integer(1)]**Integer(3)],[Integer(1),px[Integer(2)],px[Integer(2)]**Integer(2),px[Integer(2)]**Integer(3)],[Integer(1),px[Integer(3)],px[Integer(3)]**Integer(2),px[Integer(3)]**Integer(3)]]); A
22
23
/opt/sagemath-8.3/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx in sage.modules.free_module_element.FreeModuleElement.__pow__ (build/cythonized/sage/modules/free_module_element.c:15842)()
2019 NotImplementedError
2020 """
-> 2021 raise NotImplementedError
2022
2023 def _repr_(self):
NotImplementedError:
Pls help, thanks.Hell_BoyFri, 12 Oct 2018 06:36:28 -0500http://ask.sagemath.org/question/43927/jupyter notebook multi users ?http://ask.sagemath.org/question/43919/jupyter-notebook-multi-users/Hello,
I used to use notebook sagenb for teaching purposes.
Each student had a login and password to work on the same server.
I ran into several internal server errors 500 using it. so I though since it seems that jupyter notebook is more recommended I should try and switch to it.
However, I am concerned because I am not sure it allows the same type of multi-users server.
Hint from jupyter notebook login page that points to
https://jupyter-notebook.readthedocs.io/en/stable/public_server.html
tell me that it might not.
So the questions are:
1/ with "sage -n jupyter --ip='*'" is it possible to have 16 or so students connecting to the same server and working on similar worksheets (as it seemed to work rather smoothly for sagenb)?
2/ if not, is there another way to have sage use jupyter notebook for multi users?
3/ if not, is an install of jupyterhub or sagemathcloud reasonnable with no particular sysadmin skill?
4/ if not is there anything else I should try?
5/ if not, do some of you have experience of sagenb under sage 8.3 usability?
Installing sagemath on all computers is not an option for me at the moment.
Best regards,
b
PS : my sagemath on a debian 9 server compiled from source (I used to use debian packages but though it might work more smoothly with install from source)bb16Thu, 11 Oct 2018 09:30:33 -0500http://ask.sagemath.org/question/43919/How to convert an integer to fixed length binary string in Sage?http://ask.sagemath.org/question/43916/how-to-convert-an-integer-to-fixed-length-binary-string-in-sage/ I want to get
(192,14,100)=>8bit binary of 192 || 8bit binary of 14 ||8bit binary of 100 => 110000000000111001100100 => 12586596 (equivalent decimal of the 24bits binary sting).
I have written python code to do this, but this code does not work in sage. Here is the code :
L=(192,14,100)
a=0
for i in range(3):
a=(a << 8) ^ (L[i])
print a
print bin(a)
What is the best way to do so in Sage?math.mks@yandex.comThu, 11 Oct 2018 08:20:46 -0500http://ask.sagemath.org/question/43916/How to edit pixel values of color image in SageMath?http://ask.sagemath.org/question/43913/how-to-edit-pixel-values-of-color-image-in-sagemath/ I would like to change pixel values in a color [image](https://drive.google.com/file/d/1zyRvIUc1I9rC-NrU4SYjdbbPf8NOrQk0/view?usp=sharing) with Sagemath. I can do the same in python, but my program contains some parts which can not be done with python. Here are the codes for SageMath:
**MWE:**
from PIL import Image
img=Image.open('image.pgm')
pxl=img.load()
#pxls=img.getdata()
print pxl[0,0]
When I compile thse codes with sage, error occurs :
" File "smmm.sage.py", line 8, in <module>
print pxl[_sage_const_0 ,_sage_const_0 ]
TypeError: an integer is required
"
How can I fix this?math.mks@yandex.comThu, 11 Oct 2018 06:33:40 -0500http://ask.sagemath.org/question/43913/How to install database_gaphttp://ask.sagemath.org/question/43896/how-to-install-database_gap/ I have sage installed from pre-installed Sage binary. I wish to use function from the package "database_gap"
When I issue a command
sage -i database_gap
It gives me an error
make: *** No rule to make target 'all-toolchain'. Stop.
Can someone help me?
ThanksajitWed, 10 Oct 2018 07:26:45 -0500http://ask.sagemath.org/question/43896/Use of / operator when defining a functionhttp://ask.sagemath.org/question/43906/use-of-operator-when-defining-a-function/ Hello. I need a clarification on the behaviour of fractions. More precisely, I don't understand the behaviour of the / operator when used inside a def().
I noticed that / finds the integer part of the fraction when used inside a def:
def sumA():
a=randint(2,10)
b=randint(2,10)
c=randint(3,10)
d=randint(4,10)
return [a,b,c,d,a/b + c/d]
Then sumA() the following result:
[8, 3, 9, 8, 3]
That is: 8/3 + 9/8 = 3. How can I make a/b + c/d work like a sum of fractions inside this function?
Oddly enough, the behaviour is different when generating random numbers a and b and adding 1/a + 1/b.
def sumB():
a=randint(2,10)
b=randint(2,10)
return [a,b,1/a + 1/b]
This function adds the fractions in the correct way. The result of sumB() is
[5, 9, 14/45]
Finally, I noticed that writing a*1/b + c*1/d instead of a/b + c/d makes everything work like fractions:
def sumC():
a=randint(2,10)
b=randint(2,10)
c=randint(3,10)
d=randint(4,10)
return [a,b,c,d,a*1/b + c*1/d]
The result of sumC() is
[6, 7, 5, 6, 71/42]
jcarrilloWed, 10 Oct 2018 14:07:28 -0500http://ask.sagemath.org/question/43906/substitution of ideal generators of a free algebrahttp://ask.sagemath.org/question/43903/substitution-of-ideal-generators-of-a-free-algebra/I'm trying to map the generators of an ideal $I$ of a free $k$-algebra $A = k \\{ x, y \\}$ to a different free $k$-algebra $B = k \\{ u, v \\}$ (really I'm trying something more complicated, but the failure occurs in even this simplified example). I was attempting to do this via `subs` by creating a dictionary taking $x$ to $u$ and $y$ to $v$, but this is not working.
sage: A.<x, y> = FreeAlgebra(QQ, 2)
sage: I = A*[x*y - y*x - 1]*A
sage: B.<u, v> = FreeAlgebra(QQ, 2)
sage: genMap = {'x':'u', 'y':'v'}
sage: I.gen(0).subs(genMap)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-9d969fff6a4a> in <module>()
----> 1 I.gen(Integer(0)).subs(genMap)
sage/structure/element.pyx in sage.structure.element.Element.subs (build/cythonized/sage/structure/element.c:7572)()
/usr/lib/python2.7/dist-packages/sage/algebras/free_algebra_element.pyc in __call__(self, *x, **kwds)
176 for m, c in six.iteritems(self._monomial_coefficients):
177 if result is None:
--> 178 result = c*m(x)
179 else:
180 result += c*m(x)
sage/rings/rational.pyx in sage.rings.rational.Rational.__mul__ (build/cythonized/sage/rings/rational.c:21325)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:10686)()
TypeError: unsupported operand parent(s) for *: 'Rational Field' and 'Free monoid on 2 generators (x, y)'
This error seems strange to me; is it not understanding elements of $\mathbb{Q}$ and $\\{ x, y \\}$ as elements of $\mathbb{Q} \\{ x, y \\}$? I also tried to do this via a homomorphism $A \to B$ but I could not get this to work, as it seems they are not fully implemented yet for free algebras, from what I could tell. Any help or alternatives would be very appreciated.
**EDIT**: I got a slight work-around, by converting the elements to strings, replacing the variables as characters, and the evaluating the string in the target. However, I feel like this is way more costly than a substitution would be, so I am still interested in a solution.rhoadskjWed, 10 Oct 2018 10:04:18 -0500http://ask.sagemath.org/question/43903/Graph with partial edge labellinghttp://ask.sagemath.org/question/43892/graph-with-partial-edge-labelling/ Hello all,
I need to draw a graph in which some edges are labelled and some edges are not.
I know how to make all the edges labelled. But I need mixed edges (some are labelled and some are not).
Kindly help me with this.
Thank youGA316Wed, 10 Oct 2018 02:04:43 -0500http://ask.sagemath.org/question/43892/creating graph with dotted edgeshttp://ask.sagemath.org/question/43872/creating-graph-with-dotted-edges/ Hello all,
I need to draw a graph in which some edges are usual and some edges are dotted. I know how to make all the edges dotted (using the option "dotted" for the parameter edge_style of plot). But I need mixed edges (some are dotted and some are usual). Kindly help me with this.
Thank you.
GA316Mon, 08 Oct 2018 11:17:43 -0500http://ask.sagemath.org/question/43872/Numerical calculation speed: Sagemath vs. C vs. Matlabhttp://ask.sagemath.org/question/43893/numerical-calculation-speed-sagemath-vs-c-vs-matlab/I mostly use Sagemath for performing symbolic operations on trigonometric polynomials. But I was wondering if it is also a good tool in numerical methods. This includes matrix operations and iterative solution of PDEs with finite difference methods. Usually I take the Sagemath outputs in another program more suited to numerical work. But I was wondering if Sagemath itself is a viable choice in this resepct. Can you tell me about its numerical performance and speed compared to other programs such as C, Matlab, Julia, Mathematica etc.? ThanksDanialBaghWed, 10 Oct 2018 02:22:46 -0500http://ask.sagemath.org/question/43893/Anaconda - Sage conflict in .bashrchttp://ask.sagemath.org/question/43889/anaconda-sage-conflict-in-bashrc/I can't get Anaconda and Sage to play nicely with each other.
This is on a new install of Linux Mint 19. I installed sage from the repository and everything working fine. Then I installed Anaconda as directed on Anaconda's Linux installation instructions , including having the installer add to the PATH in ~/.bashrc. This broke sage. When I try to run it now, I get the error
Traceback (most recent call last):
File " /usr/share/sagemath/bin/sage-ipython", line 6, in <module>
from sage.repl.interpreter import SageTerminalApp
ImportError: No module named 'sage'
When I comment out the lines Anaconda added to my .bashrc file where it's adding to the PATH, Sage works again, but Anaconda is broken. What's causing this problem? How can I get the two to work at the same time?ttshaw1Tue, 09 Oct 2018 16:53:54 -0500http://ask.sagemath.org/question/43889/Is it possible to run (may be partially) Sage with Python 3?http://ask.sagemath.org/question/33887/is-it-possible-to-run-may-be-partially-sage-with-python-3/ I want to run sage with python3. I know that it isn't fully ported, but I want to use already ported functionality and hope it cover my needs.
One particular reason is my necessity to use `multiprocessing.pool` with `lambda` function which doesn't work with python 2 and [both workarounds](http://stackoverflow.com/questions/4827432/how-to-let-pool-map-take-a-lambda-function ) seem to not work also.
P.S. I found [third workaround](http://stackoverflow.com/a/37976180/359866) which seems to be working.petRUShkaWed, 22 Jun 2016 12:52:59 -0500http://ask.sagemath.org/question/33887/Disable modules at compile-time or runtimehttp://ask.sagemath.org/question/43878/disable-modules-at-compile-time-or-runtime/ I'm building SAGE for a humble Raspberry Pi platform (although I'm currently experimenting compilation on a good computer), and given the power of the Pi target I'd like to build and use only a reduced part of SageMath's modules. Anything too far above the level of a high-school student can be cut off, I only plan to use exact calculus and basic analysis tools.
So far I've looked at the installation guide and tried a few things with the configure script, but I found no option to disable modules.
Is there anything planned for this purpose? Or do I have to build SageMath entirely no matter what?
I considered loading only part of the Python modules at runtime, but I figure SageMath will load the others when it sees fit.
Is there a way to disable part of SageMath at runtime?LovelessMon, 08 Oct 2018 15:07:28 -0500http://ask.sagemath.org/question/43878/Is it possible to update the Sage Python?http://ask.sagemath.org/question/37181/is-it-possible-to-update-the-sage-python/ I noticed Sage can run a Python notebook, but it's 2.7 when I'm used to using 3.x. It is possible to update the Python in Sage? Also I'm on Windows so I'm using the Sage Virtualbox appliance, which might make it impossible. But is it possible in a sage native host like Linux?cybervigilanteWed, 05 Apr 2017 16:13:53 -0500http://ask.sagemath.org/question/37181/Ideal.variety() when working with symbolic ringshttp://ask.sagemath.org/question/43873/idealvariety-when-working-with-symbolic-rings/I have a system of multivariate polynomials I would like to solve (the equations come from chemical reaction networks). I have many symbolic constants, but I've managed to generate a Groebner basis with the following code (using a toy example with solutions {{x: x0, y:0},{x: 0,y: x0}):
x0 = var('x0') # In practice, there are many constants
S.<x,y> = PolynomialRing(SR,order='lex'); # in practice, there are 3-10 variables
I = S.ideal(
x**2 + y**2 - x0**2,
x + y - x0
)
print(I.dimension()) # dimension should always be zero
# >> 0
print(I.groebner_basis())
# >> [x + y - x0,
# >> y^2 + (-x0)*y]
In practice, I get many resulting equations which are extremely long, and it is numerically challenging to sequentially find the roots of these polynomials (in downstream code, I will get values for the constant parameters and then need to return solutions to these equations on the fly). Using the `I.variety()` method would be great to symbolically isolate all possible solutions, but I get confusing internal errors when I try to evaluate it.
print(I.variety()) # should be equivalent to: I.variety(ring=SR)
#/Users/ksb/SageMath/local/lib/python2.7/site-packages/sage/rings/polynomial/multi_polynomial_ideal.pyc in _variety(T, V, v)
# 2340
# 2341 variable = f.variable(0)
#-> 2342 roots = f.univariate_polynomial().roots(ring=ring, multiplicities=False)
# 2343
# 2344 for root in roots:
#
#/Users/ksb/SageMath/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_element.pyx in sage.rings.polynomial.polynomial_element.Polynomial.roots (build/cythonized/sage/rings/polynomial/polynomial_element.c:68811)()
# 7714 return l
# 7715 else:
#-> 7716 return [val for val,m in l]
# 7717 vname = 'do_not_use_this_name_in_a_polynomial_coefficient'
# 7718 var = SR(vname)
# TypeError: 'sage.symbolic.expression.Expression' object is not iterable
Is this expected behavior? When I try `f.univariate_polynomial().roots(ring=ring, multiplicities=False)` (setting `multiplicities=True` is what `I.variety()` does and leads to the error) I get `[1/2*x0,2]` for roots, which makes little sense (it seems like the roots should be `[0,-x0]`).
I would be happy to convert the `MPolynomial_polydict` (or the `sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class` generated by `univariate_polynomial()`) into a symbolic expression that I could just set it equal to zero and use `solve` on it, but I don't know how to do this type conversion. ksbMon, 08 Oct 2018 12:41:03 -0500http://ask.sagemath.org/question/43873/Python3 MigrationStatushttp://ask.sagemath.org/question/43848/python3-migrationstatus/Hello. I looked at Trac , but I couldn't make out just how far we are into migrating to python3. Looks to me that most issues are closed by now. I'd appreciate quick summary from a sage developer.rijndaelxyzSat, 06 Oct 2018 15:38:40 -0500http://ask.sagemath.org/question/43848/How to run Cython examples in SageMathCellhttp://ask.sagemath.org/question/43786/how-to-run-cython-examples-in-sagemathcell/Hi, this is not a math question, this is a programming question.
I'm trying to run the first example at doc.sagemath.org/html/en/thematic_tutorials/cython_interface by using SageMathCell service ([link](http://doc.sagemath.org/html/en/thematic_tutorials/cython_interface.html)).
For this, I've created a zip folder that I've stored in the cloud (Google Drive).
When I run the following python script in SageMathCell (I wrote it to test Cython capabilities in SageMath remote server), it seems good, but I can't see the output, that would be "Hello World".
This python script, after execution, ends with "Compiling ./Call_C_code/hello_sage.pyx..." without anyone else output.
Can you help me?
Thanks,
import os
import tempfile
import sys
from distutils.dir_util import copy_tree
directory_name = tempfile.mkdtemp()
print(directory_name)
sys.path.append(directory_name)
#https://drive.google.com/open?id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu
import urllib
url = "https://drive.google.com/uc?export=download&id=129vvaCzB0M5iuPxdSdNWRG5A2gG0DwEu"
filename = "/Call_C_code.zip"
urllib.urlretrieve(url, directory_name + filename)
# opening the zip file in READ mode
from zipfile import ZipFile
os.chdir(directory_name)
file_name = "Call_C_code.zip"
with ZipFile(file_name, 'r') as zip:
# extracting all the files
print('Extracting all the files now...')
zip.extractall()
print('Done!')
print(sys.path)
print(os.getcwd())
for root, dirs, files in os.walk("."):
for filename in files:
print(filename)
#############
%runfile Call_C_code/hello_sage.pyx
my_bridge_function()MatteoThu, 27 Sep 2018 10:20:24 -0500http://ask.sagemath.org/question/43786/error with importing sage into a python filehttp://ask.sagemath.org/question/43849/error-with-importing-sage-into-a-python-file/Im trying to import a sage package (var) in a python file
from sage.all import var
but when run the file Im getting this error :
Error
Traceback (most recent call last):
execfile("/home/sagefolder/SageMath/myapp/core/test.py")
File "/home/sagefolder/SageMath/ubbr/engine/test.py", line 20, in <module>
from sage.all import var
File "/home/sagefolder/SageMath/local/lib/python2.7/site-packages/sage/all.py", line 71, in <module>
from sage.env import SAGE_ROOT, SAGE_SRC, SAGE_DOC_SRC, SAGE_LOCAL, DOT_SAGE, SAGE_ENV
File "/home/sagefolder/SageMath/local/lib/python2.7/site-packages/sage/env.py", line 123, in <module>
_add_variable_or_fallback('SAGE_ETC', opj('$SAGE_LOCAL', 'etc'))
File "/home/sagefolder/SageMath/local/lib/python2.7/site-packages/sage/env.py", line 103, in _add_variable_or_fallback
value = sep.join(components)
TypeError: sequence item 0: expected string, NoneType found
my guess was that the problems was related to the env path. but even
sys.path.append('/path/to/the/sage/')
it does not work
It seems it has problem with the value of some env variables like 'SAGE_ROOT' and ... but according to the [installation manual][1], if I set the symbolic link
`ln -s /path/to/SageMath/sage /usr/local/bin/sage`
then all the required env variable are automatically handled.
this module is called from a django views.py which is also installed as a Sage package. if I run the the module
using
sage test.py
everything is ok but when it is called from a django view which is also installed as sage packages I got the mentioned error
I would be pleased if anybody can help me as Im doing an important project and I really need to use sage.
[1]: http://doc.sagemath.org/html/en/installation/binary.html#sec-installation-from-binariesnimaousSat, 06 Oct 2018 16:31:57 -0500http://ask.sagemath.org/question/43849/Characteristic polynomial of symbolic matrix of size 7http://ask.sagemath.org/question/43839/characteristic-polynomial-of-symbolic-matrix-of-size-7/There is a problem when computing the characteristic polynomial of a matrix of size greater than 7 containing a large number of symbolic variables.
<pre><code>a = SR.var('a', 100)
M = identity_matrix(SR, 7)
for i in range(7):
for j in range(7):
M[i,j] = a[i*7+j]
print(M.charpoly().degree()) # prints 5
</code></pre>
The value it should print is 7. Over $\mathbb{Z}[a_0,a_1,\dots]$, the result is correct.
I use Sage 8.3 (Release Date: 2018-08-03), installed from the official repository of Archlinux. The bug is present both in command line and with `sage file.sage` (if I copy and paste the code above).ScreenNameSat, 06 Oct 2018 01:04:49 -0500http://ask.sagemath.org/question/43839/Print symbolic variables like a_1 in A[1] stylehttp://ask.sagemath.org/question/43838/print-symbolic-variables-like-a_1-in-a1-style/Because of Sagemath's problem with symbolic arrays, I have defined my vectors like this:
A =[0 for j in range(4)]
for j in range(4):
A[j]=var('a_'+str(j))
I have some symbolic variables stored in another variable. Lets say I have a subroutine that works with `A[i]` and in the end, `L` becomes something such as: `L=a_1+a_2*a_3`. When I print `L`, I want to have it printed in the original vector format. So when I type `L` or `print(L)` in a cell and press enter, my desired output is `A[1]+A[2]*A[3]` and not `a_1+a_2*a_3`. I want this type of output because I am transferring SageMath outputs to C where I employ indexed arrays. How can I achieve this? DanialBaghFri, 05 Oct 2018 22:30:25 -0500http://ask.sagemath.org/question/43838/