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