Skip to content

Instantly share code, notes, and snippets.

@StefanKarpinski
Created July 24, 2012 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanKarpinski/3170899 to your computer and use it in GitHub Desktop.
Save StefanKarpinski/3170899 to your computer and use it in GitHub Desktop.
julia> quality(x,a::Rational) = log(den(a),1/abs(x-a))
julia> function maxquality(x,n)
Q = -Inf
for k = 1:n
a = rational(x,1/2^k)
if a == x break end
q = quality(x,a)
if isfinite(q) && Q < q
Q = q
end
end
return Q
end
julia> maxquality(pi,10)
3.429288337281781
julia> median(map(x->maxquality(x,10),rand(100000)))
3.189712422680679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment