LinearFunction#

class tqec.utils.LinearFunction(slope=1.0, offset=0.0)[source]#

Bases: object

Represents a linear function.

A linear function is fully described with a slope and an offset.

Methods

__init__([slope, offset])

exact_integer_div(div)

integer_eval(x)

intersection(other)

Compute the intersection between two linear functions.

is_close_to(other[, atol])

is_constant([atol])

is_scalable([atol])

Attributes

offset

slope

Detailed methods

Parameters:
  • slope (float)

  • offset (float)

__init__(slope=1.0, offset=0.0)#
Parameters:
  • slope (float)

  • offset (float)

Return type:

None

exact_integer_div(div)[source]#
Parameters:

div (int)

Return type:

LinearFunction

integer_eval(x)[source]#
Parameters:

x (int)

Return type:

int

intersection(other)[source]#

Compute the intersection between two linear functions.

Parameters:

other (LinearFunction) – the LinearFunction instance to intersect with self.

Returns:

If they intersect, return x such that self(x) = other(x). Otherwise, return None.

Return type:

float | None

is_close_to(other, atol=1e-08)[source]#
Parameters:
Return type:

bool

is_constant(atol=1e-08)[source]#
Parameters:

atol (float)

Return type:

bool

is_scalable(atol=1e-08)[source]#
Parameters:

atol (float)

Return type:

bool