]> www.ginac.de Git - ginac.git/blob - ginsh/ginsh.1.in
added the sprem() function to normal.h, and fixed some documentation
[ginac.git] / ginsh / ginsh.1.in
1 .TH ginsh 1 "January, 2000" "GiNaC @VERSION@" "The GiNaC Group"
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 COMMENTS
40 Anything following a double slash
41 .RB ( // )
42 up to the end of the line, and all lines starting with a hash mark
43 .RB ( # )
44 are treated as a comment and ignored.
45 .SS NUMBERS
46 ginsh accepts numbers in the usual decimal notations. This includes arbitrary
47 precision integers and rationals as well as floating point numbers in standard
48 or scientific notation (e.g.
49 .BR 1.2E6 ).
50 The general rule is that if a number contains a decimal point
51 .RB ( . ),
52 it is an (inexact) floating point number; otherwise it is an (exact) integer or
53 rational.
54 Integers can be specified in binary, octal, hexadecimal or arbitrary (2-36) base
55 by prefixing them with
56 .BR #b ", " #o ", " #x ", or "
57 .BI # n R
58 , respectively.
59 .SS SYMBOLS
60 Symbols are made up of a string of alphanumeric characters and the underscore
61 .RB ( _ ),
62 with the first character being non-numeric. E.g.
63 .BR a " and " mu_1
64 are acceptable symbol names, while
65 .B 2pi
66 is not. It is possible to use symbols with the same names as functions (e.g.
67 .BR sin );
68 ginsh is able to distinguish between the two.
69 .PP
70 Symbols can be assigned values by entering
71 .RS
72 .IB symbol " = " expression ;
73 .RE
74 .PP
75 To unassign the value of an assigned symbol, type
76 .RS
77 .BI unassign(' symbol ');
78 .RE
79 .PP
80 Assigned symbols are automatically evaluated (= replaced by their assigned value)
81 when they are used. To refer to the unevaluated symbol, put single quotes
82 .RB ( ' )
83 around the name, as demonstrated for the "unassign" command above.
84 .PP
85 The following symbols are pre-defined constants that cannot be assigned
86 a value by the user:
87 .RS
88 .TP 8m
89 .B Pi
90 Archimedes' Constant
91 .TP
92 .B Catalan
93 Catalan's Constant
94 .TP
95 .B Euler
96 Euler-Mascheroni Constant
97 .TP
98 .B I
99 sqrt(-1)
100 .TP
101 .B FAIL
102 an object of the GiNaC "fail" class
103 .RE
104 .PP
105 There is also the special
106 .RS
107 .B Digits
108 .RE
109 symbol that controls the numeric precision of calculations with inexact numbers.
110 Assigning an integer value to digits will change the precision to the given
111 number of decimal places.
112 .SS WILDCARDS
113 The has(), find(), match() and subs() functions accept wildcards as placeholders
114 for expressions. These have the syntax
115 .RS
116 .BI $ number
117 .RE
118 for example $0, $1 etc.
119 .SS LAST PRINTED EXPRESSIONS
120 ginsh provides the three special symbols
121 .RS
122 %, %% and %%%
123 .RE
124 that refer to the last, second last, and third last printed expression, respectively.
125 These are handy if you want to use the results of previous computations in a new
126 expression.
127 .SS OPERATORS
128 ginsh provides the following operators, listed in falling order of precedence:
129 .RS
130 .TP 8m
131 \" GINSH_OP_HELP_START
132 .B !
133 postfix factorial
134 .TP
135 .B ^
136 powering
137 .TP
138 .B +
139 unary plus
140 .TP
141 .B \-
142 unary minus
143 .TP
144 .B *
145 multiplication
146 .TP
147 .B /
148 division
149 .TP
150 .B +
151 addition
152 .TP
153 .B \-
154 subtraction
155 .TP
156 .B <
157 less than
158 .TP
159 .B >
160 greater than
161 .TP
162 .B <=
163 less or equal
164 .TP
165 .B >=
166 greater or equal
167 .TP
168 .B ==
169 equal
170 .TP
171 .B !=
172 not equal
173 .TP
174 .B =
175 symbol assignment
176 \" GINSH_OP_HELP_END
177 .RE
178 .PP
179 All binary operators are left-associative, with the exception of
180 .BR ^ " and " =
181 which are right-associative. The result of the assignment operator
182 .RB ( = )
183 is its right-hand side, so it's possible to assign multiple symbols in one
184 expression (e.g.
185 .BR "a = b = c = 2;" ).
186 .SS LISTS
187 Lists are used by the
188 .B subs
189 and
190 .B lsolve
191 functions. A list consists of an opening curly brace
192 .RB ( { ),
193 a (possibly empty) comma-separated sequence of expressions, and a closing curly
194 brace
195 .RB ( } ).
196 .SS MATRICES
197 A matrix consists of an opening square bracket
198 .RB ( [ ),
199 a non-empty comma-separated sequence of matrix rows, and a closing square bracket
200 .RB ( ] ).
201 Each matrix row consists of an opening square bracket
202 .RB ( [ ),
203 a non-empty comma-separated sequence of expressions, and a closing square bracket
204 .RB ( ] ).
205 If the rows of a matrix are not of the same length, the width of the matrix
206 becomes that of the longest row and shorter rows are filled up at the end
207 with elements of value zero.
208 .SS FUNCTIONS
209 A function call in ginsh has the form
210 .RS
211 .IB name ( arguments )
212 .RE
213 where
214 .I arguments
215 is a comma-separated sequence of expressions. ginsh provides a couple of built-in
216 functions and also "imports" all symbolic functions defined by GiNaC and additional
217 libraries. There is no way to define your own functions other than linking ginsh
218 against a library that defines symbolic GiNaC functions.
219 .PP
220 ginsh provides Tab-completion on function names: if you type the first part of
221 a function name, hitting Tab will complete the name if possible. If the part you
222 typed is not unique, hitting Tab again will display a list of matching functions.
223 Hitting Tab twice at the prompt will display the list of all available functions.
224 .PP
225 A list of the built-in functions follows. They nearly all work as the
226 respective GiNaC methods of the same name, so I will not describe them in
227 detail here. Please refer to the GiNaC documentation.
228 .PP
229 .RS
230 \" GINSH_FCN_HELP_START
231 .BI charpoly( matrix ", " symbol )
232 \- characteristic polynomial of a matrix
233 .br
234 .BI coeff( expression ", " object ", " number )
235 \- extracts coefficient of object^number from a polynomial
236 .br
237 .BI collect( expression ", " object-or-list )
238 \- collects coefficients of like powers (result in recursive form)
239 .br
240 .BI collect_distributed( expression ", " list )
241 \- collects coefficients of like powers (result in distributed form)
242 .br
243 .BI content( expression ", " symbol )
244 \- content part of a polynomial
245 .br
246 .BI decomp_rational( expression ", " symbol )
247 \- decompose rational function into polynomial and proper rational function
248 .br
249 .BI degree( expression ", " object )
250 \- degree of a polynomial
251 .br
252 .BI denom( expression )
253 \- denominator of a rational function
254 .br
255 .BI determinant( matrix )
256 \- determinant of a matrix
257 .br
258 .BI diag( expression... )
259 \- constructs diagonal matrix
260 .br
261 .BI diff( expression ", " "symbol [" ", " number] )
262 \- partial differentiation
263 .br
264 .BI divide( expression ", " expression )
265 \- exact polynomial division
266 .br
267 .BI eval( "expression [" ", " level] )
268 \- evaluates an expression, replacing symbols by their assigned value
269 .br
270 .BI evalf( "expression [" ", " level] )
271 \- evaluates an expression to a floating point number
272 .br
273 .BI evalm( expression )
274 \- evaluates sums, products and integer powers of matrices
275 .br
276 .BI expand( expression )
277 \- expands an expression
278 .br
279 .BI find( expression ", " pattern )
280 \- returns a list of all occurrences of a pattern in an expression
281 .br
282 .BI gcd( expression ", " expression )
283 \- greatest common divisor
284 .br
285 .BI has( expression ", " pattern )
286 \- returns "1" if the first expression contains the pattern as a subexpression, "0" otherwise
287 .br
288 .BI inverse( matrix )
289 \- inverse of a matrix
290 .br
291 .BI is( relation )
292 \- returns "1" if the relation is true, "0" otherwise (false or undecided)
293 .br
294 .BI lcm( expression ", " expression )
295 \- least common multiple
296 .br
297 .BI lcoeff( expression ", " object )
298 \- leading coefficient of a polynomial
299 .br
300 .BI ldegree( expression ", " object )
301 \- low degree of a polynomial
302 .br
303 .BI lsolve( equation-list ", " symbol-list )
304 \- solve system of linear equations
305 .br
306 .BI map( expression ", " pattern )
307 \- apply function to each operand; the function to be applied is specified as a pattern with the "$0" wildcard standing for the operands
308 .br
309 .BI match( expression ", " pattern )
310 \- check whether expression matches a pattern; returns a list of wildcard substitutions or "FAIL" if there is no match
311 .br
312 .BI nops( expression )
313 \- number of operands in expression
314 .br
315 .BI normal( "expression [" ", " level] )
316 \- rational function normalization
317 .br
318 .BI numer( expression )
319 \- numerator of a rational function
320 .br
321 .BI numer_denom( expression )
322 \- numerator and denumerator of a rational function as a list
323 .br
324 .BI op( expression ", " number )
325 \- extract operand from expression
326 .br
327 .BI power( expr1 ", " expr2 )
328 \- exponentiation (equivalent to writing expr1^expr2)
329 .br
330 .BI prem( expression ", " expression ", " symbol )
331 \- pseudo-remainder of polynomials
332 .br
333 .BI primpart( expression ", " symbol )
334 \- primitive part of a polynomial
335 .br
336 .BI quo( expression ", " expression ", " symbol )
337 \- quotient of polynomials
338 .br
339 .BI rem( expression ", " expression ", " symbol )
340 \- remainder of polynomials
341 .br
342 .BI series( expression ", " relation-or-symbol ", " order )
343 \- series expansion
344 .br
345 .BI sqrfree( "expression [" ", " symbol-list] )
346 \- square-free factorization of a polynomial
347 .br
348 .BI sqrt( expression )
349 \- square root
350 .br
351 .BI subs( expression ", " relation-or-list )
352 .br
353 .BI subs( expression ", " look-for-list ", " replace-by-list )
354 \- substitute subexpressions (you may use wildcards)
355 .br
356 .BI tcoeff( expression ", " object )
357 \- trailing coefficient of a polynomial
358 .br
359 .BI time( expression )
360 \- returns the time in seconds needed to evaluate the given expression
361 .br
362 .BI trace( matrix )
363 \- trace of a matrix
364 .br
365 .BI transpose( matrix )
366 \- transpose of a matrix
367 .br
368 .BI unassign( symbol )
369 \- unassign an assigned symbol
370 .br
371 .BI unit( expression ", " symbol )
372 \- unit part of a polynomial
373 .br
374 \" GINSH_FCN_HELP_END
375 .RE
376 .SS SPECIAL COMMANDS
377 To exit ginsh, enter
378 .RS
379 .B quit
380 .RE
381 or
382 .RS
383 .B exit
384 .RE
385 .PP
386 ginsh can display a (short) help for a given topic (mostly about functions
387 and operators) by entering
388 .RS
389 .BI ? topic
390 .RE
391 Typing
392 .RS
393 .B ??
394 .RE
395 will display a list of available help topics.
396 .PP
397 The command
398 .RS
399 .BI print( expression );
400 .RE
401 will print a dump of GiNaC's internal representation for the given
402 .IR expression .
403 This is useful for debugging and for learning about GiNaC internals.
404 .PP
405 The command
406 .RS
407 .BI print_latex( expression );
408 .RE
409 prints a LaTeX representation of the given
410 .IR expression .
411 .PP
412 The command
413 .RS
414 .BI print_csrc( expression );
415 .RE
416 prints the given
417 .I expression
418 in a way that can be used in a C or C++ program (complex numbers are not
419 supported, though).
420 .PP
421 The command
422 .RS
423 .BI iprint( expression );
424 .RE
425 prints the given
426 .I expression
427 (which must evaluate to an integer) in decimal, octal, and hexadecimal representations.
428 .PP
429 Finally, the shell escape
430 .RS
431 .B !
432 .RI [ "command  " [ arguments ]]
433 .RE
434 passes the given
435 .I command
436 and optionally
437 .I arguments
438 to the shell for execution. With this method, you can execute shell commands
439 from within ginsh without having to quit.
440 .SH EXAMPLES
441 .nf
442 > a = x^2\-x\-2;
443 \-2\-x+x^2
444 > b = (x+1)^2;
445 (x+1)^2
446 > s = a/b;
447 (x+1)^(\-2)*(\-2\-x+x^2)
448 > diff(s, x);
449 (2*x\-1)*(x+1)^(\-2)\-2*(x+1)^(\-3)*(\-x+x^2\-2)
450 > normal(s);
451 (x\-2)*(x+1)^(\-1)
452 > x = 3^50;
453 717897987691852588770249
454 > s;
455 717897987691852588770247/717897987691852588770250
456 > Digits = 40;
457 40
458 > evalf(s);
459 0.999999999999999999999995821133292704384960990679
460 > unassign('x');
461 x
462 > s;
463 (x+1)^(\-2)*(\-x+x^2\-2)
464 > series(sin(x),x==0,6);
465 1*x+(\-1/6)*x^3+1/120*x^5+Order(x^6)
466 > lsolve({3*x+5*y == 7}, {x, y});
467 {x==\-5/3*y+7/3,y==y}
468 > lsolve({3*x+5*y == 7, \-2*x+10*y == \-5}, {x, y});
469 {x==19/8,y==\-1/40}
470 > M = [ [a, b], [c, d] ];
471 [[\-x+x^2\-2,(x+1)^2],[c,d]]
472 > determinant(M);
473 \-2*d\-2*x*c\-x^2*c\-x*d+x^2*d\-c
474 > collect(%, x);
475 (\-d\-2*c)*x+(d\-c)*x^2\-2*d\-c
476 > solve quantum field theory;
477 parse error at quantum
478 > quit
479 .fi
480 .SH DIAGNOSTICS
481 .TP
482 .RI "parse error at " foo
483 You entered something which ginsh was unable to parse. Please check the syntax
484 of your input and try again.
485 .TP
486 .RI "argument " num " to " function " must be a " type
487 The argument number
488 .I num
489 to the given
490 .I function
491 must be of a certain type (e.g. a symbol, or a list). The first argument has
492 number 0, the second argument number 1, etc.
493 .SH AUTHOR
494 .TP
495 The GiNaC Group:
496 .br
497 Christian Bauer <Christian.Bauer@uni-mainz.de>
498 .br
499 Alexander Frink <Alexander.Frink@uni-mainz.de>
500 .br
501 Richard Kreckel <Richard.Kreckel@uni-mainz.de>
502 .SH SEE ALSO
503 GiNaC Tutorial \- An open framework for symbolic computation within the
504 C++ programming language
505 .PP
506 CLN \- A Class Library for Numbers, Bruno Haible
507 .SH COPYRIGHT
508 Copyright \(co 1999-2002 Johannes Gutenberg Universit\(:at Mainz, Germany
509
510 This program is free software; you can redistribute it and/or modify
511 it under the terms of the GNU General Public License as published by
512 the Free Software Foundation; either version 2 of the License, or
513 (at your option) any later version.
514
515 This program is distributed in the hope that it will be useful,
516 but WITHOUT ANY WARRANTY; without even the implied warranty of
517 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
518 GNU General Public License for more details.
519
520 You should have received a copy of the GNU General Public License
521 along with this program; if not, write to the Free Software
522 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.