esting issq(). */ define mknonsquarereal() = 22 * mkposreal()^2/7; define mkcomplex_2700() = mkreal_2700() + 1i * mkreal_2700(); define testcsqrt(str, n, verbose) { local x, y, z, m, i, p, v; if (isnull(verbose)) verbose = defaultverbose; if (verbose > 0) { print str:":",:; } m = 0; for (i = 1; i <= n; i++) { if (verbose > 1) print i,:; x = rand(3) ? mkreal_2700(): mkcomplex_2700(); y = scale(mknonzeroreal(), -100); if (verbose > 2) printf("%d: x = %d, y = %d\n", i, x, y); for (z = 0; z < 128; z++) { v = sqrt(x,y,z); p = checksqrt(x,y,z,v); if (p) { if (verbose > 0) printf( "*** Type %d failure for x = %r, y = %r, z = %d\n", p, x, y, z); m++; } } } if (verbose > 0) { if (m) { printf("*** %d error(s)\n", m); } else { printf("no errors\n"); } } return m; } define checksqrt(x,y,z,v) /* Returns >0 if an error is detected */ { local A, B, X, Y, t1, t2, eps, u, n, f, s; A = re(x); B = im(x); X = re(v); Y = im(v); /* checking signs of X and Y */ if (B == 0 && A <= 0) /* t1 = sgn(re(tvsqrt)) */ t1 = 0; else t1 = (z & 64) ? -1 : 1; t2 = B ? sgn(B) : (A < 0); /* t2 = sgn(im(tvsqrt)) */ if (z & 64) t2 = -t2; if (t1 == 0 && X != 0) return 1; if (t2 == 0 && Y != 0) { printf("x = %d, Y = %d, t2 = %d\n", x, Y, t2); return 2; } if (X && sgn(X) != t1) return 3; if (Y && sgn(Y) != t2) return 4; if (z & 32 && iscomsq(x)) return 5 * (x != v^2); eps = (z & 16) ? abs(y)/2 : abs(y); u = sgn(y); /* Checking X */ n = X/y; if (!isint(n)) return 6; if (t1) { f = checkavrem(A, B, abs(X), eps); if (z & 16 && f < 0) return 7; if (!(z & 16) && f <= 0) return 8; if (!(z & 16) || f == 0) { s = X ? t1 * sgn(A - X^2 + B^2/4/X^2) : t1; if (s && !checkrounding(s,n,t1,u,z)) return 9; } } /* Checking Y */ n = Y/y; if (!isint(n)) return 10; if (t2) { f = checkavrem(-A, B, abs(Y), eps); if (z & 16 && f < 0) return 11; if (!(z & 16) && f <= 0) return 12; if (!(z & 16) || f == 0) { s = Y ? t2 * sgn(-A - Y^2 + B^2/4/Y^2) : t2; if (s && !checkrounding(s,n,t2,u,z)) return 13; } } return 0; } /* * Check that the calculated absolute value X of the real part of * sqrt(A + Bi) is between (true value - eps) and (true value + eps). * Returns -1 if it is outside, 0 if on boundary, 1 if between. */ define checkavrem(A, B, X, eps) { local f; f = sgn(A - (X + eps)^2 + B^2/4/(X + eps)^2); if (f > 0) return -1; /* X < tv - eps */ if (f == 0) return 0; /* X = tv - eps */ if (X > eps) { f = sgn(A - (X - eps)^2 + B^2/4/(X - eps)^2); if (f < 0) return -1; /* X > tv + eps */ if (f == 0) return 0; /* X = tv + eps */ } return 1; /* tv - eps < X < tv + eps */ } define checkrounding(s,n,t,u,z) { local w; switch (z & 15) { case 0: w = (s == u); break; case 1: w = (s == -u); break; case 2: w = (s == t); break; case 3: w = (s == -t); break; case 4: w = (s > 0); break; case 5: w = (s < 0); break; case 6: w = (s == u/t); break; case 7: w = (s == -u/t); break; case 8: w = iseven(n); break; case 9: w = isodd(n); break; case 10: w = (u/t > 0) ? iseven(n) : isodd(n); break; case 11: w = (u/t > 0) ? isodd(n) : iseven(n); break; case 12: w = (u > 0) ? iseven(n) : isodd(n); break; case 13: w = (u > 0) ? isodd(n) : iseven(n); break; case 14: w = (t > 0) ? iseven(n) : isodd(n); break; case 15: w = (t > 0) ? isodd(n) : iseven(n); break; } return w; } define iscomsq(x) { local c; if (isreal(x)) return issq(abs(x)); c = norm(x); if (!issq(c)) return 0; return issq((re(x) + sqrt(c,1,32))/2); } /* * test2700 - perform all of the above tests a bunch of times */ define test2700(verbose, tnum) { local n; /* test parameter */ local ep; /* test parameter */ local i; /* set test parameters */ n = 32; /* internal test loop count */ if (isnull(verbose)) { verbose = defaultverbose; } if (isnull(tnum)) { tnum = 1; /* initial test number */ } /* * test a lot of stuff */ srand(2700e2700); for (i=0; i < n; ++i) { err += testcsqrt(strcat(str(tnum++),": complex sqrt",str(i)), 1, verbose); } if (verbose > 1) { if (err) { print "***", err, "error(s) found in testall"; } else { print "no errors in testall"; } } return tnum; } /* * surd - calculate using quadratic surds of the form: a + b * sqrt(D). * * Copyright (C) 1999 David I. Bell * * 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: surd.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/surd.cal,v $ * * Under source code control: 1990/02/15 01:50:38 * File existed as early as: before 1990 * * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ obj surd {a, b}; /* definition of the surd object */ global surd_type = -1; /* type of surd (value of D) */ static obj surd surd__; /* example surd for testing against */ define surd(a,b) { local x; obj surd x; x.a = a; x.b = b; return x; } define surd_print(a) { print "surd(" : a.a : ", " : a.b : ")" :; } define surd_conj(a) { local x; obj surd x; x.a = a.a; x.b = -a.b; return x; } define surd_norm(a) { return a.a^2 + abs(surd_type) * a.b^2; } define surd_value(a, xepsilon) { local epsilon; epsilon = xepsilon; if (isnull(epsilon)) epsilon = epsilon(); return a.a + a.b * sqrt(surd_type, epsilon); } define surd_add(a, b) { local obj surd x; if (!istype(b, x)) { x.a = a.a + b; x.b = a.b; return x; } if (!istype(a, x)) { x.a = a + b.a; x.b = b.b; return x; } x.a = a.a + b.a; x.b = a.b + b.b; if (x.b) return x; return x.a; } define surd_sub(a, b) { local obj surd x; if (!istype(b, x)) { x.a = a.a - b; x.b = a.b; return x; } if (!istype(a, x)) { x.a = a - b.a; x.b = -b.b; return x; } x.a = a.a - b.a; x.b = a.b - b.b; if (x.b) return x; return x.a; } define surd_inc(a) { local x; x = a; x.a++; return x; } define surd_dec(a) { local x; x = a; x.a--; return x; } define surd_neg(a) { local obj surd x; x.a = -a.a; x.b = -a.b; return x; } define surd_mul(a, b) { local obj surd x; if (!istype(b, x)) { x.a = a.a * b; x.b = a.b * b; } else if (!istype(a, x)) { x.a = b.a * a; x.b = b.b * a; } else { x.a = a.a * b.a + surd_type * a.b * b.b; x.b = a.a * b.b + a.b * b.a; } if (x.b) return x; return x.a; } define surd_square(a) { local obj surd x; x.a = a.a^2 + a.b^2 * surd_type; x.b = a.a * a.b * 2; if (x.b) return x; return x.a; } define surd_scale(a, b) { local obj surd x; x.a = scale(a.a, b); x.b = scale(a.b, b); return x; } define surd_shift(a, b) { local obj surd x; x.a = a.a << b; x.b = a.b << b; if (x.b) return x; return x.a; } define surd_div(a, b) { local x, y; if ((a == 0) && b) return 0; obj surd x; if (!istype(b, x)) { x.a = a.a / b; x.b = a.b / b; return x; } y = b; y.b = -b.b; return (a * y) / (b.a^2 - surd_type * b.b^2); } define surd_inv(a) { return 1 / a; } define surd_sgn(a) { if (surd_type < 0) quit "Taking sign of complex surd"; if (a.a == 0) return sgn(a.b); if (a.b == 0) return sgn(a.a); if ((a.a > 0) && (a.b > 0)) return 1; if ((a.a < 0) && (a.b < 0)) return -1; return sgn(a.a^2 - a.b^2 * surd_type) * sgn(a.a); } define surd_cmp(a, b) { if (!istype(a, surd__)) return ((b.b != 0) || (a != b.a)); if (!istype(b, surd__)) return ((a.b != 0) || (b != a.a)); return ((a.a != b.a) || (a.b != b.b)); } define surd_rel(a, b) { local x, y; if (surd_type < 0) quit "Relative comparison of complex surds"; if (!istype(a, surd__)) { x = a - b.a; y = -b.b; } else if (!istype(b, surd__)) { x = a.a - b; y = a.b; } else { x = a.a - b.a; y = a.b - b.b; } if (y == 0) return sgn(x); if (x == 0) return sgn(y); if ((x < 0) && (y < 0)) return -1; if ((x > 0) && (y > 0)) return 1; return sgn(x^2 - y^2 * surd_type) * sgn(x); } if (config("resource_debug") & 3) { print "obj surd {a, b} defined"; print "surd_type defined"; print "set surd_type as needed"; } Calc standard resource files ---------------------------- To load a resource file, try: read filename You do not need to add the .cal extension to the filename. Calc will search along the $CALCPATH (see ``help environment''). Normally a resource file will simply define some functions. By default, most resource files will print out a short message when they are read. For example: ; read lucas lucas(h,n) defined gen_u0(h,n,v1) defined gen_v1(h,n) defined ldebug(funct,str) defined will cause calc to load and execute the 'lucas.cal' resource file. Executing the resource file will cause several functions to be defined. Executing the lucas function: ; lucas(149,60) 1 ; lucas(146,61) 0 shows that 149*2^60-1 is prime whereas 146*2^61-1 is not. =-= Calc resource file files are provided because they serve as examples of how use the calc language, and/or because the authors thought them to be useful! If you write something that you think is useful, please send it to: calc-contrib at asthe dot com [[ NOTE: Replace 'at' with @, 'dot' is with . and remove the spaces ]] [[ NOTE: The EMail address uses 'asthe' and the web site URL uses 'isthe' ]] By convention, a resource file only defines and/or initializes functions, objects and variables. (The regress.cal and testxxx.cal regression test suite is an exception.) Also by convention, an additional usage message regarding important object and functions is printed. If a resource file needs to load another resource file, it should use the -once version of read: /* pull in needed resource files */ read -once "surd" read -once "lucas" This will cause the needed resource files to be read once. If these files have already been read, the read -once will act as a noop. The "resource_debug" parameter is intended for controlling the possible display of special information relating to functions, objects, and other structures created by instructions in calc resource files. Zero value of config("resource_debug") means that no such information is displayed. For other values, the non-zero bits which currently have meanings are as follows: n Meaning of bit n of config("resource_debug") 0 When a function is defined, redefined or undefined at interactive level, a message saying what has been done is displayed. 1 When a function is defined, redefined or undefined during the reading of a file, a message saying what has been done is displayed. 2 Show func will display more information about a functions arguments as well as more argument summary information. 3 During execution, allow calc standard resource files to output additional debugging information. The value for config("resource_debug") in both oldstd and newstd is 3, but if calc is invoked with the -d flag, its initial value is zero. Thus, if calc is started without the -d flag, until config("resource_debug") is changed, a message will be output when a function is defined either interactively or during the reading of a file. Sometimes the information printed is not enough. In addition to the standard information, one might want to print: * useful obj definitions * functions with optional args * functions with optional args where the param() interface is used For these cases we suggest that you place at the bottom of your code something that prints extra information if config("resource_debug") has either of the bottom 2 bits set: if (config("resource_debug") & 3) { print "obj xyz defined"; print "funcA([val1 [, val2]]) defined"; print "funcB(size, mass, ...) defined"; } If your the resource file needs to output special debugging information, we recommend that you check for bit 3 of the config("resource_debug") before printing the debug statement: if (config("resource_debug") & 8) { print "DEBUG: This a sample debug statement"; } =-= The following is a brief description of some of the calc resource files that are shipped with calc. See above for example of how to read in and execute these files. alg_config.cal global test_time mul_loop(repeat,x) defined mul_ratio(len) defined best_mul2() defined sq_loop(repeat,x) defined sq_ratio(len) defined best_sq2() defined pow_loop(repeat,x,ex) defined pow_ratio(len) defined best_pow2() defined These functions search for an optimal value of config("mul2"), config("sq2"), and config("pow2"). The calc default values of these configuration values were set by running this resource file on a 1.8GHz AMD 32-bit CPU of ~3406 BogoMIPS. The best_mul2() function returns the optimal value of config("mul2"). The best_sq2() function returns the optimal value of config("sq2"). The best_pow2() function returns the optimal value of config("pow2"). The other functions are just support functions. By design, best_mul2(), best_sq2(), and best_pow2() take a few minutes to run. These functions increase the number of times a given computational loop is executed until a minimum amount of CPU time is consumed. To watch these functions progress, one can set the config("user_debug") value. Here is a suggested way to use this resource file: ; read alg_config ; config("user_debug",2),; ; best_mul2(); best_sq2(); best_pow2(); ; best_mul2(); best_sq2(); best_pow2(); ; best_mul2(); best_sq2(); best_pow2(); NOTE: It is perfectly normal for the optimal value returned to differ slightly from run to run. Slight variations due to inaccuracy in CPU timings will cause the best value returned to differ slightly from run to run. One can use a calc startup file to change the initial values of config("mul2"), config("sq2"), and config("pow2"). For example one can place into ~/.calcrc these lines: config("mul2", 1780),; config("sq2", 3388),; config("pow2", 176),; to automatically and silently change these config values. See help/config and CALCRC in help/environment for more information. beer.cal Calc's contribution to the 99 Bottles of Beer web page: http://www.ionet.net/~timtroyr/funhouse/beer.html#calc NOTE: This resource produces a lot of output. :-) bernoulli.cal B(n) Calculate the nth Bernoulli number. NOTE: There is now a bernoulli() builtin function. This file is left here for backward compatibility and now simply returns the builtin function. bigprime.cal bigprime(a, m, p) A prime test, base a, on p*2^x+1 for even x>m. chi.cal Z(x[, eps]) P(x[, eps]) chi_prob(chi_sq, v[, eps]) Computes the Probability, given the Null Hypothesis, that a given Chi squared values >= chi_sq with v degrees of freedom. The chi_prob() function does not work well with odd degrees of freedom. It is reasonable with even degrees of freedom, although one must give a sufficiently small error term as the degrees gets large (>100). The Z(x) and P(x) are internal statistical functions. eps is an optional epsilon() like error term. chrem.cal chrem(r1,m1 [,r2,m2, ...]) chrem(rlist, mlist) Chinese remainder theorem/problem solver. deg.cal deg(deg, min, sec) deg_add(a, b) deg_neg(a) deg_sub(a, b) deg_mul(a, b) deg_print(a) Calculate in degrees, minutes, and seconds. For a more functional version see dms.cal. dms.cal dms(deg, min, sec) dms_add(a, b) dms_neg(a) dms_sub(a, b) dms_mul(a, b) dms_print(a) dms_abs(a) dms_norm(a) dms_test(a) dms_int(a) dms_frac(a) dms_rel(a,b) dms_cmp(a,b) dms_inc(a) dms_dec(a) Calculate in degrees, minutes, and seconds. Unlike deg.cal, increments are on the arc second level. See also hms.cal. dotest.cal dotest(dotest_file [,dotest_code [,dotest_maxcond]]) dotest_file Search along CALCPATH for dotest_file, which contains lines that should evaluate to 1. Comment lines and empty lines are ignored. Comment lines should use ## instead of the multi like /* ... */ because lines are evaluated one line at a time. dotest_code Assign the code number that is to be printed at the start of each non-error line and after **** in each error line. The default code number is 999. dotest_maxcond The maximum number of error conditions that may be detected. An error condition is not a sign of a problem, in some cases a line deliberately forces an error condition. A value of -1, the default, implies a maximum of 2147483647. Global variables and functions must be declared ahead of time because the dotest scope of evaluation is a line at a time. For example: read dotest.cal read set8700.cal dotest("set8700.line"); ellip.cal efactor(iN, ia, B, force) Attempt to factor using the elliptic functions: y^2 = x^3 + a*x + b. hello.cal Calc's contribution to the Hello World! page: http://www.latech.edu/~acm/HelloWorld.shtml http://www.latech.edu/~acm/helloworld/calc.html NOTE: This resource produces a lot of output. :-) hms.cal hms(hour, min, sec) hms_add(a, b) hms_neg(a) hms_sub(a, b) hms_mul(a, b) hms_print(a) hms_abs(a) hms_norm(a) hms_test(a) hms_int(a) hms_frac(a) hms_rel(a,b) hms_cmp(a,b) hms_inc(a) hms_dec(a) Calculate in hours, minutes, and seconds. See also dmscal. intfile.cal file2be(filename) Read filename and return an integer that is built from the octets in that file in Big Endian order. The first octets of the file become the most significant bits of the integer. file2le(filename) Read filename and return an integer that is built from the octets in that file in Little Endian order. The first octets of the file become the most significant bits of the integer. be2file(v, filename) Write the absolute value of v into filename in Big Endian order. The v argument must be on integer. The most significant bits of the integer become the first octets of the file. le2file(v, filename) Write the absolute value of v into filename in Little Endian order. The v argument must be on integer. The least significant bits of the integer become the last octets of the file. linear.cal linear(x0, y0, x1, y1, x) Returns the value y such that (x,y) in on the line (x0,y0), (x1,y1). Requires x0 != y0. 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=1 [, rept_loop=10000 [, p_elim=17]]]) Return the lowest factor of 2^n-1, for n > 0. Starts looking for factors at 2*start_k*n+1. Skips values that are multiples of primes <= p_elim. By default, start_k == 1, rept_loop = 10000 and p_elim = 17. The p_elim == 17 overhead takes ~3 minutes on an 200 Mhz r4k CPU and requires about ~13 Megs of memory. The p_elim == 13 overhead takes about 3 seconds and requires ~1.5 Megs of memory. The value p_elim == 17 is best for long factorizations. It is the fastest even thought the initial startup overhead is larger than for p_elim == 13. mod.cal lmod(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. natnumset.cal isset(a) setbound(n) empty() full() isin(a, b) addmember(a, n) rmmember(a, n) set() mkset(s) primes(a, b) set_max(a) set_min(a) set_not(a) set_cmp(a, b) set_rel(a, b) set_or(a, b) set_and(a, b) set_comp(a) set_setminus(a, b) set_diff(a,b) set_content(a) set_add(a, b) set_sub(a, b) set_mu—јљњћќÑўџѠѡѢѣѤѥÑl(a, b) set_square(a) set_pow(a, n) set_sum(a) set_plus(a) interval(a, b) isinterval(a) set_mod(a, b) randset(n, a, b) polyvals(L, A) polyvals2(L, A, B) set_print(a) Demonstration of how the string operators and functions may be used for defining and working with sets of natural numbers not exceeding a user-specified bound. 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 Pell's equation for a particular D. pi.cal qpi(epsilon) piforever() The qpi() calculate pi within the specified epsilon using the quartic convergence iteration. The piforever() prints digits of pi, nicely formatted, for as long as your free memory space and system up time allows. The piforever() function (written by Klaus Alexander Seistrup ) was inspired by an algorithm conceived by Lambert Meertens. See also the ABC Programmer's Handbook, by Geurts, Meertens & Pemberton, published by Prentice-Hall (UK) Ltd., 1990. pix.cal pi_of_x(x) Calculate the number of primes < x using A(n+1)=A(n-1)+A(n-2). This is a SLOW painful method ... the builtin pix(x) is much faster. Still, this method is interesting. pollard.cal pfactor(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 resource 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 qtime.cal qtime(utc_hr_offset) Print the time as English sentence given the hours offset from UTC. 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, quaternions 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 length of identical bits runs match what is expected. By default, run_cnt is to test the next 65536 random values. This tests the a55 generator. 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. randombitrun.cal randombitrun([run_cnt]) Using randombit(1) to generate a sequence of random bits, determine if the number and length of identical bits runs match what is expected. By default, run_cnt is to test the next 65536 random values. This tests the Blum-Blum-Shub generator. randomrun.cal randomrun([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. This tests the Blum-Blum-Shub generator. 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. This tests the a55 generator. repeat.cal repeat(digit_set, repeat_count) Return the value of the digit_set repeated repeat_count times. Both digit_set and repeat_count must be integers > 0. For example repeat(423,5) returns the value 423423423423423, which is the digit_set 423 repeated 5 times. regress.cal Test the correct execution of the calculator by reading this resource file. Errors are reported with '****' messages, or worse. :-) screen.cal up CUU /* same as up */ down = CUD CUD /* same as down */ forward CUF /* same as forward */ back = CUB CUB /* same as back */ save SCP /* same as save */ restore RCP /* same as restore */ cls home eraseline off bold faint italic blink rapidblink reverse concealed /* Lowercase indicates foreground, uppercase background */ black red green yellow blue magenta cyan white Black Red Green Yellow Blue Magenta Cyan White Define ANSI control sequences providing (i.e., cursor movement, changing foreground or background color, etc.) for VT100 terminals and terminal window emulators (i.e., xterm, Apple OS/X Terminal, etc.) that support them. For example: read screen print green:"This is green. ":red:"This is red.":black 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. set8700.cal set8700_getA1() defined set8700_getA2() defined set8700_getvar() defined set8700_f(set8700_x) defined set8700_g(set8700_x) defined Declare globals and define functions needed by dotest() (see dotest.cal) to evaluate set8700.line a line at a time. set8700.line A line-by-line evaluation file for dotest() (see dotest.cal). The set8700.cal file (and dotest.cal) should be read first. 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. sumtimes.cal timematsum(N) timelistsum(N) timematsort(N) timelistsort(N) timematreverse(N) timelistreverse(N) timematssq(N) timelistssq(N) timehmean(N,M) doalltimes(N) Give the user CPU time for various ways of evaluating sums, sums of squares, etc, for large lists and matrices. N is the size of the list or matrix to use. The doalltimes() function will run all fo the sumtimes tests. For example: doalltimes(1e6); 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 resource files 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 resource files 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 resource files 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 resource file 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 resource file 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 resource file is used by regress.cal to test trig functions. containing objects. test3500.cal global defaultverbose global err testfrem(x, y, verbose) testgcdrem(x, y, verbose) testf(str, n, verbose) testg(str, n, verbose) testh(str, n, N, verbose) test3500(verbose, n, N) This resource file is used by regress.cal to test the functions frem, fcnt, gcdrem. 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 resource file is used by regress.cal to test ptest, nextcand and prevcand builtins. 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 resource file is used by regress.cal to test REDC operations. test4600.cal stest(str [, verbose]) defined ttest([m, [n [,verbose]]]) defined sprint(x) defined findline(f,s) defined findlineold(f,s) defined test4600(verbose, tnum) defined This resource file is used by regress.cal to test searching in files. test5100.cal global a5100 global b5100 test5100(x) defined This resource file is used by regress.cal to test the new code generator declaration scope and order. test5200.cal global a5200 static a5200 f5200(x) defined g5200(x) defined h5200(x) defined This resource file is used by regress.cal to test the fix of a global/static bug. test8400.cal test8400() defined This resource file is used by regress.cal to check for quit-based memory leaks. test8500.cal global err_8500 global L_8500 global ver_8500 global old_seed_8500 global cfg_8500 onetest_8500(a,b,rnd) defined divmod_8500(N, M1, M2, testnum) defined This resource file is used by regress.cal to the // and % operators. test8600.cal global min_8600 global max_8600 global hash_8600 global hmean_8600 This resource file is used by regress.cal to test a change of allowing up to 1024 args to be passed to a builtin function. 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. xx_print.cal is_octet(a) defined list_print(a) defined mat_print (a) defined octet_print(a) defined blk_print(a) defined nblk_print (a) defined strchar(a) defined file_print(a) defined error_print(a) defined Demo for the xx_print object routines. ## Copyright (C) 2000 David I. Bell and Landon Curt Noll ## ## Primary author: 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.2 $ ## @(#) $Id: README,v 30.2 2010/09/02 06:01:39 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/README,v $ ## ## Under source code control: 1990/02/15 01:50:32 ## File existed as early as: before 1990 ## ## chongo /\oo/\ http://www.isthe.com/chongo/ ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ /* * lucas_chk - test all primes of the form h*2^n-1, 1<=h<200 and n <= high_n * * 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: lucas_chk.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/lucas_chk.cal,v $ * * Under source code control: 1991/01/11 05:41:43 * File existed as early as: 1991 * * chongo /\oo/\ http://www.isthe.com/chongo/ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * primes of the form h*2^n-1 for 1<=h<200 and 1<=n<1000 * * For all 0 <= i < prime_cnt, h_p[i]*2^n_p[i]-1 is prime. * * These values were taken from: * * "Prime numbers and Computer Methods for Factorization", by Hans Riesel, * Birkhauser, 1985, pp 384-387. * * This routine assumes that the file "lucas.cal" has been loaded. * * NOTE: There are several errors in Riesel's table that have been corrected * in this file: * * 193*2^87-1 is prime * 193*2^97-1 is NOT prime * 199*2^211-1 is prime * 199*2^221-1 is NOT prime */ static prime_cnt = 1145; /* number of primes in the list */ /* h = prime parameters */ static mat h_p[prime_cnt] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* element 0 */ 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 13, 13, 13, 13, 13, 13, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, /* 100 */ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23, 23, 23, 23, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, 27, 27, 27, /* 200 */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 37, 39, 39, 39, 39, 39, 39, 39, 39, 39, 41, 41, 41, 41, 41, 41, 41, 41, 41, /* 300 */ 41, 41, 41, 41, 43, 43, 43, 43, 43, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 47, 47, 47, 47, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 55, 55, 55, 55, 55, 55, 55, 55, 55, /* 400 */ 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 59, 59, 59, 59, 59, 59, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 67, 67, 67, 67, 67, 67, 67, 67, /* 500 */ 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 71, 71, 71, 73, 73, 73, 73, 73, 73, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, /* 600 */ 81, 81, 81, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 85, 85, 85, 85, 85, 85, 85, 85, 85, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, 89, 89, 89, 89, 89, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, /* 700 */ 93, 93, 93, 93, 93, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 97, 97, 97, 97, 97, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 101, 101, 101, 101, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 107, 109, 109, 109, 109, 109, 113, 113, 113, 113, 113, 113, 113, 113, 113, /* 800 */ 113, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, 119, 119, 119, 119, 119, 119, 119, 119, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 121, 125, 125, 125, 125, 125, 125, 127, 127, 131, 131, 131, 131, 131, 131, 131, 131, 131, 131, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 133, 137, 137, 137, 137, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 139, 143, /* 900 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, 149, 149, 149, 149, 149, 149, 149, 151, 151, 151, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 157, 157, 157, 157, 157, 157, 157, 157, 157, 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, 161, 163, 163, 163, 163, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 167, 169, 169, 169, 169, /* 1000 */ 169, 169, 169, 169, 169, 169, 169, 169, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 173, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 179, 179, 179, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 187, 187, 187, 187, 187, 191, 193, 193, 193, 193, 193, 193, 193, 197, 197, 197, 197, 197, 197, 197, 197, 197, /* 1100 */ 197, 197, 197, 197, 197, 197, 197, 197, 197, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, 199 }; /* n (exponent) prime parameters */ static mat n_p[prime_cnt] = { 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, /* element 0 */ 107, 127, 521, 607, 1, 2, 3, 4, 6, 7, 11, 18, 34, 38, 43, 55, 64, 76, 94, 103, 143, 206, 216, 306, 324, 391, 458, 470, 827, 2, 4, 8, 10, 12, 14, 18, 32, 48, 54, 72, 148, 184, 248, 270, 274, 420, 1, 5, 9, 17, 21, 29, 45, 177, 1, 3, 7, 13, 15, 21, 43, 63, 99, 109, 159, 211, 309, 343, 415, 469, 781, 871, 939, 2, 26, 50, 54, 126, 134, 246, 354, 362, 950, 3, 7, 23, 287, 291, 795, 1, 2, 4, 5, 10, 14, 17, 31, 41, 73, 80, /* 100 */ 82, 116, 125, 145, 157, 172, 202, 224, 266, 289, 293, 463, 2, 4, 6, 16, 20, 36, 54, 60, 96, 124, 150, 252, 356, 460, 612, 654, 664, 698, 702, 972, 1, 3, 5, 21, 41, 49, 89, 133, 141, 165, 189, 293, 305, 395, 651, 665, 771, 801, 923, 953, 1, 2, 3, 7, 10, 13, 18, 27, 37, 51, 74, 157, 271, 458, 530, 891, 4, 6, 12, 46, 72, 244, 264, 544, 888, 3, 9, 11, 17, 23, 35, 39, 75, 105, 107, 155, 215, 335, 635, 651, 687, 1, 2, 4, 5, 8, 10, 14, /* 200 */ 28, 37, 38, 70, 121, 122, 160, 170, 253, 329, 362, 454, 485, 500, 574, 892, 962, 4, 16, 76, 148, 184, 1, 5, 7, 11, 13, 23, 33, 35, 37, 47, 115, 205, 235, 271, 409, 739, 837, 887, 2, 3, 6, 8, 10, 22, 35, 42, 43, 46, 56, 91, 102, 106, 142, 190, 208, 266, 330, 360, 382, 462, 503, 815, 2, 6, 10, 20, 44, 114, 146, 156, 174, 260, 306, 380, 654, 686, 702, 814, 906, 1, 3, 24, 105, 153, 188, 605, 795, 813, 839, 2, 10, 14, 18, 50, 114, 122, 294, 362, /* 300 */ 554, 582, 638, 758, 7, 31, 67, 251, 767, 1, 2, 3, 4, 5, 6, 8, 9, 14, 15, 16, 22, 28, 29, 36, 37, 54, 59, 85, 93, 117, 119, 161, 189, 193, 256, 308, 322, 327, 411, 466, 577, 591, 902, 928, 946, 4, 14, 70, 78, 1, 5, 7, 9, 13, 15, 29, 33, 39, 55, 81, 95, 205, 279, 581, 807, 813, 1, 9, 10, 19, 22, 57, 69, 97, 141, 169, 171, 195, 238, 735, 885, 2, 6, 8, 42, 50, 62, 362, 488, 642, 846, 1, 3, 5, 7, 15, 33, 41, 57, 69, /* 400 */ 75, 77, 131, 133, 153, 247, 305, 351, 409, 471, 1, 2, 4, 5, 8, 10, 20, 22, 25, 26, 32, 44, 62, 77, 158, 317, 500, 713, 12, 16, 72, 160, 256, 916, 3, 5, 9, 13, 17, 19, 25, 39, 63, 67, 75, 119, 147, 225, 419, 715, 895, 2, 3, 8, 11, 14, 16, 28, 32, 39, 66, 68, 91, 98, 116, 126, 164, 191, 298, 323, 443, 714, 758, 759, 4, 6, 12, 22, 28, 52, 78, 94, 124, 162, 174, 192, 204, 304, 376, 808, 930, 972, 5, 9, 21, 45, 65, 77, 273, 677, /* 500 */ 1, 4, 5, 7, 9, 11, 13, 17, 19, 23, 29, 37, 49, 61, 79, 99, 121, 133, 141, 164, 173, 181, 185, 193, 233, 299, 313, 351, 377, 540, 569, 909, 2, 14, 410, 7, 11, 19, 71, 79, 131, 1, 3, 5, 6, 18, 19, 20, 22, 28, 29, 39, 43, 49, 75, 85, 92, 111, 126, 136, 159, 162, 237, 349, 381, 767, 969, 2, 4, 14, 26, 58, 60, 64, 100, 122, 212, 566, 638, 1, 3, 7, 15, 43, 57, 61, 75, 145, 217, 247, 3, 5, 11, 17, 21, 27, 81, 101, 107, 327, /* 600 */ 383, 387, 941, 2, 4, 8, 10, 14, 18, 22, 24, 26, 28, 36, 42, 58, 64, 78, 158, 198, 206, 424, 550, 676, 904, 5, 11, 71, 113, 115, 355, 473, 563, 883, 1, 2, 8, 9, 10, 12, 22, 29, 32, 50, 57, 69, 81, 122, 138, 200, 296, 514, 656, 682, 778, 881, 4, 8, 12, 24, 48, 52, 64, 84, 96, 1, 3, 9, 13, 15, 17, 19, 23, 47, 57, 67, 73, 77, 81, 83, 191, 301, 321, 435, 867, 869, 917, 3, 4, 7, 10, 15, 18, 19, 24, 27, 39, 60, 84, 111, /* 700 */ 171, 192, 222, 639, 954, 2, 6, 26, 32, 66, 128, 170, 288, 320, 470, 1, 9, 45, 177, 585, 1, 4, 5, 7, 8, 11, 19, 25, 28, 35, 65, 79, 212, 271, 361, 461, 10, 18, 54, 70, 3, 7, 11, 19, 63, 75, 95, 127, 155, 163, 171, 283, 563, 2, 3, 5, 6, 8, 9, 25, 32, 65, 113, 119, 155, 177, 299, 335, 426, 462, 617, 896, 10, 12, 18, 24, 28, 40, 90, 132, 214, 238, 322, 532, 858, 940, 9, 149, 177, 419, 617, 8, 14, 74, 80, 274, 334, 590, 608, 614, /* 800 */ 650, 1, 3, 11, 13, 19, 21, 31, 49, 59, 69, 73, 115, 129, 397, 623, 769, 12, 16, 52, 160, 192, 216, 376, 436, 1, 3, 21, 27, 37, 43, 91, 117, 141, 163, 373, 421, 2, 4, 44, 182, 496, 904, 25, 113, 2, 14, 34, 38, 42, 78, 90, 178, 778, 974, 3, 11, 15, 19, 31, 59, 75, 103, 163, 235, 375, 615, 767, 2, 18, 38, 62, 1, 5, 7, 9, 15, 19, 21, 35, 37, 39, 41, 49, 69, 111, 115, 141, 159, 181, 201, 217, 487, 567, 677, 765, 811, 841, 917, 2, /* 900 */ 4, 6, 8, 12, 18, 26, 32, 34, 36, 42, 60, 78, 82, 84, 88, 154, 174, 208, 256, 366, 448, 478, 746, 5, 13, 15, 31, 77, 151, 181, 245, 445, 447, 883, 4, 16, 48, 60, 240, 256, 304, 5, 221, 641, 2, 8, 14, 16, 44, 46, 82, 172, 196, 254, 556, 806, 1, 5, 33, 121, 125, 305, 445, 473, 513, 2, 6, 18, 22, 34, 54, 98, 122, 146, 222, 306, 422, 654, 682, 862, 3, 31, 63, 303, 4, 6, 8, 10, 16, 32, 38, 42, 52, 456, 576, 668, 1, 5, 11, 17, /* 1000 */ 67, 137, 157, 203, 209, 227, 263, 917, 2, 4, 6, 16, 32, 50, 76, 80, 96, 104, 162, 212, 230, 260, 480, 612, 1, 3, 9, 21, 23, 41, 47, 57, 69, 83, 193, 249, 291, 421, 433, 997, 8, 68, 108, 3, 5, 7, 9, 11, 17, 23, 31, 35, 43, 47, 83, 85, 99, 101, 195, 267, 281, 363, 391, 519, 623, 653, 673, 701, 2, 6, 10, 18, 26, 40, 46, 78, 230, 542, 1, 17, 21, 53, 253, 226, 3, 15, 27, 63, 87, 135, 543, 2, 16, 20, 22, 40, 82, 112, 178, 230, /* 1100 */ 302, 304, 328, 374, 442, 472, 500, 580, 694, 1, 5, 7, 15, 19, 23, 25, 27, 43, 65, 99, 125, 141, 165, 201, 211, 331, 369, 389, 445, 461, 463, 467, 513, 583, 835 }; /* obtain our required li³Ñ´Ñbs */ read -once "lucas.cal"; /* * lucas_chk - check the lucas function on known primes * * This function tests entries in the above h_p, n_p table * when n_p is below a given limit. * * input: * high_n skip tests on n_p[i] > high_n * [quiet] if given and != 0, then do not print individual test results * * returns: * 1 all is ok * 0 something went wrong */ define lucas_chk(high_n, quiet) { local i; /* index */ local result; /* 0 => non-prime, 1 => prime, -1 => bad test */ local error; /* number of errors and bad tests found */ /* * firewall */ if (!isint(high_n)) { ldebug("test_lucas", "high_n is non-int"); quit "FATAL: bad args: high_n must be an integer"; } if (param(0) == 1) { quiet = 0; } /* * scan thru the above prime table */ error = 0; for (i=0; i < prime_cnt; ++i) { /* skip primes where h>=2^n */ if (highbit(h_p[i]) >= n_p[i]) { if (config("resource_debug") & 8) { print "h>=2^n skip:", h_p[i]:"*2^":n_p[i]:"-1"; } continue; } /* test the prime if it is small enough */ if (n_p[i] <= high_n) { /* test the table value */ result = lucas(h_p[i], n_p[i]); /* report the test */ if (result == 0) { print "ERROR, bad primality test of",\ h_p[i]:"*2^":n_p[i]:"-1"; ++error; } else if (result == 1) { if (quiet == 0) { print h_p[i]:"*2^":n_p[i]:"-1 is prime"; } } else if (result == -1) { print "ERROR, failed to compute v(1) for",\ h_p[i]:"*2^":n_p[i]:"-1"; ++error; } else { print "ERROR, bogus return value:", result; ++error; } } } /* return the full status */ if (error == 0) { if (quiet == 0) { print "lucas_chk(":high_n:") passed"; } return 1; } else if (error == 1) { print "lucas_chk(":high_n:") failed", error, "test"; return 0; } else { print "lucas_chk(":high_n:") failed", error, "tests"; return 0; } } /* * lucas_tbl - lucasian criteria for primality tables * * 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: lucas_tbl.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/lucas_tbl.cal,v $ * * Under source code control: 1991/01/26 02:43:43 * File existed as early as: 1991 * * chongo /\oo/\ http://www.isthe.com/chongo/ * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ /* * Lucasian criteria for primality * * The following table is taken from: * * "Lucasian Criteria for the Primality of N=h*2^n-1", by Hans Riesel, * Mathematics of Computation, Vol 23 #108, p 872. * * The index of the *_val[] arrays correspond to the v(1) values found * in the table. That is, for v(1) == x: * * D == d_val[x] * a == a_val[x] * b == b_val[x] * r == r_val[x] (r == abs(a^2 - b^2*D)) * * * Note that when *_val[i] is not a number, the related v(1) value * is not found in Table 1. */ trymax = 100; mat d_val[trymax+1]; mat a_val[trymax+1]; mat b_val[trymax+1]; mat r_val[trymax+1]; /* v1= 0 INVALID */ /* v1= 1 INVALID */ /* v1= 2 INVALID */ d_val[ 3]= 5; a_val[ 3]= 1; b_val[ 3]=1; r_val[ 3]=4; d_val[ 4]= 3; a_val[ 4]= 1; b_val[ 4]=1; r_val[ 4]=2; d_val[ 5]= 21; a_val[ 5]= 3; b_val[ 5]=1; r_val[ 5]=12; d_val[ 6]= 2; a_val[ 6]= 1; b_val[ 6]=1; r_val[ 6]=1; /* v1= 7 INVALID */ d_val[ 8]= 15; a_val[ 8]= 3; b_val[ 8]=1; r_val[ 8]=6; d_val[ 9]= 77; a_val[ 9]= 7; b_val[ 9]=1; r_val[ 9]=28; d_val[10]= 6; a_val[10]= 2; b_val[10]=1; r_val[10]=2; d_val[11]= 13; a_val[11]= 3; b_val[11]=1; r_val[11]=4; d_val[12]= 35; a_val[12]= 5; b_val[12]=1; r_val[12]=10; d_val[13]= 165; a_val[13]=11; b_val[13]=1; r_val[13]=44; /* v1=14 INVALID */ d_val[15]= 221; a_val[15]=13; b_val[15]=1; r_val[15]=52; d_val[16]= 7; a_val[16]= 3; b_val[16]=1; r_val[16]=2; d_val[17]= 285; a_val[17]=15; b_val[17]=1; r_val[17]=60; /* v1=18 INVALID */ d_val[19]= 357; a_val[19]=17; b_val[19]=1; r_val[19]=68; d_val[20]= 11; a_val[20]= 3; b_val[20]=1; r_val[20]=2; d_val[21]= 437; a_val[21]=19; b_val[21]=1; r_val[21]=76; d_val[22]= 30; a_val[22]= 5; b_val[22]=1; r_val[22]=5; /* v1=23 INVALID */ d_val[24]= 143; a_val[24]=11; b_val[24]=1; r_val[24]=22; d_val[25]= 69; a_val[25]= 9; b_val[25]=1; r_val[25]=12; d_val[26]= 42; a_val[26]= 6; b_val[26]=1; r_val[26]=6; d_val[27]= 29; a_val[27]= 5; b_val[27]=1; r_val[27]=4; d_val[28]= 195; a_val[28]=13; b_val[28]=1; r_val[28]=26; d_val[29]= 93; a_val[29]= 9; b_val[29]=1; r_val[29]=12; d_val[30]= 14; a_val[30]= 4; b_val[30]=1; r_val[30]=2; d_val[31]= 957; a_val[31]=29; b_val[31]=1; r_val[31]=116; d_val[32]= 255; a_val[32]=15; b_val[32]=1; r_val[32]=30; d_val[33]=1085; a_val[33]=31; b_val[33]=1; r_val[33]=124; /* v1=34 INVALID */ d_val[35]=1221; a_val[35]=33; b_val[35]=1; r_val[35]=132; d_val[36]= 323; a_val[36]=17; b_val[36]=1; r_val[36]=34; d_val[37]=1365; a_val[37]=35; b_val[37]=1; r_val[37]=140; d_val[38]= 10; a_val[38]= 3; b_val[38]=1; r_val[38]=1; d_val[39]=1517; a_val[39]=37; b_val[39]=1; r_val[39]=148; d_val[40]= 399; a_val[40]=19; b_val[40]=1; r_val[40]=38; d_val[41]=1677; a_val[41]=39; b_val[41]=1; r_val[41]=156; d_val[42]= 110; a_val[42]=10; b_val[42]=1; r_val[42]=10; d_val[43]= 205; a_val[43]=15; b_val[43]=1; r_val[43]=20; d_val[44]= 483; a_val[44]=21; b_val[44]=1; r_val[44]=42; d_val[45]=2021; a_val[45]=43; b_val[45]=1; r_val[45]=172; d_val[46]= 33; a_val[46]= 6; b_val[46]=1; r_val[46]=3; /* v1=47 INVALID */ d_val[48]= 23; a_val[48]= 5; b_val[48]=1; r_val[48]=2; d_val[49]=2397; a_val[49]=47; b_val[49]=1; r_val[49]=188; d_val[50]= 39; a_val[50]= 6; b_val[50]=1; r_val[50]=3; d_val[51]= 53; a_val[51]= 7; b_val[51]=1; r_val[51]=4; /* v1=52 INVALID */ d_val[53]=2805; a_val[53]=51; b_val[53]=1; r_val[53]=204; d_val[54]= 182; a_val[54]=13; b_val[54]=1; r_val[54]=13; d_val[55]=3021; a_val[55]=53; b_val[55]=1; r_val[55]=212; d_val[56]= 87; a_val[56]= 9; b_val[56]=1; r_val[56]=6; d_val[57]=3245; a_val[57]=55; b_val[57]=1; r_val[57]=220; d_val[58]= 210; a_val[58]=14; b_val[58]=1; r_val[58]=14; d_val[59]=3477; a_val[59]=57; b_val[59]=1; r_val[59]=228; d_val[60]= 899; a_val[60]=29; b_val[60]=1; r_val[60]=58; d_val[61]= 413; a_val[61]=21; b_val[61]=1; r_val[61]=28; /* v1=62 INVALID */ d_val[63]=3965; a_val[63]=61; b_val[63]=1; r_val[63]=244; d_val[64]=1023; a_val[64]=31; b_val[64]=1; r_val[64]=62; d_val[65]= 469; a_val[65]=21; b_val[65]=1; r_val[65]=28; d_val[66]= 17; a_val[66]= 4; b_val[66]=1; r_val[66]=1; d_val[67]=4485; a_val[67]=65; b_val[67]=1; r_val[67]=260; d_val[68]=1155; a_val[68]=33; b_val[68]=1; r_val[68]=66; d_val[69]=4757; a_val[69]=67; b_val[69]=1; r_val[69]=268; d_val[70]= 34; a_val[70]= 6; b_val[70]=1; r_val[70]=2; d_val[71]=5037; a_val[71]=69; b_val[71]=1; r_val[71]=276; d_val[72]=1295; a_val[72]=35; b_val[72]=1; r_val[72]=70; d_val[73]= 213; a_val[73]=15; b_val[73]=1; r_val[73]=12; d_val[74]= 38; a_val[74]= 6; b_val[74]=1; r_val[74]=2; d_val[75]=5621; a_val[75]=73; b_val[75]=1; r_val[75]=292; d_val[76]=1443; a_val[76]=37; b_val[76]=1; r_val[76]=74; d_val[77]= 237; a_val[77]=15; b_val[77]=1; r_val[77]=12; d_val[78]= 95; a_val[78]=10; b_val[78]=1; r_val[78]=5; /* v1=79 INVALID */ d_val[80]=1599; a_val[80]=39; b_val[80]=1; r_val[80]=78; d_val[81]=6557; a_val[81]=79; b_val[81]=1; r_val[81]=316; d_val[82]= 105; a_val[82]=10; b_val[82]=1; r_val[82]=5; d_val[83]= 85; a_val[83]= 9; b_val[83]=1; r_val[83]=4; d_val[84]=1763; a_val[84]=41; b_val[84]=1; r_val[84]=82; d_val[85]=7221; a_val[85]=83; b_val[85]=1; r_val[85]=332; d_val[86]= 462; a_val[86]=21; b_val[86]=1; r_val[86]=21; d_val[87]=7565; a_val[87]=85; b_val[87]=1; r_val[87]=340; d_val[88]= 215; a_val[88]=15; b_val[88]=1; r_val[88]=10; d_val[89]=7917; a_val[89]=87; b_val[89]=1; r_val[89]=348; d_val[90]= 506; a_val[90]=22; b_val[90]=1; r_val[90]=22; d_val[91]=8277; a_val[91]=89; b_val[91]=1; r_val[91]=356; d_val[92]= 235; a_val[92]=15; b_val[92]=1; r_val[92]=10; d_val[93]=8645; a_val[93]=91; b_val[93]=1; r_val[93]=364; d_val[94]= 138; a_val[94]=12; b_val[94]=1; r_val[94]=6; d_val[95]=9021; a_val[95]=93; b_val[95]=1; r_val[95]=372; d_val[96]= 47; a_val[96]= 7; b_val[96]=1; r_val[96]=2; d_val[97]=1045; a_val[97]=33; b_val[97]=1; r_val[97]=44; /* v1=98 INVALID */ d_val[99]=9797; a_val[99]=97; b_val[99]=1; r_val[99]=388; d_val[100]= 51; a_val[100]= 7; b_val[100]=1; r_val[100]=2; if (config("resource_debug") & 3) { print "d_val[100] defined"; print "a_val[100] defined"; print "b_val[100] defined"; print "r_val[100] defined"; } /* * test5200 - 5200 series of the regress.cal test suite * * Copyright (C) 1999 Ernest Bowen and Landon Curt Noll * * Primary author: Ernest Bowen * * 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: test5200.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test5200.cal,v $ * * Under source code control: 1997/02/07 02:48:10 * File existed as early as: 1997 * * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */ defaultverbose = 1; /* default verbose value */ /* * test the fix of a global/static bug * * Given the following: * * global a = 10; * static a = 20; * define f(x) = a + x; * define g(x) {global a = 30; return a + x;} * define h(x) = a + x; * * Older versions of */ global a5200 = 10; static a5200 = 20; define f5200(x) = a5200 + x; define g5200(x) {global a5200 = 30; return a5200 + x;} define h5200(x) = a5200 + x; ## ## set8700 - dotest line tests for the 8700 set of regress.cal ## ## Copyright (C) 2006 Ernest Bowen and 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: set8700.line,v 30.1 2007/03/16 11:09:54 chongo Exp $ ## @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/set8700.line,v $ #