
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
giacpy
Advanced tools
:Name: giacpy :Summary: A Cython frontend to the c++ library giac. (Computer Algebra System) :Author: Frederic Han :Author-email: frederic.han@imj-prg.fr :Copyright: 2012 Frederic Han :License: GPL v2 or above :Home-page: https://www.imj-prg.fr/~frederic.han/xcas/giacpy/
Access from python to the Computer Algebra System giac via libgiac
This is an interface to be able to use from Python the Giac features.
Giac is a general purpose Computer algebra system by Bernard Parisse released under GPLv3.
giacpy is an interface to this library. It is built with cython. Graphic output is obtained with qcas by Loic Lecoq: http://git.tuxfamily.org/qcas/qcas.git
Example::
>>> import giacpy # outputs various messages
Help file ... aide_cas not found
Added 0 synonyms
>>> giacpy.ifactor(2**128+1)
59649589127497217*5704689200685129054721
>>> from giacpy import giac
>>> x,y,z=giac('x,y,z')
>>> f=(x+y+z+1)**15+1
>>> g=(f*(f+1)).normal()
>>> print g.nops()
>>> print g.factor().nops()
>>> f.diff()
Help::
>>> help("giacpy")
>>> from giacpy import normal
>>> print(normal.__doc__) ; # to have help on some giac keyword
>>> solve.htmlhelp('fr') ; # (may be not avaible on your system) to have detailled help on some giac keyword
>>> htmlhelp() ; # to have help the global help pages.
* Graphics 2D Output: (cf. help('giacpy') for examples)
If your version of giacpy has qt support, you can send graphics to qcas with the .qcas() method. For experimental interactive geometry see: help(qcas)
To build the extension from sources (unix):
You need the giac library, gmp and python headers. Ex: giac, libgmp-dev python-dev
Then execute the command: python setup.py build_ext (or try the: make or make local)
If you need some options see: python setup.py build_ext --help
To install giacpy on unix (needs libgiac): python setup.py install
For binaries of giacpy: http://webusers.imj-prg.fr/~frederic.han/xcas/giacpy/
To run tests you can try: make test or run: python -m doctest giacpy.pyx -v (in the directory of giapy.so if it is not installed)
This function evaluate a python object with the giac library.
* It creates in python a Pygen element and evaluate it with giac:
>>> from giacpy import giac,pi
>>> x,y=giac('x,y');type(x)
<type 'giacpy.Pygen'>
>>> (x+2*y).cos().texpand()
cos(x)*(2*cos(y)**2-1)-sin(x)*2*cos(y)*sin(y)
>>> from giacpy import *
>>> x,y,z=giac('x,y,z')
>>> 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)
>>> type(y);giac('y:=1');y
<type 'giacpy.Pygen'>
1
y
>>> pi>3.14 ; pi >3.15 ; giac(3)==3
True
False
True
>>> l1=giac(range(10)); l2=[1/(i**2+1) for i in l1]
>>> 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.
>>> l1+l1
[0,2,4,6,8,10,12,14,16,18]
>>> 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]
>>> V=[ [x[i]**j for i in range(9)] for j in range(9)]
>>> giac(V).dim()
[9,9]
>>> det_minor(V).factor()
(x[7]-(x[8]))*(x[6]-(x[8]))*(x[6]-(x[7]))*(x[5]-(x[8]))*(x[5]-(x[7]))*(x[5]-(x[6]))*(x[4]-(x[8]))*(x[4]-(x[7]))*(x[4]-(x[6]))*(x[4]-(x[5]))*(x[3]-(x[8]))*(x[3]-(x[7]))*(x[3]-(x[6]))*(x[3]-(x[5]))*(x[3]-(x[4]))*(x[2]-(x[8]))*(x[2]-(x[7]))*(x[2]-(x[6]))*(x[2]-(x[5]))*(x[2]-(x[4]))*(x[2]-(x[3]))*(x[1]-(x[8]))*(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[8]))*(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]))
>>> V=ranm(5,5) % 2;
>>> ker(V).rowdim()+V.rank()
5
>>> a=giac(7)%3;a;a%0;7%3
1 % 3
1
1
Do not confuse with the full python integers:
>>> type(7%3);type(a)
<type 'int'>
<type 'giacpy.Pygen'>
>>> from giacpy import *
>>> x=giac('x')
>>> (1+2*sin(3*x)).solve(x)
list[-pi/3/6,7*pi/18]
>>> solve('sin(3*x)>2*sin(x)',x)
Traceback (most recent call last):
...
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
>>> assume('x>-pi && x<pi')
x
>>> 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))]
>>> purge('x')
assume[[],[line[-pi,pi]],[-pi,pi]]
>>> solve('x>0')
list[x>0]
>>> from giacpy import *
>>> x=giac('x')
>>> 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))
>>> fMax(f,'x=-0..pi').simplify()
pi/4,3*pi/4
>>> fMax.help()
"Returns the abscissa of the maximum of the expression.
Expr,[Var]
fMax(-x^2+2*x+1,x)
fMin"
>>> sum(1/(1+x**2),'x=0..infinity').simplify()
(pi*exp(pi)**2+pi+exp(pi)**2-1)/(2*exp(pi)**2-2)
Version 0.2:
Version 0.2.1:
Version 0.2.2:
Version 0.2.3:
Version 0.2.4:
Version 0.3:
Version 0.4:
Version 0.5:
Version 0.6:
Version 0.7:
FAQs
A Cython frontend to the c++ library giac. (Computer Algebra System)
We found that giacpy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.