ised(1)
๐ธ ised(1) ๐ธ
okay bestie, welcome to the General Commands Manual glow-up for ised(1) โ it's giving iconic Unix energy, and we're doing this in four parts. This is part 1, so get comfy ๐ซถ
๐ NAME ๐
isedโ generating integer and floating point sequences. that's the whole vibe: numbers, arrays, sequences, slay.
โจ SYNOPSIS โจ
ised [--m] [--p] [--n] [--f input_file] [--a load_file] [--l
apply_to_file] [--x modify_file] [--k awk_file] [--o output_file] [--t
code_line] [--d delimiter] [--D int_format] [--F float_format] code ...
๐ฆ DESCRIPTION ๐ฆ
ised processes arithmetic expressions involving arrays and returns output array of values. Options and code lines are processed in order of appearance. If ised is called without arguments, it reads from standard input. Press ^D (EOF) or enter a single q to exit when in interactive mode.
When input consists only of arrays of length one (scalars), ised behaves as an ordinary calculator.
Options can also be used from command line in interactive mode or in files, invoked by --f.
๐ OPTIONS ๐
--f input_fileโ reads and processesinput_fileone line at a time, equivalent to giving every line as separate command line argument. btwised --f -is not equivalent to running it without arguments, as the latter also invokes interactive GNU readline prompt.--a load_fileโ loadsload_fileinto memory. Every line has its own memory slot, starting at$1. At the end, line count is saved in memory slot$0. All lines are evaluated before saving.--l apply_to_file { code | --f file }โcodeor file is applied on every line ofapply_to_file. Each line is loaded into memory slot$1while line number is in$0.--x modify_file { code | --f file }โ similar to--l, but instead of direct evaluation of lines inmodify_file, it splits the line into numbers and strings. The numbers are read and stored into$1, then thecodeor file is applied. The output has the same form as the input, with the numbers replaced with those returned by thecodeor file. The$0memory slot contains the current line number.--k awk_file { code | --f file }โ similar to--x, but instead of smartly finding the numbers and storing them all into the same array, it splits each input line at delimiters and stores each column into a separate memory slot, starting with$1. Non-numeric fields are preserved in the output without warning. Changes to the memory slots by the user are reflected in the output. The output is delimited by the delimiter, provided by--d. Ifcodeis not terminated by a semicolon, the return value ofcodeor file is appended to the rest of the output.--o output_fileโ sets the file where standard output is redirected to. Everything after this call will be redirected tooutput_file, until the next call to--o. Calling--o -reverts back to the standard output.--t code_lineโcode_lineis evaluated as usual, but results of every semicolon-terminated substatement are printed as columns. Essentially this is a transposed version of--poption. Ifcode_linecontains only one statement, the result is similar to setting delimiter to newline (\n). Ifcode_lineis to be applied line-by-line to a file, both--xand--kbehave as--l.--d delimiterโ stringdelimiteris used to delimit values of output array. Default is space.--D int_formatโ format forprintffunction for integers. Default:%d.--F float_formatโ format forprintffunction for floating point values. Default:%g.--mโ dump memory page. iykyk.--p,--nโ--pforcesisedto print results even when suppressed by semicolon. Every semicolon-terminated substatement is output with terminating newline, so this can be used to split lines when in--lmode. This option persists until it is turned off with--n.--vโ show program version and license disclaimer.
๐ COMMANDS ๐
ised operators all work on arrays of values. Even single values are treated as arrays with length of one. Spacing between operators and values is optional. Values can be either floating point or integers and retain information about their type unless changed. Same operators behave differently for each type.
In general, operators starting with colon (:) mean component-wise evaluation.
โ ๏ธ bestie, listen: behaviour in case of illegal arithmetic output (such as division by zero or root of negative values) is uncertain and may return eithernan, zero or some other non-standard result. This should not be relied upon as it may change in future releases. The case of integer overflows is to be avoided by user as the program does not issue a warning and the output is wrong and unpredictable. The same holds for conversion of floats to integers. Since version2.2.3, integer overflows are handled by implicit conversion into floating point type if compiled forx86-64architecture, but caution is still advised, as the handling may not catch all the problematic cases.
๐ Comments ๐
Lines are considered as comments if preceded by #!. If #! appears in the middle of the line, everything behind it is commented out. Completely blank lines are also ignored, but lines with whitespace characters will be treated normally. This way user can separate several blocks of output by empty lines.
Scripts can be made executable and evaluated without invoking ised explicitly. This is done by including declaration
#!/usr/local/bin/ised --f
in the first line of the script. This line is obviously treated as comment.
In apply-to-file mode, comments and blank lines are preserved in input, but don't count as active lines and therefore don't increment line counter. If a file contains mixed data, it can still be processed line-by-line if non-numerical data is commented out.
๐ Arrays and Separators ๐
Values, separated by commas (,) or spaces ( ) are treated as components of an array. Array separation has lowest precedence, so any operators are evaluated before the array is collected. Nested arrays are flattened before further evaluation. Arrays are enclosed in braces {}, outermost braces are optional.
Output to terminal and history is suppressed by semicolon ; which can occur any number of times in every line (putting it at the end suppresses all output, but still evaluates memory operations, if they're present).
Examples:
{1 2 {3 4} 5,6} = {1 2 3 4 5 6}
{1 2+3 4 5*6+7} = {1 5 4 37}
1 5 1+1 = {1 5 2}
๐ง Array Constructors ๐ง
[n]โ generates sequence0..n-1.[n1 n2]โ generates sequencen1..n2with increment1. Ifn2<n1, sequence is descending.[n1 m1..mi n2]โ generates sequence betweenn1,n2, but with cycling increments, given asm1..mi. Example:[0 1 2 10]={0 1 3 4 6 7 9}.(x)โ repeats numberx. This way parentheses can be used for evaluation precedence or for function arguments in scalar context.(x n)โ generates array ofnrepetitions of numberx.(x m1..mi n)โ generates sequence of lengthn, starting atxwith cycling incrementsm1..mi. Ifnis negative, the increments are used|n|times, so foriincrements, the output sequence has|n|*i+1elements. Examples:(0 1 2 10)={0 1 3 4 6 7 9 10 12 13}and(0 [1 5] -1)={0 1 3 6 10 15}.{x1..xi}โ array grouping.
๐ Component-wise Operators ๐
x:+y,x:-y,x:*y,x:/y,x:%y,x:^yโ result is an array, where each component is e.g. a sum (or other binary operations above) of corresponding components ofxandy. In case of different lengths of arrays, smaller length is used. Operations corresponding to above operators are: addition, subtraction, multiplication, division, modulo, exponentiation. Note that modulo works for both integer and non-integer values. Modulo always satisfies this equation:i{x/dy}*y+x%y=x.
๐ฆ Scalar-producing Operators ๐ฆ
@+xโ returns sum of components ofx.@*xโ returns product of components ofx.x+*yโ returns a result of alternating addition and subtraction, in the form((x_0+y_0)*x_1+y_1)*x_2+y_2+.... Ifxis shorter thany, the elements ofxare cyclically reused from the beginning of the array. Ifyis shorter thanx, it is padded with zeroes. This way, a scalarxcan be used to evaluate a polynomial with unit leading coefficient.gcd,lcmโ return greatest common divisor and least common multiple of the numbers in the array, respectively. If the array includes noninteger numbers, a warning is issued and an empty array is returned. The result ofgcdis negative if an odd number of the array are negative.avg,varโ return linear average and variance (mean square dispersion).avg{x}is shorter notation for@+x/d#xand doesn't require inputting the array twice or storing it in memory. Example:avg{0 1.5 3}={1.5}.nrm x yโ returns generalizedx-norm of vectory. Ifxis a vector, the result contains all specified norms.x=2corresponds to Pythagoras' theorem, which is available also as operator@=. Examples:nrm2{1 1 1}={sqrt3}andnrm{1 3}{1 1}={2. cbrt2}.
๐ธ Function Maps ๐ธ
sin,cos,tan,atn,asn,acs,abs,exp,sqt,cbt,logโ evaluates a function on every element of array, e.g.sin{1 2 3}={sin1 sin2 sin3}. Functions corresponding to above operators are sine, cosine, tangent, arc tangent, arc sine, arc cosine, magnitude, exponential, square root, cubic root, natural logarithm. Long operatorsatan,asin,acos,sqrt,cbrtare also valid. Exponential function is also available ase^, but has a lower precedence (the same as the operator^). The unary/prefix is also a function map:/x=1.0/x.x!โ evaluates factorial on every element of arrayx. For floating point values it evaluatesgamma(x+1). For negative integers, it returns1.r,f,i,dโ prefixes that modify values of array elements.rโ rounds values to closest integer.fโ returns fractional part of values. It is always in range0..1and represents distance to downwards rounded integer, even for negative values.iโ returns integer part of values. Expressionfx+ix=xalways holds.dโ converts values to floating point. For example,1/2=0but1/d2=0.5.
ranโ randomizes elements of array. For integers, it returns random integers strictly smaller than given value. For floating values it returns real numbers.phiโ bestie this is the Euler totient function, but it's picky: it only does positive integers. Nonpositive and noninteger values are literally just skipped, no notes. ๐bjx y,byx y โ applies the x-th Bessel function of the first / second kind to array y. x should be one or more integers โ floating point values get cast to integers and a warning is issued (she will call it out, sorry ๐ซถ).
โจ Tensor Operators โจ
Ok so this is the fun part. ๐
x+y,x-y,x*y,x/y,x%y,x^yโ evaluates the corresponding operation on every possible pair between elements of x and y. This is highkey the most useful when one of the arguments is a scalar (the other one does all the work, main character energy ๐).
Beware bestie: the division operator/acts as a unary operator (inversion) when it has no left operand, or has a space on the left, but not on the right. So like,/3is equivalent to1.0/3. That tiny space is doing SO much heavy lifting, do not disrespect it. ๐ญ
Examples, because visuals ate:
{1 2 3 4}*{1 -1}={1 -1 2 -2 3 -3 4 -4}
{2 3 -5}*2={4 6 -10}
xeyโ the operator for exponential notation. Useful mostly in scalar context (e.g.1.3e-5), but it can be used in general for evaluating exponential notation for all combinations. Multi-tasking icon. โจxcyโ evaluates the binomial symbol (x over y). It supports floating point values. Ngl that's slay.
Example:
3c{0 1 2 3}={1 3 3 1}
๐งฎ Polynomial Operators ๐งฎ
The following set of operators treat arrays as polynomial coefficients. First element corresponds to the zero-order term, and so on, e.g. {1 2 3} <=> 3x^2 + 2x + 1. So yes, the array is the polynomial, she contains multitudes. ๐
x++y,x--yโ polynomial addition and substraction. This is similar to the operators:+:-, but the length of the output array is equal to the length of the larger array. Size queen behaviour, honestly. ๐x**yโ computes the product of two polynomials. In terms of arrays, this evaluates to the convolution of x and y. Cute and mathematically unhinged, we love her.x//y,x%%yโ computes the quotient and remainder in long polynomial division. The returned arrays always contain floating point values, regardless of the input, and leading zeroes get trimmed from the output. Messy queen stays tidy. ๐pxx y โ evaluates polynomial x in the points given in array y.pdx โ computes the derivative of polynomial x. Equivalent to{x<<-1}:*[1 #x]. Look at her go. โญpzx โ returns all real roots of polynomial x. The resulting array is not guaranteed to be sorted in any way, so like, don't come for her about the order. ๐
This operator uses Sturm's sequence to isolate the roots, and then proceeds with Newton-Raphson iteration. It works quite well for well-behaved polynomials. Accuracy is questionable if there are roots with multiplicity 3 or higher โ so yeah, sketchy territory, be warned. ๐
The algorithm outputs warning messages if the accuracy is questionable, or if the iteration fails to converge to a result. She tells you when she's not sure, that's healthy communication.
zpx โ is the inverse of thepzoperator. It takes the set of roots and returns the minimal polynomial with the given roots, with the leading coefficient normalized to 1.
pzzp should return the same array as on the input, up to a reordering of elements (excepting the numerical errors in root finding, especially if there are multiple roots). Conversely, zppz does not necessarily return the initial array, because it ignores the normalization factor and irreducible factors that don't have any real roots. It's giving selective memory, and honestly? Valid. ๐
Fx โ returns the prime factorization of x. If x has many components, the factors get concatenated in a way that makes the product of the output array equal to the product of the input array. That makes a negative integer produce an additional-1factor, while floating point input numbers stay intact. No cap, the math checks out. ๐ฅ
๐ฆ Vector Operators ๐ฆ
x@:yโ returns the dot product of vectors x and y. In case of different array lengths, the overhead is discarded. She's not gonna fight about the leftovers. ๐x@^yโ returns the cross product of vectors x and y, if the vectors are three-dimensional. In the general case, it returns componentsz_i=x_{i+1}*y_{i+2}-x_{i+2}*y_{i+1}.
This generalization is useful for polygon geometry โ for a polygon with coordinates {x_i,y_i}, the area of the polygon is 0.5*@+{x@^y}. Similar formulas exist for polygon center and other expressions. Geometry girlies stay winning. ๐ธ
@!xโ normalizes vector x. Glow-up operator, literally.@=xโ returns the length of vector x. Shorter notation of the general norm:{@=x}={nrm2x}. Same vibes, less typing. ๐ซถ
๐ Set Operators ๐
x&yโ returns the elements that are in both x and y. Intersection besties.x|yโ concatenates arrays x and y. Produces the same result as{x y}.
[deprecated] This operator is an unnecessary waste of notation. It should have had the interleaving effect, now represented by Y. So yeah, she's on the way out, don't get attached. ๐
x\yโ returns the elements of x that are not present in y. Subtraction but make it set theory.x|&yโ is the xor operation on arrays. Returns elements present in only one of the arrays. Pick a side, babe.xYyโ interleaves the arrays x and y. (This is the one that stole the|job, iykyk.)~xโ reverses the order of array x. Backwards but make it fashion. ๐Sxโ sorts the array in ascending order.#xโ returns the number of elements in array x.#_xyโ counts occurences of elements of x in y. This is the selective variant of the#operator.
Example:
#_{0 1 4}{1 2 3 4 4 1}={0 2 2}
#__xyโ distributes elements of y into a histogram where elements of x divide the real numbers into bins. The size of the output is one element more than the size of x. The first bin extends from negative infinity to the first element of x and the last extends to the positive infinity. x is expected to be in ascending order โ so sort her first, bestie, or it's chaos. ๐ญ?xโ returns the indices of nonzero elements of x. Only integer zero counts as zero. Yes, very particular. ๐
This operator is intended for use with the index operator (_), to select elements that satisfy some logical test. For example, x_?{x<1000} returns only elements smaller than 1000.
To skip an entire array if it doesn't satisfy a condition, use the ? operator in combination with +. For example, x+?{#x==3} prints x only if its length equals 3. This functionality relies on the fact that tensor summation with an empty array returns an empty array. Sneaky, clever, iconic. โญ
?_x yโ returns the indices of elements of x in the array y. If the element is found more than once, only the first index is returned. If the element is not present in y, a value-1is returned. She's not gonna hunt around for the rest, sorry. ๐S_xโ returns the indices that would sort the array x. It's always true thatSx=x_S_x. Always. Fr fr.x=yโ returns1if the arrays are equal,0otherwise.
๐ Element Selection Operators ๐
x<<yโ for positive values of y, returns the first y values of x (like the unix utilityhead). For negative values, it returns everything except the first y values. If y is an array, it concatenates all the results. y should be an array of integers. Super useful for array cycling:
{1 2 3 4}<<{-2 2}={3 4 1 2}
x>>yโ same as above, except it works from the back of the array. Backwards queen. ๐x_yโ returns the elements of x at indices y. It interpolates for noninteger indices and wraps around for indices out of range. She's flexible like that. ๐ฆUPNOEIDXโ the conditional selectors. They return elements that satisfy a certain condition.Uโ unique, deletes duplicate elementsPโ positiveNโ negativeOโ oddEโ evenIโ integersDโ floating point valuesXโ prime numbers
minmaxโ return the smallest and the largest component of the array respectively. The duality of man, etc.Zxโzilch, returns an empty array. This operator is useful for suppressing output from functions with side-effects, such as the@operator. She's the "no thoughts head empty" operator and we stan. ๐ธ
โญ Constants โญ
piโ returns3.14159265358979323846264degโ returns the value of the angular degree in radians,0.017453292519943295769emcโ returns the Euler-Mascheroni constant,0.57721566490153286pmmpโ plus/minus and minus/plus constants. They output the arrays{1,-1}and{-1,1}respectively. They can be used to compute results of multivalued formulas simultaneously, for example a quadratic equation. Two answers, one line, efficiency icon. ๐
๐ง Memory Operators ๐ง
Memory slots are enumerated by integers. For floating point values, the integer part is used. This may change in future versions โ so like, don't build your whole personality on it. ๐
Named variables can be used instead of integer enumeration with the use of backticks.
@xyโ puts array y into the memory slots enumerated by elements of x. x should be integers. Floating point numbers are cast to integers and a warning is issued.$xโ concatenates arrays found at the memory slots enumerated by x. For negative values, it returns the array from history instead of memory,$-1being the most recent entry. x should be integers.@`<name>`yโ puts array y into the memory slot represented by the given <name>.$`<name>`โ retrieves the variable named by the given <name>.
ised manages memory as a hashed map, so a memory position can be every positive integer. Saving an array to slot $100 doesn't allocate any more memory than saving to slot $1 โ she's not dramatic about it. ๐
Results are added to history for input lines from files (--f option) or interactive mode, unless the line terminates with a semicolon. Negative slots are reserved for internal use by the named variable system and are not accessible by direct dereference. Instead, history is accessed by the negative arguments of the $ operator. So like, don't try to dereference them directly, that's not the vibe. ๐ญ
๐ฅ Comparison and Equality operators ๐ฅ
For logical evaluation, ised provides comparison operators. The result of a comparison is 1 for true and 0 for false. Equality and inequality operators also check if the types of both values are equal โ she's checking your vibe and your ID. ๐ซถ
For boolean analysis of resulting arrays, use multiplication for the and operator and summation for the or operator. Incorporating additional operators for this functionality would be redundant, as the result is equivalent. But beware: multiplication and summation have higher precedence than the comparison operators, so use the grouping operator {} to achieve the desirable effect. Don't get caught out bestie, the grouping braces are your besties. ๐
x:<yx:>yx:<=yx:>=yx:==yx:<>yโ comparison and equality, evaluated component-wise. The result is an array with the size of the shorter of the input arrays. Short queen rights. ๐ธx<yx>yx<=yx>=yx==yx<>yโ same as above, but evaluated on every possible pair of values. The size of the output array is the product of the input sizes (see Tensor operators for details and example). She's thorough, okay? ๐
๐ Function definitions ๐
ised implements a rudimentary mechanism for function definitions. It enables storing an expression and evaluating it later upon command. The functions are stored in a map structure and are accessed via integer function ids. A function id is returned when the function is declared. No particular order of the function ids should be assumed โ they're not ranked, they're not in a queue, it's giving feral. ๐
The zero (0) function id is reserved for an identity function (no-op). She does nothing and she does it perfectly. โจ
okay so real talk: these functions can do memory manipulation too, which is exactly what makes them as versatile as functions in any programming language. bestie, you can design them as procedures that straight-up ignore input and output and just operate on memory, or as plain-old-functions that take an argument and return a result, or literally any combination of both. it's giving โจrangeโจ ๐ฆ
{:expression:}โ function declaration, babes. The expression gets parsed, stored into the function memory, and its unique id comes right back at you. That id is guaranteed to be nonzero, no cap ๐. You can stash the returned id in memory and use it later. Inside the function, operatorxis what refers to the function's argument. And the function is not evaluated at this point โ it's just being declared, it's just sitting there being iconic.f::xโ function evaluation. Herefis an array of function ids, and they get applied sequentially to the arrayx, left-to-right. Read it as composition of function: the result from the previous function gets handed to the next one as its argument. ๐ฆf:::xโ function iteration. The array of function idsfgets evaluated over and over on the argumentx. The iteration stops when the argument no longer changes, or when the maximum number of iterations is reached. That max is65536by default, but you can query and change it using system callQ{105 ...}(go peep the section on system calls). You could emulate this operator with ordinary function evaluation plus the system call for setting the instruction pointer,Q{103 ...}, but ngl that implementation is quite complex. Since functional iteration until convergence is super common in math, this operator is a valuable shortcut. ๐f@::xโ function map. The array of function idsfgets evaluated on each element of the arrayx. This is meant to allow creation of user functions that don't have to handle the array nature of the argument themselves. ๐ซถxโ this bad boy evaluates to the argument supplied to the function. In case of nested functions, it refers to the innermost function's argument. Outside a function, it has the value of the current line (when used with--lor--x), or it's invalid otherwise. ๐
The function evaluation operator (::) is enough to implement all basic control structures. ised is therefore a Turing complete language. ๐ likeโฆ okay, main character energy.
function call:
{fun}::{arg}
conditional execution (if-statement):
{{false-fun true-fun}_{condition}}::{arg}
switch statement:
{{fun1 fun2 fun3 fun4 ...}_switch}::{arg}
static repetition (for-statement):
(fun n)::{arg}
recursion:
{@mem {:do-something-with $mem::x :}}::{arg}
The implementation of the function must be carefully devised, otherwise the execution might get stuck in an infinite recursion. ๐ญ you have been warned, bestie โ this one does not play.
general loop (while-statement):
{ body-fun jump-test }::{arg}
Such a simple implementation has the loop contents in body-fun and implements jump-fun such that its argument stays unchanged, but sets the program counter to zero if a condition is met. The program counter is set via system call operator Q{103 n}, where n is simply which function in the left-hand side of the operator :: is evaluated next. For example, { {:x+1:} {:x Q{103 -{x>10}}:} }::{arg} increments the argument by one until it becomes greater than 10. In that case, the system call sets the program counter to -1, which is out of range, and the evaluation stops. ๐ฌ
More complex flow control is possible, because the operator Q{103 n} can be used exactly like a goto statement. Q{102} can be used to find the current program counter and calculate relative jumps. iykyk ๐ฅ
๐ฎ System calls ๐ฎ
The internal state of ised can be accessed and modified using the system call operator Qx. The argument x is an array, where the first component is the system call id number and the rest are optional arguments to the system call. The list of system calls will be expanded in future versions of ised, so likeโฆ stay tuned, bestie. ๐
Example: use ised --l load_file '$1 Q{$1>3}' to output the specified file, but terminate as soon as it encounters a number greater than 3. clean, simple, slays.
The system call ids are available as named variables, specified between the backticks as `<name>`. For instance, a call Q{`EXIT` 42} terminates the program with a return value of 42. ๐
The list of system call numbers and names:
0 [NOP]โ no-op. literally nothing. that's the whole vibe. ๐1 [EXIT]โ exit. Exits with return value0, or the value specified as an optional argument. say bye bestie ๐100 [BREAK]โ break. Interrupts the loading of files by commands--f,--l,--aor--x, and aborts evaluation of the current line.101 [CONT]โ continue. Aborts evaluation of the current line and proceeds to the next line in the file. moving on ๐102 [PC]โ get program counter. Returns the index of the currently evaluated function in the innermost evaluation operator::.103 [PCSET]โ set program counter. Sets the index of the next evaluated function in the innermost operator::. If the argument is out of bounds, it terminates the evaluation. If it's called without arguments, it does nothing. ๐ซ104 [STACKDEPTH]โ get stack depth. Returns the number of nested functions around the call. If you're not in a function, it returns0.105 [MAXITER]โ get/set iteration limit. Without an argument, the iteration limit for operator:::is returned. With an argument, it's changed to the given (nonnegative) value. ๐๏ธ1000 [HISTORY_COUNT]โ get history count. Returns the number of history entries, or-1if history is disabled.1001 [HISTORY_ENABLE]โ disable history. Disables remembering previous results โ or enables it, if called with a nonzero argument. yes the name says disable and it also enables, we contain multitudes. ๐1002 [HISTORY_CLEAR]โ clear history. Clears the history. fresh start era โจ2000 [MEM_INDEX]โ get/set indexing memory slot. Without arguments, it sets the memory slot where the current line number is stored (default is0). With an argument, it sets it.2001 [MEM_INPUT]โ get/set input memory slot. Same as2000, but for the memory slot where the current input line is stored (default is1).2002 [MEM_OFFSET]โ get/set file loading offset. Same as2000, but for the memory slot where--acontinues loading lines to. At startup, this is0, so the first memory slot filled is$1, and it's advanced with each loaded line. ๐ฅ2003 [MEM_CLEAR]โ delete from memory. Clears the entire contents of memory if called without arguments. The optional argument is a list of memory slots to delete. ๐งน2004 [MEM_LIST]โ get memory list. Lists the occupied memory slots.2050 [FUN_CLEAR]โ delete function. Clears all the functions if called without arguments. The optional argument is a list of function ids to delete.2051 [FUN_LIST]โ get function list. Lists the occupied function ids.3000 [VERSION]โ ised version. Returns the array containing the version number{major,minor,revision}. ๐ท๏ธ3001 [SIZEOF_INT]โ int size. Returns the size of the integer type in bytes.3002 [SIZEOF_FLOAT]โ float size. Returns the size of the float type in bytes.3003 [DEBUG]โ debug level. Returns the debugging level, set at compile-time.3004 [READLINE_STATUS]โ readline status. Returns the array indicating if various libreadline functionalities are enabled (use--vfor details).3005 [OVERFLOW_STATUS]โ overflow enabled. Returns1if overflow handling was enabled at compile-time, and0otherwise.5000 [TIME]โ system time. Returns unix time in seconds if called without arguments. The arguments can be a list of values, which specify the time fields to output:0 [TIME.EPOCH]= epoch1 [TIME.SEC]= sec2 [TIME.MIN]= min3 [TIME.HOUR]= hour4 [TIME.MONTHDAY]= month-day5 [TIME.MONTH]= month6 [TIME.YEAR]= year7 [TIME.WEEKDAY]= week-day8 [TIME.YEARDAY]= year-day
5001 [PROCESS_TIME]โ process time. Returns an array containing real time, user time and system time, in seconds. โฑ๏ธ5002 [SLEEP]โ sleep. Sleeps for the amount of seconds specified in the argument. self care honestly ๐ด5050 [PID]โ pid. Returns the PID of this process. ๐ชช
For instance, a call Q{`TIME` `TIME.YEAR` `TIME.MONTH` `TIME.DAY`} may return the array {2013 10 31}. ๐
๐ Unicode operators ๐
Since version 2.6.0, ised can be compiled to support some additional operators that include utf-8 encoded unicode characters. Mostly, these are just aliases to the existing operators. ๐ซ
Warning: the following table requires utf-8 support by the terminal displaying this man page. ๐ likeโฆ make sure your terminal is actually invited to the party, bestie.
the table itself is coming up next, and it's gonna be a whole moment โ stay with me ๐๐ฆ๐
Like, here's the full alias chart bestie โ every ASCII spelling on the left, its UTF-8 glow-up on the right. Copy these exactly, they're load-bearing ๐
โโโโโโโโโโโโโโโโโโโโโโโ
โ The list of aliases โ
โโโโโโโโโโโฌโโโโโโโโโโโโค
โ ASCII โ UTF-8 โ
โโโโโโโโโโโผโโโโโโโโโโโโค
โ :: โ โ โ
โ ::: โ โ โ
โ @:: โ โท โ
โ @+ โ ฮฃ โ
โ @* โ ฮ โ
โ sqrt โ โ โ
โ cbrt โ โ โ
โ & โ โฉ โ
โ \ โ โ โ
โ | โ โช โ
โ ?_ โ โ * โ
โ Z โ โ
โ
โ I โ โค โ
โ D โ โ โ
โ X โ โ โ
โ << โ โซ โ
โ >> โ โช โ
โ :<= โ :โค โ
โ :>= โ :โฅ โ
โ :== โ :โก โ
โ :<> โ :โ โ
โ <= โ โค โ
โ >= โ โฅ โ
โ == โ โก โ
โ <> โ โ โ
โ pi โ ฯ โ
โ aa โ ฮฑ โ
โ deg โ ยฐ * โ
โ emc โ ฮณ โ
โ pm โ ยฑ * โ
โ mp โ โ * โ
โ @: โ ยท โ
โ @^ โ ร โ
โ phi โ ฯ โ
โ {::} โ ฮป * โ
โโโโโโโโโโโดโโโโโโโโโโโโ
So the operators with the lil asterisk up there? They do not behave exactly like their ASCII twins โ they're the โจ spicy โจ ones. Like, โ is infix, whereas ?_ needs both of its operands to its right. Different vibes, same idea, don't mix them up ๐ซถ
the ยฐ operator, she's got range
The ยฐ operator multiplies the preceding number by the degree value, and it does it with high precedence โ but only if there's no space between them. An isolated ยฐ operator just behaves like a regular numerical constant, equal to deg. This is what lets sin60ยฐ replace sin{60*deg} ๐ and like, note that the braces are not needed with the ยฐ operator. slay.
ยฑ and โ are built different
Same logic applies to ยฑ and โ, and this is the part where people get it twisted so listen up: they are not precomputed constant arrays {1,-1} and {-1,1}. Nope. They behave more like the operators + and -. If you use them in the infix sense, they do addition and subtraction on each pair of the left and right argument, like:
{1 2 3}ยฑ{4 5}={5 -3 6 -4 6 -2 7 -3 7 -1 8 -2}
If you use them in the prefix sense, they convert each element of the following array into its positive and negative version:
ยฑ{4 5}={4 -4 5 -5}
The plus and minus here operate on the innermost level โ as opposed to the expression pm*{4 5}={4 5 -4 -5}. This alternative lets you pick whichever variant is better suited for the evaluation you actually have going on ๐
ฮป said "I'll handle the function spec"
The lambda operator ฮป offers an alternative to function specification. It's a prefix operator with a very low precedence (equal to the union operator |), so the braces aren't always necessary. For instance:
(ฮปx^2 3)::[10]
that performs the squaring operation three times in succession ๐ฅ The space after x^2 is enough to terminate the function specification. But in a different scenario, regular braces are needed:
{ฮปx^2}::[10]
Because without the braces, the expression would be equivalent to ฮป{x^2::[10]}, which is probably not the expression you wanted, bestie ๐ญ
โจ EXAMPLES โจ
ised '@0[2 100];$0\{$0*$0}'
returns all prime numbers up to 100. It utilises memory to prevent code repetition ๐
ised '(0 (1 2 10) 10)'
generates squares of numbers up to 10, by using nested constructors. Inner constructor generates increments for outer constructor ๐ง
ised --l file '$0 ~$1'
reverses lines of file and prepends line numbers.
ised '@0 {0.5*{1+sqt5}};r{{$0^[1 20]:-(-$0)^-[1 20]}/sqt5}'
generates Fibonacci sequence using direct exponential formula โญ
ised --d '\n' '[0 1/d5 10]'
generates evenly spaced values between 0 and 10, separated by a newline. Same functionality as
seq 0 0.2 10
ised --d '\n' '[0 pi/100 pi]' | ised --F '%+12.6f' --l - 'd{$1 sin$1
cos$1 tan$1 exp$1 $1^2}'
generates nicely formatted table of several functions in range between 0 and pi. Note the use of placeholder - for standard input ๐
ised --o tmp_file --t '[0 pi/100 pi]' --o - --F '%+12.6f' --l tmp_file
'd{$1 sin$1 cos$1 tan$1 exp$1 $1^2}'
previous example, achieved in one pass using a temporary intermediate file. Note the use of placeholder - for standard output ๐ฆ
ised '{1.4^[11]}@:{1./[11]!} exp1.4'
calculation of exp(1.4) by summation of series, compared to exact value.
ised '@1 60;@2 72;@3[1 $1];{$1%$3==0}:*{$2%$3==0}:*$3\0'
returns list of common divisors of 60 and 72. Numbers 60 and 72 are first stored in memory, together with list of possible divisors, for easier readability. Note the use of multiplication for boolean and evaluation. The same can be achieved more elegantly with operator ?:
ised '@1 60;@2 72;@3[1 $1];$3_?{{$1%$3==0}:*{$2%$3==0}}'
ised '@1 60;@2 72;{$1*[1 $2]&$2*[1 $1]}_0'
returns least common multiple of 60 and 72.
ised --d '+' '2^[10]' | ised
illustration how changing output format can produce useful input for other programs, in this case, ised itself. This is useful for easier input of operator repetition, for example the power tower:
ised --d '^' '(1/sqt2 10)' | ised --l - '-$1'
this outputs solution of equation 2^x=x^2.
ised '@1{2}@2{3}@3{-5};{-$2+pm*sqt{$2^2-4*$1*$3}}/{2*$1}'
solves quadratic equation 2x^2+3x-5. Capability of handling arrays is exploited to give both solutions at once. pm operator is shorthand for array {1,-1}. In the utf-8 notation, the expression reads
ised '@1{2}@2{3}@3{-5};{-$2ยฑโ{$2^2-4*$1*$3}}/{2*$1}'
The same can be achieved with built-in polynomial solver:
ised '@1{2}@2{3}@3{-5};pz{$3 $2 $1}'
Note that the intermediate variables $1,$2,$3 were only used to make the expression more readable ๐
yes 0 | ised '@2{145}' --l - '@2{{$2/2 3*$2+1}_{$2%2}} Q{100 $2==1}'
outputs the Hailstone sequence for the number 145. It uses GNU core utility yes to produce an infinite loop and terminates using a conditional system call 100 (break) ๐
ised --D '%02d' --d ':' 'Q{5002 60-Q{5000 1}};Q{5000 3 2 1}'
Waits for the minute to change and then displays the current time, so that the seconds will be zero. It uses the time-related system call utilities 5000 (system time) and 5002 (sleep) โญ
๐ AUTHOR ๐
Simon Copar
๐ธ SEE ALSO ๐ธ
okay that's the whole page bestie, you're officially an ised girlie now ๐ซถ this iconicness is from ised(1), dated May 1, 2014 โ go forth and compute, periodt ๐โจ
๐ฆ where this page comes from
- nixos 26.05: ised 2.7.1
- nixpkgs unstable: ised 2.7.1
- Copyright (c) 2007-2014, Simon Copar
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms