Struct mostinefficientsha::term::Term [] [src]

pub struct Term {
    // some fields omitted
}

A Term is either constant, symbolic or the result of a logical operation of other terms.

A Term can be evaluated to a f64 fuzzy bit that is between 0 and 1.

During later use, many Terms will span some large trees of logic operations. The root term of each tree should then be lazily evaluated if needed. The f64 evaluation result depends on the type of operation the tree consists of and the leaves, that are either symbolic (0.0 to 1.0) or constant (0.0 or 1.0).

The implementation uses reference counted terms RTerm = Rc<Term> to prevent copying large parts of trees and allow caching during evaluations. This makes the Term network structure not a tree, but an acyclic directed graph with multiple roots, I guess.

During those lazy evaluations, every Term caches its value. This caching is not done for successive calls to the root term. It is instead important since some sub trees may be used by thousands of other terms. In other words, the flattened out structure may be very large. (Gigabytes if the logic structure of SHA256 is printed into an ascii file.)

Use reset() to clear the cache.

Methods

impl Term
[src]

Create a Symbol type term with unassigned value. Assign value with set().

Shortcut for creating a true constant.

Shortcut for creating a false constant.

Create a Constant type term with given value.

Checks if this term is of type constant.

Returns the constant value of this Term. Panics if type is not Constant.

Creates a new RTerm that lazily evaluates to the xor operation a ^ b of the two input terms.

Creates a new RTerm that lazily evaluates to the or operation a | b of the two input terms.

Creates a new RTerm that lazily evaluates to the and operation a & b of the two input terms.

Creates a new RTerm that lazily evaluates to the not operation !a of the input term.

Shortcut for ( ab , a&b ). The first term is the sum bit of a logic half adder, the second term is the carry bit.

Shortcut for ( abc , (a&b)c&(ab) ). The first term is the sum bit of a logic full adder, the second term is the carry bit.

Sets the value of a Symbol type term. Panics if the type is not Symbol.

Reset the cached value of this term and all terms this term depends on. Does not reset anything if this term has already been reset.

Evaluate this term by recursively evaluating all sub terms.

Cache the evaluated value.

Xor: result = abs(a-b)

And: result = a*b

Or: result = min[ sqrt(a)+sqrt(b) , 1 ]

Not: result = 1-a

Stack size needed when evaluating this Term recursively. The stack_cnt is the current stack size. (Use 0 at the root term). It also returns the maximum logic depth. This value is created by utilizing the eval cache. So you must call reset() before and after using this function.

Returns: (max_logic_depth, max_stacksize)

Returns the number of RTerms that contribute to the evaluation of this RTerm. This function uses the eval cache, so you must call reset() before and after using this function. To prevent double counting, this function returns the actual number on the first call and zero on all following calls.

Returns: number_of_uncounted_rterms_including_this_rterm

Returns the number of Terms that contribute to the evaluation if the tree would have been flattened.

Trait Implementations

impl Clone for Term
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Term
[src]

Formats the value using the given formatter.