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