ginsh(1)
β¨ NAME β¨
okay so picture this: you wanna mess around with symbolic math but you do not wanna write a whole C++ program about it. Enter ginsh β the GiNaC Interactive Shell π. This is the ginsh(1) page, straight from The GiNaC Group's manual, and it's literally your lil interactive playground on top of the GiNaC symbolic computation framework. no cap. π¦
β¨ SYNOPSIS β¨
ginsh [file...]
β¨ DESCRIPTION β¨
So ginsh is an interactive frontend for the GiNaC symbolic computation framework β¨.
And real talk, bestie: it's meant to be a tool for testing and experimenting with GiNaC's features. It is not a replacement for traditional interactive computer algebra systems, so don't come for it π.
It can do many of the things those traditional systems can do, but here's the catch β ginsh provides no programming constructs like loops or conditional expressions π. If you need that functionality, you're advised to write your program in C++, using the "native" GiNaC class framework. That's the move. π
β¨ USAGE β¨
INPUT FORMAT
After startup, ginsh shows you a prompt β > β which is its way of saying "i'm ready, talk to me π
". That prompt means it's ready to accept your input.
Acceptable input is numeric or symbolic expressions made up of:
- numbers, like
42,2/3or0.17π’ - symbols, like
xorresultπ·οΈ - mathematical operators like
+and*β - functions, like
sinornormalπ§
Every input expression must be terminated with either a semicolon (;) or a colon (:). Here's the tea:
- terminate with
;βginshevaluates the expression and prints the result to stdout π¨οΈ - terminate with
:βginshonly evaluates the expression, and does not print the result π€«
It's possible to enter multiple expressions on one line, iconic. And whitespace (spaces, tabs, newlines) can be applied freely between tokens β go wild, it does not care πΈ.
To quit ginsh, enter quit or exit, or type an EOF (Ctrl-D) at the prompt. bye bestie π
COMMENTS
Anything following a double slash (//) up to the end of the line, and all lines starting with a hash mark (#), are treated as a comment and ignored. so you can leave lil notes to yourself, obsessed π
NUMBERS
ginsh accepts numbers in the usual decimal notations β¨. That includes:
- arbitrary precision integers and rationals
- floating point numbers in standard or scientific notation (e.g.
1.2E6)
The general rule, and this is the one to remember: if a number contains a decimal point (.), it's an (inexact) floating point number; otherwise it's an (exact) integer or rational π.
Integers can be specified in binary, octal, hexadecimal, or arbitrary (2-36) base by prefixing them with #b, #o, #x, or #nR, respectively. slay. π₯
SYMBOLS
Symbols are made up of a string of alphanumeric characters and the underscore (_), with the first character being non-numeric. So for example a and mu_1 are acceptable symbol names, while 2pi is not π.
It's possible to use symbols with the same names as functions (e.g. sin) β ginsh is able to distinguish between the two. main character energy fr π§
Symbols can be assigned values by entering:
symbol = expression;
To unassign the value of an assigned symbol, type:
unassign('symbol');
Assigned symbols are automatically evaluated (= replaced by their assigned value) when they are used. To refer to the unevaluated symbol, put single quotes (') around the name, as demonstrated for the unassign command above. π«Ά
Symbols are considered to be in the complex domain by default, i.e. they're treated as if they stand in for complex numbers. This behavior can be changed by using the keywords real_symbols and complex_symbols, and it affects all newly created symbols β¨.
The following symbols are pre-defined constants that cannot be assigned a value by the user:
Piβ Archimedes' ConstantCatalanβ Catalan's ConstantEulerβ Euler-Mascheroni ConstantIβsqrt(-1)FAILβ an object of the GiNaC "fail" class
There's also the special Digits symbol that controls the numeric precision of calculations with inexact numbers. Assigning an integer value to digits will change the precision to the given number of decimal places. π
WILDCARDS
The has(), find(), match() and subs() functions accept wildcards as placeholders for expressions. These have the syntax:
$number
for example $0, $1 etc. π
LAST PRINTED EXPRESSIONS
ginsh provides the three special symbols %, %% and %%% that refer to the last, second last, and third last printed expression, respectively. These are handy if you want to use the results of previous computations in a new expression πβ¨
OPERATORS
ginsh provides the following operators, listed in falling order of precedence:
!β postfix factorial^β powering+β unary plus-β unary minus*β multiplication/β division+β addition-β subtraction<β less than>β greater than<=β less or equal>=β greater or equal==β equal!=β not equal=β symbol assignment
All binary operators are left-associative, with the exception of ^ and =, which are right-associative π. The result of the assignment operator (=) is its right-hand side, so it's possible to assign multiple symbols in one expression (e.g. a = b = c = 2;). multi-assign ate and left no crumbs π
LISTS
Lists are used by the subs and lsolve functions. A list consists of:
- an opening curly brace (
{) - a (possibly empty) comma-separated sequence of expressions
- a closing curly brace (
})
MATRICES
A matrix consists of an opening square bracket ([), a non-empty comma-separated sequence of matrix rows, and a closing square bracket (]).
Each matrix row consists of an opening square bracket ([), a non-empty comma-separated sequence of expressions, and a closing square bracket (]).
If the rows of a matrix are not of the same length, the width of the matrix becomes that of the longest row, and shorter rows are filled up at the end with elements of value zero πΈ
FUNCTIONS
A function call in ginsh has the form:
name(arguments)
where arguments is a comma-separated sequence of expressions.
ginsh provides a couple of built-in functions and also "imports" all symbolic functions defined by GiNaC and additional libraries. There is no way to define your own functions other than linking ginsh against a library that defines symbolic GiNaC functions. iykyk π
ginsh provides Tab-completion on function names: if you type the first part of a function name, hitting Tab will complete the name if possible. If the part you typed is not unique, hitting Tab again will display a list of matching functions. Hitting Tab twice at the prompt will display the list of all available functions β¨. genuinely so handy bestie.
A list of the built-in functions follows. They nearly all work as the respective GiNaC methods of the same name, so i'm not gonna describe them in detail here. Please refer to the GiNaC documentation. π
and okay the actual list is right around the corner, so stay with me π
okay bestie, the function dump continues β buckle up, because there's a lot of slay in here π
charpoly(matrix, symbol)β the characteristic polynomial of a matrix. it's giving eigenvalue energy πcoeff(expression, object, number)β pulls out the coefficient ofobject^numberfrom a polynomial.collect(expression, object-or-list)β gathers the coefficients of like powers. the result comes back in recursive form.collect_distributed(expression, list)β same "collect coefficients of like powers" deal, except the result is in distributed form.collect_common_factors(expression)β scoops the common factors out of the terms of sums.conjugate(expression)β complex conjugation. periodt.content(expression, symbol)β the content part of a polynomial.decomp_rational(expression, symbol)β decomposes a rational function into a polynomial and a proper rational function.degree(expression, object)β degree of a polynomial.denom(expression)β denominator of a rational function.determinant(matrix)β determinant of a matrix. iconic.diag(expression...)β constructs a diagonal matrix.diff(expression, symbol [, number])β partial differentiation.divide(expression, expression)β exact polynomial division.evalf(expression)β evaluates an expression to a floating point number.evalm(expression)β evaluates sums, products and integer powers of matrices.expand(expression)β expands an expression.factor(expression)β factorizes an expression (univariate, bestie).find(expression, pattern)β hands you a list of all the occurrences of a pattern in an expression.fsolve(expression, symbol, number, number)β numerically finds a root of a real-valued function within an interval.gcd(expression, expression)β greatest common divisor.has(expression, pattern)β returns"1"if the first expression contains the pattern as a subexpression,"0"otherwise.integer_content(expression)β integer content of a polynomial.inverse(matrix)β inverse of a matrix.is(relation)β returns"1"if the relation is true,"0"otherwise (so false or undecided both get the"0", no cap).lcm(expression, expression)β least common multiple.lcoeff(expression, object)β leading coefficient of a polynomial.ldegree(expression, object)β low degree of a polynomial.lsolve(equation-list, symbol-list)β solves a system of linear equations.map(expression, pattern)β applies a function to each operand; you specify the function to be applied as a pattern, with the"$0"wildcard standing in for the operands.match(expression, pattern)β checks whether an expression matches a pattern; you get back a list of wildcard substitutions, or"FAIL"if there's no match.nops(expression)β number of operands in an expression.normal(expression)β rational function normalization.numer(expression)β numerator of a rational function.numer_denom(expression)β numerator and denumerator of a rational function, as a list.op(expression, number)β extract an operand from an expression.power(expr1, expr2)β exponentiation, which is literally equivalent to writingexpr1^expr2.prem(expression, expression, symbol)β pseudo-remainder of polynomials.primpart(expression, symbol)β primitive part of a polynomial.quo(expression, expression, symbol)β quotient of polynomials.rank(matrix)β rank of a matrix.rem(expression, expression, symbol)β remainder of polynomials.resultant(expression, expression, symbol)β resultant of two polynomials with respect to symbols.series(expression, relation-or-symbol, order)β series expansion.series_to_poly(series)β converts a series into a polynomial by dropping theOrder()term.sprem(expression, expression, symbol)β sparse pseudo-remainder of polynomials.sqrfree(expression [, symbol-list])β square-free factorization of a polynomial.sqrfree_parfrac(expression, symbol)β square-free partial fraction decomposition of a rational function.sqrt(expression)β square root.subs(expression, relation-or-list)/subs(expression, look-for-list, replace-by-list)β substitute subexpressions (wildcards? allowed, go off π¦).tcoeff(expression, object)β trailing coefficient of a polynomial.time(expression)β returns the time in seconds needed to evaluate the expression you handed it.trace(matrix)β trace of a matrix.transpose(matrix)β transpose of a matrix.unassign('symbol')β unassigns an assigned symbol (mind the quotes, please!).unit(expression, symbol)β unit part of a polynomial.
β¨ SPECIAL COMMANDS β¨
Wanna dip out of ginsh? type
quit
or
exit
ginsh can also show you a (short) help blurb for a given topic β mostly about functions and operators β if you type
?topic
and if you type
??
you get a whole list of the available help topics. it's giving menu π
The command
print(expression);
prints a dump of GiNaC's internal representation for the given expression. this one is lowkey iconic for debugging, and also for learning about GiNaC internals π
The command
print_latex(expression);
prints a LaTeX representation of the given expression.
The command
print_csrc(expression);
prints the given expression in a way that can be used in a C or C++ program.
The command
iprint(expression);
prints the given expression (which must evaluate to an integer) in decimal, octal, and hexadecimal representations.
Finally, the shell escape
! [command [arguments]]
passes the given command, and optionally its arguments, to the shell for execution. with this method you can execute shell commands from inside ginsh without having to quit at all. main character energy, fr fr π
π EXAMPLES π
> a = x^2-x-2;
-2-x+x^2
> b = (x+1)^2;
(x+1)^2
> s = a/b;
(x+1)^(-2)*(-2-x+x^2)
> diff(s, x);
(2*x-1)*(x+1)^(-2)-2*(x+1)^(-3)*(-x+x^2-2)
> normal(s);
(x-2)*(x+1)^(-1)
> x = 3^50;
717897987691852588770249
> s;
717897987691852588770247/717897987691852588770250
> Digits = 40;
40
> evalf(s);
0.999999999999999999999995821133292704384960990679
> unassign('x');
x
> s;
(x+1)^(-2)*(-x+x^2-2)
> series(sin(x),x==0,6);
1*x+(-1/6)*x^3+1/120*x^5+Order(x^6)
> lsolve({3*x+5*y == 7}, {x, y});
{x==-5/3*y+7/3,y==y}
> lsolve({3*x+5*y == 7, -2*x+10*y == -5}, {x, y});
{x==19/8,y==-1/40}
> M = [ [a, b], [c, d] ];
[[-x+x^2-2,(x+1)^2],[c,d]]
> determinant(M);
-2*d-2*x*c-x^2*c-x*d+x^2*d-c
> collect(%, x);
(-d-2*c)*x+(d-c)*x^2-2*d-c
> solve quantum field theory;
parse error at quantum
> quit
not the parse error at quantum bestie π she tried, she really did.
π DIAGNOSTICS π
parse error at foo
You entered something which ginsh was unable to parse. Please check the syntax of your input and try again.
argument num to function must be a type
The argument number num to the given function must be of a certain type (e.g. a symbol, or a list). The first argument has number 0, the second argument number 1, etc.
π AUTHOR π
The GiNaC maintainers <https://www.ginac.de/>.
π₯ SEE ALSO π₯
- GiNaC Tutorial - An open framework for symbolic computation within the C++ programming language
- CLN - A Class Library for Numbers, Bruno Haible
πΈ COPYRIGHT πΈ
Copyright Β© 1999-2026 Johannes Gutenberg UniversitΓ€t Mainz, Germany
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
ngl bestie, "without even the implied warranty of merchantability" is the most brutal sentence in the whole manpage. read it and weep π
and that's a wrap, babes π this whole thing is from GiNaC 1.8.10, dated January, 2000, and it's page ginsh(1) β go forth and compute, you absolute legend πβ¨π¦
π¦ where this page comes from
- nixos 26.05: ginac 1.8.10
- nixpkgs unstable: ginac 1.8.10
- ubuntu resolute: ginac-tools 1.8.10-1 Β· GPL-2.0-or-later
- ubuntu stonking: ginac-tools 1.8.10-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms