formform.calc
API for the calc
module of formform
.
char->const
(char->const c)
(char->const sort-code c)
Coerces a char
to a corresponding constant
.
chars->dna
(chars->dna dna-seq)
(chars->dna sort-code dna-seq)
Converts a seqable?
of chars to formDNA.
Note that nuim-code
is the default ordering. If a different sort-code
is specified, digits
will be reordered to match the code.
const->digit
(const->digit c)
(const->digit sort-code c)
Converts a constant
to a digit
corresponding to an optional sort-code
or the default nuim-code
.
digit->const
(digit->const n)
(digit->const sort-code n)
Converts a digit to its corresponding constant representation.
digits->dna
(digits->dna dna-seq)
(digits->dna sort-code dna-seq)
Converts a seqable?
of digits (as string/char or integer) to formDNA.
Note that nuim-code
is the default ordering. If a different sort-code
is specified, digits
will be reordered to match the code.
dna->digits
(dna->digits dna)
(dna->digits sort-code dna)
Converts formDNA to a sequence of digits corresponding to a sort-code
.
Note that nuim-code
is the default ordering. If a different sort-code
is specified, dna
will be reordered to match the code.
dna->vdict
(dna->vdict dna)
(dna->vdict opts dna)
Generates a vdict from a given dna.
- optional
sorted?
defaults to false since sorting large vspace dimensions can be expensive
dna-dimension
(dna-dimension xs)
Calculates the dimension of a formDNA
/dna-seq
(corresponds to the number of variables in a FORM). The length of a dna-seq
is 4^d for its dimension d.
- the input sequence can have any type of elements
dna-perspectives
(dna-perspectives dna)
(dna-perspectives opts dna)
Given a formDNA, generates all of its permutations and returns a map from permuted term order to the corresponding formDNA.
equal-dna
(equal-dna & dnas)
Equality check for formDNA. Two formDNAs are considered equal, if they contain the same constants in the same order. Stricter than equiv-dna
, where permutations are considered equal.
equiv-dna
(equiv-dna & dnas)
Equivalence check for formDNA. Two formDNAs are considered equivalent, if they belong to the same equivalence-class of dna-perspectives
(i.e. if they are permutations of each other).
expand-dna-seq
(expand-dna-seq dna-seq ext-dim)
(expand-dna-seq dna-seq dim ext-dim)
Expands a dna-seq
to a given target dimension by repeating elements.
Note: dna-seq
can have any type of elements (not only constants)
filter-dna
(filter-dna dna vpoint)
Filters a dna
by selecting specific parts corresponding to a given vpoint
, which acts as a coordinate vector in its value space.
- use holes
:_
to indicate a variable selection
make-compare-consts
(make-compare-consts sort-code)
Given a sort-code
(try calc.nuim-code
or calc.nmui-code
), returns a comparator function to sort single constants, formDNA or arbitrary sequences of constants (can be mixed).
- can also compare map-entries by keys of comparable types
make-dna
(make-dna & xs)
Creates a formDNA from arguments, which may be valid chars, keywords, integers or sequences thereof.
- valid chars are: \n \u \i \m (upper- or lowercase) and \0 \1 \2 \3
- valid integers are: 0 1 2 3
- valid keywords are: :N :U :I :M
- total argument count (including count of sequence args) must match a valid formDNA length, which is 4^d, where d is a natural number
permute-dna
(permute-dna dna perm-order)
(permute-dna opts dna perm-order)
FIXME: write docs
rand-dna
(rand-dna dim)
(rand-dna dim elems)
Generates a random formDNA/dna-seq
of dimension dim
. A vector of 4 custom elements can be provided as a second argument.
rand-vpoint
(rand-vpoint)
(rand-vpoint dim)
Generates a random vpoint either as an infinite lazy seq or with given dimension dim
.
reduce-dna-seq
(reduce-dna-seq dna-seq)
(reduce-dna-seq terms dna-seq)
Reduces a dna-seq
by eliminating redundant/contingent terms.
- returns a tuple
[terms dna-seq]
, whereterms
is a sequence that represents the remaining terms after reduction - takes an optional
terms
sequence of any kind of items that will be used instead of the default arithmetic sequence[0 1 2 …]
to represent each term (length has to match the formDNA dimension)
Note: dna-seq
can have any type of elements (not only constants)
reorder-dna-seq
(reorder-dna-seq dna-seq sort-code-from sort-code-to)
Reorders given formDNA/dna-seq
from sort-code-from
to sort-code-to
.
Note:
dna-seq
can have any type of elements (not only constants)- does NOT change the encoding of the elements, just their ordering
vdict
(vdict vpoint->result)
(vdict opts vpoint->result)
Generates a vdict given a map vpoint->result (result is a constant).
- if the corresponding vspace is not a subset of the set of keys from
vp->r
, the remaining results will be filled with :N or a given default constant - optional
sorted?
defaults to false since sorting large vspace dimensions can be expensive
vspace
(vspace dim)
(vspace sort-code dim)
Generates a vspace of dimension dim
, optionally with custom sort-code
.
- returns a lazy-seq which may be too memory-expensive to fully realize for dimensions greater than 11 (> 200 Mio. elements in total!)