E.1 Python Code:

import math

K = 500
squarecount = 0
squaretot = 0
butterflycount = 0
butterflytot = 0


for x in range(-K,K):
    for y in range(-K,K): %filtration I, term K
        squaretot +=1
        if math.gcd(x,y)==1:
            if math.gcd(x-1,y)==1:
                squarecount += 1
for y in range(-K,K):
    Y = abs(y)
    for x in range(-Y,Y):
    %filtration B, taking only a triangle as with the density is the same
        butterflytot += 1
        if math.gcd(x,y)==1:
            if math.gcd(x-1,y)==1:
                butterflycount += 1
squaredens = squarecount/squaretot
butterflydens = butterflycount/butterflytot
%take densities as each filtration has a different numbeer of points
ratio = squaredens/butterflydens
print(ratio)