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.Sat, 15 Sep 2018 16:50:41 -0500How to load local PARI/GP script in Sage notebook?http://ask.sagemath.org/question/43681/how-to-load-local-parigp-script-in-sage-notebook/I have a PARI/GP script which I want to load and run locally on my laptop inside a Sage notebook. I tried to open a new notebook in the same directory where my script is located, and run this:
%default_mode gp
But, it throws the following error:
> UsageError: Line magic function '%default_mode` not found.
Please note that I'm using Sage 8.3. How can I run a PARI/GP script locally?ninhoSat, 15 Sep 2018 16:50:41 -0500http://ask.sagemath.org/question/43681/Pari error when factoring polynomialhttp://ask.sagemath.org/question/42742/pari-error-when-factoring-polynomial/ I ran the following code to factor a polynomial over a number field:
U.<z> = CyclotomicField(32)
P.<x> = PolynomialRing(U)
f = x^16-256
print f.factor()
This code works for all substitutions of 256 by another value I have tried, but this one gives an error:
Traceback (most recent call last):
File "p_is_2_test.sage.py", line 10, in <module>
print f.factor()
File "sage/rings/polynomial/polynomial_element.pyx", line 4199, in sage.rings.polynomial.polynomial_element.Polynomial.factor (build/cythonized/sage/rings/polynomial/polynomial_element.c:39418)
File "cypari2/auto_gen.pxi", line 17246, in cypari2.gen.Gen_auto.nffactor
File "cypari2/handle_error.pyx", line 196, in cypari2.handle_error._pari_err_handle
cypari2.handle_error.PariError: inconsistent concatenation t_COL (8 elts) , t_VEC (8 elts)
This seems like some bug in sage, but I am not quite sure what to make of the error. Does anyone know how to deal with this error and to properly let sage factor this polynomial?MadPidgeonTue, 26 Jun 2018 14:58:15 -0500http://ask.sagemath.org/question/42742/Using multiple lines of pari/gp code in a Sage notebookhttp://ask.sagemath.org/question/41758/using-multiple-lines-of-parigp-code-in-a-sage-notebook/I am struggling to get multiple lines of pari/gp code working in a Jupyter Sage notebook.
When I enter:
%%gp
for(x=1,10,print(x))
it all works fine, however when I for instance write:
%%gp
for(x=1,10,{
print(x);
})
the system just 'hangs' and doesn't return any output. The same issue occurs in the Cocalc Sage cloud environment. I also tried 'pari/gp in your browser' and there it works fine.
Am I doing something wrong or isn't the multi-line pari/gp option supported in Sage?RuudHSun, 25 Mar 2018 15:58:41 -0500http://ask.sagemath.org/question/41758/Using Sage plotting capability on data from PARI/GPhttp://ask.sagemath.org/question/41029/using-sage-plotting-capability-on-data-from-parigp/I am trying to plot data in Sage that is generated by a function in PARI/GP, however keep getting type errors.
I use this simple example to illustrate the point:
f=(gp("Z(s)=zeta(s)"))
f(2)
This gives the correct output 1.6449340668482264364724151666460251892 and appears to be a 'normal' floating point number that I can indeed multiply/add with.
However, when I try the following:
plot(f,(2,6))
It keeps coming back with
TypeError: Error executing code in GP
I have studied most of the (limited) info on the Pari/GP interface and did read that PARI/GP always returns a string. I therefore tried to convert the returned value into a float, int etc., however nothing works. I very likely do something wrong (or not allowed) and would be grateful for any advice on what could be the issue here (esp. since f(2) gives the correct numerical floating point result).
Thanks!
RuudHThu, 08 Feb 2018 05:49:41 -0600http://ask.sagemath.org/question/41029/Change Precision of complex_roots()http://ask.sagemath.org/question/39987/change-precision-of-complex_roots/I am trying to find the complex roots of the polynomial
poly = x^7 - 6*x^6 + 15*x^5 - 20*x^4 + 15*x^3 - 6*x^2 + x
But when I do poly.complex_roots(), the system gives:
PariError: overflow in expo()
Apparently there are options for how much precision you want when computing roots -- one option is to use Pari, which is the high-precision option, and the other NumPy, which is the low-precision option. The default is set to use Pari, which apparently overloads when I try to compute the roots of this polynomial (and many others as well, this polynomial is just one example).
How do I change the complex_roots() function to get lower-precision roots?cshiringWed, 06 Dec 2017 23:10:52 -0600http://ask.sagemath.org/question/39987/Change Precision on complex_roots()http://ask.sagemath.org/question/39988/change-precision-on-complex_roots/ I am trying to find the complex roots of the polynomial
poly = x^7 - 6*x^6 + 15*x^5 - 20*x^4 + 15*x^3 - 6*x^2 + x
But when I do poly.complex_roots(), the system gives:
PariError: overflow in expo()
Apparently there are options for how much precision you want when computing roots -- one option is to use Pari, which is the high-precision option, and the other NumPy, which is the low-precision option. The default is set to use Pari, which apparently overloads when I try to compute the roots of this polynomial (and many others as well, this polynomial is just one example).
How do I change the complex_roots() function to get lower-precision roots?
Alternatively, how do I deal with the PariError?
cshiringWed, 06 Dec 2017 23:13:28 -0600http://ask.sagemath.org/question/39988/RuntimeError when starting pari/library not foundhttp://ask.sagemath.org/question/33725/runtimeerror-when-starting-parilibrary-not-found/ Hello,
I am using a binary distribution of sage 7.1 for debian jessie and "installed" it to /opt.
Now, when I want to use pari, I get a runtime error:
```
sage: %gp
```
```
--> Switching to PARI/GP interpreter <--
```
```
pari: sqrt(4)
```
```
RuntimeError: unable to start pari
```
The full backtrace can be found here: paste.kde.org/pvqeoh3ve
however, the following works:
```
LD_LIBRARY_PATH=/opt/sage-7.1/local/lib sage
```
It seems that sage is unable to find that library when starting pari.
Setting SAGE_ROOT does not help. Did I miss some configuration file to set the library path for sage?
fxrhThu, 09 Jun 2016 07:58:27 -0500http://ask.sagemath.org/question/33725/Number field arithmetic in Pari/gphttp://ask.sagemath.org/question/32487/number-field-arithmetic-in-parigp/Hi all,
I would like to do number field arithmetic in Pari. To be more precise, I would like let Pari do the following job as Sage does,
K.<a> = NumberField(f(x))
L.<b> = NumberField(g(x))
where f(x), g(x) are irreducible polynomials over the rational. I would like to do arithmetic with a,b. This is easily done in Sage. How can I do this by Pari?
ThanksDianbin BaoSun, 07 Feb 2016 17:04:39 -0600http://ask.sagemath.org/question/32487/Define a big matrix in Sagehttp://ask.sagemath.org/question/32473/define-a-big-matrix-in-sage/Hi all,
I would like to define a big matrix E (130$\times$ 30) with entries being a list like E[11,1] = [x, [1,-2]];
E[14,1] = [x, [1,-1,-2,1]];
or 0.
These entries are stored in a separate file which is readable by Pari but not Sage.
How do I define it by Sage?Dianbin BaoSat, 06 Feb 2016 13:47:22 -0600http://ask.sagemath.org/question/32473/write output of for loop in pari to filehttp://ask.sagemath.org/question/32491/write-output-of-for-loop-in-pari-to-file/Hi all,
I would like to write the output of a for loop in Pari to a file named 'foo', However the output of a for loop has no numbering contrast with other output. If I look at the numbers labeling the outputs before and after the for loop and use that number in the following command
\w n foo
Then what I get in foo is 0. What happened and how can this be fixed?
Dianbin BaoSun, 07 Feb 2016 20:36:16 -0600http://ask.sagemath.org/question/32491/save gp object to sage readable sobjhttp://ask.sagemath.org/question/32470/save-gp-object-to-sage-readable-sobj/Hi all,
I am doing computation with a Pari readable table. Since I am a beginner to Pari, I would like to know that after defining a number field for example $K=nfinit(x^2-76)$, how do I play around with the generator $x$? This is super easy in Sage and may be silly question for people familiar with Pari. It also solve my problem if you know how to save a big matrix defined in Pari to an object readable by Sage.
Dianbin BaoFri, 05 Feb 2016 15:34:25 -0600http://ask.sagemath.org/question/32470/Plotting parametric matrix discriminantshttp://ask.sagemath.org/question/24881/plotting-parametric-matrix-discriminants/Greetings, I am struggling with the problem concerting characteristic polynomial determinants. I'm intending to plot curves in the (a,b)-plane of parametric matrices, which signal the points of some eigenvalues being zero. To this end, I use the following code
var('a b')
A = matrix([[a+sqrt(-1)b,-1,0],[-1,0,-1],[0,-1,a-sqrt(-1)b]])
p=A.charpoly('t')
d=p.discriminant()
region_plot(d>=0, (a,-4,1), (b,-4,1),incol='gray',figsize=5,axes=true)
which however produces the error
File "handle_error.pyx", line 90, in sage.libs.pari.handle_error._pari_handle_exception (build/cythonized/sage/libs/pari/handle_error.c:1178) sage.libs.pari.gen.PariError: incorrect type in gtofp
Printing the discriminant explicitly and then plotting it works fine
var('a b')
A = matrix([[a+sqrt(-1)*b,-1,0],[-1,0,-1],[0,-1,a-sqrt(-1)*b]])
p=A.charpoly('t')
d=p.discriminant()
d2=-4*b^2*a^4 + (-8*b^4 - 40*b^2 + 4)*a^2 + (-4*b^6 + 24*b^4 - 48*b^2 + 32)
region_plot(d2>=0, (a,-2,2), (b,-2,2),incol='gray',figsize=5,axes=true)
although both quantities seem to be of the same type
<type 'sage.symbolic.expression.Expression'>
any ideas about what am I missing?mamuteekSun, 16 Nov 2014 05:35:12 -0600http://ask.sagemath.org/question/24881/newton's method for multiple variables / arbitrary precisionhttp://ask.sagemath.org/question/11367/newtons-method-for-multiple-variables-arbitrary-precision/I am trying to find a numerical approximation with arbitrary precision to a real solution to a system of multivariate polynomial equations.
I start out with an approximation which is somewhat close to solving the system, up to an precision of about 1e-05. (Meaning that the equations that I try to evaluate are not zero, but smaller than 1e-05 for my starting value)
In [this question](http://ask.sagemath.org/question/3974/solving-system-of-polynomial-equations-over-reals) is it recommended to use scipy's fmin_tnc method, which is what I did. This works out very nicely and it quickly gave a new solution which now solves my system with precision 1e-07. In the [Scipy doc](http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.optimize.fmin_tnc.html) it is stated that one can set the "epsilon" parameter, but not smaller than machine precision. So it seems like I can't get much more precision with this method?!
Let's say I want to solve my system with precision 1e-250. My questions are:
1. Can I use the fmin_tnc function to find solutions with higher precision?
2. I there another way in sage to find real solutions to polynomial systems locally (e.g. with the pari/gp)?mfTue, 20 May 2014 11:25:59 -0500http://ask.sagemath.org/question/11367/pariError when computing discriminanthttp://ask.sagemath.org/question/9233/parierror-when-computing-discriminant/Consider the following piece of code:
Qx.<x> = PolynomialRing(Rationals())
K = NumberField(x^2+1, 'a')
OOK = K.ring_of_integers() #K.maximal_order() has same effect
OOa = OOK.extension(x^3+2, 'alpha'); OOa
This returns "`Univariate Quotient Polynomial Ring in alpha over Maximal Order in Number Field in a with defining polynomial x^2 + 1 with modulus alpha^3 + 2`". Why is this the case? I would have expected it to have the same effect as
Qx.<x> = PolynomialRing(Rationals())
00b = ZZ.extension([x^3+2,x^2+1], 'beta,b'); OOb
Namely, that it returns `"Relative Order in Number Field in beta with defining polynomial x^3 + 2 over its base field`".
Moreover, and perhaps more interestingly, when one tries to run the command `OOa.discriminant()` after the first piece of code, "`PariError: (5)`" is returned. Running the analogous command, `OOb.absolute_discriminant()` after the second piece of code, one gets -746496. I presume the fact that these two commands return different results is explained in [Quotients of Univariate Polynomial Rings](http://www.sagemath.org/doc/reference/sage/rings/polynomial/polynomial_quotient_ring.html "Quotients of Univariate Polynomial Rings") when it says
> The discriminant of the quotient polynomial ring need not equal the discriminant of the corresponding number field, since the discriminant of a number field is by definition the discriminant of the ring of integers of the number field.
even though we are not computing the discriminant of a number field in the second piece of code. However, why is a pariError returned when trying to compute the discriminant of `OOa`? Surely this must be somehow linked to the fact that the two blocks of code return completely different things. Is this indeed the case? Any help would be appreciated.
Leonhard MoosbruggerTue, 14 Aug 2012 02:58:15 -0500http://ask.sagemath.org/question/9233/Implementing PARI/GP scriptshttp://ask.sagemath.org/question/23138/implementing-parigp-scripts/ Hello, I have the following `gp` script which I would like to use in SAGE.
Script: http://pages.cs.wisc.edu/~yeoh/nt/satoh-fgh.gp
Description: http://pari.math.u-bordeaux.fr/archives/pari-users-0011/msg00005.html
This script is used to find cardinality of an elliptic curve over binary fields. I've also taken a look at
http://trac.sagemath.org/ticket/11548
but was unable to implement either.
I thought that just copying and pasting the codes would enable me to call the functions used, but I was wrong. I'm using SAGE on VirtualBox on Windows. Any help will be appreciated!BlackadderSun, 29 Jun 2014 20:01:58 -0500http://ask.sagemath.org/question/23138/Zeta function gone wild?http://ask.sagemath.org/question/8418/zeta-function-gone-wild/Playing with number fields we reached some weird numerical results. Investigating the problem boiled down to weird output of zeta functions at odd positive integers from 7 onward.
For example,
sage: K.<a> = NumberField(x^2-2)
sage: K.zeta_function()(7)
82.7603619399160
sage: K.zeta_function(prec=100)(7)
45333.379954778857657650185188
sage: K.zeta_function(prec=200)(7)
5.6555192254423051174292272646037247772094677139829119697339e8
These answers seem to be all erroneous. Close values behave fine:
sage: K.zeta_function()(7.0000001)
1.00787667933529
sage: K.zeta_function()(7.00000001)
1.00787667982152
sage: K.zeta_function()(7.000000001)
1.00787669344227
sage: K.zeta_function()(7.0000000001)
1.00787388932573
(the problem begins afterwards).
Another way to obtain this value is
sage: quadratic_L_function__exact(7,2)*zeta(7)
TypeError: n must be a critical value!
which doesn't work. It turns out that this does work:
sage: quadratic_L_function__numerical(7,2)*zeta(7).n()
1.00787667988590
but this does not help us for general number fields (only quadratic).
The same happens with Riemann zeta function, which is the Dedekind zeta function of $\mathbb{Q}$:
sage: K.<a> = NumberField(x)
sage: K.zeta_function()(7)
verbose -1 (371: dokchitser.py, __call__) Warning: Loss of 2 decimal digits due to cancellation
52.5237126027390 # Wrong!
sage: zeta(7).n() # Checking Riemann directly
1.00834927738192 # okie dokie
sage: K.zeta_function()(7.00001)
verbose -1 (371: dokchitser.py, __call__) Warning: Loss of 2 decimal digits due to cancellation
1.00834921704698 # correct
so we get a warning here, and the value at 7 is wrong, but at 7.00001 things are fine.
We are guessing that this relates to zeros/poles of Gamma in the functional equation for zeta. However, since `zeta(7)` and `quadratic_L_function__numerical` do work fine, perhaps there is a way to calculate other zeta functions there as well?
parzanThu, 27 Oct 2011 05:01:44 -0500http://ask.sagemath.org/question/8418/algebraic integer - PARI/GPhttp://ask.sagemath.org/question/9174/algebraic-integer-parigp/in sage you check if an algebraic number is an algebraic integer with is_integral. If I have a number(s) in an algebraic number field, and I want to check if it is an algebraic integers how do I do it in Pari/GP. Please help! Excuse me for using the forum for sage for questions about Pari/GP.paussseMon, 23 Jul 2012 12:11:12 -0500http://ask.sagemath.org/question/9174/gp and sagehttp://ask.sagemath.org/question/10299/gp-and-sage/From gp I have some result and then define a function with 2 variables (using this result). Now I would like to plot this function in 3D- space. The problem is there in only 2D- plot functions in gp, so, I would like to use "sage" for plotting.
Could you please show me how to import the result from gp to sage?
Thank you so much.
Phuong Ha.
Phuong HaSun, 30 Jun 2013 06:33:40 -0500http://ask.sagemath.org/question/10299/Pari source codehttp://ask.sagemath.org/question/10189/pari-source-code/I'm terribly sorry for asking such a basis question, but can anyone tell me I may be able to find an online access to PARI source code similar to the one we have for sage?
http://hg.sagemath.org/sage-main/src/1077314f4166?at=default
If there isn't one, is there an easy way to view the source code?BlackadderTue, 04 Jun 2013 06:06:39 -0500http://ask.sagemath.org/question/10189/Arbitrary precision BesselYhttp://ask.sagemath.org/question/9679/arbitrary-precision-bessely/Hi,
I consider using Sage for some calculations which contain Bessel functions of complex arguments. Since I have to mix Bessel functions with very small and very large arguments I require precision higher than 15 digits.
Unfortunately, I recognized that BesselY is not implemented in PARI. But BesselJ and BesselH1 are. My physicists understanding of math tells me, I could just use "(BesselH1-BesselJ)/i". But I am surprised that this has not been discussed before (at least I couldn't find it), since this would allow a quick implementation of BesselY. Am I missing something that's obvious for math experts? Or can I just use above definition to get an arbitrary precision BesselY?
Many thanks
Frank
FrankStThu, 03 Jan 2013 02:52:57 -0600http://ask.sagemath.org/question/9679/Accessing functions inside .gp fileshttp://ask.sagemath.org/question/9058/accessing-functions-inside-gp-files/I am newbie thus please forgive me if my request is trivial! I want to read a
file of gp extension. And in that file, I have functions. How could call these
functions when I want to use it? </br>
Example: In sage notebook() </br>
1. pari.allocatemem(90000000)</br>
2. Z.<x>=GF(2)[] </br>
3. p = x^163 + x^7 + x^6 + x^3 + 1</br>
4. b = 0x423d0900aeb5645491fee539c297946cbc6a4f1f5</br>
5. p1 = p.polynomial(x)</br>
6. bb = Z(b.digits(2))</br>
7. a1 = gp.Mod(bb._pari_(), p)</br>
8. pari.read(get_remote_file("http://pages.cs.wisc.edu/~yeoh/nt/satoh-fgh.gp"))</br>
9. gp.ecpc(p1, a1)</br>
When, I try the above code in a terminal, it works fine. But when I try it in
sage notebook(), it works till line 8. And when it reaches 9, it says </br>
Traceback (click to the left of this block for traceback)</br>
...</br>
*** not a function in function call</br>
That means, I am unable to call the function ecpc inside the file. Thus, could
you help me how to access that function being outside?twoforoneSun, 10 Jun 2012 21:55:47 -0500http://ask.sagemath.org/question/9058/Running PARI/GP and Sagehttp://ask.sagemath.org/question/7839/running-parigp-and-sage/Suppose I have a function a(i) in PARI/GP code. To evaluate something like a(5) in sage code I write pari('a[5]'). However, running the for loop on pari('a[i]') doesn't seem to work. Is there a work around for this?805801Wed, 29 Jun 2011 21:35:14 -0500http://ask.sagemath.org/question/7839/coerce pari type or string to rational function workaround?http://ask.sagemath.org/question/8114/coerce-pari-type-or-string-to-rational-function-workaround/I am getting some rational functions from pari/gp and want to work with them in Sage. I can't figure out how to do the coercion. I tried coercing them directly, and even via a string.
Here's what I've tried:
Make a pari type rational function:
sage: test = gp.simplify((x+y)/y)
This is the field I want to put it in:
sage: R.<x,y> = PolynomialRing(QQ)
sage: S = R.fraction_field()
coercing directly doesn't work:
sage: S(test)
Traceback (most recent call last):
...
TypeError: unable to convert 1/y*x + 1 to a rational
So I tried making a string out of it:
sage: str(test)
'1/y*x + 1'
Of course, sage would accept that string if I typed it in directly:
sage: S(1/y*x + 1)
(x + y)/y
But it won't accept it as a string:
sage: S(str(test))
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field
sage: S('1/y*x + 1')
Traceback (most recent call last):
...
TypeError: no canonical coercion from Fraction Field of Multivariate Polynomial Ring in x, y over Rational Field to Rational Field
All of this works fine for polynomials (just remove the denominator of y from the example above). I think these are bugs and I will report them as such, if you agree. But in the meantime, does anyone have a workaround I can use?Kate StangeSun, 22 May 2011 09:11:39 -0500http://ask.sagemath.org/question/8114/