Root Functions#

Root#

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

Bases: Function

Generic function for representing n ** 1/x, unlike Sqrt the Root function doesn’t reduce values to its simplest form.

>>> r = Root(3, Variable('x'))
## Same as (x ** (1/3))
>>> r.evaluate(x=27)
3.0
>>> r = Root(Variable('y'), Variable('x'))
## Same as x ** y
>>> r.evaluate(y=1/3, x=27)
3.0
Parameters:
  • base (Any[Like[cake.BasicNode]]) – The base to raise the parameter to, if base < 0 then the value raised is equal to (1/base)

  • parameter (Any[Like[cake.BasicNode]]) – Function parameter

  • coefficient (Any[Like[cake.BasicNode]]) – Function coefficient

  • power (Any[Like[cake.BasicNode]]) – Value the function is raised to

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

evaluate(to_radians: bool = False, use_preprocess: bool = False, use_postprocess: bool = False, use_prehandler: bool = False, **kwds) Any#

Evaluates the function, returning a result.

Parameters:
  • to_radians (bool) – Whether to convert value given to radians, useful for trig applications.

  • use_preprocess (bool) – Whether to use given pre processor, if any.

  • use_postprocess (bool) – Whether to use given post processor, if any.

  • use_prehandler (bool) – Whether to use given pre handler, if any.

  • **kwds (Any[Like[cake.BasicNode]]) – Any values for variables to use.

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.

Sqrt#

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

Bases: Root

Built in sqrt function, which implements reducing into simplest form if possible.

>>> f = Sqrt(Variable('x'))
>>> f.evaluate(x=18)
3*Sqrt(2)
>>> f.evaluate(x=4)
Real(2.0)
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#

Returns a shallow copy of the function

evaluate(to_radians: bool = False, use_preprocess: bool = False, use_postprocess: bool = False, use_prehandler: bool = False, **kwds) Any#

Evaluates the function, returning a result.

Parameters:
  • to_radians (bool) – Whether to convert value given to radians, useful for trig applications.

  • use_preprocess (bool) – Whether to use given pre processor, if any.

  • use_postprocess (bool) – Whether to use given post processor, if any.

  • use_prehandler (bool) – Whether to use given pre handler, if any.

  • **kwds (Any[Like[cake.BasicNode]]) – Any values for variables to use.

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.

true_value(to_radians: bool = False, use_prehandler: bool = False, use_postprocess: bool = False, **kwds) Any[source]#

Reduces the value of the function to its true value if possible

>>> Sqrt(2).true_value()
Real(1.4142135623730951)
>>> Sqrt(2, coefficient=Variable('x')).true_value(x=2)
Real(2.8284271247461903)

Inherits all parameters from Function.evaluate()