README.txt 11 KB
Newer Older
Han Frederic's avatar
Han Frederic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

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

22
This is an interface to be able to use from Python the Giac features.
Han Frederic's avatar
Han Frederic committed
23 24 25 26

   * Giac is a general purpose Computer algebra system by Bernard Parisse released under GPLv3.

      - http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
27 28 29
      - It is build on C and C++ libraries:
        PARI, NTL (arithmetic), CoCoA (Groebner basis), GSL (numerics),
        GMP (big integers), MPFR (bigfloats)
Han Frederic's avatar
Han Frederic committed
30 31 32 33 34
      - 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.


Frederic HAN's avatar
MAJ doc  
Frederic HAN committed
35
   * 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
Han Frederic's avatar
Han Frederic committed
36 37 38 39 40 41 42 43


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

Example::

Frederic HAN's avatar
MAJ doc  
Frederic HAN committed
44 45 46 47 48
    >>> import giacpy  # outputs various messages
    Help file ... aide_cas not found
    Added 0 synonyms
    >>> giacpy.ifactor(2**128+1)
    59649589127497217*5704689200685129054721
Han Frederic's avatar
Han Frederic committed
49 50 51 52 53 54 55 56 57 58 59
    >>> 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")
Frederic HAN's avatar
MAJ doc  
Frederic HAN committed
60 61 62
    >>> 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
Han Frederic's avatar
Han Frederic committed
63 64 65 66 67 68 69 70 71 72 73
    >>> 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
-------

Frederic HAN's avatar
MAJ doc  
Frederic HAN committed
74
   * To build the extension from sources (unix):
Han Frederic's avatar
Han Frederic committed
75 76

      - You need the giac library, gmp and python headers. Ex: giac, libgmp-dev python-dev
77

Han Frederic's avatar
Han Frederic committed
78 79 80 81 82 83
      - 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

Frederic HAN's avatar
MAJ doc  
Frederic HAN committed
84
   * For binaries of giacpy: http://webusers.imj-prg.fr/~frederic.han/xcas/giacpy/
Han Frederic's avatar
Han Frederic committed
85 86 87 88 89 90 91 92 93 94 95 96 97

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

98

Han Frederic's avatar
Han Frederic committed
99 100 101 102 103 104 105 106 107 108 109 110
     >>> 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.

111
    >>> from giacpy import *
Han Frederic's avatar
Han Frederic committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    >>> 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.
150

Han Frederic's avatar
Han Frederic committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    >>> 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:
168

Han Frederic's avatar
Han Frederic committed
169 170 171 172 173 174 175
    >>> type(7%3);type(a)
    <type 'int'>
    <type 'giacpy.Pygen'>

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

176
   * In general equations needs symbols such as = < > or that have another meaning in Python. So those objects must be quoted.
Han Frederic's avatar
Han Frederic committed
177 178 179 180 181 182 183 184 185 186

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

Han Frederic's avatar
Han Frederic committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

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

203

Han Frederic's avatar
Han Frederic committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
   * 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
---------


229 230
   * Version 0.2:
      - Add a comparison function to Pygen. (with coersion)
Han Frederic's avatar
Han Frederic committed
231 232 233
      - Add a basic definition for most giac functions.
      - Add some help.

234
   * Version 0.2.1:
Han Frederic's avatar
Han Frederic committed
235 236 237 238
      - 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.

239
   * Version 0.2.2:
Han Frederic's avatar
Han Frederic committed
240 241 242 243 244 245 246 247 248 249
      - 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

250
   * Version 0.2.3:
Han Frederic's avatar
Han Frederic committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
      - 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.
268
      	  + add proba_epsilon in GiacSetting.
Han Frederic's avatar
Han Frederic committed
269 270 271 272 273 274 275 276 277 278 279
	  + 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].
280 281 282 283

   * Version 0.5:
      - 0.5.0:
          + Put all the Qt/Graphics functions in an independant submodule
284
          + Add a save method for Pygen and a loadgiacgen function.
Frederic HAN's avatar
0.5.2  
Frederic HAN committed
285 286
      - 0.5.2:
          + Update keywords and clean __init__.py docstring
287 288
      - 0.5.3:
          + improve setup.py for mingw built
Frederic HAN's avatar
0.5.4  
Frederic HAN committed
289 290 291
      - 0.5.4:
          + update giac.dll windows binary to giac 1.2.3-57 with subsop patch
	    and rowreduction-R55929 patch
292
          + post1: update win64 giac.dll to fix: interface with pari; matrix mul
Frederic HAN's avatar
Frederic HAN committed
293
            for integers
Frederic HAN's avatar
Frederic HAN committed
294 295 296 297

   * Version 0.6:
      - 0.6.0:
          + add a __setitem__ for Pygen elements. Ex: A[1,2]=3
Frederic HAN's avatar
Frederic HAN committed
298
	  + add Linear algebra tutorial in the giac docstring.
299 300
      - 0.6.1:
          + update giac keywords.
Frederic HAN's avatar
0.6.2  
Frederic HAN committed
301 302 303
      - 0.6.2:
          + add _repr_html_ and _repr_latex_ for jupyter output
	  + rebuild giac.dll without ntl.
Frederic HAN's avatar
Frederic HAN committed
304 305
      - 0.6.3:
          + fix for randseed, srand
Frederic HAN's avatar
Frederic HAN committed
306
	  + update keywords
Frederic HAN's avatar
Frederic HAN committed
307
	  + remove qcas from tree; libqcas
Frederic HAN's avatar
Frederic HAN committed
308
      - 0.6.4:
309
	  + try to guess qt install from qmake
Frederic HAN's avatar
Frederic HAN committed
310
	  + upgrade giac.dll to 1.4.9.43
Frederic HAN's avatar
Frederic HAN committed
311
	  + fix keywords update
Frederic HAN's avatar
Frederic HAN committed
312 313
      - 0.6.5:
	  + Add GPL-2 in MANIFEST.in
314
      - 0.6.6:
Frederic HAN's avatar
Frederic HAN committed
315
          + disable include_package_data in setup.py to not install .cpp files
316 317 318
	    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
319 320 321
      - 0.6.7:
          + udapte keywords for giac 1.5.0
	  + update windows built with giac-1.5.0-3 with NTL+glpk+nauty enabled
Frederic HAN's avatar
0.6.8  
Frederic HAN committed
322 323 324
      - 0.6.8:
          + udapte keywords for giac 1.5.0.53
	  + update windows built with giac-1.5.0-49
Frederic HAN's avatar
0.6.9  
Frederic HAN committed
325 326 327
      - 0.6.9:
	  + update windows built with giac-1.5.0-63
          + doctest fix NULL ouput
Frederic HAN's avatar
0.7.0  
Frederic HAN committed
328 329 330
      - 0.7.0:
          + fix a build error with  giac>1.5.0-75
	  + update windows built with giac-1.5.0-85
Frederic HAN's avatar
0.6.9  
Frederic HAN committed
331