NAME rewind - set position at the beginning of some or all files SYNOPSIS rewind([f_1, f_2, ...]) TYPES f_1, f_2, ... open file streams return null value or error DESCRIPTION With one or more arguments f_1, ..., this function sets the position for each f_i at the beginning. With no argument, this operation is applied to all user-opened files. EXAMPLE ; f = fopen("curds","r"); ; x = fgetc(f); ; rewind(f); ; y = fgetc(f); ; print x == y 1 LIMITS The number of arguments is not to exceed 1024. LINK LIBRARY int rewindid(FILEID id); SEE ALSO errno, fclose, feof, ferror, fflush, fgetc, fgetline, fgets, files, fopen, fprintf, fputc, fputs, fseek, fsize, ftell, isfile, printf, prompt ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: rewind,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rewind,v $ ## ## Under source code control: 1996/04/30 03:05:18 ## File existed as early as: 1996 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ What is calc? Calc is an interactive calculator which provides for easy large numeric calculations, but which also can be easily programmed for difficult or long calculations. It can accept a command line argument, in which case it executes that single command and exits. Otherwise, it enters interactive mode. In this mode, it accepts commands one at a time, processes them, and displays the answers. In the simplest case, commands are simply expressions which are evaluated. For example, the following line can be input: 3 * (4 + 1) and the calculator will print: 15 Calc as the usual collection of arithmetic operators +, -, /, * as well as ^ (exponentiation), % (modulus) and // (integer divide). For example: 3 * 19^43 - 1 will produce: 29075426613099201338473141505176993450849249622191102976 Notice that calc values can be very large. For example: 2^23209-1 will print: 402874115778988778181873329071 ... many digits ... 3779264511 The special '.' symbol (called dot), represents the result of the last command expression, if any. This is of great use when a series of partial results are calculated, or when the output mode is changed and the last result needs to be redisplayed. For example, the above result can be modified by typing: . % (2^127-1) and the calculator will print: 47385033654019111249345128555354223304 For more complex calculations, variables can be used to save the intermediate results. For example, the result of adding 7 to the previous result can be saved by typing: curds = 15 whey = 7 + 2*curds Functions can be used in expressions. There are a great number of pre-defined functions. For example, the following will calculate the factorial of the value of 'old': fact(whey) and the calculator prints: 13763753091226345046315979581580902400000000 The calculator also knows about complex numbers, so that typing: (2+3i) * (4-3i) cos(.) will print: 17+6i -55.50474777265624667147+193.9265235748927986537i The calculator can calculate transcendental functions, and accept and display numbers in real or exponential format. For example, typing: config("display", 70) epsilon(1e-70) sin(1) prints: 0.8414709848078965066525023216302989996225630607983710656727517099919104 Calc can output values in terms of fractions, octal or hexadecimal. For example: config("mode", "fraction"), (17/19)^23 base(16), (19/17)^29 will print: 19967568900859523802559065713/257829627945307727248226067259 0x9201e65bdbb801eaf403f657efcf863/0x5cd2e2a01291ffd73bee6aa7dcf7d1 All numbers are represented as fractions with arbitrarily large numerators and denominators which are always reduced to lowest terms. Real or exponential format numbers can be input and are converted to the equivalent fraction. Hex, binary, or octal numbers can be input by using numbers with leading '0x', '0b' or '0' characters. Complex numbers can be input using a trailing 'i', as in '2+3i'. Strings and characters are input by using single or double quotes. Commands are statements in a C-like language, where each input line is treated as the body of a procedure. Thus the command line can contain variable declarations, expressions, labels, conditional tests, and loops. Assignments to any variable name will automatically define that name as a global variable. The other important thing to know is that all non-assignment expressions which are evaluated are automatically printed. Thus, you can evaluate an expression's value by simply typing it in. Many useful built-in mathematical functions are available. Use the: help builtin command to list them. You can also define your own functions by using the 'define' keyword, followed by a function declaration very similar to C. define f2(n) { local ans; ans = 1; while (n > 1) ans *= (n -= 2); return ans; } Thus the input: f2(79) will produce; 1009847364737869270905302433221592504062302663202724609375 Functions which only need to return a simple expression can be defined using an equals sign, as in the example: define sc(a,b) = a^3 + b^3 Thus the input: sc(31, 61) will produce; 256772 Variables in functions can be defined as either 'global', 'local', or 'static'. Global variables are common to all functions and the command line, whereas local variables are unique to each function level, and are destroyed when the function returns. Static variables are scoped within single input files, or within functions, and are never destroyed. Variables are not typed at definition time, but dynamically change as they are used. For more information about the calc language and features, try: help overview In particular, check out the other help functions listed in the overview help file. ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: intro,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/intro,v $ ## ## Under source code control: 1991/07/21 04:37:21 ## File existed as early as: 1991 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME fcnt - count of number of times a specified integer divides an integer SYNOPSIS fcnt(x,y) TYPES x integer y integer return non-negative integer DESCRIPTION If x is nonzero and abs(y) > 1, fcnt(x,y) returns the greatest non-negative n for which y^n is a divisor of x. In particular, zero is returned if x is not divisible by y. If x is zero or if y = -1, 0 or 1, fcnt(x,y) is defined to be zero. EXAMPLE ; print fcnt(7,4), fcnt(24,4), fcnt(48,4) 0 1 2 LIMITS none LINK LIBRARY long zfacrem(ZVALUE x, ZVALUE y, ZVALUE *rem) SEE ALSO frem, gcdrem ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: fcnt,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/fcnt,v $ ## ## Under source code control: 1995/12/18 12:03:02 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME system - issue a shell command SYNOPSIS system(cmd) TYPES cmd str return int DESCRIPTION This function excutes the shell command found in the srtring, cmd. The return value is system dependent. On POSIX P1003.1 compliant systems the return value is defined by the waitpid system call. Typically a shell command that returns with a 0 exit status will cause this function to return a 0 value. On some systems, a shell command that returns with an exit status of e will cause this function to return e*256. Core dumps, termination due to signals and other waitpid values will change the return value. On POSIX P1003.1 compliant systems, if cmd is empty then this function will determine if the shell is executable. If the shell is executable, 0 is returned otherwise non-zero is returned. EXAMPLE ; system("") 0 ; system("true") 0 ; system("exit 2") 512 ; system("date") Sun Jul 9 03:21:48 PDT 1995 0 LIMITS none LINK LIBRARY none SEE ALSO cmdbuf, argv ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: system,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/system,v $ ## ## Under source code control: 1995/07/09 03:48:57 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ Environment variables CALCPATH A :-separated list of directories used to search for resource filenames (*.cal files) that do not begin with: / ./ ../ ~ If this variable does not exist, a compiled value is used. Typically compiled in value is: .:./cal:~/cal:${CALC_SHAREDIR}:${CUSTOMCALDIR} which is usually: .:./cal:~/cal:/usr/share/calc:/usr/share/calc/custom This value is used by the READ command. It is an error if no such readable file is found. The CALCBINDINGS file searches the CALCPATH as well. CALCRC On startup (unless -h or -q was given on the command line), calc searches for files along the :-separated $CALCRC environment variable. If this variable does not exist, a compiled value is used. Typically compiled in value is: ${CALC_SHAREDIR}/startup:~/.calcrc:./.calcinit which is usually: /usr/share/calc/startup:~/.calcrc:./.calcinit Missing files along the $CALCRC path are silently ignored. CALCBINDINGS On startup (unless -h or -q was given on the command line), calc reads key bindings from the filename specified in the $CALCRC environment variable. These key bindings are used for command line editing and the command history. If this variable does not exist, a compiled value is used. Typically compiled in value is: bindings The bindings file is searched along the CALCPATH. Unlike the READ command, a .cal extension is not added. If the file could not be opened, or if standard input is not a terminal, then calc will still run, but fancy command line editing is disabled. NOTE: If calc was compiled with GNU-readline support, the CALCBINDINGS facility is ignored and the standard readline mechanisms (see readline(3)) are used. HOME This value is taken to be the home directory of the current user. It is used when files begin with '~/'. If this variable does not exist, the home directory password entry of the current user is used. If that information is not available, '.' is used. PAGER When invoking help, this environment variable is used to display a help file. If this variable does not exist, a compiled value is used. Typically compiled in value is something such as 'more', 'less', 'pg' or 'cat'. SHELL When a !-command is used, the program indicated by this environment variable is used. If this variable does not exist, a compiled value is used. Typically compiled in value is something such as 'sh' is used. ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: environment,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/environment,v $ ## ## Under source code control: 1991/07/23 05:47:25 ## File existed as early as: 1991 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME strprintf - formatted print to a string SYNOPSIS strprintf(fmt, x_1, x_2, ...) TYPES fmt string x_1, x_2, ... any return string DESCRIPTION This function returns the string formed from the characters that would be printed to standard output by printf(fmt, x_1, x_2, ...). EXAMPLE ; strprintf("h=%d, i=%d", 2, 3); "h=2, i=3" ; c = config("epsilon", 1e-6); c = config("display", 6); ; c = config("tilde", 1); c = config("outround", 0); ; c = config("fullzero", 0); ; fmt = "%f,%10f,%-10f,%10.4f,%.4f,%.f.\n"; ; a = sqrt(3); ; strprintf(fmt,a,a,a,a,a,a); "1.732051, 1.732051,1.732051 , ~1.7320,~1.7320,~1. " LIMITS The number of arguments of strprintf() is not to exceed 1024. LINK LIBRARY none SEE ALSO strcat, strcpy, strerror, strlen, strncmp, strncpy, strpos, strscan, strscanf, substr, printf, fprintf, print ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: strprintf,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/strprintf,v $ ## ## Under source code control: 1996/03/12 22:50:41 ## File existed as early as: 1996 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME insert - insert one or more elements into a list at a given position SYNOPSIS insert(x, y, z_0, z_1, ...) TYPES x lvalue whose value is a list y int z_0, ... any return null value DESCRIPTION If after evaluation of z_0, z_1, ..., x is a list with contents (x_0, x_1, ..., x_y-1, x_y, ..., x_n-1), then after insert(), x has contents (x_0, x_1, ..., x_y-1, z_0, z_1, ..., x_y, ..., x_n-1), i.e. z_0, z_1, ... are inserted in order immediately before the element with index y (so that z_0 is now x[[y]]), or if y = n, after the last element x_n-1. An error occurs if y > n. EXAMPLE ; A = list(2,3,4) ; print A list (3 elements, 3 nonzero): [[0]] = 2 [[1]] = 3 [[2]] = 4 ; insert(A, 1, 5, 6) ; print A list (5 elements, 5 nonzero): [[0]] = 1 [[1]] = 5 [[2]] = 6 [[3]] = 3 [[4]] = 4 ; insert(A, 2, remove(A)) ; print A list (5 elements, 5 nonzero): [[0]] = 1 [[1]] = 5 [[2]] = 4 [[3]] = 6 [[4]] = 3 LIMITS insert() can have at most 100 arguments o <= y <= size(x) LINK LIBRARY none SEE ALSO append, delete, islist, pop, push, remove, rsearch, search, select, size ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: insert,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/insert,v $ ## ## Under source code control: 1994/03/19 03:13:18 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME int - return the integer part of a number or of numbers in a value SYNOPSIS int(x) TYPES If x is an object of type xx, int(x) requires xx_int to have been defined; other conditions on x and the value returned depend on the definition of xx_int. For other x: x number (real or complex), matrix return number or matrix DESCRIPTION If x is an integer, int(x) returns x. For other real values of x, int(x) returns the value of i for which x = i + f, where i is an integer, sgn(f) = sgn(x) and abs(f) < 1. If x is complex, int(x) returns int(re(x)) + int(im(x))*1i. If x is a matrix, int(x) returns the matrix m with the same structure as x in which m[[i]] = int(x[[i]]). EXAMPLE ; print int(3), int(22/7), int(27/7), int(-3.125), int(2.15 - 3.25i) 3 3 3 -3 2-3i LIMITS none LINK LIBRARY NUMBER *qint(NUMBER *x) COMPLEX *c_int(COMPLEX *x) MATRIX *matint(MATRIX *x) SEE ALSO frac, ceil, floor, quo ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: int,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/int,v $ ## ## Under source code control: 1994/09/30 00:57:18 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME inputlevel - current input level SYNOPSIS inputlevel() TYPES return nonnegative integer DESCRIPTION This function returns the input level at which it is called. When calc starts, it is at level zero. The level is increased by 1 each time execution starts of a read file command or a call to eval(S) for some expression S which evaluates to a string. It decreases by 1 when a file being read reaches EOF or a string being eval-ed reaches '\0', or earlier if a quit statement is encountered at top calculation-level in the flle or string. It decreases to zero if an abort statement is encountered at any function-level in the file or string. If a quit or abort statement is encountered at top calculation-level at top input-level, calc is exited. Zero input level is also called top input level; greater values of inputlevel() indicate reading at greater depths. EXAMPLE n/a LIMITS none LINK LIBRARY none SEE ALSO read, eval, quit, abort, calclevel ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: inputlevel,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/inputlevel,v $ ## ## Under source code control: 1999/10/31 06:01:21 ## File existed as early as: 1999 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME blocks - return a named block or number of unfreed named blocks SYNOPSIS blocks([id]) TYPES id non-negative integer return named block or null value DESCRIPTION With no argument blocks() returns the number of blocks that have been created but not freed by the blkfree function. With argument id less than the number of named blocks that have been created, blocks(id) returns the named block with identifying index id. These indices 0, 1, 2, ... are assigned to named blocks in the order of their creation. EXAMPLE ; A = blk("alpha") ; B = blk("beta") = {1,2,3} ; blocks() 2 ; blocks(1) block 1: beta chunksize = 256, maxsize = 256, datalen = 3 010203 ; blocks(2) Error 10211 ; strerror() "Non-allocated index number for blocks" LIMITS none LINK LIBRARY none SEE ALSO blk, blkfree ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: blocks,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/blocks,v $ ## ## Under source code control: 1997/04/05 13:07:13 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME csc - trigonometric cosecant function SYNOPSIS csc(x [,eps]) TYPES x real eps nonzero real, defaults to epsilon() return real DESCRIPTION Calculate the cosecant of x to a multiple of eps, with error less in absolute value than .75 * eps. EXAMPLE ; print csc(1, 1e-5), csc(1, 1e-10), csc(1, 1e-15), csc(1, 1e-20) 1.1884 1.1883951058 1.188395105778121 1.18839510577812121626 LIMITS none LINK LIBRARY NUMBER *qcsc(NUMBER *x, NUMBER *eps) SEE ALSO sin, cos, tan, sec, cot, epsilon ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: csc,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/csc,v $ ## ## Under source code control: 1995/11/13 03:49:00 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME asech - inverse hyperbolic secant SYNOPSIS asech(x [,eps]) TYPES x real, 0 < x <= 1 eps nonzero real, defaults to epsilon() return real DESCRIPTION Returns the asech of x to a multiple of eps with error less in absolute value than .75 * eps. asech(x) is the real number v for which sech(v) = x. It is given by asech(x) = ln((1 + sqrt(1 - x^2))/x) EXAMPLE ; print asech(.5,1e-5), asech(.5,1e-10), asech(.5,1e-15), asech(.5,1e-20) 1.31696 1.3169578969 1.316957896924817 1.31695789692481670862 LIMITS none LINK LIBRARY NUMBER *qasech(NUMBER *x, NUMBER *eps) SEE ALSO asinh, acosh, atanh, acsch, acoth, epsilon ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: asech,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/asech,v $ ## ## Under source code control: 1995/11/13 03:49:00 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME poly - evaluate a polynomial SYNOPSIS poly(a, b, ..., x) poly(clist, x, y, ...) TYPES For first case: a, b, ... Arithmetic x Arithmetic return Depends on argument types For second case: clist List of coefficients x, y, ... Coefficients return Depends on argument types Here an arithmetic type is one for which the required + and * operations are defined, e.g. real or complex numbers or square matrices of the same size. A coefficient is either of arithmetic type or a list of coefficients. DESCRIPTION If the first argument is not a list, and the necessary operations are defined: poly(a_0, a_1, ..., a_n, x) returns the value of: a_n + (a_n-1 + ... + (a_1 + a_0 * x) * x ...) * x If the coefficients a_0, a_1, ..., a_n and x are elements of a commutative ring, e.g. if the coefficients and x are real or complex numbers, this is the value of the polynomial: a_0 * x^n + a_1 * x^(n-1) + ... + a_(n-1) * x + a_n. For other structures (e.g. if addition is not commutative), the order of operations may be relevant. In particular: poly(a, x) returns the value of a. poly(a, b, x) returns the value of b + a * x poly(a, b, c, x) returns the value of c + (b + a * x) * x If the first argument is a list as if defined by: clist = list(a_0, a_1, ..., a_n) and the coefficients a_i and x are are of arithmetic type, poly(clist, x) returns: a_0 + (a_1 + (a_2 + ... + a_n * x) * x) which for a commutative ring, expands to: a_0 + a_1 * x + ... + a_n * x^n. If clist is the empty list, the value returned is the number 0. Note that the order of the coefficients for the list case is the reverse of that for the non-list case. If one or more elements of clist is a list and there are more than one arithmetic arguments x, y, ..., the coefficient corresponding to such an element is the value of poly for that list and the next argument in x, y, ... For example: poly(list(list(a,b,c), list(d,e), f), x, y) returns: (a + b * y + c * y^2) + (d + e * y) * x + f * x^2. Arguments in excess of those required for clist are ignored, e.g.: poly(list(1,2,3), x, y) returns the same as poly(list(1,2,3), x). If the number of arguments is less than greatest depth of lists in clist, the "missing" arguments are deemed to be zero. E.g.: poly(list(list(1,2), list(3,4), 5), x) returns the same as: poly(list(1, 3, 5), x). If in the clist case, one or more of x, y, ... is a list, the arguments to be applied to the polynomial are the successive non-list values in the list or sublists. For example, if the x_i are not lists: poly(clist, list(x_0, x_1), x_2, list(list(x_3, x_4), x_5)) returns the same as: poly(clist, x_0, x_1, x_2, x_3, x_4, x_5). EXAMPLE ; print poly(2, 3, 5, 7), poly(list(5, 3, 2), 7), 5 + 3 * 7 + 2 * 7^2 124 124 124 ; mat A[2,2] = {1,2,3,4} ; mat I[2,2] = {1,0,0,1} print poly(2 * I, 3 * I, 5 * I, A) mat [2,2] (4 elements, 4 nonzero) [0,0] = 22 [0,1] = 26 [1,0] = 39 [1,1] = 61 ; P = list(list(0,0,1), list(0,2), 3); x = 4; y = 5 ; print poly(P,x,y), poly(P, list(x,y)), y^2 + 2 * y * x + 3 * x^2 113 113 113 LIMITS The number of arguments is not to exceed 1024 LINK LIBRARY BOOL evalpoly(LIST *clist, LISTELEM *x, VALUE *result); SEE ALSO list ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: poly,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/poly,v $ ## ## Under source code control: 1995/12/02 02:40:43 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME randperm - randomly permute a list or matrix SYNOPSIS randperm(x) TYPES x list or matrix return same as x DESCRIPTION For a list or matrix x, randperm(x) returns a copy of x in which the elements have been randomly permuted. The value of x is not changed. This function uses the rand() subtractive 100 shuffle pseudo-random number generator. EXAMPLE ; A = list(1,2,2,3,4) ; randperm(A) list (5 elements, 5 nonzero): [[0]] = 4 [[1]] = 1 [[2]] = 2 [[3]] = 3 [[4]] = 2 ; randperm(A) list (5 elements, 5 nonzero): [[0]] = 2 [[1]] = 1 [[2]] = 4 [[3]] = 2 [[4]] = 3 LIMITS none LINK LIBRARY none SEE ALSO comp, fact, rand, perm ## Copyright (C) 1999-2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: randperm,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/randperm,v $ ## ## Under source code control: 1995/07/10 02:09:31 ## File existed as early as: 1995 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME agd - inverse gudermannian function SYNOPSIS agd(z [,eps]) TYPES z number (real or complex) eps nonzero real, defaults to epsilon() return number or infinite error value DESCRIPTION Calculate the inverse gudermannian of z to a nultiple of eps with errors in real and imaginary parts less in absolute value than .75 * eps, or an error value if z is very close to one of the one of the branch points of agd(z).. agd(z) is usually defined initially for real z with abs(z) < pi/2 by one of the formulae agd(z) = ln(sec(z) + tan(z)) = 2 * atanh(tan(z/2)) = asinh(tan(z)), or as the integral from 0 to z of (1/cos(t))dt. For complex z, the principal branch, approximated by gd(z, eps), has cuts along the real axis outside -pi/2 < z < pi/2. If z = x + i * y and abs(x) < pi/2, agd(z) is given by agd(z) = atanh(sin(x)/cosh(y)) + i * atan(sinh(y)/cos(x)> EXAMPLE ; print agd(1, 1e-5), agd(1, 1e-10), agd(1, 1e-15) 1.22619 1.2261911709 1.226191170883517 ; print agd(2, 1e-5), agd(2, 1e-10) 1.52345-3.14159i 1.5234524436-3.1415926536i ; print agd(5, 1e-5), agd(5, 1e-10), agd(5, 1e-15) -1.93237 -1.9323667197 -1.932366719745925 ; print agd(1+2i, 1e-5), agd(1+2i, 1e-10) .22751+1.42291i .2275106584+1.4229114625i LIMITS none LINK LIBRARY COMPLEX *c_agd(COMPLEX *x, NUMBER *eps) SEE ALSO gd, exp, ln, sin, sinh, etc. ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: agd,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/agd,v $ ## ## Under source code control: 1997/09/06 20:03:34 ## File existed as early as: 1997 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME calcpath - current CALCPATH search path SYNOPSIS calcpath() TYPES return string DESCRIPTION This function returns the current value of the CALCPATH search path. A search path is a :-separated list of directories used to search for a filename. The CALCPATH is taken from the $CALCPATH environment variable or if no such variable exists, a compiled in default search path is used. See "help environment" and "help calcpath" for more information on CALCPATH. EXAMPLE n/a LIMITS none LINK LIBRARY char *calcpath; SEE ALSO environment, fpathopen ## Copyright (C) 2006 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: calcpath,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/calcpath,v $ ## ## Under source code control: 2006/05/07 23:56:04 ## File existed as early as: 2006 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME istype - whether the type of a value is the same as another SYNOPSIS istype(x, y) TYPES x any, &any y any, &any return int DESCRIPTION Determine if x has the same type as y. This function will return 1 if x and y are of the same type, 0 otherwise. EXAMPLE ; print istype(2, 3), istype(2, 3.0), istype(2, 2.3) 1 1 1 ; print istype(2, 3i), istype(2, "2"), istype(2, null()) 0 0 0 ; mat a[2] ; b = list(1,2,3) ; c = assoc() ; obj chongo {was, here} d; ; print istype(a,b), istype(b,c), istype(c,d) 0 0 0 LIMITS none LINK LIBRARY none SEE ALSO isassoc, isatty, isblk, isconfig, isdefined, iserror, iseven, isfile, ishash, isident, isint, islist, ismat, ismult, isnull, isnum, isobj, isobjtype, isodd, isprime, isrand, israndom, isreal, isrel, issimple, issq, isstr ## Copyright (C) 1999 Landon Curt Noll ## ## Calc is open software; you can redistribute it and/or modify it under ## the terms of the version 2.1 of the GNU Lesser General Public License ## as published by the Free Software Foundation. ## ## Calc 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 Lesser General ## Public License for more details. ## ## A copy of version 2.1 of the GNU Lesser General Public License is ## distributed with calc under the filename COPYING-LGPL. You should have ## received a copy with calc; if not, write to Free Software Foundation, Inc. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ## ## @(#) $Revision: 30.1 $ ## @(#) $Id: istype,v 30.1 2007/03/16 11:10:42 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/istype,v $ ## ## Under source code control: 1994/10/21 02:21:31 ## File existed as early as: 1994 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ NAME mat - keyword to create a matrix value SYNOPSIS mat [index-range-list] [ = {value_0. ...} ] mat [] [= {value_0, ...}] mat variable_1 ... [index-range-list] [ = {value_0, ...} ] mat variable_1 ... [] [ = {value_0, ...} ] mat [index-range-list_1[index-ranges-list_2] ... [ = { { ...} ...} ] decl id_1 id_2 ... [index-range-list] ... TYPES index-range-list range_1 [, range_2, ...] up to 4 ranges range_1, ... integer, or integer_1 : integer_2 value, value_1, ... any variable_1 ... lvalue decl declarator = global, static or local id_1, ... identifier DESCRIPTION The expression mat [index-range-list] returns a matrix value. This may be assigned to one or more lvalues A, B, ... by either mat A B ... [index-range-list] or A = B = ... = mat[index-range-list] If a variable is specified by an expression that is not a symbol with possibly object element specifiers, the expression should be enclosed in parentheses. For example, parentheses are required in mat (A[2]) [3] and mat (*p) [3] but mat P.x [3] is acceptable. When an index-range is specified as integer_1 : integer_2, where integer_1 and integer_2 are expressions which evaluate to integers, the index-range consists of all integers from the minimum of the two integers to the maximum of the two integers. For example, mat[2:5, 0:4] and mat[5:2, 4:0] return the same matrix value. If an index-range is an expression which evaluates to an integer, the range is as if specified by 0 : integer - 1. For example, mat[4] and mat[0:3] return the same 4-element matrix; mat[-2] and mat[-3:0] return the same 4-element matrix. If the variable A has a matrix value, then for integer indices i_1, i_2, ..., equal in number to the number of ranges specified at its creation, and such that each index is in the corresponding range, the matrix element associated with those index list is given as an lvalue by the expressions A[i_1, i_2, ...]. The elements of the matrix are stored internally as a linear array in which locations are arranged in order of increasing indices. For example, in order of location, the six element of A = mat [2,3] are A[0,0], A[0,1], A[0,2], A[1,0], A[1,,1], A[1,2]. These elements may also be specified using the double-bracket operator with a single integer index as in A[[0]], A[[1]], ..., A[[5]]. If p is assigned the value &A[0.0], the address of A[[i]] for 0 <= i < 6 is p + i as long as A exists and a new value is not assigned to A. When a matrix is created, each element is initially assigned the value zero. Other values may be assigned then or later using the "= {...}" assignment operation. Thus A = {value_0, value_1, ...} assigns the values value_0, value_1, ... to the elements A[[0]], A[[1]], ... Any blank "value" is passed over. For example, A = {1, , 2} will assign the value 1 to A[[0]], 2 to A[[2]] and leave all other elements unchanged. Values may also be assigned to elements by simple assignments, as in A[0,0] = 1, A[0,2] = 2; If the index-range is left blank but an initializer list is specified as in: ; mat A[] = {1, 2 } ; B = mat[] = {1, , 3, } the matrix created is one-dimensional. If the list contains a positive number n of values or blanks, the result is as if the range were specified by [n], i.e. the range of indices is from 0 to n - 1. In the above examples, A is of size 2 with A[0] = 1 and A[1] = 2; B is of size 4 with B[0] = 1, B[1] = B[3] = 0, B[2] = 3. The specification mat[] = { } creates the same as mat[1]. If the index-range is left blank and no initializer list is specified, as in mat C[] or C = mat[], the matrix assigned to C has zero dimension; this has one element C[]. To assign a value using "= { ...}" at the same time as creating C, parentheses are required as in (mat[]) = {value} or (mat C[]) = {value}. Later a value may be assigned to C[] by C[] = value or C = {value}. The value assigned at any time to any element of a matrix can be of any type - number, string, list, matrix, object of previously specified type, etc. For some matrix operations there are of course conditions that elements may have to satisfy: for example, addition of matrices requires that addition of corresponding elements be possible. If an element of a matrix is a structure for which indices or an object element specifier is required, an element of that structure is referred to by appropriate uses of [ ] or ., and so on if an element of that element is required. For example, one may have an expressions like: ; A[1,2][3].alpha[2]; if A[1,2][3].alpha is a list with at least three elements, A[1,2][3] is an object of a type like obj {alpha, beta}, A[1,2] is a matrix of type mat[4] and A is a mat[2,3] matrix. When an element of a matrix is a matrix and the total number of indices does not exceed 4, the indices can be combined into one list, e.g. the A[1,2][3] in the above example can be shortened to A[1,2,3]. (Unlike C, A[1,2] cannot be expressed as A[1][2].) The function ismat(V) returns 1 if V is a matrix, 0 otherwise. isident(V) returns 1 if V is a square matrix with diagonal elements 1, off-diagonal elements zero, or a zero- or one-dimensional matrix with every element 1; otherwise zero is returned. Thus isident(V) = 1 indicates that for V * A and A * V where A is any matrix of for which either product is defined and the elements of A are real or complex numbers, that product will equal A. If V is matrix-valued, test(V) returns 0 if every element of V tests as zero; otherwise 1 is returned. The dimension of a matrix A, i.e. the number of index-ranges in the initial creation of the matrix, is returned by the function matdim(A). For 1 <= i <= matdim(A), the minimum and maximum values for the i-th index range are returned by matmin(A, i) and matmax(A,i), respectively. The total number of elements in the matrix is returned by size(A). The sum of the elements in the matrix is returned by matsum(A). The default method of printing matrices is to give a line of information about the matrix, and to list on separate lines up to 15 elements, the indices and either the value (for numbers, strings, objects) or some descriptive information for lists or matrices, etc. Numbers are displayed in the current number-printing mode. The maximum number of elements to be printed can be assigned any nonnegative integer value m by config("maxprint", m). Users may define another method of printing matrices by defining a function mat_print(M); for example, for a not too big 2-dimensional matrix A it is a common practice to use a loop like: define mat_print(A) { local i,j; for (i = matmin(A,1); i <= matmax(A,1); i++) { if (i != matmin(A,1)) printf("\t"); for (j = matmin(A,2); j <= matmax(A,2); j++) printf(" [%d,%d]: %e", i, j, A[i,j]); if (i != matmax(A,1)) printf("\n"); } } So that when one defines a 2D matrix such as: ; mat X[2,3] = {1,2,3,4,5,6} then printing X results in: [0,0]: 1 [0,1]: 2 [0,2]: 3 [1,0]: 4 [1,1]: 5 [1,2]: 6 The default printing may be restored by ; undefine mat_print; The keyword "mat" followed by two or more index-range-lists returns a matrix with indices specified by the first list, whose elements are matrices as determined by the later index-range-lists. For example mat[2][3] is a 2-element matrix, each of whose elements has as its value a 3-element matrix. Values may be assigned to the elements of the innermost matrices by nested = {...} operations as in ; mat [2][3] = {{1,2,3},{4,5,6}} An example of the use of mat with a declarator is ; global mat A B [2,3], C [4] This creates, if they do not already exist, three global variables with names A, B, C, and assigns to A and B the value mat[2,3] and to C mat[4]. Some operations are defined for matrices. A == B Returns 1 if A and B are of the same "shape" and "corresponding" elements are equal; otherwise 0 is returned. Being of the same shape means they have the same dimension d, and for each i <= d, matmax(A,i) - matmin(A,i) == matmax(B,i) - matmin(B,i), One consequence of being the same shape is that the matrices will have the same size. Elements "correspond" if they have the same double-bracket indices; thus A == B implies that A[[i]] == B[[i]] for 0 <= i < size(A) == size(B). A + B A - B These are defined A and B have the same shape, the element with double-bracket index j being evaluated by A[[j]] + B[[j]] and A[[j]] - B[[j]], respectively. The index-ranges for the results are those for the matrix A. A[i,j] If A is two-dimensional, it is customary to speak of the indices i, j in A[i,j] as referring to rows and columns; the number of rows is matmax(A,1) - matmin(A,1) + 1; the number of columns if matmax(A,2) - matmin(A,2) + 1. A matrix is said to be square if it is two-dimensional and the number of rows is equal to the number of columns. A * B Multiplication is defined provided certain conditions by the dimensions and shapes of A and B are satisfied. If both have dimension 2 and the column-index-list for A is the same as the row-index-list for B, C = A * B is defined in the usual way so that for i in the row-index-list of A and j in the column-index-list for B, C[i,j] = Sum A[i,k] * B[k,j] the sum being over k in the column-index-list of A. The same formula is used so long as the number of columns in A is the same as the number of rows in B and k is taken to refer to the offset from matmin(A,2) and matmin(B,1), respectively, for A and B. If the multiplications and additions required cannot be performed, an execution error may occur or the result for C may contain one or more error-values as elements. If A or B has dimension zero, the result for A * B is simply that of multiplying the elements of the other matrix on the left by A[] or on the right by B[]. If both A and B have dimension 1, A * B is defined if A and B have the same size; the result has the same index-list as A and each element is the product of corresponding elements of A and B. If A and B have the same index-list, this multiplication is consistent with multiplication of 2D matrices if A and B are taken to represent 2D matrices for which the off-diagonal elements are zero and the diagonal elements are those of A and B. the real and complex numbers. If A is of dimension 1 and B is of dimension 2, A * B is defined if the number of rows in B is the same as the size of A. The result has the same index-lists as B; each row of B is multiplied on the left by the corresponding element of A. If A is of dimension 2 and B is of dimension 1, A * B is defined if number of columns in A is the same as the size of A. The result has the same index-lists as A; each column of A is multiplied on the right by the corresponding element of B. The algebra of additions and multiplications involving both one- and two-dimensional matrices is particularly simple when all the elements are real or complex numbers and all the index-lists are the same, as occurs, for example, if for some positive integer n, all the matrices start as mat [n] or mat [n,n]. det(A) If A is a square, det(A) is evaluated by an algorithm that returns the determinant of A if the elements of A are real or complex numbers, and if such an A is non-singular, inverse(A) returns the inverse of A indexed in the same way as A. For matrix A of dimension 0 or 1, det(A) is defined as the product of the elements of A in the order in which they occur in A, inverse(A) returns a matrix indexed in the same way as A with each element inverted. The following functions are defined to return matrices with the same index-ranges as A and the specified operations performed on all elements of A. Here num is an arbitrary complex number (nonzero when it is a¿ÐÀÐÁÐÂÐÃÐÄÐ divisor), int an integer, rnd a rounding-type specifier integer, real a real number. num * A A * num A / num - A conj(A) A << int, A >> int scale(A, int) round(A, int, rnd) bround(A, int, rnd) appr(A, real, rnd) int(A) frac(A) A // real A % real A ^ int If A and B are one-dimensional of the same size dp(A, B) returns their dot-product, i.e. the sum of the products of corresponding elements. If A and B are one-dimension and of size 3, cp(A, B) returns their cross-product. randperm(A) returns a matrix indexed the same as A in which the elements of A have been randomly permuted. sort(A) returns a matrix indexed the same as A in which the elements of A have been sorted. If A is an lvalue whose current value is a matrix, matfill(A, v) assigns the value v to every element of A, and if also, A is square, matfill(A, v1, v2) assigns v1 to the off-diagonal elements, v2 to the diagonal elements. To create and