Skip to main content
3 of 5
explanations yay
algorithmshark
  • 8.8k
  • 2
  • 33
  • 55

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, is 1/(1/x - 1/(x+1)) which is after a bit of algebra is x*(x+1) or x*x + x.
  • When you sub everything into foc, it's really 1/((a+b)*(a+b) + a+b - (a-b)*(a-b) -a+b + (-b) + (-b)) which is just 1/((a+b)^2 - (a-b)^2).
  • After difference of squares, or just plain expansion, you get that foc is 1/(4*a*b).
  • Finally, c is the reciprocal of 4 times foc, so 1/(4/(4*a*b)) becomes a*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.

algorithmshark
  • 8.8k
  • 2
  • 33
  • 55