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 }\$\{(a,b) \in \mathbb{R}^2 : a\pm b=0 \text{ or } a\pm b = -1\}\$. That's probably measure zero?
sum = a+b
nb = -b
diff = a+nb
rfc = 1/(1/(1/sum + -1/(sum+1)) + -1/(1/diff + -1/(diff+1)) + nb + nb) # rfc = 1/4c
c = 1/(rfc + rfc + rfc + rfc)
# sum is 2: =+
# nb is 2: =-
# diff is 2: =+
# rfc is 18: =///+-/++-//+-/+++
# c is 5: =/+++
# total = 29 operations
The structure of rfc
(Reciprocal-Four-C) is more evident if we define a macro:
s(x) = 1/(1/x + -1/(x+1)) # //+-/+ (no = in count, macros don't exist)
rfc = 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
rfc
, 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
rfc
is1/(4*a*b)
. - Finally,
c
is the reciprocal of 4 timesrfc
, so1/(4/(4*a*b))
becomesa*b
.