Ask Your Question
1

set precision for pari in Sage

asked 2022-03-23 08:37:44 +0100

Lee gravatar image

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2022-03-23 17:27:34 +0100

Max Alekseyev gravatar image

updated 2022-03-26 21:53:51 +0100

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))
edit flag offensive delete link more

Comments

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

Lee gravatar imageLee ( 2022-03-24 12:03:13 +0100 )edit

See updated answer.

Max Alekseyev gravatar imageMax Alekseyev ( 2022-03-26 21:44:26 +0100 )edit
1

answered 2022-03-23 09:22:40 +0100

FrédéricC gravatar image

updated 2022-03-23 09:35:23 +0100

slelievre gravatar image

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
edit flag offensive delete link more

Comments

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.

Lee gravatar imageLee ( 2022-03-23 09:48:46 +0100 )edit

Give us a precise example in your question.

FrédéricC gravatar imageFrédéricC ( 2022-03-23 15:41:02 +0100 )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?

Lee gravatar imageLee ( 2022-03-24 12:00:02 +0100 )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.

Max Alekseyev gravatar imageMax Alekseyev ( 2022-03-26 21:44:37 +0100 )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.

Lee gravatar imageLee ( 2022-03-27 06:18:37 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-03-23 08:37:44 +0100

Seen: 559 times

Last updated: Mar 26 '22