# set precision for pari in Sage

In the pari program, we can use \pb 256 to set the precision. For the pari in Sage, how to use this command ?

edit retag close merge delete

Sort by » oldest newest most voted

To change real precision in gp run gp.default("realprecision",256).

However, this issue in your code is not in pari's precision per se, but in loss of precision when pari's object is converted to Sage (it may be a bug in cypari2). Here is an equivalent code with explicit precision control (for both Sage and Pari) based on gp. interface:

myC = ComplexField(200)        # precision in bits, we use it for conversion to Sage
gp.default("realprecision",60)    # precision in decimal digits for pari's routines

K.<a>=CyclotomicField(3)
E=gp.ellinit([0,0,0,0,-432*(1+3*a)^4])
S=gp.mfinit([63,2,Mod(37,63)])
L=gp.mfeigenbasis(S)
symb = gp.mfsymbol(L[1])

def phiE(c):
return myC(gp.mfsymboleval(symb,[gp.oo(), c]))*2*myC(pi)*I

print(phiE(gp.oo()))
print(phiE(0))
print(phiE(1/1000))

more

Thanks a lot ! But this seem not effect when I use Sage. Please see the example I give in the comment below.

( 2022-03-24 12:03:13 +0200 )edit

( 2022-03-26 21:44:26 +0200 )edit

maybe

pari.set_real_precision(prec)


Get its documentation with ?:

sage: pari.set_real_precision?
Signature:      pari.set_real_precision(n)
Docstring:
Sets the PARI default real precision in decimal digits.

This is used both for creation of new objects from strings and for
printing. It is the number of digits *IN DECIMAL* in which real
numbers are printed. It also determines the precision of objects
created by parsing strings (e.g. pari('1.2')), which is *not* the
normal way of creating new PARI objects in CyPari2. It has *no*
effect on the precision of computations within the pari library.

Returns the previous PARI real precision.

Examples:

>>> import cypari2
>>> pari = cypari2.Pari()
>>> pari.set_real_precision(60)
15
>>> pari('1.2')
1.20000000000000000000000000000000000000000000000000000000000
>>> pari.set_real_precision(15)
60
Init docstring: Initialize self.  See help(type(self)) for accurate signature.
File:
Type:           method


Type pari.set and press the TAB key for a list of similar functions.

sage: pari.set
pari.set_debug_level
pari.set_real_precision
pari.set_real_precision_bits
pari.set_series_precision
pari.setbinop
pari.setintersect
pari.setisset
pari.setminus
pari.setrand
pari.setsearch
pari.setunion

more

Thanks a lot! I tried this command pari.set_real_precision(), but when I use mfsymboleval, the precision does not change. In the pari program, if I add \pb 256 at the beginning, it does effect. So I want to know how to do the same thing in Sage.

( 2022-03-23 09:48:46 +0200 )edit

Give us a precise example in your question.

( 2022-03-23 15:41:02 +0200 )edit

For example, I run the following code in sage

from cypari2 import Pari
pari = Pari()
print(R)
K.<a>=CyclotomicField(3)
E=pari([0,0,0,0,-432*(1+3*a.n(3000))^4]).ellinit()
S=pari([63,2,Mod(37,63)]).mfinit()
L=pari(S).mfeigenbasis()
symb=L[0].mfsymbol();

def phiE(c):
#return E.ellztopoint(pari(symb.mfsymboleval([oo, c])*2*pi*I).polcoef(0))
return symb.mfsymboleval([oo, c])*2*pi*I
#return pari(symb.mfsymboleval([oo, c])*2*pi*I).polcoef(0)

print(phiE(oo))
print(phiE(0))
print(phiE(1/1000))


the output is with very little precision. How can I get the output with high precision?

( 2022-03-24 12:00:02 +0200 )edit

This is not an issue with precision in pari but rather a loss of precision when pari object symb.mfsymboleval([oo, c]) is converted to Sage. Perhaps, it's a bug in cypari2.

( 2022-03-26 21:44:37 +0200 )edit

Thanks a lot ! I find that the .mfsymbol() can set precision in Sage. For example, I use pari.mfsymbol(S,L[0],256) can increase the precision to 256.

( 2022-03-27 06:18:37 +0200 )edit