- Do
- I prefer and use these functions over the official Scheme syntactic sugar.
(((fileVal "Do") 'Do) 6 (lambda (j) (write (+ j 2)))) ; => 765432
(((fileVal "Do") 'DoL) 5 (lambda (j) (* j 2))) ; => (0 2 4 6 8)
(((fileVal "Do") 'DoV) 4 (lambda (j) (+ j 4))) ; => #(4 5 6 7)
More info
- Equal
- An equivalence test for potentially infinite Scheme structures.
More info
- RC4
- A source of quality pseudo random generators based on the RC4 crypto algorithm.
(let ((g ((fileVal "RC4") 'nb "Seed stuff"))) (list (g 4) (g 3) (g 2)))
yields (3453575773 3264371 6246).
(g n) yields integers uniformly distributed in [0, 28n).
(let ((g ((fileVal "RC4") 'sb "Seed stuff"))) (list (g) (g) (g)))
yields (205 217 98), integers uniformly distributed in [0, 28).
These successive values are the eight bit bytes of the RC4 key-stream.
(((fileVal "RC4") 'rbi "Seed stuff") n)
yields a generator of integers uniformly distributed in [0, n).
More info
- RND
- Generator of sequences of random normal deviates.
(let ((sg ((fileVal "RND") "frSeed"))) (let r ((n 10000) (m 0) (s 0))
(if (zero? n) (cons m s) (let ((w (sg))) (r (- n 1) (+ m w) (+ s (* w w)))))))
yields (41.62913630233171 . 10215.783961421654).
- rr
- Random rational generator
(let ((g ((fileVal "rr") "Seed"))) (list (g) (g)))
yields (-37/113 125/23).
- egcd
- Extended Euclidean Algorithm.
((fileVal "egcd") a b) yields (x . y) such that ax+by = (gcd a b)
((fileVal "egcd") 100 144) => (13 . -9)
gcd(100, 144) = 4, 1300 – 1296 = 4
- Factorial
- ((fileVal "Factorial") n) yields n! for n > –1.
It works for integral and half integral values.
((fileVal "Factorial") -0.5) => (–1/2)! = 1.7724538509055159 = √π.
- gamma
-
| Definition: |  |
| Calculation: |  |
The incomplete Gamma function
((fileVal "gamma") s z) => γ(s, z).
For constant s and large values of z γ(s, z) is asymptotic to some constant.
Power series don’t do this well.
This Algol68 code can run in multiple precision so as to extend the range.
- Chi2
- The χ2 distribution, both density:
(((fileVal "Chi2") 'f) x k) = f(x; k)
and cumulative:
(((fileVal "Chi2") 'F) x k) = F(x; k)
A meagre corroboration
- pias
- To search an arithmetic sequence for the first prime.
Candidates are tested with the Miller–Rabin primality test.
((fileVal "pias") a b)
reports the first prime among a + nb for n = 0, 1, 2, ... .
There is extraneous printed output during the computation consisting of a comma for each candidate which is excluded for being divisible by a prime less than 18, and a construct such as (123 #f) when the Miller–Rabin test finds the candidate to be composite for n = 123.
Running this program for largish numbers suggests that the probability of false positives is very much less than 1/2 which is the proven upper bound on the probability.
Indeed I have seen no false positives in a few hundred cases.
((fileVal "pias") (expt 10 100) -1)
indicates that 10100 – 797 is the largest prime less than 10100.
(101000–1769 is prime too.)
more info.
- piasd
- like pias above but if result is p then both p and 2p+1 are prime.
- mod-exp
- ((fileVal "mod-exp") p q m) yields pq modulo m.
p, q and m are integers: q ≥ 0 and m ≥ 2.
- Miller–Rabin
- The Miller–Rabin primality test:
If p is prime and 1 < a < p then ((fileVal "Miller-Rabin") a p) is true.
If p is composite then it is false for almost all a's.
Cumulative count of false positives less than 5n for the composite 225+1: (3 5 7 10 12 14 19 25 … )
- try
- Conventional try-catch function.
((fileVal "try") (lambda (e) (write "working") 'w)
(lambda (t) (write (list "exception" t)) 'e))
; => "working"w
((fileVal "try") (lambda (e) (write "attempting") (e "peculiar") (write "don't get here!"))
(lambda (t) (write (list "exception" t)) 'e))
; => "attempting"("exception" "peculiar")e
More info
- transpose
- (fileVal "transpose") transposes a matrix expressed as a lists of equal length lists.
Its argument must not be null.
- transpose0
- ((fileVal "transpose0") 0 zero?) is a function that transposes an infinite list of infinite lists where all but a finite number of terms are zero and suppressed.
Adding a 0 to the end of a matrix row or adding an empty row to the end of a matrix results in a Scheme value denotation the same infinite matrix.
More info
- sort
-
((fileVal "sort") '(5 3 4 882 3 5 44 3 9 -7) <) => (-7 3 3 3 4 5 5 9 44 882)
- Set
- A suite of set functions.
Transcribed from a source with a GNU license.
The suite is parameterized by a total ordering function for set elements.
If sy is a symbol from the list of values listed here, then (((fileVal "Set") comp) 'sy) yields the value described on the same page.
(comp a b) must return a negative number, 0, or a positive number depending on whether a<b, a=b or a>b respectively.
((fileVal "Set") (lambda (i j) -)) returns a map from symbols to set tools, in this case sets of numbers.
If m is such a map then (m 'union) returns the set-union operator.
See this for more detail.
- Farey
- Farey Sequence: ((fileVal "Farey") n) => Fn.
- stream
- Routines to convert between streams and lists.
(ylppa (fileVal "stream") (lambda (sm si SG->lst lst->SG fs Cart string->SG)
; Scope of stream functions
(SG->lst (sm (si 6) -)) ; => (0 -1 -2 -3 -4 -5)
))
more detail
- Matrix
- Determinants and matrix functions over arbitrary fields.
Arguments to (fileVal "Matrix")
- Random scalar generator
- the zero element for the field
- a predicate that tests its field argument for being zero
- the multiplicative identity of the field
- the addition operator that takes two field arguments and returns their sum
- the unary additive inverse function
- the field multiplication operator for two field arguments
- the multiplicative inverse function
Yields the list:
- Random n×n Matrix Generator (rmg n)
- Matrix multiplication
- Matrix inversion (2nd arg is continuation for singular matrix)
- Inner product of two vectors
- Transpose
- Determinant
- Identity test
- Binary vector equality test
- Binary matrix equality test
(rmg k) returns a random k by k matrix.
They may deployed:
(ylppa ((fileVal "Matrix") '() 0 zero? 1 + - * /)
(lambda (rm matm matinv ip tr det i? v= m=)
; Scope of matrix functions over Scheme numbers
(det '((1 3 2)(4 0.6 2)(3 8 4)))
)) ; => 16.8
If the ‘Matrix Generator’ is not used then the ‘Random scalar generator’ is not required.
Note that we do not supply a good random scalar generator since we do not need a random matrix generator.
The code inverts matrices of quaternions; see quatApp below.
Thus it probably handles division rings.
It even inverts matrices in associative algebras with dense inverses such as Clifford Matrices.
More info
- MatInverse
- A concrete matrix invert built from above.
((fileVal "MatInverse") '((2 4 5)(3 2 5)(5 7 4)))
yields ((-27/53 19/53 10/53) (13/53 -17/53 5/53) (11/53 6/53 -8/53)).
Any Scheme numbers may be used including, rational, complex and floating point.
- diag
- ((fileVal "diag") num-list) yields a diagonal matrix with elements of num-list down the diagonal.
- ranoth
- ((fileVal "ranoth") "ran seed" n) yields a generator of random orthogonal n by n real matrices, i.e. matrices from O(n).
The distribution is invariant over O(n).
Adapted from this.
Notes on testing.
- gRREF
- Reduced Row Echelon Form of matrix parameterized by field.
(let ((R ((fileVal "gRREF") zero? 0 1 / * - C)))
((R 'rref) m) ; Reduced Row Echelon Form of matrix m.
((R 'rank) m) ; rank of m
((R 'minspan) m) ; spanning subset of m
)
Arguments - and * are binary; / is unary.
Argument C is for ‘canonical’.
If C is true then the resulting transformation omits trailing zero vectors and this modification makes the matrix canonical with respect to which subspace its vectors span.
The classical definition of RREF requires as many rows in the output as in the input.
The returned RREF function returns the classical answer if C is false (#f).
more info
- Intersect
- Compute intersection of subspaces of vector space where subspaces are denoted by a lists of spanning vectors.
((fileVal "Intersect") a b) yields the intersection.
See demos at end of source and here.
Detailed info
- gIntersect
- Specification.
Compute intersection of subspaces of vector space over field where subspaces are identified by a list of spanning vectors.
See demos at end of source and here.
more info
- testInter
- Code to test gIntersect above.
More info.
- PGc
- Projective Geometry: Specs
- PGLat
- Verifying lattice properties of subspaces
- Desargues
- Corroborating Desargues’ theorem.
comments
- finFieldMat
- ((fileVal "finFieldMat") p q n) yields some tools for n by n matrices whose elements are from GF(pq).
The yield is (random mp inv ip tr deter it? v= m=).
Returned values are those of Matrix.
- finFieldMatTest
- ((fileVal "finFieldMatTest") p q n) runs a test of the above finite field n by n matrix logic from GF(pq).
- Jacobi
- ((fileVal "Jacobi") a n) is the Jacobi symbol sometimes written
.
- DivisionAlgebra
- (fileVal "DivisionAlgebra")automates the Cayley-Diskson construction of the Division Algebras.
More info
- k4ZerDiv
- Zero Divisors in Sedenions
- divAlgSurvey
- (fileVal "divAlgSurvey") builds the first five Cayley-Diskson algebras and reports their algebraic properites.
More info
- quaternion
- (fileVal "quaternion") yields a list of quaternion tools:
(random quaternion generator, zero, zero predicate, one, addition, negation, multiplication, inverse).
Here is an alternate ab-initio construction of the quaternions.
- quatApp
- (fileVal "quatApp") builds matrices of quaternions and successfully inverts them with Matrix!
- GFp
- For a prime p, ((fileVal "GFp") p) yields a list of the four operations over GF(p),
+, –, *, /.
The ops – and / are unary, the operands are non negative integers less than p.
- GFsqrt
- is a modular square root routine.
If p is prime then ((fileVal "GFsqrt") (* r r) p) yields r or p–r.
This addresses other finite fields.
- finiteField
- Code to perform arithmetic over any finite field.
This module exports tools of interest to builders of alternate representations.
Detailed specs are here.
Most users want GFpq below.
- GFpq
- ((fileVal "GFpq") p q st)
returns a tool list
- sample generator,
- zero,
- zero predicate,
- one,
- sum,
- negation,
- product,
- inverse,
such as needed for input to the Matrix module.
The finite field is GF(pq) and st is a non-empty string which seeds the random generator.
The following illustrates matrices from Finite fields:
(ylppa (ylppa ((fileVal "GFpq") 17 4 "p") (fileVal "Matrix"))
(lambda (rmg mm inv ip tr det i? v= m=)
(let ((inv (lambda (q) ((fileVal "try") (lambda (w) (inv q w))(lambda (e) "e")))))
(let* ((m (rmg 4))(mi (inv m))) (list m mi (inv mi) (i? (mm m mi)))))))
=> (…, …, …, #t)
- rip
- ((fileVal "rip") p q) searches randomly for irreducible polynomials of degree q over GF(p).
Perhaps there are no 5th order irreducible binomials over GF(6700417) and searching lexicographically is thus frustrating.
They are abundant further on.
((fileVal "rip") 6700417 5) yields (8 . #6(5538386 4064128 2588321 4310749 3668254 1)).
It took 8 trials to find this irreducible polynomial.
- ffqr
- ((fileVal "ffqr") p q) counts quadratic residues in finite field GF(pq).
See theorem.
- Clifford0
- Simplest Clifford algebra. => (functor reals) where functor generates Cn+1 from Cn and reals is the reals.
More info
- CliffTst0
- Simple corroboration of above.
More info
- Clifford1
- Fuller Clifford algebra.
More info
- CliffTst1
- Simple corroboration of above.
More info
- Clifford2
- Fuller Clifford algebra with pretty good division.
More info
- CliffTst2
- Simple corroboration of above.
More info
- IndCliff
- Clifford studied algebras based on negative definite quadratic forms.
This package generates ‘Clifford algebras’ based on indefinite forms.
((fileVal "IndCliff") (list + - - -)) generates a pseudo
Clifford algebra where γ02 = 1 instead of –1.
See test code at end of file for the returned values.
- IndCliffTst
- Demonstration of isometry with explanation.
- CliffMat
- (fileVal "CliffMat") Generates a 3×3 matrix of Clifford numbers (Cl(3)) using small rationals.
It inverts the matrix using the ‘almost everywhere inverse’.
It checks that the inverse times the original is the identity.
- CliffMat2
- (fileVal "CliffMat2") Generates a 5×5 matrix of Clifford numbers (Cl(4)) using random normal deviates as constituent floating point reals.
It inverts the matrix using the ‘almost everywhere inverse’.
It checks that the inverse times the original is the identity within a tolerance of 2–48.