Skip to main content

A Cython frontend to the c++ library giac. (Computer Algebra System)

Project description

=============
Giacpy
=============

: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

------------
Introduction
------------

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.

- http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
- It is build on C and C++ libraries:
PARI, NTL (arithmetic), CoCoA (Groebner basis), 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, sommation...
- Linear Algebra with numerical or symbolic coefficients.


* 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


-----------
Short Usage
-----------

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)


-------
Install
-------

* 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)


-----------------------------------
Short Tutorial on the giac function
-----------------------------------

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)


Coercion, Pygen and internal giac variables:
--------------------------------------------

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

>>> 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)


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

>>> type(y);giac('y:=1');y
<type 'giacpy.Pygen'>
1
y

* There are some natural coercion to Pygen elements:

>>> pi>3.14 ; pi >3.15 ; giac(3)==3
True
False
True


Lists of Pygen and Giac lists:
------------------------------

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

>>> 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]


* 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.

>>> 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]))

* Modular objects with %

>>> 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'>

Syntaxes with reserved or unknown Python symbols:
-------------------------------------------------

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

>>> 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


* You can also add some hypothesis to a giac symbol:

>>> 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))]

* To remove those hypothesis use the giac function: purge

>>> purge('x')
assume[[],[line[-pi,pi]],[-pi,pi]]
>>> solve('x>0')
list[x>0]


* Same problems with the ..

>>> 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)





---------
Changelog
---------


* Version 0.2:
- Add a comparison function to Pygen. (with coersion)
- Add a basic definition for most giac functions.
- Add some help.

* Version 0.2.1:
- Add __neg__ and __pos__ support for Pygen. (Ex: -pi)
- Change __repr__ to hide too long outputs.
- Make ** be the default printing for powers in giac.

* Version 0.2.2:
- Change Pygen() to Pygen('NULL'). (Ex: rand())
- Add direct acces to the python double value of a Pygen: a._double
- Add conversion to giac modulars via the operator %
- Add ctrl-c support during list initialisation and iteration
- Modification of __getitem__ to allow formal variables with indexes.
- Add htmlhelp method for Pygen objects.
- Improve the giac initialisation of Python long integers. (basic Horner method instead of strings)
- Improve help(giac) and doctests
- Add support for the slice notation with giac lists

* Version 0.2.3:
- Fix Pygen() None initialisation. Add crash test and improve speed in _wrap_gen
- Add a small Makefile
- Add a GiacSettings class with some frontends to the cas settings.
- Add French keywords

* Version 0.2.4:
- Update giac 1.1 keywords.

* Version 0.3:
- Add a qt output for 2d graphics via qcas.
- Fixes for giac 1.1

* Version 0.4:
- Fixes for Python 3 compatibility
- Qt/qcas can be disabled at compilation. (cf setup.py)
- 0.4.1:
+ add some giac keywords.
+ add proba_epsilon in GiacSetting.
+ test if the html doc is present locally, otherwise open the web doc.
- 0.4.2:
+ add digits and epsilon in GiacSetting.
+ Fix for interruptions of giac operators.
+ Put all the GiacKeywords in a new class: GiacFunction to enable docstrings from giac.
- 0.4.3:
+ Update qcas to current version. (svg export added)
+ New evaluation with threads to have better interruptions.
- 0.4.4:
+ Add sqrt and complex flags in giac settings.
+ Add support for multi indexes. Ex A[1,2].

* Version 0.5:
- 0.5.0:
+ Put all the Qt/Graphics functions in an independant submodule
+ Add a save method for Pygen and a loadgiacgen function.
- 0.5.2:
+ Update keywords and clean __init__.py docstring
- 0.5.3:
+ improve setup.py for mingw built
- 0.5.4:
+ update giac.dll windows binary to giac 1.2.3-57 with subsop patch
and rowreduction-R55929 patch
+ post1: update win64 giac.dll to fix: interface with pari; matrix mul
for integers

* Version 0.6:
- 0.6.0:
+ add a __setitem__ for Pygen elements. Ex: A[1,2]=3
+ add Linear algebra tutorial in the giac docstring.
- 0.6.1:
+ update giac keywords.
- 0.6.2:
+ add _repr_html_ and _repr_latex_ for jupyter output
+ rebuild giac.dll without ntl.
- 0.6.3:
+ fix for randseed, srand
+ update keywords
+ remove qcas from tree; libqcas
- 0.6.4:
+ try to guess qt install from qmake
+ upgrade giac.dll to 1.4.9.43
+ fix keywords update
- 0.6.5:
+ Add GPL-2 in MANIFEST.in
- 0.6.6:
+ disable include_package_data in setup.py to not install *.cpp files
and remove from install directory other source files that are not needed
by python nor by cython users.
+ windows rebuilt with giac-1.4.9-45 with NTL enabled
- 0.6.7:
+ udapte keywords for giac 1.5.0
+ update windows built with giac-1.5.0-3 with NTL+glpk+nauty enabled

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

giacpy-0.6.7.tar.gz (443.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

giacpy-0.6.7-cp37-cp37m-win_amd64.whl (17.5 MB view details)

Uploaded CPython 3.7mWindows x86-64

giacpy-0.6.7-cp37-cp37m-win32.whl (16.1 MB view details)

Uploaded CPython 3.7mWindows x86

giacpy-0.6.7-cp36-cp36m-win_amd64.whl (17.5 MB view details)

Uploaded CPython 3.6mWindows x86-64

giacpy-0.6.7-cp36-cp36m-win32.whl (16.1 MB view details)

Uploaded CPython 3.6mWindows x86

giacpy-0.6.7-cp35-cp35m-win_amd64.whl (17.5 MB view details)

Uploaded CPython 3.5mWindows x86-64

giacpy-0.6.7-cp35-cp35m-win32.whl (16.1 MB view details)

Uploaded CPython 3.5mWindows x86

giacpy-0.6.7-cp34-cp34m-win_amd64.whl (17.5 MB view details)

Uploaded CPython 3.4mWindows x86-64

giacpy-0.6.7-cp34-cp34m-win32.whl (16.1 MB view details)

Uploaded CPython 3.4mWindows x86

giacpy-0.6.7-cp27-cp27m-win_amd64.whl (17.4 MB view details)

Uploaded CPython 2.7mWindows x86-64

giacpy-0.6.7-cp27-cp27m-win32.whl (16.1 MB view details)

Uploaded CPython 2.7mWindows x86

File details

Details for the file giacpy-0.6.7.tar.gz.

File metadata

  • Download URL: giacpy-0.6.7.tar.gz
  • Upload date:
  • Size: 443.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7.tar.gz
Algorithm Hash digest
SHA256 e3117a14c31eeefe4631b2a917de4f26429fda82fffed3be6d1768b2f8393e0f
MD5 ef35f911693381fb6dd64af7cee02c6f
BLAKE2b-256 72851237f3a642a20459113732954aae89e1d1ae0c19885af3eb9f548810f90e

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 17.5 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for giacpy-0.6.7-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 9f7ecfada98a7e2ec3b1aa2bb5875bde6c0750f520b30fe0e9569094b8fdec0a
MD5 5aebfd5ba9bbae1862c3ed662bc7ff57
BLAKE2b-256 f05ad8a4cc5b2d83ac7a7013a613535dc6906a5176568bb2acb823d2d94cb973

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp37-cp37m-win32.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 16.1 MB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for giacpy-0.6.7-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 7b925e86dca56cb0188e8cc933d883e7bab7bc3c9f76cf2dda942263f076fdb9
MD5 4dd463e0ebe31b53df44cecbc6b33f00
BLAKE2b-256 1fc3426a77dc71054529cd28888283395d285b7d5001738b3e4315a48af2c932

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 17.5 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 5ecd34b281b88fd477e084fb4905be7ebf1f31315977ea36d6eaf7b7b33e1cc6
MD5 062c7466592b536497fe349aaa102cec
BLAKE2b-256 a54cb8b31a59c2c50c59239acdad7b04be03e5904ee9b218360210ba408f476b

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp36-cp36m-win32.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 16.1 MB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 156d56ea8435a6932117d4769a0bb6d74285f9f52b234a08ed8fc90c134b6dfe
MD5 c8579b1244df8c947177d2bb49202517
BLAKE2b-256 5d938c3172090a4a4b90576485faf3ca4f14b3032227f435c3d1ead295d6abed

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 17.5 MB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 384eb96190ca8aa519f87e797317632a8968e25923b17d6ac2c520a86a516eda
MD5 4575c47537fcc40bda241cfd981ecca7
BLAKE2b-256 25056ff69cdc2f1d6409d9705a9296cbf811d023c9f0000fd12406b0e9ad57fd

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp35-cp35m-win32.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 16.1 MB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 5aede8d900a8b8b8088defe1a5da43b40f6111f0e5a186532d94e24823b2333f
MD5 41f1a3a26184ae4c918ecb2968051d99
BLAKE2b-256 a8bf21ba4495c2c138dea13bc8a176515a394d2da0c039743ed7475563d46f8f

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp34-cp34m-win_amd64.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp34-cp34m-win_amd64.whl
  • Upload date:
  • Size: 17.5 MB
  • Tags: CPython 3.4m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 089c8991106142a293c215bf41a8b2b28cc89bd038a761ff15e63a699db85e80
MD5 33feb95f80aa86e529d2c0e0dee5a876
BLAKE2b-256 3279d4d0060da6e61d94f9980c40ce69e53c755810606f2608a012cb37192abd

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp34-cp34m-win32.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp34-cp34m-win32.whl
  • Upload date:
  • Size: 16.1 MB
  • Tags: CPython 3.4m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 5a940528d35d02ac2decf7c8830357f37c309614194652d4891d99189963b429
MD5 1cad73edaae34f000a2073916f843eff
BLAKE2b-256 0510d1efa05e72f04650f0b92e0b3a81631c877af9117e8550ee80af52e79455

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 17.4 MB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 37d5cc95d80e3c03673daa62c7649795a3f2579b033b3d8c91af351546c24df2
MD5 9625c6628ef9c38fc33b6e9b35745998
BLAKE2b-256 ba6de0dba7e948456c5ea371e406438881a4c9a3bef0a69ed00f491922af95ae

See more details on using hashes here.

File details

Details for the file giacpy-0.6.7-cp27-cp27m-win32.whl.

File metadata

  • Download URL: giacpy-0.6.7-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 16.1 MB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.3.2 requests/2.18.4 setuptools/37.0.0 requests-toolbelt/0.8.0 tqdm/4.19.6 CPython/2.7.15

File hashes

Hashes for giacpy-0.6.7-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 2b7ea0dc54af4fa53446e2d0a40215e8ed994bf9d259bb31d4661ecbde6dbba7
MD5 5a88f96b811256ff8753f10387dd9cdd
BLAKE2b-256 43ee28a076f1cf07f118c4ba43b0a4f48002a23430281b3b68136bd4c474a709

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page