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 ?
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))
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.
See also: "set_real_precision_bits()" to set the precision in bits.
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
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?
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.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2022-03-23 08:37:44 +0100
Seen: 576 times
Last updated: Mar 26 '22
how to get output in a mixed fraction?
HowTo Compute Past Largest Cython Supported Wordsize (efficiently)?
Sage binary system requirements
2D plotting in sage looks wrong
Set global precision for reals?
How to find if computation is in a notebook or sage prompt ?