Haskell - 77/108107 Chars
usage:
in both the solutions, typing a%b will return whether a+bi is a gaussian prime.
the lowest i managed, but no creativity or performance (77 chars)
p n=all(\x->rem n x>0)[2..n-1]
a%0=rem a 4==3&&p(abs a)
0%a=a%0
a%b=p$a^2+b^2
this solution just powers through all numbers below n to check if it's prime.
ungolfed version:
isprime = all (\x -> rem n x != 0) [2..n-1] -- none of the numbers between 2 and n-1 divide n.
isGaussianPrime a 0 = rem a 4==3 && isprime (abs a)
isGaussianPrime 0 a = isGaussianPrime a 0 -- the definition is symmetric
isGaussianPrime a b = isprime (a^2 + b^2)
the next solution has an extra feature - memoization.
once you checked if some integer n is prime, you won't need to recalculate the "primeness" of all numbers smaller than or equal to n, as it will be stored in the computer.
(107 chars. the comments are for clarity)
s(p:x)=p:s[n|n<-x,rem n p>0] --the sieve function
l=s[2..] --infinite list of primes
p n=n==filter(>=n)l!!0 --check whether n is in the list of primes
a%0=rem a 4==3&&p(abs a)
0%a=a%0
a%b=p$a*a+b*b
ungolfed version:
primes = sieve [2..] where
sieve (p:xs) = p:filter (\n -> rem n p /= 0) xs
isprime n = n == head (filter (>=n) primes) -- checks if the first prime >= n is equal to n. if it is, n is prime.
isGaussianPrime a 0 = rem a 4==3 && isprime (abs a)
isGaussianPrime 0 a = isGaussianPrime a 0 -- the definition is symmetric
isGaussianPrime a b = isprime (a^2 + b^2)
this uses the sieve of Eratosthenes to compute an infinite list of all primes (called l for list in the code). (infinite lists are a well known trick of haskell).
how is it possible to have an infinite list?
at the start of the program, the list is unevaluated, and instead of storing the lists elements, the computer stores the way to compute them. but as the program accesses the list it partially evaluates itself up to the request. so, if the program were to request the fourth item in the list, the computer would compute all primes up to the forth that aren't already evaluated, store them, and the rest would remain unevaluated, stored as the way to compute them once needed.
note that all of this is given freely by the lazy nature of the Haskell language, none of that is apparent from the code itself.
both versions of the program are overloaded, so they can handle arbitrarily-sized data.
factor
in Bash,mf
andmF
in CJam, ...) \$\endgroup\$