mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Release calc version 2.10.2t30
This commit is contained in:
489
lib/README
Normal file
489
lib/README
Normal file
@@ -0,0 +1,489 @@
|
||||
# Copyright (c) 1996 David I. Bell and Landon Curt Noll
|
||||
# Permission is granted to use, distribute, or modify this source,
|
||||
# provided that this copyright notice remains intact.
|
||||
|
||||
The following calc library files are provided because they serve as
|
||||
examples of how use the calc language, and because the authors thought
|
||||
them to be useful!
|
||||
|
||||
If you write something that you think is useful, please send it to:
|
||||
|
||||
dbell@auug.org.au
|
||||
chongo@toad.com {uunet,pyramid,sun}!hoptoad!chongo
|
||||
|
||||
By convention, a lib file only defines and/or initializes functions,
|
||||
objects and variables. (The regression test is an exception.) Also by
|
||||
convention, the a usage message regarding each important object and
|
||||
function is printed at the time of the read.
|
||||
|
||||
If a lib file needs to load another lib file, it should use the -once
|
||||
version of read:
|
||||
|
||||
/* pull in needed library files */
|
||||
read -once "surd"
|
||||
read -once "lucas"
|
||||
|
||||
This will cause the needed library files to be read once. If these
|
||||
files have already been read, the read -once will act as a noop.
|
||||
|
||||
By convention, the global variable lib_debug is used to control
|
||||
the verbosity of debug information printed by lib files. By default,
|
||||
the lib_debug has a value of 0. If lib_debug < 0, then no debug
|
||||
messages are printed. If lib_debug >= 0, then only usage message
|
||||
regarding each important object are printed at the time of the read.
|
||||
If lib_debug == 0, then only such usage messages are printed; no
|
||||
other debug information is printed.
|
||||
|
||||
To conform to the above convention, your lib files should end with
|
||||
lines of the form:
|
||||
|
||||
global lib_debug;
|
||||
if (lib_debug >= 0) {
|
||||
print "funcA(side_a, side_b, side_c) defined";
|
||||
print "funcB(size, mass) defined";
|
||||
}
|
||||
|
||||
|
||||
=-=
|
||||
|
||||
|
||||
bernoulli.cal
|
||||
|
||||
B(n)
|
||||
|
||||
Calculate the nth Bernoulli number.
|
||||
|
||||
|
||||
bigprime.cal
|
||||
|
||||
bigprime(a, m, p)
|
||||
|
||||
A prime test, base a, on p*2^x+1 for even x>m.
|
||||
|
||||
|
||||
chrem.cal
|
||||
|
||||
chrem(r1,m1 [,r2,m2, ...])
|
||||
chrem(rlist, mlist)
|
||||
|
||||
Chinese remainder theorem/problem solver.
|
||||
|
||||
|
||||
cryrand.cal
|
||||
|
||||
obj cryobj
|
||||
cryrand(len)
|
||||
scryrand([seed, [len1, len2]])
|
||||
scryrand(seed, ip, iq, ir)
|
||||
random([a, [b]])
|
||||
srandom(seed)
|
||||
randstate([cryobj | 0])
|
||||
|
||||
cryptographically strong pseudo-romandom number generator
|
||||
|
||||
|
||||
deg.cal
|
||||
|
||||
dms(deg, min, sec)
|
||||
dms_add(a, b)
|
||||
dms_neg(a)
|
||||
dms_sub(a, b)
|
||||
dms_mul(a, b)
|
||||
dms_print(a)
|
||||
|
||||
Calculate in degrees, minutes, and seconds.
|
||||
|
||||
|
||||
ellip.cal
|
||||
|
||||
factor(iN, ia, B, force)
|
||||
|
||||
Attempt to factor using the elliptic functions: y^2 = x^3 + a*x + b.
|
||||
|
||||
|
||||
lucas.cal
|
||||
|
||||
lucas(h, n)
|
||||
|
||||
Perform a primality test of h*2^n-1, with 1<=h<2*n.
|
||||
|
||||
|
||||
lucas_chk.cal
|
||||
|
||||
lucas_chk(high_n)
|
||||
|
||||
Test all primes of the form h*2^n-1, with 1<=h<200 and n <= high_n.
|
||||
Requires lucas.cal to be loaded. The highest useful high_n is 1000.
|
||||
|
||||
Used by regress.cal during the 2100 test set.
|
||||
|
||||
|
||||
lucas_tbl.cal
|
||||
|
||||
Lucasian criteria for primality tables.
|
||||
|
||||
|
||||
mersenne.cal
|
||||
|
||||
mersenne(p)
|
||||
|
||||
Perform a primality test of 2^p-1, for prime p>1.
|
||||
|
||||
|
||||
mfactor.cal
|
||||
|
||||
mfactor(n [, start_k [, rept_loop])
|
||||
|
||||
Return the lowest factor of 2^n-1, for n > 0. Starts looking for factors
|
||||
at 2*start_k*n+1. By default, start_k == 1.
|
||||
|
||||
Be default, mfactor() does not report the search progress. When
|
||||
rept_loop > 0, then a report is given every 4*rept_loop loops.
|
||||
|
||||
|
||||
mod.cal
|
||||
|
||||
mod(a)
|
||||
mod_print(a)
|
||||
mod_one()
|
||||
mod_cmp(a, b)
|
||||
mod_rel(a, b)
|
||||
mod_add(a, b)
|
||||
mod_sub(a, b)
|
||||
mod_neg(a)
|
||||
mod_mul(a, b)
|
||||
mod_square(a)
|
||||
mod_inc(a)
|
||||
mod_dec(a)
|
||||
mod_inv(a)
|
||||
mod_div(a, b)
|
||||
mod_pow(a, b)
|
||||
|
||||
Routines to handle numbers modulo a specified number.
|
||||
|
||||
|
||||
pell.cal
|
||||
|
||||
pellx(D)
|
||||
pell(D)
|
||||
|
||||
Solve Pell's equation; Returns the solution X to: X^2 - D * Y^2 = 1.
|
||||
Type the solution to pells equation for a particular D.
|
||||
|
||||
|
||||
pi.cal
|
||||
|
||||
qpi(epsilon)
|
||||
|
||||
Calculate pi within the specified epsilon using the quartic convergence
|
||||
iteration.
|
||||
|
||||
|
||||
pollard.cal
|
||||
|
||||
factor(N, N, ai, af)
|
||||
|
||||
Factor using Pollard's p-1 method.
|
||||
|
||||
|
||||
poly.cal
|
||||
|
||||
Calculate with polynomials of one variable. There are many functions.
|
||||
Read the documentation in the library file.
|
||||
|
||||
|
||||
prompt.cal
|
||||
|
||||
adder()
|
||||
showvalues(str)
|
||||
|
||||
Demonstration of some uses of prompt() and eval().
|
||||
|
||||
|
||||
psqrt.cal
|
||||
|
||||
psqrt(u, p)
|
||||
|
||||
Calculate square roots modulo a prime
|
||||
|
||||
|
||||
quat.cal
|
||||
|
||||
quat(a, b, c, d)
|
||||
quat_print(a)
|
||||
quat_norm(a)
|
||||
quat_abs(a, e)
|
||||
quat_conj(a)
|
||||
quat_add(a, b)
|
||||
quat_sub(a, b)
|
||||
quat_inc(a)
|
||||
quat_dec(a)
|
||||
quat_neg(a)
|
||||
quat_mul(a, b)
|
||||
quat_div(a, b)
|
||||
quat_inv(a)
|
||||
quat_scale(a, b)
|
||||
quat_shift(a, b)
|
||||
|
||||
Calculate using quaternions of the form: a + bi + cj + dk. In these
|
||||
functions, quaternians are manipulated in the form: s + v, where
|
||||
s is a scalar and v is a vector of size 3.
|
||||
|
||||
|
||||
randbitrun.cal
|
||||
|
||||
randbitrun([run_cnt])
|
||||
|
||||
Using randbit(1) to generate a sequence of random bits, determine if
|
||||
the number and kength of identical bits runs match what is expected.
|
||||
By default, run_cnt is to test the next 65536 random values.
|
||||
|
||||
|
||||
randmprime.cal
|
||||
|
||||
randmprime(bits, seed [,dbg])
|
||||
|
||||
Find a prime of the form h*2^n-1 >= 2^bits for some given x. The initial
|
||||
search points for 'h' and 'n' are selected by a cryptographic pseudo-random
|
||||
number generator. The optional argument, dbg, if set to 1, 2 or 3
|
||||
turn on various debugging print statements.
|
||||
|
||||
|
||||
randrun.cal
|
||||
|
||||
randrun([run_cnt])
|
||||
|
||||
Perform the "G. Run test" (pp. 65-68) as found in Knuth's "Art of
|
||||
Computer Programming - 2nd edition", Volume 2, Section 3.3.2 on
|
||||
the builtin rand() function. This function will generate run_cnt
|
||||
64 bit values. By default, run_cnt is to test the next 65536
|
||||
random values.
|
||||
|
||||
|
||||
regress.cal
|
||||
|
||||
Test the correct execution of the calculator by reading this library file.
|
||||
Errors are reported with '****' mssages, or worse. :-)
|
||||
|
||||
|
||||
seedrandom.cal
|
||||
|
||||
seedrandom(seed1, seed2, bitsize [,trials])
|
||||
|
||||
Given:
|
||||
seed1 - a large random value (at least 10^20 and perhaps < 10^93)
|
||||
seed2 - a large random value (at least 10^20 and perhaps < 10^93)
|
||||
size - min Blum modulus as a power of 2 (at least 100, perhaps > 1024)
|
||||
trials - number of ptest() trials (default 25) (optional arg)
|
||||
|
||||
Returns:
|
||||
the previous random state
|
||||
|
||||
Seed the cryptographically strong Blum generator. This functions allows
|
||||
one to use the raw srandom() without the burden of finding appropriate
|
||||
Blum primes for the modulus.
|
||||
|
||||
|
||||
solve.cal
|
||||
|
||||
solve(low, high, epsilon)
|
||||
|
||||
Solve the equation f(x) = 0 to within the desired error value for x.
|
||||
The function 'f' must be defined outside of this routine, and the low
|
||||
and high values are guesses which must produce values with opposite signs.
|
||||
|
||||
|
||||
sumsq.cal
|
||||
|
||||
ss(p)
|
||||
|
||||
Determine the unique two positive integers whose squares sum to the
|
||||
specified prime. This is always possible for all primes of the form
|
||||
4N+1, and always impossible for primes of the form 4N-1.
|
||||
|
||||
|
||||
surd.cal
|
||||
|
||||
surd(a, b)
|
||||
surd_print(a)
|
||||
surd_conj(a)
|
||||
surd_norm(a)
|
||||
surd_value(a, xepsilon)
|
||||
surd_add(a, b)
|
||||
surd_sub(a, b)
|
||||
surd_inc(a)
|
||||
surd_dec(a)
|
||||
surd_neg(a)
|
||||
surd_mul(a, b)
|
||||
surd_square(a)
|
||||
surd_scale(a, b)
|
||||
surd_shift(a, b)
|
||||
surd_div(a, b)
|
||||
surd_inv(a)
|
||||
surd_sgn(a)
|
||||
surd_cmp(a, b)
|
||||
surd_rel(a, b)
|
||||
|
||||
Calculate using quadratic surds of the form: a + b * sqrt(D).
|
||||
|
||||
|
||||
test1700.cal
|
||||
|
||||
value
|
||||
|
||||
This script is used by regress.cal to test the read and use keywords.
|
||||
|
||||
|
||||
test2600.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
testismult(str, n, verbose)
|
||||
testsqrt(str, n, eps, verbose)
|
||||
testexp(str, n, eps, verbose)
|
||||
testln(str, n, eps, verbose)
|
||||
testpower(str, n, b, eps, verbose)
|
||||
testgcd(str, n, verbose)
|
||||
cpow(x, n, eps)
|
||||
cexp(x, eps)
|
||||
cln(x, eps)
|
||||
mkreal()
|
||||
mkcomplex()
|
||||
mkbigreal()
|
||||
mksmallreal()
|
||||
testappr(str, n, verbose)
|
||||
checkappr(x, y, z, verbose)
|
||||
checkresult(x, y, z, a)
|
||||
test2600(verbose, tnum)
|
||||
|
||||
This script is used by regress.cal to test some of builtin functions
|
||||
in terms of accuracy and roundoff.
|
||||
|
||||
|
||||
test2700.cal
|
||||
|
||||
global defaultverbose
|
||||
mknonnegreal()
|
||||
mkposreal()
|
||||
mkreal_2700()
|
||||
mknonzeroreal()
|
||||
mkposfrac()
|
||||
mkfrac()
|
||||
mksquarereal()
|
||||
mknonsquarereal()
|
||||
mkcomplex_2700()
|
||||
testcsqrt(str, n, verbose)
|
||||
checksqrt(x, y, z, v)
|
||||
checkavrem(A, B, X, eps)
|
||||
checkrounding(s, n, t, u, z)
|
||||
iscomsq(x)
|
||||
test2700(verbose, tnum)
|
||||
|
||||
This script is used by regress.cal to test sqrt() for real and complex
|
||||
values.
|
||||
|
||||
|
||||
test3100.cal
|
||||
|
||||
obj res
|
||||
global md
|
||||
res_test(a)
|
||||
res_sub(a, b)
|
||||
res_mul(a, b)
|
||||
res_neg(a)
|
||||
res_inv(a)
|
||||
res(x)
|
||||
|
||||
This script is used by regress.cal to test determinants of a matrix
|
||||
|
||||
|
||||
test3300.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
testi(str, n, N, verbose)
|
||||
testr(str, n, N, verbose)
|
||||
test3300(verbose, tnum)
|
||||
|
||||
This script is used by regress.cal to provide for more determinant tests.
|
||||
|
||||
|
||||
test3400.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
test1(str, n, eps, verbose)
|
||||
test2(str, n, eps, verbose)
|
||||
test3(str, n, eps, verbose)
|
||||
test4(str, n, eps, verbose)
|
||||
test5(str, n, eps, verbose)
|
||||
test6(str, n, eps, verbose)
|
||||
test3400(verbose, tnum)
|
||||
|
||||
This script is used by regress.cal to test trig functions.
|
||||
containing objects.
|
||||
|
||||
test4000.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
global BASEB
|
||||
global BASE
|
||||
global COUNT
|
||||
global SKIP
|
||||
global RESIDUE
|
||||
global MODULUS
|
||||
global K1
|
||||
global H1
|
||||
global K2
|
||||
global H2
|
||||
global K3
|
||||
global H3
|
||||
plen(N) defined
|
||||
rlen(N) defined
|
||||
clen(N) defined
|
||||
ptimes(str, N, n, count, skip, verbose) defined
|
||||
ctimes(str, N, n, count, skip, verbose) defined
|
||||
crtimes(str, a, b, n, count, skip, verbose) defined
|
||||
ntimes(str, N, n, count, skip, residue, mod, verbose) defined
|
||||
testnextcand(str, N, n, cnt, skip, res, mod, verbose) defined
|
||||
testnext1(x, y, count, skip, residue, modulus) defined
|
||||
testprevcand(str, N, n, cnt, skip, res, mod, verbose) defined
|
||||
testprev1(x, y, count, skip, residue, modulus) defined
|
||||
test4000(verbose, tnum) defined
|
||||
|
||||
This script is used by regress.cal to test ptest, nextcand and
|
||||
prevcand buildins.
|
||||
|
||||
test4100.cal
|
||||
|
||||
global defaultverbose
|
||||
global err
|
||||
global K1
|
||||
global K2
|
||||
global BASEB
|
||||
global BASE
|
||||
rlen_4100(N) defined
|
||||
olen(N) defined
|
||||
test1(x, y, m, k, z1, z2) defined
|
||||
testall(str, n, N, M, verbose) defined
|
||||
times(str, N, n, verbose) defined
|
||||
powtimes(str, N1, N2, n, verbose) defined
|
||||
inittimes(str, N, n, verbose) defined
|
||||
test4100(verbose, tnum) defined
|
||||
|
||||
This script is used by regress.cal to test REDC operations.
|
||||
|
||||
unitfrac.cal
|
||||
|
||||
unitfrac(x)
|
||||
|
||||
Represent a fraction as sum of distinct unit fractions.
|
||||
|
||||
|
||||
varargs.cal
|
||||
|
||||
sc(a, b, ...)
|
||||
|
||||
Example program to use 'varargs'. Program to sum the cubes of all
|
||||
the specified numbers.
|
Reference in New Issue
Block a user