Liking cljdoc? Tell your friends :D

formform.calc

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

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_
raw docstring

--clj/s

Alias to rel.

Alias to [[rel]].
sourceraw docstring

char->constclj/s

(char->const c)
(char->const sort-code c)

Coerces a char to a corresponding constant.

Coerces a `char` to a corresponding `constant`.
sourceraw docstring

chars->dnaclj/s

(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`.
sourceraw docstring

compare-constsclj/s

Comparator for constants using the default nuim-code.

Comparator for constants using the default `nuim-code`.
sourceraw docstring

const->digitclj/s

(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`.
sourceraw docstring

const?clj/s

Checks if the argument is a valid constant.

Checks if the argument is a valid constant.
sourceraw docstring

constsclj/s

Set of all 4 constants.

Set of all 4 constants.
sourceraw docstring

digit->constclj/s

(digit->const n)
(digit->const sort-code n)

Converts a digit to its corresponding constant representation.

Converts a digit to its corresponding constant representation.
sourceraw docstring

digits->dnaclj/s

(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)`.
sourceraw docstring

dna->digitsclj/s

(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.
sourceraw docstring

dna->vdictclj/s

(dna->vdict dna)
(dna->vdict dna opts)

Generates a vdict from a given formDNA (dna).

  • optional sorted? defaults to false since sorting large vspace dimensions can be expensive
Generates a vdict from a given formDNA (`dna`).

* optional `sorted?` defaults to false since sorting large vspace dimensions can be expensive
sourceraw docstring

dna->vmapclj/s

(dna->vmap dna)
source

dna-dimensionclj/s

(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
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
sourceraw docstring

dna-dimension?clj/s

source

dna-getclj/s

(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.
sourceraw docstring

dna-perspectivesclj/s

(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.
sourceraw docstring

dna?clj/s

source

equal-dna?clj/s

(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?]].
sourceraw docstring

equal-partial-dna?clj/s

(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).
sourceraw docstring

equiv-dna?clj/s

(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?]].
sourceraw docstring

equiv-partial-dna?clj/s

(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).
sourceraw docstring

expand-dnaclj/s

(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)
sourceraw docstring

expand-dna-seqclj/s

Obsolete → please use expand-dna instead.

Obsolete → please use [[expand-dna]] instead.
sourceraw docstring

filter-dnaclj/s

(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 :_ in vpoint to indicate a variable selection
Filters 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
sourceraw docstring

invclj/s

(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.
sourceraw docstring

make-compare-constsclj/s

(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).

  • can also compare map-entries by keys of comparable types
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
sourceraw docstring

make-dnaclj/s

(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
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
sourceraw docstring

nmui-codeclj/s

source

nuim-codeclj/s

source

partial-dna?clj/s

source

permute-dnaclj/s

(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.
sourceraw docstring

rand-constclj/s

(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.
sourceraw docstring

rand-const-weightedclj/s

(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:

  • 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)
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)
sourceraw docstring

rand-dnaclj/s

(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.
sourceraw docstring

rand-dna-weightedclj/s

(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:

  • 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)
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)
sourceraw docstring

rand-vpointclj/s

(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.
sourceraw docstring

rand-vpoint-weightedclj/s

(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:

  • 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)
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)
sourceraw docstring

reduce-dnaclj/s

(reduce-dna dna-seq)
(reduce-dna dna-seq terms)

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)

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)
sourceraw docstring

reduce-dna-seqclj/s

Obsolete → please use reduce-dna instead.

Obsolete → please use [[reduce-dna]] instead.
sourceraw docstring

relclj/s

(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.
sourceraw docstring

reorder-dnaclj/s

(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)
  • does NOT change the encoding of the elements, just their ordering
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
sourceraw docstring

reorder-dna-seqclj/s

Obsolete → please use reorder-dna instead.

Obsolete → please use [[reorder-dna]] instead.
sourceraw docstring

sort-code?clj/s

source

val-holeclj/s

“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.
sourceraw docstring

vdictclj/s

(vdict vpoint->result)
(vdict vpoint->result opts)

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
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
sourceraw docstring

vdict->vmapclj/s

(vdict->vmap vdict)

Generates a vmap from a given vdict.

Generates a vmap from a given vdict.
sourceraw docstring

vdict?clj/s

source

vmap-dimensionclj/s

(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).
sourceraw docstring

vmap-perspectivesclj/s

(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.
sourceraw docstring

vmap?clj/s

source

vpoint?clj/s

source

vspaceclj/s

(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!)
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!)
sourceraw docstring

vspace?clj/s

source

|clj/s

Alias to inv.

Alias to [[inv]].
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close