Top-Level Math Module¶
Module: piethorn.math
Overview¶
The top-level math module exposes boolean gate helpers and a skewed random number generator.
LogicGates¶
- class LogicGates(reverse=False)¶
Evaluate boolean and boolean-like values with standard gate operations.
Example¶
from piethorn.math import LogicGates gates = LogicGates() gates.and_gate([True, 1, True]) gates.or_gate(False, 1) gates.not_gate([True, False, 1])
Methods¶
and_gate(*boolean)or_gate(*boolean)not_gate(*boolean)nand_gate(*boolean)nor_gate(*boolean)xor_gate(*boolean)xnor_gate(*boolean)
skew¶
- skew(skew_at=0.6, weight=0.9, minimum=0, maximum=100, is_int=False)¶
Generate a bounded random value biased toward
skew_at.from piethorn.math import skew skew(skew_at=0.4, weight=0.2, minimum=10, maximum=20, is_int=True)
Autodoc¶
- class piethorn.math.LogicGates(reverse=False)¶
Evaluate basic boolean gates with configurable truthy polarity.
- and_gate(*boolean)¶
Return the logical AND of the provided boolean-like values.
- nand_gate(*boolean)¶
Return the logical NAND of the provided boolean-like values.
- nor_gate(*boolean)¶
Return the logical NOR of the provided boolean-like values.
- not_gate(*boolean)¶
Return the logical NOT of one value or each value in a collection.
- or_gate(*boolean)¶
Return the logical OR of the provided boolean-like values.
- xnor_gate(*boolean)¶
Return the logical XNOR of the provided boolean-like values.
- xor_gate(*boolean)¶
Return the logical XOR of the provided boolean-like values.
- piethorn.math.skew(skew_at=0.6, weight=0.9, minimum=0, maximum=100, is_int=False)¶
Generates a random percentage skewed towards skew_at. The generation has a skew of two points, the first is the declared skew_at, the second is (skew_at/2) + (minimum/100) this second skew is called the mix_skew.
The default skew is a skew at 60% with a weight of 90% for a range of 0-100% with a return of a float.
- Parameters:
skew_at – The point around which values are skewed (0-1).
weight – The probability that values fall below skew_at (0-1). If this value is zero, then no skew. If this value is one then it will be heavily skewed, but values beyond skew_at are still possible.
minimum – The lowest percent that can be given. (0-100)
maximum – The largest percent that can be given. (0-100)
is_int – Whether to return the random percent as an integer.
- Returns:
A skewed random percentage within [minimum, maximum].