Builtin

maths.top

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.

a b c

See Triangle of Power Notation and Logarithms and Triangle of Power (3Blue1Brown on Youtube).

a b = c a b = c b c = a c b = a a c = b log a c = b

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}
sqwPNOPNAMECOLORWEIGHTCITY
144P1NutRed12London
144P5CamBlue12Paris
196P4ScrewRed14London
289P2BoltGreen17Paris
289P3ScrewBlue17Rome
361P6CogRed19London

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)
PNOPNAMECOLORWEIGHTCITYc
P1NutRed12London144
P2BoltGreen17Paris289
P3ScrewBlue17Rome289
P4ScrewRed14London196
P5CamBlue12Paris144
P6CogRed19London361

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.