ginsh(1)

πŸ“¦
version 1.8.10 Β· 6 versions
, in nixos 26.05, nixpkgs unstable, ubuntu resolute, ubuntu stonking

✨ 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/3 or 0.17 πŸ”’
  • symbols, like x or result 🏷️
  • mathematical operators like + and * βž•
  • functions, like sin or normal 🧚

Every input expression must be terminated with either a semicolon (;) or a colon (:). Here's the tea:

  • terminate with ; β†’ ginsh evaluates the expression and prints the result to stdout πŸ–¨οΈ
  • terminate with : β†’ ginsh only 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' Constant
  • Catalan β€” Catalan's Constant
  • Euler β€” Euler-Mascheroni Constant
  • I β€” 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 of object^number from 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 writing expr1^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 symbol s.
  • series(expression, relation-or-symbol, order) β€” series expansion.
  • series_to_poly(series) β€” converts a series into a polynomial by dropping the Order() 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 Β© 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