{{{id=1| from sage.libs.giac import * /// }}} {{{id=3| giacpy? ///

File: /usr/local/sage-5.10/devel/sage/sage/libs/giac/giacpy.pyx

Type: <type ‘module’>

Definition: giacpy( [noargspec] )

Docstring:

Name:giacpy
Summary:A Cython frontend to the c++ library giac. (Computer Algebra System)
License:GPL v2 or above
Home-page:http://www.math.jussieu.fr/~han/xcas/giacpy/
Author:Frederic Han
Author-email:han@math.jussieu.fr

This is the sage version of giacpy.

  • Giacpy is an interface to the c++ giac library. This interface is built with cython, and the resulting speed is similar to giac’s one.
  • Giac is a general purpose Computer algebra system by Bernard Parisse released under GPLv3.
    • http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
    • It is build on C and C++ libraries: NTL (arithmetic), GSL (numerics), GMP (big integers), MPFR (bigfloats)
    • It provides fast algorithms for multivariate polynomial operations (product, GCD, factorisation) and
    • symbolic computations: solver, simplifications, limits/series, integration, summation...
    • Linear Algebra with numerical or symbolic coefficients.

AUTHORS:

EXAMPLES:

  • The class Pygen is the main tool to interact from python/sage with the c++ library giac via cython. The initialisation of a Pygen just create an object in giac, but the mathematical computation is not done. This class is mainly for cython users.
  • Most common usage of this package in sage will be with the libgiac() function. This function is just the composition of the Pygen initialisation and the evaluation of this object in giac.
sage: from giacpy import libgiac,giacsettings
// Giac share root-directory:/usr/local/sage-5.10/local/share/giac/
// Using keyword file /usr/local/sage-5.10/local/share/giac/doc/fr/keywords
// Giac share root-directory:/usr/local/sage-5.10/local/share/giac/
Help file /usr/local/sage-5.10/local/share/giac/doc/fr/aide_cas not found
Added 0 synonyms
sage: x,y,z=libgiac('x,y,z');  # add some giac objects
sage: f=(x+3*y)/(x+z+1)^2 -(x+z+1)^2/(x+3*y)
sage: f.factor()
(3*y-x^2-2*x*z-x-z^2-2*z-1)*(3*y+x^2+2*x*z+3*x+z^2+2*z+1)/((x+z+1)^2*(3*y+x))
sage: f.normal()
(-x^4-4*x^3*z-4*x^3-6*x^2*z^2-12*x^2*z-5*x^2+6*x*y-4*x*z^3-12*x*z^2-12*x*z-4*x+9*y^2-z^4-4*z^3-6*z^2-4*z-1)/(x^3+3*x^2*y+2*x^2*z+2*x^2+6*x*y*z+6*x*y+x*z^2+2*x*z+x+3*y*z^2+6*y*z+3*y)
  • To obtain more hints on giacpy consider the help of the libgiac function.
sage: libgiac?             
  • Some settings of giac are available via the giacsettings element. (Ex: maximal number of threads in computations, allowing probabilistic algorithms or not...
sage: R=PolynomialRing(QQ,8,'x')
sage: I=sage.rings.ideal.Katsura(R,8)
sage: giacsettings.proba_epsilon=1e-15;
sage: Igiac=libgiac(I.gens());
sage: time Bgiac=Igiac.gbasis([R.gens()],'revlex')  
Running a probabilistic check for the reconstructed Groebner basis. If successfull, error probability is less than 1e-15 and is estimated to be less than 10^-109. Use proba_epsilon:=0 to certify (this takes more time).
Time: CPU 0.46 s, Wall: 0.50 s
sage: giacsettings.proba_epsilon=0;
sage: Igiac=libgiac(I.gens());
sage: time Bgiac=Igiac.gbasis([R.gens()],'revlex') 
Time: CPU 2.74 s, Wall: 2.75 s

GETTING HELP:

  • To obtain some help on a giac keyword use the help() method. In sage the htmlhelp() method for Pygen element is disabled. Just use the ? or .help() method.
sage: libgiac.gcd?             
"Returns the greatest common divisor of 2 polynomials of several variables or of 2 integers or of 2 rationals.
(Intg or Poly),(Intg or Poly)
gcd(45,75);gcd(15/7,50/9);gcd(x^2-2*x+1,x^3-1);gcd(t^2-2*t+1,t^2+t-2);gcd((x^2-1)*(y^2-1)*z^2,x^3*y^3*z+(-(y^3))*z+x^3*z-z)
lcm,euler,modgcd,ezgcd,psrgcd,heugcd,Gcd"

EXAMPLES:

sage: from giacpy import *
sage: x=libgiac('x');f=1/(2+sin(5*x))
sage: f.int()
2/5/sqrt(3)*(atan((2*tan(5*x/2)+1)/sqrt(3))+pi*floor(5*x/2/pi+1/2))
sage: f.series(x,0,3)
1/2-5/4*x+25/8*x^2-125/48*x^3+x^4*order_size(x)
sage: libgiac(sqrt(5)+pi).approx(100)
5.377660631089582934871817052010779119637787758986631545245841837718337331924013898042449233720899343

Graphics 2D Output via qcas (the qt frontend to giac) is disabled in the sage version of giacpy.

}}} {{{id=4| libgiac? ///

File: /usr/local/sage-5.10/devel/sage/sage/libs/giac/giacpy.pyx

Type: <type ‘instance’>

Definition: libgiac(s)

Docstring:

This function evaluate a python/sage object with the giac library. It creates in python/sage a Pygen element and evaluate it with giac:

sage: from giacpy import libgiac
sage: x,y=libgiac('x,y')
sage: (x+2*y).cos().texpand()
cos(x)*(2*cos(y)^2-1)-sin(x)*2*cos(y)*sin(y)
  • Coercion, Pygen and internal giac variables:

    The most usefull objects will be the Python object of type Pygen.

    sage: from giacpy import *
    sage: x,y,z=libgiac('x,y,z')
    sage: f=sum([x[i] for i in range(5)])^15/(y+z);f.coeff(x[0],12)
    (455*(x[1])^3+1365*(x[1])^2*x[2]+1365*(x[1])^2*x[3]+1365*(x[1])^2*x[4]+1365*x[1]*(x[2])^2+2730*x[1]*x[2]*x[3]+2730*x[1]*x[2]*x[4]+1365*x[1]*(x[3])^2+2730*x[1]*x[3]*x[4]+1365*x[1]*(x[4])^2+455*(x[2])^3+1365*(x[2])^2*x[3]+1365*(x[2])^2*x[4]+1365*x[2]*(x[3])^2+2730*x[2]*x[3]*x[4]+1365*x[2]*(x[4])^2+455*(x[3])^3+1365*(x[3])^2*x[4]+1365*x[3]*(x[4])^2+455*(x[4])^3)/(y+z)
    

    Warning: The complex number sqrt(-1) is exported in python as I. (But it may appears as i)

    sage: libgiac((1+I*sqrt(3))^3).normal(); libgiac(1+I)
    -8
    1+i
    

    Python integers and reals can be directly converted to giac.

    sage: from giacpy import *
    sage: a=libgiac(2^1024);a.nextprime();(libgiac(1.234567)).erf().approx(10)
    179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137859
    0.9191788641
    

    The Python object y defined above is of type Pygen. It is not an internal giac variable. (Most of the time you won’t need to use internal giac variables).

    sage: from giacpy import *
    sage: libgiac('y:=1');y
    1
    y
    

    There are some natural coercion to Pygen elements:

    sage: from giacpy import *
    sage: libgiac(pi)>3.14 ; libgiac(pi) >3.15 ; libgiac(3)==3
    True
    False
    True
    
  • Lists of Pygen and Giac lists:

    Here l1 is a giac list and l2 is a python list of Pygen type objects.

    sage: from giacpy import *
    sage: l1=libgiac(range(10)); l2=[1/(i^2+1) for i in l1]
    sage: sum(l2)
    33054527/16762850
    

    So l1+l1 is done in giac and means a vector addition. But l2+l2 is done in Python so it is the list concatenation.

    sage: from giacpy import *
    sage: l1+l1
    [0,2,4,6,8,10,12,14,16,18]
    sage: l2+l2
    [1, 1/2, 1/5, 1/10, 1/17, 1/26, 1/37, 1/50, 1/65, 1/82, 1, 1/2, 1/5, 1/10, 1/17, 1/26, 1/37, 1/50, 1/65, 1/82]
    

    Here V is not a Pygen element. We need to push it to giac to use a giac method like dim, or we need to use an imported function.

    sage: from giacpy import *
    sage: V=[ [x[i]^j for i in range(8)] for j in range(8)]
    sage: libgiac(V).dim()
    [8,8]
    sage: libgiac.det_minor(V).factor()
    (x[6]-(x[7]))*(x[5]-(x[7]))*(x[5]-(x[6]))*(x[4]-(x[7]))*(x[4]-(x[6]))*(x[4]-(x[5]))*(x[3]-(x[7]))*(x[3]-(x[6]))*(x[3]-(x[5]))*(x[3]-(x[4]))*(x[2]-(x[7]))*(x[2]-(x[6]))*(x[2]-(x[5]))*(x[2]-(x[4]))*(x[2]-(x[3]))*(x[1]-(x[7]))*(x[1]-(x[6]))*(x[1]-(x[5]))*(x[1]-(x[4]))*(x[1]-(x[3]))*(x[1]-(x[2]))*(x[0]-(x[7]))*(x[0]-(x[6]))*(x[0]-(x[5]))*(x[0]-(x[4]))*(x[0]-(x[3]))*(x[0]-(x[2]))*(x[0]-(x[1]))
    
  • Modular objects with %

    sage: from giacpy import * sage: V=libgiac.ranm(5,6) % 2; sage: V.ker().rowdim()+V.rank() 6 sage: a=libgiac(7)%3;a;a%0;7%3 1 % 3 1 1

    Do not confuse with the python integers:

    sage: type(7%3)==type(a);type(a)==type(7%3) False False

  • Syntaxes with reserved or unknown Python/sage symbols:

    In general equations needs symbols such as = < > or that have another meaning in Python. So those objects must be quoted.

    sage: from giacpy import *
    sage: x=libgiac('x')
    sage: (1+2*sin(3*x)).solve(x).simplify()
    Warning, argument is not an equation, solving 1+2*sin(3*x)=0
    list[-pi/18,7*pi/18]
    
    sage: libgiac.solve('sin(3*x)>2*sin(x)',x)        
    ...
    RuntimeError: Unable to find numeric values solving equation. For trigonometric equations this may be solved using assumptions, e.g. assume(x>-pi && x<pi) Error: Bad Argument Value
    

    You can also add some hypothesis to a giac symbol:

    sage: libgiac.assume(‘x>-pi && x<pi’) x sage: libgiac.solve(‘sin(3*x)>2*sin(x)’,x) list[((x>(-5*pi/6)) and (x<(-pi/6))),((x>0) and (x<(pi/6))),((x>(5*pi/6)) and (x<pi))]

    To remove those hypothesis use the giac function: purge

    sage: libgiac.purge(‘x’) assume[[],[line[-pi,pi]],[-pi,pi]] sage: libgiac.solve(‘x>0’) list[x>0]

    Same problems with the ..

    sage: from pygiac import *
    sage: x=libgiac('x')
    sage: f=1/(5+cos(4*x));f.int(x)
    1/2/(2*sqrt(6))*(atan(2*tan(4*x/2)/sqrt(6))+pi*floor(4*x/2/pi+1/2))
    sage: libgiac.fMax(f,'x=-0..pi').simplify()
    pi/4,3*pi/4
    sage: libgiac.fMax.help()  
    "Returns the abscissa of the maximum of the expression.
    Expr,[Var]
    fMax(-x^2+2*x+1,x)
    fMin"
    sage: libgiac.sum(1/(1+x^2),'x=0..infinity').simplify()
    (pi*exp(pi)^2+pi+exp(pi)^2-1)/(2*exp(pi)^2-2)
    
}}} {{{id=5| giacsettings? ///

File: /usr/local/sage-5.10/devel/sage/sage/libs/giac/giacpy.pyx

Type: <type ‘sage.libs.giac.giacpy.GiacSetting’>

Definition: giacsettings(*args)

Docstring:

A class to customise the Computer Algebra System settings

  • property digits:

    Default digits number used for approximations:

    sage: from giacpy import giacsettings,libgiac
    sage: giacsettings.digits=20;giacsettings.digits
    20
    sage: libgiac.approx('1/7')
    0.14285714285714285714
    sage: giacsettings.digits=12;
    
  • property eval_level:

    Recursive level of substitution of variables during an evaluation:

    sage: from giacpy import giacsettings,libgiac
    sage: giacsettings.eval_level=1
    sage: libgiac("purge(a):;b:=a;a:=1;b")
    "Done",a,1,a
    sage: giacsettings.eval_level=25; giacsettings.eval_level
    25
    sage: libgiac("purge(a):;b:=a;a:=1;b")
    "Done",a,1,1
    
  • property proba_epsilon:

    Maximum probability of a wrong answer with a probabilist algorithm. Set this number to 0 to disable probabilist algorithms (slower):

    sage: from giacpy import giacsettings,libgiac
    sage: giacsettings.proba_epsilon=0;libgiac('proba_epsilon')
    0.0
    sage: giacsettings.proba_epsilon=10^(-13)
    sage: libgiac('proba_epsilon')<10^(-14)
    False
    
  • property epsilon:

    Value used by the epsilon2zero function:

    sage: from giacpy import giacsettings,libgiac
    sage: giacsettings.epsilon=1e-10
    sage: P=libgiac('1e-11+x+5')
    sage: P==x+5
    False
    sage: (P.epsilon2zero()).simplify()
    x+5
    
}}} {{{id=6| /// }}}