API for the calc module of formform.
constant
→ representation of a value in FORM logic
A sort-code specifies a numeric ordering for constants, which is useful for conversion to integers and formDNA interpretation order. It is always assumed to be in nuim-code by default:
0 = :n → unmarked
1 = :u → undetermined
2 = :i → imaginary
3 = :m → marked
Make sure you convert to/from nuim-code when using different codes!
formDNA
→ representation of a value structure in FORM logic
formDNA perspective
→ permutation of formDNA
→ representation of a different perspective on the value structure
vpoint
→ relate values as a point
→ vector of constant-coordinates in a vspace
vspace
→ relate vpoints as a space
→ vector of all n-dimensional vpoints
vdict
→ map vpoints to values in a dictionary
→ (sorted) key-value map from vspace to formDNA
vmap
→ map recursively decomposed vspace to value structure
→ mapping from vspace topology to formDNA
API for the `calc` module of `formform`.
## Concepts
### Values
**constant**
→ representation of a _value_ in FORM logic
* _value_ → element of a _value system_
* _value_ → state indicated by an _expression_
* _value system_ → system of differences
A `sort-code` specifies a numeric ordering for _constants_, which is useful for conversion to integers and _formDNA_ interpretation order. It is always assumed to be in _nuim-code_ by default:
0 = :n → unmarked
1 = :u → undetermined
2 = :i → imaginary
3 = :m → marked
Make sure you convert to/from `nuim-code` when using different codes!
### Value Structures
**formDNA**
→ representation of a _value structure_ in FORM logic
* becomes a quaternary number when reversed and converted to digits
* _value structure_ → specific structure in _value system_
**formDNA perspective**
→ permutation of _formDNA_
→ representation of a different perspective on the _value structure_
**vpoint**
→ relate _values_ as a point
→ vector of _constant_-coordinates in a _vspace_
**vspace**
→ relate _vpoints_ as a space
→ vector of all n-dimensional _vpoints_
**vdict**
→ map _vpoints_ to _values_ in a dictionary
→ (sorted) key-value map from _vspace_ to _formDNA_
- for value table generation
- like a flat _vmap_
**vmap**
→ map recursively decomposed _vspace_ to _value structure_
→ mapping from _vspace_ topology to _formDNA_
(char->const c)(char->const sort-code c)Coerces a char to a corresponding constant.
Coerces a `char` to a corresponding `constant`.
(chars->dna dna-seq)(chars->dna from-sort-code dna-seq)Converts a seqable? of chars to formDNA.
Note that nuim-code is the default ordering and is always assumed for formDNA. If a different sort-code is specified, the input sequence (expected in this code) will be reordered to match nuim-code.
Converts a `seqable?` of chars to formDNA. Note that `nuim-code` is the default ordering and is always assumed for _formDNA_. If a different `sort-code` is specified, the input sequence (expected in this code) will be reordered to match `nuim-code`.
Comparator for constants using the default nuim-code.
Comparator for constants using the default `nuim-code`.
(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.
Converts a `constant` to a `digit` corresponding to an optional `sort-code` or the default `nuim-code`.
Checks if the argument is a valid constant.
Checks if the argument is a valid constant.
(digit->const n)(digit->const sort-code n)Converts a digit to its corresponding constant representation.
Converts a digit to its corresponding constant representation.
(digits->dna dna-seq)(digits->dna from-sort-code dna-seq)Converts a seqable? of digits (as string/char or integer) to formDNA.
Note that nuim-code is the default ordering and is always assumed for formDNA. If a different sort-code is specified, the input sequence (expected in this code) will be mapped and reordered to match nuim-code. If you just want the mapping without reordering, use something like (mapv digit->const dna).
Converts a `seqable?` of digits (as string/char or integer) to formDNA. Note that `nuim-code` is the default ordering and is always assumed for _formDNA_. If a different `sort-code` is specified, the input sequence (expected in this code) will be mapped and reordered to match `nuim-code`. If you just want the mapping without reordering, use something like `(mapv digit->const dna)`.
(dna->digits dna)(dna->digits to-sort-code dna)Converts formDNA to a sequence of digits corresponding to a sort-code.
Note that nuim-code is the default ordering and is always assumed for formDNA. If a different sort-code is specified, the input dna (expected in nuim-code) will be mapped and reordered to match this code.
Converts formDNA to a sequence of digits corresponding to a `sort-code`. Note that `nuim-code` is the default ordering and is always assumed for _formDNA_. If a different `sort-code` is specified, the input dna (expected in `nuim-code`) will be mapped and reordered to match this code.
(dna->vdict dna)(dna->vdict dna opts)Generates a vdict from a given formDNA (dna).
sorted? defaults to false since sorting large vspace dimensions can be expensiveGenerates a vdict from a given formDNA (`dna`). * optional `sorted?` defaults to false since sorting large vspace dimensions can be expensive
(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.
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-get dna vpoint)Extracts a single value from a dna according to a given vpoint index, which is a sequence of constants corresponding to each term→value association.
Extracts a single value from a `dna` according to a given `vpoint` index, which is a sequence of constants corresponding to each term→value association.
(dna-perspectives dna)(dna-perspectives dna opts)Given a formDNA (dna), generates all of its permutations and returns a map from permuted term order to the corresponding formDNA.
Given a formDNA (`dna`), generates all of its permutations and returns a map from permuted term order to the corresponding formDNA.
(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.
Note: partial formDNA (which includes holes (:_)) cannot be compared and thus are not valid input. If you know/assume equality for holes or just want to ignore them in comparison, use equal-partial-dna?.
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. Note: partial formDNA (which includes holes (`:_`)) cannot be compared and thus are not valid input. If you know/assume equality for holes or just want to ignore them in comparison, use [[equal-partial-dna?]].
(equal-partial-dna? & dnas)Equality check for partial formDNA (derived from equal-dna?), under the assumption that all holes (:_) originate from the same expression and thus their supposed value would be equal (which is the same as just ignoring them).
Equality check for partial formDNA (derived from [[equal-dna?]]), under the assumption that all holes (`:_`) originate from the same expression and thus their supposed value would be equal (which is the same as just ignoring them).
(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).
Note: partial formDNA (which includes holes (:_)) cannot be compared and thus are not valid input. If you know/assume equality for holes or just want to ignore them in comparison, use equiv-partial-dna?.
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). Note: partial formDNA (which includes holes (`:_`)) cannot be compared and thus are not valid input. If you know/assume equality for holes or just want to ignore them in comparison, use [[equiv-partial-dna?]].
(equiv-partial-dna? & dnas)Equivalence check for partial formDNA (derived from equiv-dna?), under the assumption that all holes (:_) originate from the same expression and thus their supposed value would be equal (which is the same as just ignoring them).
Equivalence check for partial formDNA (derived from [[equiv-dna?]]), under the assumption that all holes (`:_`) originate from the same expression and thus their supposed value would be equal (which is the same as just ignoring them).
(expand-dna dna-seq ext-dim)(expand-dna 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)
Expands a `dna-seq` to a given target dimension by repeating elements. Note: `dna-seq` can have any type of elements (not only constants)
Obsolete → please use expand-dna instead.
Obsolete → please use [[expand-dna]] instead.
(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.
:_ in vpoint to indicate a variable selectionFilters a `dna` by selecting specific parts corresponding to a given `vpoint`, which acts as a coordinate vector in its value space. * use holes `:_` in `vpoint` to indicate a variable selection
(inv & consts-or-dnas)Inverts the value of a given constant or formDNA. With multiple arguments, will relate all arguments (via rel) and then invert the result.
Note: value holes (:_) will invert to value holes.
Inverts the value of a given constant or formDNA. With multiple arguments, will relate all arguments (via [[rel]]) and then invert the result. Note: value holes (`:_`) will invert to value holes.
(make-compare-consts sort-code)Given a sort-code (try nuim-code or nmui-code), returns a comparator function to sort single constants, formDNA or arbitrary sequences of constants (can be mixed).
Given a `sort-code` (try [[nuim-code]] or [[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 & xs)Creates a formDNA from arguments, which may be valid chars, keywords, integers or sequences thereof.
\n \u \i \m (upper- or lowercase) and \0 \1 \2 \30 1 2 3:n :u :i :mCreates 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 dna perm-order)(permute-dna dna perm-order opts)Given a formDNA (dna), generates its permutation (called a “perspective”) that matches the given perm-order.
perm-order must be a sequence of indices that correspond to each term/subdna of the dna. Think of each place in the sequence as a depth (shallowest → deepest) and each index as an identifier of the term in that depth.
For example, [0 1 2] is the default order of terms in a 3-dimensional formDNA. [1 2 0] would permute the terms, such that in the resulting formDNA term 0 is in depth 2, term 1 in depth 0 and term 2 in depth 1.
Given a formDNA (`dna`), generates its permutation (called a “perspective”) that matches the given `perm-order`. `perm-order` must be a sequence of indices that correspond to each term/subdna of the `dna`. Think of each place in the sequence as a depth (shallowest → deepest) and each index as an identifier of the term in that depth. For example, `[0 1 2]` is the default order of terms in a 3-dimensional formDNA. `[1 2 0]` would permute the terms, such that in the resulting formDNA term 0 is in depth 2, term 1 in depth 0 and term 2 in depth 1.
(rand-const)(rand-const seed)Generates a random constant. A seed (an integer) can be provided as a second argument for reproducability.
Generates a random constant. A seed (an integer) can be provided as a second argument for reproducability.
(rand-const-weighted const-weights)(rand-const-weighted const-weights seed)Same as rand-const, but takes a weights argument to specify the relative probability of each of the four constants to be randomly chosen.
Weights can be provided either as:
[1 0 2 5]) in n-u-i-m order{:i 1 :u 2}), where missing weights are 0:u/:i/m against :n (whose weight is 1 - x)Same as [[rand-const]], but takes a `weights` argument to specify the relative probability of each of the four constants to be randomly chosen.
Weights can be provided either as:
* a sequence of 4 non-negative numbers (e.g. `[1 0 2 5]`) in n-u-i-m order
* a map (e.g. `{:i 1 :u 2}`), where missing weights are 0
* a single number in the interval [0.0, 1.0] that represents the ratio of `:u`/`:i`/`m` against `:n` (whose weight is 1 - x)(rand-dna dim)(rand-dna dim seed)Generates a random formDNA of dimension dim. A seed (an integer) can be provided as a second argument for reproducability.
Generates a random formDNA of dimension `dim`. A seed (an integer) can be provided as a second argument for reproducability.
(rand-dna-weighted dim const-weights)(rand-dna-weighted dim const-weights seed)Same as rand-dna, but takes a weights argument to specify the relative probability of each of the four constants to be randomly chosen.
Weights can be provided either as:
[1 0 2 5]) in n-u-i-m order{:i 1 :u 2}), where missing weights are 0:u/:i/m against :n (whose weight is 1 - x)Same as [[rand-dna]], but takes a `weights` argument to specify the relative probability of each of the four constants to be randomly chosen.
Weights can be provided either as:
* a sequence of 4 non-negative numbers (e.g. `[1 0 2 5]`) in n-u-i-m order
* a map (e.g. `{:i 1 :u 2}`), where missing weights are 0
* a single number in the interval [0.0, 1.0] that represents the ratio of `:u`/`:i`/`m` against `:n` (whose weight is 1 - x)(rand-vpoint dim)(rand-vpoint dim seed)Generates a random vpoint with given dimension dim (= length of the vpoint). A seed (an integer) can be provided as a second argument for reproducability.
Generates a random vpoint with given dimension `dim` (= length of the vpoint). A seed (an integer) can be provided as a second argument for reproducability.
(rand-vpoint-weighted dim const-weights)(rand-vpoint-weighted dim const-weights seed)Same as rand-vpoint, but takes a weights argument to specify the relative probability of each of the four constants to be randomly chosen.
Weights can be provided either as:
[1 0 2 5]) in n-u-i-m order{:i 1 :u 2}), where missing weights are 0:u/:i/m against :n (whose weight is 1 - x)Same as [[rand-vpoint]], but takes a `weights` argument to specify the relative probability of each of the four constants to be randomly chosen.
Weights can be provided either as:
* a sequence of 4 non-negative numbers (e.g. `[1 0 2 5]`) in n-u-i-m order
* a map (e.g. `{:i 1 :u 2}`), where missing weights are 0
* a single number in the interval [0.0, 1.0] that represents the ratio of `:u`/`:i`/`m` against `:n` (whose weight is 1 - x)(reduce-dna dna-seq)(reduce-dna dna-seq terms)Reduces a dna-seq by eliminating redundant/contingent terms.
[terms dna-seq], where terms is a sequence that represents the remaining terms after reductionterms 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)
Reduces a `dna-seq` by eliminating redundant/contingent terms. * returns a tuple `[terms dna-seq]`, where `terms` 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)
Obsolete → please use reduce-dna instead.
Obsolete → please use [[reduce-dna]] instead.
(rel & consts-or-dnas)Relates the values of all given arguments (which must either be all constants or all formDNAs) to each other.
Note: relations with value holes (:_) can only be dominated by the mark (:m) and will otherwise result in value holes.
Relates the values of all given arguments (which must either be all constants or all formDNAs) to each other. Note: relations with value holes (`:_`) can only be dominated by the mark (`:m`) and will otherwise result in value holes.
(reorder-dna 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)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
Obsolete → please use reorder-dna instead.
Obsolete → please use [[reorder-dna]] instead.
“Value hole” – placeholder for an unknown/missing result. Denotes a constant, but like a black box, we cannot know which one.
“Value hole” – placeholder for an unknown/missing result. Denotes a constant, but like a black box, we cannot know which one.
(vdict vpoint->result)(vdict vpoint->result opts)Generates a vdict given a map vpoint->result (result is a constant).
vp->r, the remaining results will be filled with :n or a given default constantsorted? defaults to false since sorting large vspace dimensions can be expensiveGenerates 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
(vdict->vmap vdict)Generates a vmap from a given vdict.
Generates a vmap from a given vdict.
(vmap-dimension vmap)Returns the dimension of a vmap (equivalent to dna-dimension of the corresponding formDNA).
Returns the dimension of a vmap (equivalent to [[dna-dimension]] of the corresponding formDNA).
(vmap-perspectives dna-psps)Given a group of all perspectives from a formDNA, returns these perspectives as vmaps.
Given a group of all perspectives from a formDNA, returns these perspectives as vmaps.
(vspace dim)(vspace sort-code dim)Generates a vspace of dimension dim, optionally with custom sort-code.
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!)
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |