Basic#
Basic classes are the bases of all classes and hold the definitions which make up other classes,
this helps maintain constistancy within the cake library.
We don’t recomend you use these classes when making your own but instead implement them from the Core region.
ABC’s#
ABCs in the cake library contain the derivatives of all the standard cake classes.
- class cake._abc.Basic[source]#
-
Represents a basic object which all objects in the cake library derive from, Using this class we can check if any object belongs to the cake library
- class cake._abc.BasicEvaluator(*args, **kwds)[source]#
Bases:
Basic,Maybe[BasicNode]An object which can be evaluated, like a
BasicSolvableobject except it is abit more then just an expression.
- class cake._abc.BasicExpression(*args, **kwds)[source]#
Bases:
Like[Iterator[BasicNode]],BasicSolvableAn object which represents a generic expression.
- class cake._abc.BasicFunction(*args, **kwds)[source]#
Bases:
BasicEvaluatorRepresents a mathmatical function
- class cake._abc.BasicNode[source]#
Bases:
BasicRepresents an object which can be represented as a node in an expression, Objects such as shapes and matrices which cannot form an
Expressionobject don’t inherit this object.>>> issubclass(Variable, BasicNode) True >>> issubclass(Number, BasicNode) True >>> issubclass(Function, BasicNode) True
- class cake._abc.BasicSolvable(*args, **kwds)[source]#
Bases:
Basic,Maybe[BasicNode]An object which can be solved via the function
solve
- class cake._abc.BasicVariable(*args, **kwds)[source]#
Bases:
BasicSolvable,Like[BasicExpression]Represents a variable
Basics#
- class cake.basic.Complex(real: N, imag: N = 0, /)[source]#
Bases:
NumberRepresents a complex number
- class cake.basic.Function(parameter: Any, coefficient: Any = 1, power: Any = 1)[source]#
Bases:
BasicFunction,BasicNodeBase class for creating functions, behaves similarly to an Variable in the sense the value of the function is not calcuated until called. This feature allows it to intake Variables as values.
- auto_prehandle: bool#
Whether to automatically pre-handle a value, this is right before the value is passed through the handler
Warning
this is after the value is converted to radians!
- abstract evaluate(to_radians: bool = False, use_preprocess: bool = False, use_postprocess: bool = False, use_prehandler: bool = False, **kwds) Any[source]#
Evaluates the function returning either an updated version of the parameter or a value.
>>> F = Function(Expression(Add(3, 'x'))) >>> F Function(3 + x) >>> F.evaluate(x=3) Function(3 + 3) ## Result is returned here >>> F.evaluate() Function(3 + x) ## Function is returned as x is still Variable
- class cake.basic.Rational(value_or_numerator, denominator=None)[source]#
Bases:
RealRepresents a rational number
- class cake.basic.Variable(repr: str, coefficient: Any = 1, power: Any = 1)[source]#
Bases:
BasicVariable,BasicNodeRepresents an Variable value, this can be used inplace of any integer throughout the cake library.
Note
Where a specific type is required, having a default value is preferable
Solving for when ‘a’ is known
>>> a = Variable('a') >>> expr = (a + 5) / 2 >>> expr.solve() == expr True >>> expr.solve(a=9) Real(7.0)
Solving for ‘a’ when result is known
>>> expr Expression((a + 5) / 2) >>> equation = expr.to_equation(right=10) # So we now have an equation where (a + 5) / 2 = 10 >>> equation *= 2 # Equivalent to multiplying both sides by 2 # a + 5 = 20 >>> equation -= 5 # a = 15 >>> equation.result(as_unknown=True) Variable('a', default_value=15)