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