File: cas.tex

package info (click to toggle)
giac 1.9.0.93%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 117,732 kB
  • sloc: cpp: 404,272; ansic: 205,462; python: 30,548; javascript: 28,788; makefile: 17,997; yacc: 2,690; lex: 2,464; sh: 705; perl: 314; lisp: 216; asm: 62; java: 41; xml: 36; sed: 16; csh: 7; pascal: 6
file content (243 lines) | stat: -rw-r--r-- 10,561 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
\documentclass{article}
\begin{document}
\section{Installation}
Insure that you have installed GMP, FLTK, optionnaly GSL, NTL and PARI 
and you that have a recent version  of {\tt gcc} (e.g. 2.95, 2.96, note
that GCC 3.0 will compile GMP but not FLTK AFAIK).
Then~:\\
{\tt tar xvfz giac-0.2.2.tar.gz}\\
{\tt cd giac-0.2.2} \\
{\tt ./configure --enable-fltk-support --enable-debug-support} \\
{\tt make}\\
Now become {\tt root}:\\
{\tt su}\\
and eventually~:\\
{\tt make install}

\section{Using the {\tt cas} command.}
You can invoke {\tt cas} directly from the command line (in an {\tt xterm}
window for example). But (except for very simple input) you must
quote the arguments so that the shell does not interpret badly parentheses
or {\tt *}, ....
For example~:
\verb|cas 'factor(x^3-1)'|\\
Or you can call \verb|factor| as a command, like~:\\
\verb|factor x^3-1|\\
Note that you don't require quote here since argument can not be interpreted
by the shell.

You can also put a filename instead of an argument. Then all commands
in this filename will be executed. For example, using your favorite
editor (e.g. emacs) create a file named {\tt test} containing:
\begin{verbatim}
factor(x^100-1);
rref([[1,2,3],[4,5,6]])
\end{verbatim}
(note that you don't have to quote inside a file) and run~:\\
{\tt cas test}

If you want to assign variables a value, just make a file having the
variable name with the value of the variable in the file. For example, edit a
file named {\tt mat}, write {\tt [[1,2,3],[4,5,6]]}, save the file
and try one of the following command~:\\
{\tt cas 'ker(mat)'}\\
{\tt ker mat}

You can store the result of a {\tt cas} command using the usual redirection
symbol, for example~:\\
{\tt ker mat > kermat}
will create a file named {\tt kermat} that you can use as a variable name
later. You can also pipe the result of a command as argument of 
another command, e.g.~:\\
\verb?gcd x^4-1 x^6-1 | factor?

The syntax is as similar as possible to usual CAS (especially HP49/40G CAS). 
Vectors are delimited by {\tt [ ]} and coordinates are separated by {\tt ,}.
Matrices are vectors of vectors.

If you want to know how much time was needed to evaluate your cas query,
just define the environment variable \verb|SHOW_TIME|, if your shell is
\verb|tcsh|~:\\
\verb|setenv SHOW_TIME 1|\\
will define the environment variable and\\
\verb|unsetenv SHOW_TIME|\\
will undefine it. With \verb|bash|,\\
\verb|export SHOW_TIME=1|\\
defines the variable and\\
\verb|unset SHOW_TIME|\\
undefines the variable.

Currently implemented~:
\begin{enumerate}
\item usual arithmetic on integers, reals, complex, vectors and matrices:
{\tt abs},  {\tt arg},  {\tt conj},
{\tt evalf},  {\tt im}, {\tt inv},  {\tt max}, {\tt min}, 
{\tt re}, {\tt sign},  {\tt sqrt}.
For the usual operations, since {\tt *} is interpreted by the shell, 
you must quote {\tt '*'} or escape \verb|\*| the multiplication symbol. 
For division, I use currently the quoted or escaped symbol {\tt \%}, this
is likely to change.
\item more advanced arithmetic: {\tt cyclotomic}, {\tt egcd}, {\tt gcd}, 
{\tt ichinrem}, {\tt iquo}, {\tt irem}, \verb|is_prime| (returns 2 if
certainly prime, 0 if not prime, 1 if probably prime), 
{\tt nextprime}, {\tt prevprime}, {\tt jacobi}, {\tt legendre}, {\tt smod}.
\item transcendental functions: {\tt acos}, {\tt acosh}, {\tt alog},  
{\tt asin}, {\tt asinh}, {\tt atan}, {\tt atanh}, 
{\tt cos}, {\tt cosh}, {\tt exp}, {\tt Log}, {\tt log10},  
{\tt sin}, {\tt sinh}, {\tt tan}, {\tt tanh}. 
\item polynomial functions: {\tt normal}: rational simplification \\
{\tt factor}: factorization over the integers or Gau\ss\ integers\\
{\tt partfrac}: partial fraction expansion \\
{\tt resultant}: resultant of 2 polynomials \\
{\tt solve}: solving polynomial-like equations
\item rewriting functions: {\tt fdistrib} (full distribute $\times$ over $+$)\\
 {\tt simplify}: currently rational simplification only \\
{\tt texpand}, {\tt tlin}: trigonometric expansion and linearization
\item calculus: {\tt derive}: derivation\\
{\tt lim}, {\tt series} : limits and series expansion \\
{\tt integrate}: integration of rational fractions
\item linear algebra: {\tt rref}, {\tt ker}, {\tt image}, {\tt det}, 
{\tt pcar}, {\tt trace}, {\tt tran}, {\tt egv}, {\tt egvl}, 
{\tt jordan}.
\item conversion functions: {\tt e2r} (entier to rational) and
{\tt r2e} (rational to entier). They expect a list of variables with
respect to which the expression should be a rational fraction, you can
use {\tt lname} or {\tt lvar} to get this list. The internal format
for rational fractions is parsed directly from the command line:
\begin{itemize}
\item integers, Gau\ss\ integers: usual notation ({\tt 2}, {\tt 3-5*i})  
\item dense univariate polynomial: like a vector with coefficients
by descending power ({\tt [1,2,3]} for $x^2+2x+3$) 
\item sparse univariate polynomial and series expansion: a sum of
monomials, each monomial is a couple of coefficient and exponent separated
by {\tt ,}, e.g. {\tt \{1,1/2\}+\{2,3\}} for $x^{1/2}+2x^3$. For
a series expansion, use {\tt undef} as coefficient for the remainder
term.
\item sparse multivariate polynomials: same notation, but the second
term of the couple is a vector of indices, the powers of the variables
in the monomial, e.g. {\tt \{ 2,[1,3]\} }, for the 2-d polynomial
$2xy^3$ with respect to the list of variables $[x,y]$.
\item (internal) algebraic extension objects. Similar notation, but
use {\tt :} instead of {\tt ,}. The first term of the couple is a
polynomial with respect to an algebraic integer $\theta$, defined by the second
term of the couple. This second term might be the minimal polynomial
of $\theta$ or another extension with as first term an approximate
value or an index and second term the minimal polynomial in order to
differentiate the different roots of the minimal polynomial. The
minimal polynomial is a dense univariate polynomial.
For second order extension, there are only two models of monic minimal
polynomials used: $x^2-d$ if $d \neq 1 \pmod 4$ and $x^2-x=\frac{d-1}{4}$
otherwise and by convention $\theta=\sqrt{d}$ in the first case
or $\theta=\frac{1+\sqrt{d}}{2}$. This to insure that every monic polynomial
of second order can be factored over such an extension without introducing
fractions.
\item Fractions: using the {\tt /} division sign.
\end{itemize}
\end{enumerate}

A somewhat more complex example~:\\
\verb? ( sin x ; tan x ) | \% | lim?\\
We first compute $\sin(x)$ and $\tan(x)$, then we pipe both answer to the
division function and pipe the result to the limit function.
This is equivalent to~:\\
\verb|lim 'sin(x)/tan(x)'|\\
but it demonstrates how it is possible to build expressions using the
shell syntax: the shell is used as a polish notation calculator with
mixed syntax (infix for sin and tan, reverse polish notation when we pipe).
This gives some flexibility to make small programs using the shell.

A final example: open a file {\tt testjordan} and write~:
\begin{verbatim}
[[1,1,-1,2,-1],\
 [2,0,1,-4,-1],\
 [0,1,1,1,1],\
 [0,1,2,0,1],\
 [0,0,-3,3,-1]]
\end{verbatim}
then write the command~:\\
{\tt ( jordan testjordan ; cas p j ) | sto }\\
or {\tt cas 'sto(jordan(testjordan),[p,j])'}
that will compute the Jordan decomposition of the matrix and store the
passage matrix in {\tt p} and the Jordan normal form in {\tt j}.
If you want to check that $p j p^{-1}$ is the original matrix,
you can write the following command~:\\
\verb?cas p j 'inv(p)' | \* | normal ?\\
or {\tt cas 'normal(p*j*inv(p))'}

\section{\TeX\ translation}
The \LaTeX\ translation of the commands are logged in the file 
{\tt session.tex} in the current directory except when you set the
\verb|SHOW_TIME| environment variables. They require a preamble that
you can copy from the file {\tt doc/preamble.tex}.

Note that every new command is appended to {\tt session.tex}, it is
a good idea to remove this file from time to time.

You can translate formulas in \LaTeX\ using the {\tt cas2tex} command
and get directly a compilable \LaTeX\ source file.
For example~:\\
{\tt cas2tex '[[1,2],[3,4]]' > essai.tex}\\
followed by~:\\
{\tt latex essai.tex}\\
Or in one step~:\\
{\tt cas2tex '[[1,2],[3,4]]' | latex --}\\
(this produces the file {\tt texput.dvi})

\section{Programming in C++}
First example~:
\begin{verbatim}
#include <giac/giac.h>
using namespace std;
using namespace giac;

int main(){
  gen e(string("x^2-1"));
  cout << factor(e) << endl;
}
\end{verbatim}
Write this as {\tt essai.cc} and compile it~:\\
{\tt g++ -g essai.cc -lgiac -lgmp}\\
and run it~:\\
{\tt ./a.out}

\subsection{Organization of the source code}
Note that you can use \verb|#include <giac/giac.h>| to include all headers
of the library.
\begin{itemize}
\item \verb|gen.cc/.h|: arithmetic operations on the base class entier
\item \verb|identificateur.cc/.h|: global name 
\item \verb|unary.cc/.h|: unary operators class including non unary operations
viewed as unary operation on the vector of it's arguments
\item \verb|symbolic.cc/.h|: symbolic object class
\item \verb|usual.cc/.h| Usual unary operations 
\item \verb|vecteur.cc/.h|: linear algebra
\item \verb|derive.cc intg.cc lin.cc series.cc subst.cc/.h|: Calculus.
Derive is OK as well as rational fraction integration, the rest has 
to be implemented
\item \verb|moyal.cc/.h|: pseudo-diff operators
\item \verb|tex.cc/.h|: \LaTeX\ conversion
\item \verb|sym2poly.cc/.h|: conversion polynomials to symbolic
\item \verb|index.cc/index.h|: class for indexation of multivariate tensors
\item \verb|poly.h, monomial.h|: multivariate template class tensors
\item \verb|gausspol.cc/.h|: specialization of template tensors 
to entier coeffs
\item \verb|input_parser.yy input_lexer.ll input_lexer.h|: parser 
\item \verb|modpoly.cc/.h|: univariate dense polynomials over integers 
and modular integers (Warning: gcd-like functions do not work if non 
modular arithmetic)
\item \verb|modfactor.cc/.h|: 
factorization of univariate dense square-free polynomials
(Requires NTL or PARI for lll and knapsack to be full speed functional)
\item \verb|series.cc/.h|: 
series expansion and limits using the mrv algorithm.
\end{itemize}

See {\tt giac.texinfo} for a short description of the classes available.
Some examples of programs are provided: {\tt src/factor.cc}, 
{\tt src/normalize.cc},
{\tt src/cas.cc}, {\tt src/partfrac.cc} and {\tt src/integrate.cc}.
To compile these programs, you can either use~:\\
\verb|g++ -g |{\em name.cc\/} \verb| -lgmp -lgiac|\\
or launch \verb|emacs| and run it's compile command (menu Tools).

\end{document}