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]#

Bases: ABC, object

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 BasicSolvable object except it is abit more then just an expression.

abstract evaluate(**kwds) Any[source]#

Values for evaluating the object for a desired value.

Note

The parameter format may change for certain objects.

class cake._abc.BasicExpression(*args, **kwds)[source]#

Bases: Like[Iterator[BasicNode]], BasicSolvable

An object which represents a generic expression.

class cake._abc.BasicFunction(*args, **kwds)[source]#

Bases: BasicEvaluator

Represents a mathmatical function

class cake._abc.BasicNode[source]#

Bases: Basic

Represents an object which can be represented as a node in an expression, Objects such as shapes and matrices which cannot form an Expression object 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

abstract solve(**kwds) Any[source]#

Values for solving the object for a desired value.

Note

The parameter format may change for certain objects.

class cake._abc.BasicVariable(*args, **kwds)[source]#

Bases: BasicSolvable, Like[BasicExpression]

Represents a variable

class cake._abc.Like(*args, **kwds)[source]#

Bases: Generic[Self]

Typehint used throughout the cake library, used to symbolise that a class behaves or can be shown as another implementation.

class cake._abc.Maybe(*args, **kwds)[source]#

Bases: Generic[Self]

Typehint used throughout the cake library, used to hint that an object may derive or be included in another category of objects.

Basics#

class cake.basic.Complex(real: N, imag: N = 0, /)[source]#

Bases: Number

Represents a complex number

class cake.basic.Function(parameter: Any, coefficient: Any = 1, power: Any = 1)[source]#

Bases: BasicFunction, BasicNode

Base 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_postprocess: bool#

Whether to automatically post process value

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!

auto_preprocess: bool#

Whether to automatically preprocess value

auto_to_radians: bool#

Convert value to radians before passing through function

coefficient: Any#

Functions coefficient

copy() Function[source]#

Returns a shallow copy of the function

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
property name: str#
parameter: Any#

Internal parameter of function

postprocessor: Callable[[Any], Any]#

postprocessor function

power: Any#

Power function is raised to

prehandler: Callable[[Any], Any]#

prehandler function

preprocessor: Callable[[dict], dict]#

preprocessor function, the value passed is the dictionary of given values, must return a new mapping of values to use instead.

class cake.basic.Integral(value: int)[source]#

Bases: Rational

Represents a integral number

class cake.basic.Number(_Number__value: N, /)[source]#

Bases: BasicNode, Number

Represents a basic number

property check_before_set: Any#
property value: Any#
class cake.basic.Rational(value_or_numerator, denominator=None)[source]#

Bases: Real

Represents a rational number

denominator: Number#
numerator: Number#
class cake.basic.Real(value: N, /)[source]#

Bases: Complex

Represents a real/float

to_rational() Rational[source]#
class cake.basic.Variable(repr: str, coefficient: Any = 1, power: Any = 1)[source]#

Bases: BasicVariable, BasicNode

Represents 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)
coefficient: Any#
classmethod many(*symbols) List[Variable][source]#

Returns a list of Variables from the input given

>>> Variable.many('x', 'y')
[Variable('x'), Variable('y')]
>>> Variable.many(('x', 5), ('y', 1, 2), 'z')
[Variable('x', coefficient=5), Variable('y', coefficient=1, power=2), Variable('z')]
power: Any#
property representation: str#
property set_repr: str#