]> www.ginac.de Git - ginac.git/blob - ginsh/ginsh.1
- added documentation to ex_to_series() and series_to_poly()
[ginac.git] / ginsh / ginsh.1
1 .TH ginsh 1 "October, 1999" "GiNaC"
2 .SH NAME
3 ginsh \- GiNaC Interactive Shell
4 .SH SYNPOSIS
5 .B ginsh
6 .RI [ file\&... ]
7 .SH DESCRIPTION
8 .B ginsh
9 is an interactive frontend for the GiNaC symbolic computation framework.
10 It is intended as a tool for testing and experimenting with GiNaC's
11 features, not as a replacement for traditional interactive computer
12 algebra systems. Although it can do many things these traditional systems
13 can do, ginsh provides no programming constructs like loops or conditional
14 expressions. If you need this functionality you are advised to write
15 your program in C++, using the "native" GiNaC class framework.
16 .SH USAGE
17 .SS INPUT FORMAT
18 After startup, ginsh displays a prompt ("> ") signifying that it is ready
19 to accept your input. Acceptable input are numeric or symbolic expressions
20 consisting of numbers (e.g.
21 .BR 42 ", " 2/3 " or " 0.17 ),
22 symbols (e.g.
23 .BR x " or " result ),
24 mathematical operators like
25 .BR + " and  " * ,
26 and functions (e.g.
27 .BR sin " or " normal ).
28 Every input expression must be terminated with either a semicolon
29 .RB ( ; )
30 or a colon
31 .RB ( : ).
32 If terminated with a semicolon, ginsh will evaluate the expression and print
33 the result to stdout. If terminated with a colon, ginsh will only evaluate the
34 expression but not print the result. It is possible to enter multiple
35 expressions on one line. Whitespace (spaces, tabs, newlines) can be applied
36 freely between tokens. To quit ginsh, enter
37 .BR quit " or " exit ,
38 or type an EOF (Ctrl-D) at the prompt.
39 .SS NUMBERS
40 ginsh accepts numbers in all formats accepted by CLN (the Class Library for
41 Numbers, that is the foundation of GiNaC's numerics). This includes arbitrary
42 precision integers and rationals as well as floating point numbers in standard
43 or scientific notation (e.g.
44 .BR 1.2E6 ).
45 The general rule is that if a number contains a decimal point
46 .RB ( . ),
47 it is an (inexact) floating point number; otherwise it is an (exact) integer or
48 rational.
49 .SS SYMBOLS
50 Symbols are made up of a string of alphanumeric characters and the underscore
51 .RB ( _ ),
52 with the first character being non-numeric. E.g.
53 .BR a " and " mu_1
54 are acceptable symbol names, while
55 .B 2pi
56 is not. It is possible to use symbols with the same names as functions (e.g.
57 .BR sin );
58 ginsh is able to distinguish between the two.
59 .PP
60 Symbols can be assigned values by entering
61 .RS
62 .IB symbol " = " expression ;
63 .RE
64 .PP
65 To unassign the value of an assigned symbol, type
66 .RS
67 .BI unassign(' symbol ');
68 .RE
69 .PP
70 Assigned symbols are automatically evaluated (= replaced by their assigned value)
71 when they are used. To refer to the unevaluated symbol, put single quotes
72 .RB ( ' )
73 around the name, as demonstrated for the "unassign" command above.
74 .PP
75 The following symbols are pre-defined constants that cannot be assigned
76 a value by the user:
77 .RS
78 .TP 8m
79 .B Pi
80 Archimedes' Constant
81 .TP
82 .B Catalan
83 Catalan's Constant
84 .TP
85 .B EulerGamma
86 Euler-Mascheroni Constant
87 .TP
88 .B I
89 sqrt(-1)
90 .TP
91 .B FAIL
92 an object of the GiNaC "fail" class
93 .RE
94 .PP
95 There is also the special
96 .RS
97 .B Digits
98 .RE
99 symbol that controls the numeric precision of calculations with inexact numbers.
100 Assigning an integer value to digits will change the precision to the given
101 number of decimal places.
102 .SS LAST PRINTED EXPRESSIONS
103 ginsh provides the three special symbols
104 .RS
105 ", "" and """
106 .RE
107 that refer to the last, second last, and third last printed expression, respectively.
108 These are handy if you want to use the results of previous computations in a new
109 expression.
110 .SS OPERATORS
111 ginsh provides the following operators, listed in falling order of precedence:
112 .RS
113 .TP 8m
114 .B !
115 postfix factorial
116 .TP
117 .B ^
118 powering
119 .TP
120 .B +
121 unary plus
122 .TP
123 .B \-
124 unary minus
125 .TP
126 .B *
127 multiplication
128 .TP
129 .B %
130 non-commutative multiplication
131 .TP
132 .B /
133 division
134 .TP
135 .B +
136 addition
137 .TP
138 .B \-
139 subtraction
140 .TP
141 .B <
142 less than
143 .TP
144 .B >
145 greater than
146 .TP
147 .B <=
148 less or equal
149 .TP
150 .B >=
151 greater or equal
152 .TP
153 .B ==
154 equal
155 .TP
156 .B !=
157 not equal
158 .TP
159 .B =
160 symbol assignment
161 .RE
162 .PP
163 All binary operators are left-associative, with the exception of
164 .BR ^ " and " =
165 which are right-associative. The result of the assignment operator
166 .RB ( = )
167 is its right-hand side, so it's possible to assign multiple symbols in one
168 expression (e.g.
169 .BR "a = b = c = 2;" ).
170 .SS LISTS
171 Lists are used by the
172 .B subs
173 and
174 .B lsolve
175 functions. A list consists of an opening square bracket
176 .RB ( [ ),
177 a (possibly empty) comma-separated sequence of expressions, and a closing square
178 bracket
179 .RB ( ] ).
180 .SS MATRICES
181 A matrix consists of an opening double square bracket
182 .RB ( [[ ),
183 a non-empty comma-separated sequence of matrix rows, and a closing double square
184 bracket
185 .RB ( ]] ).
186 Each matrix row consists of an opening double square bracket
187 .RB ( [[ ),
188 a non-empty comma-separated sequence of expressions, and a closing double square
189 bracket
190 .RB ( ]] ).
191 If the rows of a matrix are not of the same length, the width of the matrix
192 becomes that of the longest row and shorter rows are filled up at the end
193 with elements of value zero.
194 .SS FUNCTIONS
195 A function call in ginsh has the form
196 .RS
197 .IB name ( arguments )
198 .RE
199 where
200 .I arguments
201 is a comma-separated sequence of expressions. ginsh provides a couple of built-in
202 functions and also "imports" all symbolic functions defined by GiNaC and additional
203 libraries. There is no way to define your own functions other than linking ginsh
204 against a library that defines symbolic GiNaC functions.
205 .PP
206 ginsh provides Tab-completion on function names: if you type the first part of
207 a function name, hitting Tab will complete the name if possible. If the part you
208 typed is not unique, hitting Tab again will display a list of matching functions.
209 Hitting Tab twice at the prompt will display the list of all available functions.
210 .PP
211 A list of the built-in functions follows. They nearly all work as the
212 respective GiNaC methods of the same name, so I will not describe them in
213 detail here. Please refer to the GiNaC documentation.
214 .PP
215 .RS
216 .BI beta( expression ", " expression )
217 .br
218 .BI charpoly( matrix ", " symbol )
219 .br
220 .BI coeff( expression ", " symbol ", " number )
221 .br
222 .BI collect( expression ", " symbol )
223 .br
224 .BI content( expression ", " symbol )
225 .br
226 .BI degree( expression ", " symbol )
227 .br
228 .BI denom( expression )
229 .br
230 .BI determinant( matrix )
231 .br
232 .BI diag( expression... )
233 .br
234 .BI diff( expression ", " "symbol [" ", " number] )
235 .br
236 .BI divide( expression ", " expression )
237 .br
238 .BI eval( "expression [" ", " number] )
239 .br
240 .BI evalf( "expression [" ", " number] )
241 .br
242 .BI expand( expression )
243 .br
244 .BI gcd( expression ", " expression )
245 .br
246 .BI has( expression ", " expression )
247 .br
248 .BI inverse( matrix )
249 .br
250 .BI is( relation )
251 \- returns "1" if the
252 .I relation
253 is true, "0" otherwise (false or undecided)
254 .br
255 .BI lcm( expression ", " expression )
256 .br
257 .BI lcoeff( expression ", " symbol )
258 .br
259 .BI ldegree( expression ", " symbol )
260 .br
261 .BI lsolve( list ", " list )
262 .br
263 .BI nops( expression )
264 .br
265 .BI normal( "expression [" ", " number] )
266 .br
267 .BI numer( expression )
268 .br
269 .BI op( expression ", " number )
270 .br
271 .BI power( expression ", " expression )
272 .br
273 .BI prem( expression ", " expression ", " symbol )
274 .br
275 .BI primpart( expression ", " symbol )
276 .br
277 .BI quo( expression ", " expression ", " symbol )
278 .br
279 .BI rem( expression ", " expression ", " symbol )
280 .br
281 .BI series( expression ", " "symbol [" ", " "number [" ", " number]] )
282 .br
283 .BI sqrfree( expression ", " symbol )
284 .br
285 .BI sqrt( expression )
286 .br
287 .BI subs( expression ", " relation-or-list )
288 .br
289 .BI subs( expression ", " list ", " list )
290 .br
291 .BI tcoeff( expression ", " symbol )
292 .br
293 .BI time( expression )
294 \- returns the time in seconds needed to evaluate the given
295 .I expression
296 .br
297 .BI trace( matrix )
298 .br
299 .BI transpose( matrix )
300 .br
301 .BI unassign( symbol )
302 .br
303 .BI unit( expression ", " symbol )
304 .RE
305 .SS SPECIAL COMMANDS
306 To exit ginsh, enter
307 .RS
308 .B quit
309 .RE
310 or
311 .RS
312 .B exit
313 .RE
314 .PP
315 The command
316 .RS
317 .BI print( expression );
318 .RE
319 will print a dump of GiNaC's internal representation for the given
320 .IR expression .
321 This is useful for debugging and for learning about GiNaC internals.
322 .PP
323 Finally, the shell escape
324 .RS
325 .B !
326 .RI [ "command  " [ arguments ]]
327 .RE
328 passes the given
329 .I command
330 and optionally
331 .I arguments
332 to the shell for execution. With this method, you can execute shell commands
333 from within ginsh without having to quit.
334 .SH EXAMPLES
335 .nf
336 > a = x^2\-x\-2;
337 \-x+x^2\-2
338 > b = (x+1)^2;
339 (x+1)^2
340 > s = a/b;
341 (x+1)^(\-2)*(\-x+x^2\-2)
342 > diff(s, x);
343 (2*x\-1)*(x+1)^(\-2)\-2*(x+1)^(\-3)*(\-x+x^2\-2)
344 > normal(s);
345 (x\-2)*(x+1)^(\-1)
346 > x = 3^50;
347 717897987691852588770249
348 > s;
349 717897987691852588770247/717897987691852588770250
350 > Digits = 40;
351 40
352 > evalf(s);
353 0.999999999999999999999995821133292704384960990679L0
354 > unassign('x');
355 x
356 > s;
357 (x+1)^(\-2)*(\-x+x^2\-2)
358 > lsolve([3*x+5*y == 7], [x, y]);
359 [x==\-5/3*y+7/3,y==y]
360 > lsolve([3*x+5*y == 7, \-2*x+10*y == \-5], [x, y]);
361 [x==19/8,y==\-1/40]
362 > M = [[ [[a, b]], [[c, d]] ]];
363 [[ [[\-x+x^2\-2,(x+1)^2]], [[c,d]] ]]
364 > determinant(M);
365 \-2*d\-2*x*c\-x^2*c\-x*d+x^2*d\-c
366 > collect(", x);
367 (\-d\-2*c)*x+(d\-c)*x^2\-2*d\-c
368 > quit
369 .fi
370 .SH DIAGNOSTICS
371 .TP
372 .RI "parse error at " foo
373 You entered something which ginsh was unable to parse. Please check the syntax
374 of your input and try again.
375 .TP
376 .RI "argument " num " to " function " must be a " type
377 The argument number
378 .I num
379 to the given
380 .I function
381 must be of a certain type (e.g. a symbol, or a list). The first argument has
382 number 0, the second argument number 1, etc.
383 .SH AUTHOR
384 .TP
385 The GiNaC Group:
386 .br
387 Christian Bauer <Christian.Bauer@uni-mainz.de>
388 .br
389 Alexander Frink <Alexander.Frink@uni-mainz.de>
390 .br
391 Richard B. Kreckel <Richard.Kreckel@uni-mainz.de>
392 .SH SEE ALSO
393 GiNaC Tutorial \- An open framework for symbolic computation within the
394 C++ programming language
395 .PP
396 CLN \- A Class Library for Numbers, Bruno Haible
397 .SH COPYRIGHT
398 Copyright \(co 1999 Johannes Gutenberg Universit\(:at Mainz, Germany
399
400 This program is free software; you can redistribute it and/or modify
401 it under the terms of the GNU General Public License as published by
402 the Free Software Foundation; either version 2 of the License, or
403 (at your option) any later version.
404
405 This program is distributed in the hope that it will be useful,
406 but WITHOUT ANY WARRANTY; without even the implied warranty of
407 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
408 GNU General Public License for more details.
409
410 You should have received a copy of the GNU General Public License
411 along with this program; if not, write to the Free Software
412 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.