1ginsh(1) The GiNaC Group ginsh(1)
2
3
4
6 ginsh - GiNaC Interactive Shell
7
9 ginsh [file...]
10
12 ginsh is an interactive frontend for the GiNaC symbolic computation
13 framework. It is intended as a tool for testing and experimenting with
14 GiNaC's features, not as a replacement for traditional interactive com‐
15 puter algebra systems. Although it can do many things these traditional
16 systems can do, ginsh provides no programming constructs like loops or
17 conditional expressions. If you need this functionality you are advised
18 to write your program in C++, using the "native" GiNaC class framework.
19
21 INPUT FORMAT
22 After startup, ginsh displays a prompt ("> ") signifying that it is
23 ready to accept your input. Acceptable input are numeric or symbolic
24 expressions consisting of numbers (e.g. 42, 2/3 or 0.17), symbols
25 (e.g. x or result), mathematical operators like + and *, and func‐
26 tions (e.g. sin or normal). Every input expression must be terminated
27 with either a semicolon (;) or a colon (:). If terminated with a semi‐
28 colon, ginsh will evaluate the expression and print the result to std‐
29 out. If terminated with a colon, ginsh will only evaluate the expres‐
30 sion but not print the result. It is possible to enter multiple expres‐
31 sions on one line. Whitespace (spaces, tabs, newlines) can be applied
32 freely between tokens. To quit ginsh, enter quit or exit, or type an
33 EOF (Ctrl-D) at the prompt.
34
35 COMMENTS
36 Anything following a double slash (//) up to the end of the line, and
37 all lines starting with a hash mark (#) are treated as a comment and
38 ignored.
39
40 NUMBERS
41 ginsh accepts numbers in the usual decimal notations. This includes
42 arbitrary precision integers and rationals as well as floating point
43 numbers in standard or scientific notation (e.g. 1.2E6). The general
44 rule is that if a number contains a decimal point (.), it is an (inex‐
45 act) floating point number; otherwise it is an (exact) integer or
46 rational. Integers can be specified in binary, octal, hexadecimal or
47 arbitrary (2-36) base by prefixing them with #b, #o, #x, or #nR ,
48 respectively.
49
50 SYMBOLS
51 Symbols are made up of a string of alphanumeric characters and the
52 underscore (_), with the first character being non-numeric. E.g. a and
53 mu_1 are acceptable symbol names, while 2pi is not. It is possible to
54 use symbols with the same names as functions (e.g. sin); ginsh is able
55 to distinguish between the two.
56
57 Symbols can be assigned values by entering
58 symbol = expression;
59
60 To unassign the value of an assigned symbol, type
61 unassign('symbol');
62
63 Assigned symbols are automatically evaluated (= replaced by their
64 assigned value) when they are used. To refer to the unevaluated symbol,
65 put single quotes (') around the name, as demonstrated for the "unas‐
66 sign" command above.
67
68 Symbols are considered to be in the complex domain by default, i.e.
69 they are treated as if they stand in for complex numbers. This behavior
70 can be changed by using the keywords real_symbols and complex_symbols
71 and affects all newly created symbols.
72
73 The following symbols are pre-defined constants that cannot be assigned
74 a value by the user:
75
76 Pi Archimedes' Constant
77
78 Catalan Catalan's Constant
79
80 Euler Euler-Mascheroni Constant
81
82 I sqrt(-1)
83
84 FAIL an object of the GiNaC "fail" class
85
86 There is also the special
87 Digits
88 symbol that controls the numeric precision of calculations with inexact
89 numbers. Assigning an integer value to digits will change the preci‐
90 sion to the given number of decimal places.
91
92 WILDCARDS
93 The has(), find(), match() and subs() functions accept wildcards as
94 placeholders for expressions. These have the syntax
95 $number
96 for example $0, $1 etc.
97
98 LAST PRINTED EXPRESSIONS
99 ginsh provides the three special symbols
100 %, %% and %%%
101 that refer to the last, second last, and third last printed expression,
102 respectively. These are handy if you want to use the results of previ‐
103 ous computations in a new expression.
104
105 OPERATORS
106 ginsh provides the following operators, listed in falling order of
107 precedence:
108
109
110 ! postfix factorial
111
112 ^ powering
113
114 + unary plus
115
116 - unary minus
117
118 * multiplication
119
120 / division
121
122 + addition
123
124 - subtraction
125
126 < less than
127
128 > greater than
129
130 <= less or equal
131
132 >= greater or equal
133
134 == equal
135
136 != not equal
137
138 = symbol assignment
139
140
141 All binary operators are left-associative, with the exception of ^ and
142 = which are right-associative. The result of the assignment operator
143 (=) is its right-hand side, so it's possible to assign multiple symbols
144 in one expression (e.g. a = b = c = 2;).
145
146 LISTS
147 Lists are used by the subs and lsolve functions. A list consists of an
148 opening curly brace ({), a (possibly empty) comma-separated sequence of
149 expressions, and a closing curly brace (}).
150
151 MATRICES
152 A matrix consists of an opening square bracket ([), a non-empty comma-
153 separated sequence of matrix rows, and a closing square bracket (]).
154 Each matrix row consists of an opening square bracket ([), a non-empty
155 comma-separated sequence of expressions, and a closing square bracket
156 (]). If the rows of a matrix are not of the same length, the width of
157 the matrix becomes that of the longest row and shorter rows are filled
158 up at the end with elements of value zero.
159
160 FUNCTIONS
161 A function call in ginsh has the form
162 name(arguments)
163 where arguments is a comma-separated sequence of expressions. ginsh
164 provides a couple of built-in functions and also "imports" all symbolic
165 functions defined by GiNaC and additional libraries. There is no way to
166 define your own functions other than linking ginsh against a library
167 that defines symbolic GiNaC functions.
168
169 ginsh provides Tab-completion on function names: if you type the first
170 part of a function name, hitting Tab will complete the name if possi‐
171 ble. If the part you typed is not unique, hitting Tab again will dis‐
172 play a list of matching functions. Hitting Tab twice at the prompt
173 will display the list of all available functions.
174
175 A list of the built-in functions follows. They nearly all work as the
176 respective GiNaC methods of the same name, so I will not describe them
177 in detail here. Please refer to the GiNaC documentation.
178
179 charpoly(matrix, symbol) - characteristic polynomial of a matrix
180 coeff(expression, object, number) - extracts coefficient of
181 object^number from a polynomial
182 collect(expression, object-or-list) - collects coefficients of
183 like powers (result in recursive form)
184 collect_distributed(expression, list) - collects coefficients of
185 like powers (result in distributed form)
186 collect_common_factors(expression) - collects common factors
187 from the terms of sums
188 conjugate(expression) - complex conjugation
189 content(expression, symbol) - content part of a polynomial
190 decomp_rational(expression, symbol) - decompose rational func‐
191 tion into polynomial and proper rational function
192 degree(expression, object) - degree of a polynomial
193 denom(expression) - denominator of a rational function
194 determinant(matrix) - determinant of a matrix
195 diag(expression...) - constructs diagonal matrix
196 diff(expression, symbol [, number]) - partial differentiation
197 divide(expression, expression) - exact polynomial division
198 eval(expression [, level]) - evaluates an expression, replacing
199 symbols by their assigned value
200 evalf(expression [, level]) - evaluates an expression to a
201 floating point number
202 evalm(expression) - evaluates sums, products and integer powers
203 of matrices
204 expand(expression) - expands an expression
205 factor(expression) - factorizes an expression (univariate)
206 find(expression, pattern) - returns a list of all occurrences of
207 a pattern in an expression
208 fsolve(expression, symbol, number, number) - numerically find
209 root of a real-valued function within an interval
210 gcd(expression, expression) - greatest common divisor
211 has(expression, pattern) - returns "1" if the first expression
212 contains the pattern as a subexpression, "0" otherwise
213 integer_content(expression) - integer content of a polynomial
214 inverse(matrix) - inverse of a matrix
215 is(relation) - returns "1" if the relation is true, "0" other‐
216 wise (false or undecided)
217 lcm(expression, expression) - least common multiple
218 lcoeff(expression, object) - leading coefficient of a polynomial
219 ldegree(expression, object) - low degree of a polynomial
220 lsolve(equation-list, symbol-list) - solve system of linear
221 equations
222 map(expression, pattern) - apply function to each operand; the
223 function to be applied is specified as a pattern with the "$0"
224 wildcard standing for the operands
225 match(expression, pattern) - check whether expression matches a
226 pattern; returns a list of wildcard substitutions or "FAIL" if
227 there is no match
228 nops(expression) - number of operands in expression
229 normal(expression [, level]) - rational function normalization
230 numer(expression) - numerator of a rational function
231 numer_denom(expression) - numerator and denumerator of a ratio‐
232 nal function as a list
233 op(expression, number) - extract operand from expression
234 power(expr1, expr2) - exponentiation (equivalent to writing
235 expr1^expr2)
236 prem(expression, expression, symbol) - pseudo-remainder of poly‐
237 nomials
238 primpart(expression, symbol) - primitive part of a polynomial
239 quo(expression, expression, symbol) - quotient of polynomials
240 rank(matrix) - rank of a matrix
241 rem(expression, expression, symbol) - remainder of polynomials
242 resultant(expression, expression, symbol) - resultant of two
243 polynomials with respect to symbol s
244 series(expression, relation-or-symbol, order) - series expansion
245 sprem(expression, expression, symbol) - sparse pseudo-remainder
246 of polynomials
247 sqrfree(expression [, symbol-list]) - square-free factorization
248 of a polynomial
249 sqrt(expression) - square root
250 subs(expression, relation-or-list)
251 subs(expression, look-for-list, replace-by-list) - substitute
252 subexpressions (you may use wildcards)
253 tcoeff(expression, object) - trailing coefficient of a polyno‐
254 mial
255 time(expression) - returns the time in seconds needed to evalu‐
256 ate the given expression
257 trace(matrix) - trace of a matrix
258 transpose(matrix) - transpose of a matrix
259 unassign('symbol') - unassign an assigned symbol (mind the
260 quotes, please!)
261 unit(expression, symbol) - unit part of a polynomial
262
263
264 SPECIAL COMMANDS
265 To exit ginsh, enter
266 quit
267 or
268 exit
269
270 ginsh can display a (short) help for a given topic (mostly about func‐
271 tions and operators) by entering
272 ?topic
273 Typing
274 ??
275 will display a list of available help topics.
276
277 The command
278 print(expression);
279 will print a dump of GiNaC's internal representation for the given
280 expression. This is useful for debugging and for learning about GiNaC
281 internals.
282
283 The command
284 print_latex(expression);
285 prints a LaTeX representation of the given expression.
286
287 The command
288 print_csrc(expression);
289 prints the given expression in a way that can be used in a C or C++
290 program.
291
292 The command
293 iprint(expression);
294 prints the given expression (which must evaluate to an integer) in dec‐
295 imal, octal, and hexadecimal representations.
296
297 Finally, the shell escape
298 ! [command [arguments]]
299 passes the given command and optionally arguments to the shell for exe‐
300 cution. With this method, you can execute shell commands from within
301 ginsh without having to quit.
302
304 > a = x^2-x-2;
305 -2-x+x^2
306 > b = (x+1)^2;
307 (x+1)^2
308 > s = a/b;
309 (x+1)^(-2)*(-2-x+x^2)
310 > diff(s, x);
311 (2*x-1)*(x+1)^(-2)-2*(x+1)^(-3)*(-x+x^2-2)
312 > normal(s);
313 (x-2)*(x+1)^(-1)
314 > x = 3^50;
315 717897987691852588770249
316 > s;
317 717897987691852588770247/717897987691852588770250
318 > Digits = 40;
319 40
320 > evalf(s);
321 0.999999999999999999999995821133292704384960990679
322 > unassign('x');
323 x
324 > s;
325 (x+1)^(-2)*(-x+x^2-2)
326 > series(sin(x),x==0,6);
327 1*x+(-1/6)*x^3+1/120*x^5+Order(x^6)
328 > lsolve({3*x+5*y == 7}, {x, y});
329 {x==-5/3*y+7/3,y==y}
330 > lsolve({3*x+5*y == 7, -2*x+10*y == -5}, {x, y});
331 {x==19/8,y==-1/40}
332 > M = [ [a, b], [c, d] ];
333 [[-x+x^2-2,(x+1)^2],[c,d]]
334 > determinant(M);
335 -2*d-2*x*c-x^2*c-x*d+x^2*d-c
336 > collect(%, x);
337 (-d-2*c)*x+(d-c)*x^2-2*d-c
338 > solve quantum field theory;
339 parse error at quantum
340 > quit
341
343 parse error at foo
344 You entered something which ginsh was unable to parse. Please
345 check the syntax of your input and try again.
346
347 argument num to function must be a type
348 The argument number num to the given function must be of a cer‐
349 tain type (e.g. a symbol, or a list). The first argument has
350 number 0, the second argument number 1, etc.
351
353 The GiNaC Group:
354 Christian Bauer <Christian.Bauer@uni-mainz.de>
355 Alexander Frink <Alexander.Frink@uni-mainz.de>
356 Richard Kreckel <Richard.Kreckel@uni-mainz.de>
357 Jens Vollinga <vollinga@thep.physik.uni-mainz.de>
358
360 GiNaC Tutorial - An open framework for symbolic computation within the
361 C++ programming language
362
363 CLN - A Class Library for Numbers, Bruno Haible
364
366 Copyright © 1999-2009 Johannes Gutenberg Universität Mainz, Germany
367
368 This program is free software; you can redistribute it and/or modify it
369 under the terms of the GNU General Public License as published by the
370 Free Software Foundation; either version 2 of the License, or (at your
371 option) any later version.
372
373 This program is distributed in the hope that it will be useful, but
374 WITHOUT ANY WARRANTY; without even the implied warranty of MER‐
375 CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
376 Public License for more details.
377
378 You should have received a copy of the GNU General Public License along
379 with this program; if not, write to the Free Software Foundation, Inc.,
380 675 Mass Ave, Cambridge, MA 02139, USA.
381
382
383
384GiNaC 1.5.6 January, 2000 ginsh(1)