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 find(expression, pattern) - returns a list of all occurrences of
206 a pattern in an expression
207 fsolve(expression, symbol, number, number) - numerically find
208 root of a real-valued function within an interval
209 gcd(expression, expression) - greatest common divisor
210 has(expression, pattern) - returns "1" if the first expression
211 contains the pattern as a subexpression, "0" otherwise
212 integer_content(expression) - integer content of a polynomial
213 inverse(matrix) - inverse of a matrix
214 is(relation) - returns "1" if the relation is true, "0" other‐
215 wise (false or undecided)
216 lcm(expression, expression) - least common multiple
217 lcoeff(expression, object) - leading coefficient of a polynomial
218 ldegree(expression, object) - low degree of a polynomial
219 lsolve(equation-list, symbol-list) - solve system of linear
220 equations
221 map(expression, pattern) - apply function to each operand; the
222 function to be applied is specified as a pattern with the "$0"
223 wildcard standing for the operands
224 match(expression, pattern) - check whether expression matches a
225 pattern; returns a list of wildcard substitutions or "FAIL" if
226 there is no match
227 nops(expression) - number of operands in expression
228 normal(expression [, level]) - rational function normalization
229 numer(expression) - numerator of a rational function
230 numer_denom(expression) - numerator and denumerator of a ratio‐
231 nal function as a list
232 op(expression, number) - extract operand from expression
233 power(expr1, expr2) - exponentiation (equivalent to writing
234 expr1^expr2)
235 prem(expression, expression, symbol) - pseudo-remainder of poly‐
236 nomials
237 primpart(expression, symbol) - primitive part of a polynomial
238 quo(expression, expression, symbol) - quotient of polynomials
239 rank(matrix) - rank of a matrix
240 rem(expression, expression, symbol) - remainder of polynomials
241 resultant(expression, expression, symbol) - resultant of two
242 polynomials with respect to symbol s
243 series(expression, relation-or-symbol, order) - series expansion
244 sprem(expression, expression, symbol) - sparse pseudo-remainder
245 of polynomials
246 sqrfree(expression [, symbol-list]) - square-free factorization
247 of a polynomial
248 sqrt(expression) - square root
249 subs(expression, relation-or-list)
250 subs(expression, look-for-list, replace-by-list) - substitute
251 subexpressions (you may use wildcards)
252 tcoeff(expression, object) - trailing coefficient of a polyno‐
253 mial
254 time(expression) - returns the time in seconds needed to evalu‐
255 ate the given expression
256 trace(matrix) - trace of a matrix
257 transpose(matrix) - transpose of a matrix
258 unassign(symbol) - unassign an assigned symbol
259 unit(expression, symbol) - unit part of a polynomial
260
261
262 SPECIAL COMMANDS
263 To exit ginsh, enter
264 quit
265 or
266 exit
267
268 ginsh can display a (short) help for a given topic (mostly about func‐
269 tions and operators) by entering
270 ?topic
271 Typing
272 ??
273 will display a list of available help topics.
274
275 The command
276 print(expression);
277 will print a dump of GiNaC's internal representation for the given
278 expression. This is useful for debugging and for learning about GiNaC
279 internals.
280
281 The command
282 print_latex(expression);
283 prints a LaTeX representation of the given expression.
284
285 The command
286 print_csrc(expression);
287 prints the given expression in a way that can be used in a C or C++
288 program.
289
290 The command
291 iprint(expression);
292 prints the given expression (which must evaluate to an integer) in dec‐
293 imal, octal, and hexadecimal representations.
294
295 Finally, the shell escape
296 ! [command [arguments]]
297 passes the given command and optionally arguments to the shell for exe‐
298 cution. With this method, you can execute shell commands from within
299 ginsh without having to quit.
300
302 > a = x^2-x-2;
303 -2-x+x^2
304 > b = (x+1)^2;
305 (x+1)^2
306 > s = a/b;
307 (x+1)^(-2)*(-2-x+x^2)
308 > diff(s, x);
309 (2*x-1)*(x+1)^(-2)-2*(x+1)^(-3)*(-x+x^2-2)
310 > normal(s);
311 (x-2)*(x+1)^(-1)
312 > x = 3^50;
313 717897987691852588770249
314 > s;
315 717897987691852588770247/717897987691852588770250
316 > Digits = 40;
317 40
318 > evalf(s);
319 0.999999999999999999999995821133292704384960990679
320 > unassign('x');
321 x
322 > s;
323 (x+1)^(-2)*(-x+x^2-2)
324 > series(sin(x),x==0,6);
325 1*x+(-1/6)*x^3+1/120*x^5+Order(x^6)
326 > lsolve({3*x+5*y == 7}, {x, y});
327 {x==-5/3*y+7/3,y==y}
328 > lsolve({3*x+5*y == 7, -2*x+10*y == -5}, {x, y});
329 {x==19/8,y==-1/40}
330 > M = [ [a, b], [c, d] ];
331 [[-x+x^2-2,(x+1)^2],[c,d]]
332 > determinant(M);
333 -2*d-2*x*c-x^2*c-x*d+x^2*d-c
334 > collect(%, x);
335 (-d-2*c)*x+(d-c)*x^2-2*d-c
336 > solve quantum field theory;
337 parse error at quantum
338 > quit
339
341 parse error at foo
342 You entered something which ginsh was unable to parse. Please
343 check the syntax of your input and try again.
344
345 argument num to function must be a type
346 The argument number num to the given function must be of a cer‐
347 tain type (e.g. a symbol, or a list). The first argument has
348 number 0, the second argument number 1, etc.
349
351 The GiNaC Group:
352 Christian Bauer <Christian.Bauer@uni-mainz.de>
353 Alexander Frink <Alexander.Frink@uni-mainz.de>
354 Richard Kreckel <Richard.Kreckel@uni-mainz.de>
355 Jens Vollinga <vollinga@thep.physik.uni-mainz.de>
356
358 GiNaC Tutorial - An open framework for symbolic computation within the
359 C++ programming language
360
361 CLN - A Class Library for Numbers, Bruno Haible
362
364 Copyright © 1999-2006 Johannes Gutenberg Universität Mainz, Germany
365
366 This program is free software; you can redistribute it and/or modify it
367 under the terms of the GNU General Public License as published by the
368 Free Software Foundation; either version 2 of the License, or (at your
369 option) any later version.
370
371 This program is distributed in the hope that it will be useful, but
372 WITHOUT ANY WARRANTY; without even the implied warranty of MER‐
373 CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
374 Public License for more details.
375
376 You should have received a copy of the GNU General Public License along
377 with this program; if not, write to the Free Software Foundation, Inc.,
378 675 Mass Ave, Cambridge, MA 02139, USA.
379
380
381
382GiNaC 1.3.6 January, 2000 ginsh(1)