29 operations
Does not work for the set { (a,b) ∈ R2 | a+b = 0 or a+b = -1 or a-b = 0 or a-b = -1 }. That's probably measure zero?
sum = a+b
nb = -b
diff = a+nb
foc = 1/(1/(1/sum + -1/(sum+1)) + -1/(1/diff + -1/(diff+1)) + nb + nb) # foc = 1/4c
c = 1/(foc + foc + foc + foc)
# sum is 2: =+
# nb is 2: =-
# diff is 2: =+
# foc is 18: =///+-/++-//+-/+++
# c is 5: =/+++
# total = 29 operations
The structure of foc
is more evident if we define a macro:
s(x) = 1/(1/x + -1/(x+1)) # //+-/+ (no = in count, macros don't exist)
foc = 1/(s(sum) + - s(diff) + nb + nb) # =/s+-s++ (6+2*s = 18)
Let's do the math:
s(x)
, mathematically, is1/(1/x - 1/(x+1))
which is after a bit of algebra isx*(x+1)
orx*x + x
.- When you sub everything into
foc
, it's really1/((a+b)*(a+b) + a+b - (a-b)*(a-b) -a+b + (-b) + (-b))
which is just1/((a+b)^2 - (a-b)^2)
. - After difference of squares, or just plain expansion, you get that
foc
is1/(4*a*b)
. - Finally,
c
is the reciprocal of 4 timesfoc
, so1/(4/(4*a*b))
becomesa*b
.
I don't know why I called it foc
. At first I thought it was 4/c (Four-Over-C) but that was just my head being muddled by reciprocal logic. Whoops.