Generate CBD Models from Equations¶
Transforms equations/textual denotations to CBD models.
- class pyCBD.converters.eq2CBD.eq2CBD[source]¶
Bases:
objectConverts equations (textual denotation) into corresponding CBD models.
After instantiating this class, the
parse()method may be called to obtain the CBD model(s).All equations must be in the form of
<output> = <expression>, where<output>identifies the name of an output of the resulting CBD and<expression>defines the corresponding logic. To prevent the creation of an output,:=may be used instead of=. Multiple equations can be listed, separated by newlines. Variables used in the expressions will be linked to one another if needs be. When a variable is used without any descriptive reference, it will be used as an input. For instance, the texty = 6 * xwill be transformed into a CBD with a single outputyand a single inputx.Variable names must match the regex
[a-zA-Z_][a-zA-Z0-9_]*and must not be any allowed function name (see below). The variabletimeis reserved and will be replaced by aTimeBlock.The following operations are allowed and transformed w.r.t. the standard library’s building blocks (
pyCBD.lib.std). The order of operations applied is: parentheses, function calls, exponents, multiplication/division and addition/subtraction.(A): Places sub-equationAin parentheses, giving precedence on the computation of that equation.-A: Negation of a variable or value. In the case of a constant value, no additional negator will be added to the CBD, unless explicitly requested by placing the value within parentheses: i.e.-(4).1/A: Inversion of a variable or value. In the case of a constant value, no additional inverter will be added to the CBD, unless explicitly requested by placing the value within parentheses: i.e.1/(4).~Aor!Aornot A: Adds aNotBlockbefore sub-equationA.A + B + C - D: Sum of two (or more) sub-equations. Whenever a subtraction is encountered, it will be replaced by an addition of the negator and the other terms. In the case of a constant value, the same logic as mentioned above is applied.A * B * C / D: Multiplication of two (or more) sub-equations. Whenever a division is encountered, it will be replaced by the multiplication of the inverted value and other factors. In the case of a constant value, the same logic as mentioned above is applied.A^B: Raises sub-equationAto the power of sub-equationB.A % BorA mod B: Modulo-divides sub-equationAby sub-equationB.A == B: Tests equality between sub-equationsAandB.A <= B: Tests inequality between sub-equationsAandB. TheLessThanOrEqualsBlockwill be used here.A < B: Tests inequality between sub-equationsAandB. TheLessThanBlockwill be used here.A >= B: Tests inequality between sub-equationsAandB. Behind the scenes, this code will be handled as if it wereB <= A.A > B: Tests inequality between sub-equationsAandB. Behind the scenes, this code will be handled as if it wereB < A.A or BorA || B: Merges bothAandBin anOrBlock.A and BorA && B: Merges bothAandBin anAndBlock.f(A): executes functionfon sub-equationA. Besides all single-argument functions from themathmodule (see thepyCBD.lib.std.GenericBlock), the allowed functions (case-insensitive) are:
function
argument/input port count
CBD block
int1
abs1
root2
sqrt1
pyCBD.lib.std.RootBlockwith second input fixed to 2clamporsat3
mux3 (last argument is the
selectinput)d2 (second argument is the
IC)der3 (second argument is the
IC, third is thedelta_t)i3 (second argument is the
IC, third is thedelta_t)