Math
oqd_core.interface.math
¶
SupportedFuncNames = Literal['abs', 'sin', 'cos', 'tan', 'exp', 'log', 'sinh', 'cosh', 'tanh', 'atan', 'acos', 'asin', 'atanh', 'asinh', 'acosh', 'heaviside', 'conj', 'real', 'imag', 'atan2']
module-attribute
¶
List of supported functions
MathExprSubtypes = Annotated[Union[Annotated[MathNum, Tag('MathNum')], Annotated[MathVar, Tag('MathVar')], Annotated[MathImag, Tag('MathImag')], Annotated[MathFunc, Tag('MathFunc')], Annotated[MathAdd, Tag('MathAdd')], Annotated[MathSub, Tag('MathSub')], Annotated[MathMul, Tag('MathMul')], Annotated[MathDiv, Tag('MathDiv')], Annotated[MathPow, Tag('MathPow')]], Discriminator(lambda v: v['class_'] if isinstance(v, dict) else getattr(v, 'class_'))]
module-attribute
¶
Alias for the union of concrete MathExpr subtypes
CastMathExpr = Annotated[MathExprSubtypes, BeforeValidator(MathExpr.cast)]
module-attribute
¶
Annotated type that cast typical numeric python types to MathExpr
ConstantMathExpr = Annotated[CastMathExpr, AfterValidator(_isconstant)]
module-attribute
¶
Annotated type for constant MathExpr
MathExpr
¶
Bases: TypeReflectBaseModel
Class representing the abstract syntax tree (AST) for a mathematical expression
Source code in oqd-core/src/oqd_core/interface/math.py
MathTerminal
¶
MathVar
¶
Bases: MathTerminal
Class representing a variable in a MathExpr
Examples:
Source code in oqd-core/src/oqd_core/interface/math.py
MathNum
¶
MathImag
¶
Bases: MathTerminal
Class representing the imaginary unit in a MathExpr abstract syntax tree (AST)
Source code in oqd-core/src/oqd_core/interface/math.py
MathFunc
¶
Bases: MathExpr
Class representing a named function applied to a MathExpr abstract syntax tree (AST)
Attributes:
| Name | Type | Description |
|---|---|---|
func |
SupportedFuncNames
|
Named function to apply |
expr |
Union[CastMathExpr, List[CastMathExpr]]
|
Arguments of the named function |
Source code in oqd-core/src/oqd_core/interface/math.py
MathBinaryOp
¶
MathAdd
¶
Bases: MathBinaryOp
Class representing the addition of MathExprs
Attributes:
| Name | Type | Description |
|---|---|---|
expr1 |
MathExpr
|
Left hand side |
expr2 |
MathExpr
|
Right hand side |
Source code in oqd-core/src/oqd_core/interface/math.py
MathSub
¶
Bases: MathBinaryOp
Class representing the subtraction of MathExprs
Attributes:
| Name | Type | Description |
|---|---|---|
expr1 |
MathExpr
|
Left hand side |
expr2 |
MathExpr
|
Right hand side |
Source code in oqd-core/src/oqd_core/interface/math.py
MathMul
¶
Bases: MathBinaryOp
Class representing the multiplication of MathExprs
Attributes:
| Name | Type | Description |
|---|---|---|
expr1 |
MathExpr
|
Left hand side |
expr2 |
MathExpr
|
Right hand side |
Source code in oqd-core/src/oqd_core/interface/math.py
MathDiv
¶
Bases: MathBinaryOp
Class representing the division of MathExprs
Attributes:
| Name | Type | Description |
|---|---|---|
expr1 |
MathExpr
|
Left hand side |
expr2 |
MathExpr
|
Right hand side |
Source code in oqd-core/src/oqd_core/interface/math.py
MathPow
¶
Bases: MathBinaryOp
Class representing the exponentiation of MathExprs
Attributes:
| Name | Type | Description |
|---|---|---|
expr1 |
MathExpr
|
Left hand side |
expr2 |
MathExpr
|
Right hand side |