Tips for golfing in PARI/GP PARI/GP is a free computer algebra system. It is designed for (algebraic) number theory, not golfing, but that's part of the attraction. Unsurprisingly, it fares best at mathematical tasks; its support for string manipulation is primitive. (Having said that, advice for golfing non-mathematical tasks is also welcome.)

As usual, please post one tip per answer.

These tips should be at least somewhat specific to PARI/GP; advice which applies to 'most' languages belongs at Tips for golfing in &lt;all languages&gt;. Some general tips which don't need to be included:


Compress whitespace. (In GP all whitespace outside of strings is optional.)
Use single-character variables. (There are 50 choices, a-z and A-Z except I and O.)
Use &lt; and &gt; rather than &lt;= and &gt;= when possible.
Chain assignments. (a=b=c or a+=b*=c)
Use operators to replace commands (or longer operators!) when possible.

length(v) → #v (saves 5-7 bytes)

matsize(M)[2] → #M (saves 9-11 bytes)

matsize(M)[1] → #M~ (saves 8-10 bytes)

floor(x) → x\1 (saves 3-5 bytes)

round(x) → x\/1 (saves 2-4 bytes)*

shift(x,n) → x&gt;&gt;n or x&lt;&lt;n (saves 2-6 bytes)

sqr(x) → x^2 (saves 1-3 bytes)

deriv(x) → x' (saves 4-6 bytes)

mattranspose(M) → M~ (saves 11-13 bytes)

factorial(n) → n! (saves 8-10 bytes)

&amp;&amp; → &amp; (saves 1 byte; note that this syntax is deprecated)

|| → | (saves 1 byte; only works in older versions)

* Prior to 2.8.1 (2016) the \/ operator did not work correctly on t_REAL numbers&mdash;update if you haven't!