Module: sage.interfaces.gp
Interface to GP/Pari
Type gp.[tab] for a list of all the functions available
from your Gp install. Type gp.[tab]? for Gp's
help about a given function. Type gp(...) to create
a new Gp object, and gp.eval(...) to run a string
using Gp (and get the result back as a string).
We illustrate objects that wrap GP objects (gp is the PARI interpreter):
sage: M = gp('[1,2;3,4]')
sage: M
[1, 2; 3, 4]
sage: M * M
[7, 10; 15, 22]
sage: M + M
[2, 4; 6, 8]
sage: M.matdet()
-2
sage: E = gp.ellinit([1,2,3,4,5]) sage: E.ellglobalred() [10351, [1, -1, 0, -1], 1] sage: E.ellan(20) [1, 1, 0, -1, -3, 0, -1, -3, -3, -3, -1, 0, 1, -1, 0, -1, 5, -3, 4, 3]
sage: primitive_root(7)
3
sage: x = gp("znlog( Mod(2,7), Mod(3,7))")
sage: 3^x % 7
2
sage: print gp("taylor(sin(x),x)")
x - 1/6*x^3 + 1/120*x^5 - 1/5040*x^7 + 1/362880*x^9 - 1/39916800*x^11 +
1/6227020800*x^13 - 1/1307674368000*x^15 + O(x^16)
GP has a powerful very efficient algorithm for numerical computation of integrals.
sage: gp("a = intnum(x=0,6,sin(x))")
0.03982971334963397945434770208 # 32-bit
0.039829713349633979454347702077075594548 # 64-bit
sage: gp("a")
0.03982971334963397945434770208 # 32-bit
0.039829713349633979454347702077075594548 # 64-bit
sage: gp.kill("a")
sage: gp("a")
a
Note that gp ASCII plots do work in SAGE, as follows:
sage: print gp.eval("plot(x=0,6,sin(x))")
0.9988963 |''''''''''''_x"...x_''''''''''''''''''''''''''''''''''''''''''|
| x" "x |
| _" "_ |
| x x |
| " " |
| " " |
| _" "_ |
| _ _ |
| _ _ |
|_ _ |
_,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
| " |
| " |
| " |
| " "
| "_ _"|
| _ _ |
| _ _ |
| x x |
| "_ _" |
| x_ _x |
-0.998955 |............................................."x____x".........|
0 6
The GP interface reads in even very long input (using files) in a robust manner, as long as you are creating a new object.
sage: t = '"%s"'%10^10000 # ten thousand character string. sage: a = gp.eval(t) sage: a = gp(t)
In SAGE, the PARI large galois groups datafiles should be installed by default:
sage: f = gp('x^9 - x - 2')
sage: f.polgalois()
[362880, -1, 34, "S9"]
Author Log:
Module-level Functions
| ) |
| ) |
sage: gp.version() # random output ((2, 3, 1), 'GP/PARI CALCULATOR Version 2.3.1 (0)')
| x) |
| ) |
Class: Gp
Type gp.[tab] for a list of all the functions available
from your Gp install. Type gp.[tab]? for Gp's
help about a given function. Type gp(...) to create
a new Gp object, and gp.eval(...) to run a string
using Gp (and get the result back as a string).
| self, [stacksize=10000000], [maxread=100000], [script_subdirectory=None], [logfile=None], [server=None], [server_tmpdir=None], [init_list_length=1024]) |
Functions: console,
get,
get_precision,
get_real_precision,
help,
kill,
new_with_bits_prec,
quit,
read,
set,
set_precision,
set_real_precision,
trait_names,
version
| self, var) |
| self) |
| self) |
| self, [verbose=False], [timeout=0.25]) |
sage: a = gp('10'); a
10
sage: gp.quit()
sage: a
(invalid object -- defined in terms of closed session)
sage: gp(pi)
3.1415926535897932384626433832795028842 # 64-bit
3.141592653589793238462643383 # 32-bit
| self, var, value) |
| self, [prec=None]) |
| self, [prec=None]) |
Special Functions: __reduce__,
_equality_symbol,
_eval_line,
_false_symbol,
_next_var_name,
_object_class,
_quit_string,
_read_in_file_command,
_repr_,
_true_symbol
Class: GpElement
This example illustrates dumping and loading GP elements to compressed strings.
sage: a = gp(39393) sage: loads(a.dumps()) == a True
Since dumping and loading uses the string representation of the object, it need not result in an identical object from the point of view of PARI:
sage: E = gp('ellinit([1,2,3,4,5])')
sage: loads(E.dumps()) == E
False
sage: loads(E.dumps())
[1, 2, 3, 4, 5, 9, 11, 29, 35, -183, -3429, -10351, 6128487/10351,
[-1.618909932267371342378000940, -0.3155450338663143288109995302 -
2.092547096911958607981689447*I, -0.3155450338663143288109995302 +
2.092547096911958607981689447*I]~, 2.780740013766729771063197627,
-1.390370006883364885531598814 + 1.068749776356193066159263547*I,
-1.554824121162190164275074561 + 3.415713103000000000000000000 E-29*I,
0.7774120605810950821375372806 - 1.727349756386839866714149879*I,
2.971915267817909670771647951] # 32-bit
[1, 2, 3, 4, 5, 9, 11, 29, 35, -183, -3429, -10351, 6128487/10351,
[-1.6189099322673713423780009396072169750,
-0.31554503386631432881099953019639151248 -
2.0925470969119586079816894466366945829*I,
-0.31554503386631432881099953019639151248 +
2.0925470969119586079816894466366945829*I]~,
2.7807400137667297710631976271813584994,
-1.3903700068833648855315988135906792497 +
1.0687497763561930661592635474375038788*I,
-1.5548241211621901642750745610982915039 +
7.9528267991764473360000000000000000000 E-39*I,
0.77741206058109508213753728054914575197 -
1.7273497563868398667141498789110695181*I,
2.9719152678179096707716479509361896060] # 64-bit
sage: E
[1, 2, 3, 4, 5, 9, 11, 29, 35, -183, -3429, -10351, 6128487/10351,
[-1.618909932267371342378000940, -0.3155450338663143288109995302 -
2.092547096911958607981689447*I, -0.3155450338663143288109995302 +
2.092547096911958607981689447*I]~, 2.780740013766729771063197627,
-1.390370006883364885531598814 + 1.068749776356193066159263547*I,
-1.554824121162190164275074561 + 3.415713103 E-29*I,
0.7774120605810950821375372806 - 1.727349756386839866714149879*I,
2.971915267817909670771647951] # 32-bit
[1, 2, 3, 4, 5, 9, 11, 29, 35, -183, -3429, -10351, 6128487/10351,
[-1.6189099322673713423780009396072169750,
-0.31554503386631432881099953019639151248 -
2.0925470969119586079816894466366945829*I,
-0.31554503386631432881099953019639151248 +
2.0925470969119586079816894466366945829*I]~,
2.7807400137667297710631976271813584994,
-1.3903700068833648855315988135906792497 +
1.0687497763561930661592635474375038788*I,
-1.5548241211621901642750745610982915039 + 7.952826799176447336 E-39*I,
0.77741206058109508213753728054914575197 -
1.7273497563868398667141498789110695181*I,
2.9719152678179096707716479509361896060] # 64-bit
The two elliptic curves look the same, but internally the floating point numbers are slightly different.
Functions: trait_names
Special Functions: __bool__,
__float__,
__len__,
__long__,
_complex_mpfr_field_
| self) |
| self) |
| self, CC) |
sage: CC(gp(1+15*I)) 1.00000000000000 + 15.0000000000000*I sage: CC(gp(11243.9812+15*I)) 11243.9812000000 + 15.0000000000000*I sage: ComplexField(10)(gp(11243.9812+15*I)) 1.1e4 + 15.*I
Class: GpFunction
Special Functions: _sage_doc_
Class: GpFunctionElement
Special Functions: _sage_doc_
See About this document... for information on suggesting changes.