maths.top{a:float, b:float, c:float}
A relation generator for the Triangle Of Power function. Needs at least two arguments. It handles exponents, logarithms and roots in a symmetrical way.
See Triangle of Power Notation and Logarithms and Triangle of Power (3Blue1Brown on Youtube).
Examples
power, 23
import("maths")
print(maths.top(a:=2.0, b:=3.0))
┌──────┐ │ c │ ├──────┤ │ 8.00 │ └──────┘
root, 3√8
import("maths")
print(maths.top(b:=3.0, c:=8.0))
┌──────┐ │ a │ ├──────┤ │ 2.00 │ └──────┘
Note: this relation generator would return both answers for a square root.
log, log2(8)
import("maths")
print(maths.top(a:=2.0, c:=8.0))
┌──────┐ │ b │ ├──────┤ │ 3.00 │ └──────┘
bulk operation
import("maths")
$P{*, sqw:=maths.top(a:=to_float(WEIGHT), b:=2.0)..c}
| sqw | PNO | PNAME | COLOR | WEIGHT | CITY |
|---|---|---|---|---|---|
| 144 | P1 | Nut | Red | 12 | London |
| 144 | P5 | Cam | Blue | 12 | Paris |
| 196 | P4 | Screw | Red | 14 | London |
| 289 | P2 | Bolt | Green | 17 | Paris |
| 289 | P3 | Screw | Blue | 17 | Rome |
| 361 | P6 | Cog | Red | 19 | London |
Note: we need to convert WEIGHT from an int to a float using to_float, and we assume each WEIGHT has only one result, c, otherwise we get an error because ..c would be undefined.
bulk operation, with composition
import("maths")
$P{*, a:=to_float(WEIGHT), b:=2.0}(maths.top)
| PNO | PNAME | COLOR | WEIGHT | CITY | c |
|---|---|---|---|---|---|
| P1 | Nut | Red | 12 | London | 144 |
| P2 | Bolt | Green | 17 | Paris | 289 |
| P3 | Screw | Blue | 17 | Rome | 289 |
| P4 | Screw | Red | 14 | London | 196 |
| P5 | Cam | Blue | 12 | Paris | 144 |
| P6 | Cog | Red | 19 | London | 361 |
Note: we still need to convert WEIGHT to a float but if there were to be multiple results for c (not possible with this example) then we wouldn't error but instead would get extra tuples.