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