Python - 121121 120 chars
def p(x,s=2):
while s<abss*s<=abs(x)**.5:yield x%s;s+=1
f=lambda a,b:(all(p(a*a+b*b))if b else f(b,a))if a else(b%4>2)&all(p(b))
p
checks whether abs(x)
is prime by iterating over all numbers from 2 to abs(x)**.5
(which is sqrt(abs(x))
). It does so by yielding x % s
for each s
. all
then checks whether all the yielded values are non-zero and stops generating values once it encounters a divisor of x
. In f
, f(b,a)
replaces the case for b==0
, inspired by @killmous'@killmous' Haskell answer.
-1 char and bugfix from @PeterTaylor