]> www.ginac.de Git - ginac.git/blob - ginsh/ginsh.1
35abed2e4764a65bd3ee6db62f8b0cd47e32fe4a
[ginac.git] / ginsh / ginsh.1
1 .TH ginsh 1 "October, 1999" "GiNaC"
2 .SH NAME
3 ginsh \- GiNaC Interactive Shell
4 .SH SYNPOSIS
5 .B ginsh
6 .SH DESCRIPTION
7 .B ginsh
8 is an interactive frontend for the GiNaC symbolic computation framework.
9 It is intended as a tool for testing and experimenting with GiNaC's
10 features, not as a replacement for traditional interactive computer
11 algebra systems. Although it can do many things these traditional systems
12 can do, ginsh provides no programming constructs like loops or conditional
13 expressions. If you need this functionality you are advised to write
14 your program in C++, using the "native" GiNaC class framework.
15 .SH USAGE
16 .SS INPUT FORMAT
17 After startup, ginsh displays a prompt ("> ") signifying that it is ready
18 to accept your input. Acceptable input are numeric or symbolic expressions
19 consisting of numbers (e.g.
20 .BR 42 ", " 2/3 " or " 0.17 ),
21 symbols (e.g.
22 .BR x " or " result ),
23 mathematical operators like
24 .BR + " and  " * ,
25 and functions (e.g.
26 .BR sin " or " normal ).
27 ginsh will evaluate the expression and print the result to stdout. Every
28 input expression must be terminated by a semicolon
29 .RB ( ; ),
30 and it is possible to enter multiple expressions on one line. Whitespace
31 (spaces, tabs, newlines) can be applied freely between tokens. To quit ginsh,
32 enter
33 .BR quit " or " exit ,
34 or type an EOF (Ctrl-D) at the prompt.
35 .SS NUMBERS
36 ginsh accepts numbers in all formats accepted by CLN (the Class Library for
37 Numbers, that is the foundation of GiNaC's numerics). This includes arbitrary
38 precision integers and rationals as well as floating point numbers in standard
39 or scientific notation (e.g.
40 .BR 1.2E6 ).
41 The general rule is that if a number contains a decimal point
42 .RB ( . ),
43 it is an (inexact) floating point number; otherwise it is an (exact) integer or
44 rational.
45 .SS SYMBOLS
46 Symbols are made up of a string of alphanumeric characters and the underscore
47 .RB ( _ ),
48 with the first character being non-numeric. E.g.
49 .BR a " and " mu_1
50 are acceptable symbol names, while
51 .B 2pi
52 is not. It is possible to use symbols with the same names as functions (e.g.
53 .BR sin );
54 ginsh is able to distinguish between the two.
55 .PP
56 Symbols can be assigned values by entering
57 .RS
58 .IB symbol " = " expression ;
59 .RE
60 .PP
61 To unassign the value of an assigned symbol, type
62 .RS
63 .BI unassign(' symbol ');
64 .RE
65 .PP
66 Assigned symbols are automatically evaluated (= replaced by their assigned value)
67 when they are used. To refer to the unevaluated symbol, put single quotes
68 .RB ( ' )
69 around the name, as demonstrated for the "unassign" command above.
70 .PP
71 The following symbols are pre-defined constants that cannot be assigned
72 a value by the user:
73 .RS
74 .TP 8m
75 .B Pi
76 Archimedes' Constant
77 .TP
78 .B Catalan
79 Catalan's Constant
80 .TP
81 .B EulerGamma
82 Euler-Mascheroni Constant
83 .TP
84 .B I
85 sqrt(-1)
86 .TP
87 .B FAIL
88 an object of the GiNaC "fail" class
89 .RE
90 .PP
91 There is also the special
92 .RS
93 .B Digits
94 .RE
95 symbol that controls the numeric precision of calculations with inexact numbers.
96 Assigning an integer value to digits will change the precision to the given
97 number of decimal places.
98 .SS LAST PRINTED EXPRESSIONS
99 ginsh provides the three special symbols
100 .RS
101 ", "" and """
102 .RE
103 that refer to the last, second last, and third last printed expression, respectively.
104 These are handy if you want to use the results of previous computations in a new
105 expression.
106 .SS OPERATORS
107 ginsh provides the following operators, listed in falling order of precedence:
108 .RS
109 .TP 8m
110 .B !
111 postfix factorial
112 .TP
113 .B ^
114 powering
115 .TP
116 .B +
117 unary plus
118 .TP
119 .B \-
120 unary minus
121 .TP
122 .B *
123 multiplication
124 .TP
125 .B %
126 non-commutative multiplication
127 .TP
128 .B /
129 division
130 .TP
131 .B +
132 addition
133 .TP
134 .B \-
135 subtraction
136 .TP
137 .B <
138 less than
139 .TP
140 .B >
141 greater than
142 .TP
143 .B <=
144 less or equal
145 .TP
146 .B >=
147 greater or equal
148 .TP
149 .B ==
150 equal
151 .TP
152 .B !=
153 not equal
154 .TP
155 .B =
156 symbol assignment
157 .RE
158 .PP
159 All binary operators are left-associative, with the exception of
160 .BR ^ " and " =
161 which are right-associative. The result of the assignment operator
162 .RB ( = )
163 is its right-hand side, so it's possible to assign multiple symbols in one
164 expression (e.g.
165 .BR "a = b = c = 2;" ).
166 .SS LISTS
167 Lists are used by the
168 .B subs
169 and
170 .B lsolve
171 functions. A list consists of an opening square bracket
172 .RB ( [ ),
173 a (possibly empty) comma-separated sequence of expressions, and a closing square
174 bracket
175 .RB ( ] ).
176 .SS MATRICES
177 A matrix consists of an opening double square bracket
178 .RB ( [[ ),
179 a non-empty comma-separated sequence of matrix rows, and a closing double square
180 bracket
181 .RB ( ]] ).
182 Each matrix row consists of an opening double square bracket
183 .RB ( [[ ),
184 a non-empty comma-separated sequence of expressions, and a closing double square
185 bracket
186 .RB ( ]] ).
187 If the rows of a matrix are not of the same length, the width of the matrix
188 becomes that of the longest row and shorter rows are filled up at the end
189 with elements of value zero.
190 .SS FUNCTIONS
191 A function call in ginsh has the form
192 .RS
193 .IB name ( arguments )
194 .RE
195 where
196 .I arguments
197 is a comma-separated sequence of expressions. ginsh provides a couple of built-in
198 functions and also "imports" all symbolic functions defined by GiNaC and additional
199 libraries. There is no way to define your own functions other than linking ginsh
200 against a library that defines symbolic GiNaC functions.
201 .PP
202 ginsh provides Tab-completion on function names: if you type the first part of
203 a function name, hitting Tab will complete the name if possible. If the part you
204 typed is not unique, hitting Tab again will display a list of matching functions.
205 Hitting Tab twice at the prompt will display the list of all available functions.
206 .PP
207 A list of the built-in functions follows. They nearly all work as the
208 respective GiNaC methods of the same name, so I will not describe them in
209 detail here. Please refer to the GiNaC documentation.
210 .PP
211 .RS
212 .BI beta( expression ", " expression )
213 .br
214 .BI charpoly( matrix ", " symbol )
215 .br
216 .BI coeff( expression ", " symbol ", " number )
217 .br
218 .BI collect( expression ", " symbol )
219 .br
220 .BI content( expression ", " symbol )
221 .br
222 .BI degree( expression ", " symbol )
223 .br
224 .BI denom( expression )
225 .br
226 .BI determinant( matrix )
227 .br
228 .BI diag( expression... )
229 .br
230 .BI diff( expression ", " "symbol [" ", " number] )
231 .br
232 .BI divide( expression ", " expression )
233 .br
234 .BI eval( "expression [" ", " number] )
235 .br
236 .BI evalf( "expression [" ", " number] )
237 .br
238 .BI expand( expression )
239 .br
240 .BI gcd( expression ", " expression )
241 .br
242 .BI has( expression ", " expression )
243 .br
244 .BI inverse( matrix )
245 .br
246 .BI is( relation )
247 \- returns "1" if the
248 .I relation
249 is true, "0" otherwise (false or undecided)
250 .br
251 .BI lcm( expression ", " expression )
252 .br
253 .BI lcoeff( expression ", " symbol )
254 .br
255 .BI ldegree( expression ", " symbol )
256 .br
257 .BI lsolve( list ", " list )
258 .br
259 .BI nops( expression )
260 .br
261 .BI normal( "expression [" ", " number] )
262 .br
263 .BI numer( expression )
264 .br
265 .BI op( expression ", " number )
266 .br
267 .BI power( expression ", " expression )
268 .br
269 .BI prem( expression ", " expression ", " symbol )
270 .br
271 .BI primpart( expression ", " symbol )
272 .br
273 .BI quo( expression ", " expression ", " symbol )
274 .br
275 .BI rem( expression ", " expression ", " symbol )
276 .br
277 .BI series( expression ", " "symbol [" ", " "number [" ", " number]] )
278 .br
279 .BI sqrfree( expression ", " symbol )
280 .br
281 .BI sqrt( expression )
282 .br
283 .BI subs( expression ", " relation-or-list )
284 .br
285 .BI subs( expression ", " list ", " list )
286 .br
287 .BI tcoeff( expression ", " symbol )
288 .br
289 .BI time( expression )
290 \- returns the time in seconds needed to evaluate the given
291 .I expression
292 .br
293 .BI trace( matrix )
294 .br
295 .BI transpose( matrix )
296 .br
297 .BI unassign( symbol )
298 .br
299 .BI unit( expression ", " symbol )
300 .RE
301 .SS SPECIAL COMMANDS
302 To exit ginsh, enter
303 .RS
304 .B quit
305 .RE
306 or
307 .RS
308 .B exit
309 .RE
310 .PP
311 The command
312 .RS
313 .BI print( expression );
314 .RE
315 will print a dump of GiNaC's internal representation for the given
316 .IR expression .
317 This is useful for debugging and for learning about GiNaC internals.
318 .PP
319 Finally, the shell escape
320 .RS
321 .B !
322 .RI [ "command  " [ arguments ]]
323 .RE
324 passes the given
325 .I command
326 and optionally
327 .I arguments
328 to the shell for execution. With this method, you can execute shell commands
329 from within ginsh without having to quit.
330 .SH EXAMPLES
331 .nf
332 > a = x^2\-x\-2;
333 \-x+x^2\-2
334 > b = (x+1)^2;
335 (x+1)^2
336 > s = a/b;
337 (x+1)^(\-2)*(\-x+x^2\-2)
338 > diff(s, x);
339 (2*x\-1)*(x+1)^(\-2)\-2*(x+1)^(\-3)*(\-x+x^2\-2)
340 > normal(s);
341 (x\-2)*(x+1)^(\-1)
342 > x = 3^50;
343 717897987691852588770249
344 > s;
345 717897987691852588770247/717897987691852588770250
346 > Digits = 40;
347 40
348 > evalf(s);
349 0.999999999999999999999995821133292704384960990679L0
350 > unassign('x');
351 x
352 > s;
353 (x+1)^(\-2)*(\-x+x^2\-2)
354 > lsolve([3*x+5*y == 7], [x, y]);
355 [x==\-5/3*y+7/3,y==y]
356 > lsolve([3*x+5*y == 7, \-2*x+10*y == \-5], [x, y]);
357 [x==19/8,y==\-1/40]
358 > M = [[ [[a, b]], [[c, d]] ]];
359 [[ [[\-x+x^2\-2,(x+1)^2]], [[c,d]] ]]
360 > determinant(M);
361 \-2*d\-2*x*c\-x^2*c\-x*d+x^2*d\-c
362 > collect(", x);
363 (\-d\-2*c)*x+(d\-c)*x^2\-2*d\-c
364 > quit
365 .fi
366 .SH DIAGNOSTICS
367 .TP
368 .RI "parse error at " foo
369 You entered something which ginsh was unable to parse. Please check the syntax
370 of your input and try again.
371 .TP
372 .RI "argument " num " to " function " must be a " type
373 The argument number
374 .I num
375 to the given
376 .I function
377 must be of a certain type (e.g. a symbol, or a list). The first argument has
378 number 0, the second argument number 1, etc.
379 .SH AUTHOR
380 .TP
381 The GiNaC Group:
382 .br
383 Christian Bauer <Christian.Bauer@uni-mainz.de>
384 .br
385 Alexander Frink <Alexander.Frink@uni-mainz.de>
386 .br
387 Richard B. Kreckel <Richard.Kreckel@uni-mainz.de>
388 .SH SEE ALSO
389 GiNaC Tutorial \- An open framework for symbolic computation within the
390 C++ programming language
391 .PP
392 CLN \- A Class Library for Numbers, Bruno Haible
393 .SH COPYRIGHT
394 Copyright \(co 1999 Johannes Gutenberg Universit\(:at Mainz, Germany
395
396 This program is free software; you can redistribute it and/or modify
397 it under the terms of the GNU General Public License as published by
398 the Free Software Foundation; either version 2 of the License, or
399 (at your option) any later version.
400
401 This program is distributed in the hope that it will be useful,
402 but WITHOUT ANY WARRANTY; without even the implied warranty of
403 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
404 GNU General Public License for more details.
405
406 You should have received a copy of the GNU General Public License
407 along with this program; if not, write to the Free Software
408 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.