Perfect powers in J
a guest Mar 14th, 2012 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- NB. Perfect powers
- NB. Integer logs and roots; work for extended precision.
- ilog=: <.@^.
- iroot=: <.@%:
- NB. 'x isEvenRoot y' is true if the xth root of y is an integer.
- isEvenRoot=: ] = iroot ^ [
- NB. 'primesTo y' returns the primes up to the first prime >= y.
- primesTo=: 3 : 'p: i.>: _1 p: y'
- NB. Return a list of the prime powers that "factor" y.
- perfectPowersOf=: 3 : '(primesTo 2 ilog y) (isEvenRoot # [) y'
- NB. Just check if that list is longer than 0.
- isPerfectPower=: 3 : '0<#perfectPowersOf y'
RAW Paste Data