View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
David Hilberg David Hilberg is offline
external usenet poster
 
Posts: 84
Default Eulier Totient Function

Postscript: Some newsreaders may not be showing the exponentiation signs
in the formula. You should have:

ROW(INDIRECT("1:"&$E$4))^0

both times, and not:

ROW(INDIRECT("1:"&$E$4))0

- David

David Hilberg wrote:
Euler Totient Function, a.k.a Euler Phi Function Φ(N):

= $E$4 * PRODUCT(
IF(
($E$4-2=MMULT(--(0<MOD(ROW(INDIRECT("1:"&$E$4))*(0=MOD($E$4,
ROW(INDIRECT("1:"&$E$4)))), TRANSPOSE(ROW(INDIRECT("1:"&$E$4))))),
ROW(INDIRECT("1:"&$E$4))^0)) * ROW(INDIRECT("1:"&$E$4))*(0=MOD($E$4,
ROW(INDIRECT("1:"&$E$4))))
=0,
1,
1-1/(
($E$4-2=MMULT(--(0<MOD(ROW(INDIRECT("1:"&$E$4))*(0=MOD($E$4,
ROW(INDIRECT("1:"&$E$4)))), TRANSPOSE(ROW(INDIRECT("1:"&$E$4))))),
ROW(INDIRECT("1:"&$E$4))^0)) * ROW(INDIRECT("1:"&$E$4))*(0=MOD($E$4,
ROW(INDIRECT("1:"&$E$4))))
)))

Array-enter the above with Ctrl+Shift+Enter.

I would have replied sooner, but the implementation proved oilier than I
thought. It would actually have been easier to create a
user-defined-function with Visual Basic that would be faster and would
handle larger numbers.

Notes:
- Euler's totient function counts the number of coprimes to N that are
less than or equal to N.
- The formula used is N times the product of all 1-1/P, where the P's
are the distinct prime divisors of N.
- The number N in cell E4 mustn't be too large. N=1000 -- computing a
million-element array. This function may calculate slooowly.
- I broke up the lines to show that the comparison in the IF's first
argument uses the the same expression as the denominator in the last
argument. The expression is a list of primes interspersed with zeros.

:)

David


Bernard Liengme wrote:

The OP misspelt Euler, so it is Euler's totient function
See http://en.wikipedia.org/wiki/Euler's_totient_function
best wishes