]> www.ginac.de Git - ginac.git/blob - ginsh/ginsh.1
- added on-line help system
[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 \" GINSH_OP_HELP_START
115 .B !
116 postfix factorial
117 .TP
118 .B ^
119 powering
120 .TP
121 .B +
122 unary plus
123 .TP
124 .B \-
125 unary minus
126 .TP
127 .B *
128 multiplication
129 .TP
130 .B %
131 non-commutative multiplication
132 .TP
133 .B /
134 division
135 .TP
136 .B +
137 addition
138 .TP
139 .B \-
140 subtraction
141 .TP
142 .B <
143 less than
144 .TP
145 .B >
146 greater than
147 .TP
148 .B <=
149 less or equal
150 .TP
151 .B >=
152 greater or equal
153 .TP
154 .B ==
155 equal
156 .TP
157 .B !=
158 not equal
159 .TP
160 .B =
161 symbol assignment
162 \" GINSH_OP_HELP_END
163 .RE
164 .PP
165 All binary operators are left-associative, with the exception of
166 .BR ^ " and " =
167 which are right-associative. The result of the assignment operator
168 .RB ( = )
169 is its right-hand side, so it's possible to assign multiple symbols in one
170 expression (e.g.
171 .BR "a = b = c = 2;" ).
172 .SS LISTS
173 Lists are used by the
174 .B subs
175 and
176 .B lsolve
177 functions. A list consists of an opening square bracket
178 .RB ( [ ),
179 a (possibly empty) comma-separated sequence of expressions, and a closing square
180 bracket
181 .RB ( ] ).
182 .SS MATRICES
183 A matrix consists of an opening double square bracket
184 .RB ( [[ ),
185 a non-empty comma-separated sequence of matrix rows, and a closing double square
186 bracket
187 .RB ( ]] ).
188 Each matrix row consists of an opening double square bracket
189 .RB ( [[ ),
190 a non-empty comma-separated sequence of expressions, and a closing double square
191 bracket
192 .RB ( ]] ).
193 If the rows of a matrix are not of the same length, the width of the matrix
194 becomes that of the longest row and shorter rows are filled up at the end
195 with elements of value zero.
196 .SS FUNCTIONS
197 A function call in ginsh has the form
198 .RS
199 .IB name ( arguments )
200 .RE
201 where
202 .I arguments
203 is a comma-separated sequence of expressions. ginsh provides a couple of built-in
204 functions and also "imports" all symbolic functions defined by GiNaC and additional
205 libraries. There is no way to define your own functions other than linking ginsh
206 against a library that defines symbolic GiNaC functions.
207 .PP
208 ginsh provides Tab-completion on function names: if you type the first part of
209 a function name, hitting Tab will complete the name if possible. If the part you
210 typed is not unique, hitting Tab again will display a list of matching functions.
211 Hitting Tab twice at the prompt will display the list of all available functions.
212 .PP
213 A list of the built-in functions follows. They nearly all work as the
214 respective GiNaC methods of the same name, so I will not describe them in
215 detail here. Please refer to the GiNaC documentation.
216 .PP
217 .RS
218 \" GINSH_FCN_HELP_START
219 .BI beta( expression ", " expression )
220 \- beta function
221 .br
222 .BI charpoly( matrix ", " symbol )
223 \- characteristic polynomial of a matrix
224 .br
225 .BI coeff( expression ", " symbol ", " number )
226 \- extracts coefficient of symbol^number from a polynomial
227 .br
228 .BI collect( expression ", " symbol )
229 \- collects coefficients of like powers
230 .br
231 .BI content( expression ", " symbol )
232 \- content part of a polynomial
233 .br
234 .BI degree( expression ", " symbol )
235 \- degree of a polynomial
236 .br
237 .BI denom( expression )
238 \- denominator of a rational function
239 .br
240 .BI determinant( matrix )
241 \- determinant of a matrix
242 .br
243 .BI diag( expression... )
244 \- constructs diagonal matrix
245 .br
246 .BI diff( expression ", " "symbol [" ", " number] )
247 \- partial differentiation
248 .br
249 .BI divide( expression ", " expression )
250 \- exact polynomial division
251 .br
252 .BI eval( "expression [" ", " level] )
253 \- evaluates an expression, replacing symbols by their assigned value
254 .br
255 .BI evalf( "expression [" ", " level] )
256 \- evaluates an expression to a floating point number
257 .br
258 .BI expand( expression )
259 \- expands an expression
260 .br
261 .BI gcd( expression ", " expression )
262 \- greatest common divisor
263 .br
264 .BI has( expression ", " expression )
265 \- returns "1" if the first expression contains the second as a subexpression, "0" otherwise
266 .br
267 .BI inverse( matrix )
268 \- inverse of a matrix
269 .br
270 .BI is( relation )
271 \- returns "1" if the relation is true, "0" otherwise (false or undecided)
272 .br
273 .BI lcm( expression ", " expression )
274 \- least common multiple
275 .br
276 .BI lcoeff( expression ", " symbol )
277 \- leading coefficient of a polynomial
278 .br
279 .BI ldegree( expression ", " symbol )
280 \- low degree of a polynomial
281 .br
282 .BI lsolve( equation-list ", " symbol-list )
283 \- solve system of linear equations
284 .br
285 .BI nops( expression )
286 \- number of operands in expression
287 .br
288 .BI normal( "expression [" ", " level] )
289 \- rational function normalization
290 .br
291 .BI numer( expression )
292 \- numerator of a rational function
293 .br
294 .BI op( expression ", " number )
295 \- extract operand from expression
296 .br
297 .BI power( expr1 ", " expr2 )
298 \- exponentiation (equivalent to writing expr1^expr2)
299 .br
300 .BI prem( expression ", " expression ", " symbol )
301 \- pseudo-remainder of polynomials
302 .br
303 .BI primpart( expression ", " symbol )
304 \- primitive part of a polynomial
305 .br
306 .BI quo( expression ", " expression ", " symbol )
307 \- quotient of polynomials
308 .br
309 .BI rem( expression ", " expression ", " symbol )
310 \- remainder of polynomials
311 .br
312 .BI series( expression ", " "symbol [" ", " "point [" ", " order]] )
313 \- series expansion
314 .br
315 .BI sqrfree( expression ", " symbol )
316 \- square-free factorization of a polynomial
317 .br
318 .BI sqrt( expression )
319 \- square root
320 .br
321 .BI subs( expression ", " relation-or-list )
322 .br
323 .BI subs( expression ", " look-for-list ", " replace-by-list )
324 \- substitute subexpressions
325 .br
326 .BI tcoeff( expression ", " symbol )
327 \- trailing coefficient of a polynomial
328 .br
329 .BI time( expression )
330 \- returns the time in seconds needed to evaluate the given expression
331 .br
332 .BI trace( matrix )
333 \- trace of a matrix
334 .br
335 .BI transpose( matrix )
336 \- transpose of a matrix
337 .br
338 .BI unassign( symbol )
339 \- unassign an assigned symbol
340 .br
341 .BI unit( expression ", " symbol )
342 \- unit part of a polynomial
343 .br
344 \" GINSH_FCN_HELP_END
345 .RE
346 .SS SPECIAL COMMANDS
347 To exit ginsh, enter
348 .RS
349 .B quit
350 .RE
351 or
352 .RS
353 .B exit
354 .RE
355 .PP
356 ginsh can display a (short) help for a given topic (mostly about functions
357 and operators) by entering
358 .RS
359 .BI ? topic
360 .RE
361 Typing
362 .RS
363 .B ??
364 .RE
365 will display a list of available help topics.
366 .PP
367 The command
368 .RS
369 .BI print( expression );
370 .RE
371 will print a dump of GiNaC's internal representation for the given
372 .IR expression .
373 This is useful for debugging and for learning about GiNaC internals.
374 .PP
375 Finally, the shell escape
376 .RS
377 .B !
378 .RI [ "command  " [ arguments ]]
379 .RE
380 passes the given
381 .I command
382 and optionally
383 .I arguments
384 to the shell for execution. With this method, you can execute shell commands
385 from within ginsh without having to quit.
386 .SH EXAMPLES
387 .nf
388 > a = x^2\-x\-2;
389 \-x+x^2\-2
390 > b = (x+1)^2;
391 (x+1)^2
392 > s = a/b;
393 (x+1)^(\-2)*(\-x+x^2\-2)
394 > diff(s, x);
395 (2*x\-1)*(x+1)^(\-2)\-2*(x+1)^(\-3)*(\-x+x^2\-2)
396 > normal(s);
397 (x\-2)*(x+1)^(\-1)
398 > x = 3^50;
399 717897987691852588770249
400 > s;
401 717897987691852588770247/717897987691852588770250
402 > Digits = 40;
403 40
404 > evalf(s);
405 0.999999999999999999999995821133292704384960990679L0
406 > unassign('x');
407 x
408 > s;
409 (x+1)^(\-2)*(\-x+x^2\-2)
410 > lsolve([3*x+5*y == 7], [x, y]);
411 [x==\-5/3*y+7/3,y==y]
412 > lsolve([3*x+5*y == 7, \-2*x+10*y == \-5], [x, y]);
413 [x==19/8,y==\-1/40]
414 > M = [[ [[a, b]], [[c, d]] ]];
415 [[ [[\-x+x^2\-2,(x+1)^2]], [[c,d]] ]]
416 > determinant(M);
417 \-2*d\-2*x*c\-x^2*c\-x*d+x^2*d\-c
418 > collect(", x);
419 (\-d\-2*c)*x+(d\-c)*x^2\-2*d\-c
420 > solve quantum field theory;
421 parse error at quantum
422 > quit
423 .fi
424 .SH DIAGNOSTICS
425 .TP
426 .RI "parse error at " foo
427 You entered something which ginsh was unable to parse. Please check the syntax
428 of your input and try again.
429 .TP
430 .RI "argument " num " to " function " must be a " type
431 The argument number
432 .I num
433 to the given
434 .I function
435 must be of a certain type (e.g. a symbol, or a list). The first argument has
436 number 0, the second argument number 1, etc.
437 .SH AUTHOR
438 .TP
439 The GiNaC Group:
440 .br
441 Christian Bauer <Christian.Bauer@uni-mainz.de>
442 .br
443 Alexander Frink <Alexander.Frink@uni-mainz.de>
444 .br
445 Richard B. Kreckel <Richard.Kreckel@uni-mainz.de>
446 .SH SEE ALSO
447 GiNaC Tutorial \- An open framework for symbolic computation within the
448 C++ programming language
449 .PP
450 CLN \- A Class Library for Numbers, Bruno Haible
451 .SH COPYRIGHT
452 Copyright \(co 1999 Johannes Gutenberg Universit\(:at Mainz, Germany
453
454 This program is free software; you can redistribute it and/or modify
455 it under the terms of the GNU General Public License as published by
456 the Free Software Foundation; either version 2 of the License, or
457 (at your option) any later version.
458
459 This program is distributed in the hope that it will be useful,
460 but WITHOUT ANY WARRANTY; without even the implied warranty of
461 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
462 GNU General Public License for more details.
463
464 You should have received a copy of the GNU General Public License
465 along with this program; if not, write to the Free Software
466 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.