CoCalc Shared FilesRationals.sagews
Author: Erez Nesharim
Views : 82
Description: Plots into jpg all rationals in [0,1]^2 with denominator < 21
def Hyperbola(center,radius):
"""
This function draws an axis aligned hyperbola in the torus R^2/Z^2 around center with radius
"""


counter=0
beta=1/2*(1+sqrt(5))
#H = 20
H = 10
#P = [(k/r,0) for r in srange(1,H+1) for k in srange(r+1)]
P = [(frac((k+beta)/r),0) for r in srange(1,H+1) for k in srange(r+1)]
Q=uniq(P)
len(Q)
W=points(Q, axes=False)
#W=points(Q, size=3, aspect_ratio=1, figsize=(9,9), axes=False)
#W.save('twoDim.png')
# title('All rationals with denominator < 21')
# saveas(f,['reallyAll',num2str(floor(100*i)),num2str(floor(100*j)),'.jpg'

<string>:1: DeprecationWarning: the output of uniq(X) being sorted is deprecated; use sorted(set(X)) instead if you want sorted output See https://trac.sagemath.org/27014 for details.
55
counter=0
H = 5
P = [(k/r, l/r) for r in srange(1,H+1) for l in srange(r+1) for k in srange(r+1)]
Q=uniq(P)
len(Q)
W=points(Q, size=3, aspect_ratio=1, figsize=(9,9), axes=False)
#W.save('twoDim.png')
# title('All rationals with denominator < 21')
# saveas(f,['reallyAll',num2str(floor(100*i)),num2str(floor(100*j)),'.jpg'


69

H=10
P = [(k/r, l/r, m/r) for r in srange(1,H) for l in srange(r+1) for k in srange(r+1) for m in srange(r+1)]
Q=uniq(P)
len(Q)
W1=points(Q, size=3, aspect_ratio=1, axes = False, figsize=(9,9))
W1.save('threeDim.png')

2633 2693

W.show()

l = len(Q)
c = 0.1
for i in range(0,l):
W += circle(Q[i], c/(lcm(Q[i][0].denominator(),Q[i][1].denominator()))^2, rgbcolor=(1,1,0), fill=True)

W.show(xmin=0,xmax=1,ymin=0,ymax=1)

counter=0
H = 5
P = [(k/r, l/r) for r in srange(1,H+1) for l in srange(r+1) for k in srange(r+1)]
Q=uniq(P)
l=len(Q)
W=points(Q, size=3, aspect_ratio=1, figsize=(9,9), axes=False)
t = var('t')
c = 0.02
for i in range(0,l):
x_center = Q[i][0]
y_center = Q[i][1]
Z = Z1+Z2+Z3+Z4
W += Z

W+=points(Q, size=10, aspect_ratio=1, figsize=(9,9), axes=False)


W.show(xmin=-0.2,xmax=1.2,ymin=-0.2,ymax=1.2)


t=var('t')
c=1/4
x_center=1/2
y_center=1/2
#Z = implicit_plot(x^2 + y^2 - 4, (x, -3, 3), (y, -3, 3))
#Z = parametric_plot((cos(t),sin(t)),(t,0,2*pi),fill=True)
Z1 = parametric_plot((t,c/(t-x_center)+y_center),(t,x_center-1,x_center+1),fill='axis',xmin=x_center-1,xmax=x_center+1,ymin=y_center-1,ymax=y_center+1,exclude=[x_center])
Z2 = parametric_plot((t,-c/(t-x_center)+y_center),(t,x_center-1,x_center+1),fill='axis',xmin=x_center-1,xmax=x_center+1,ymin=y_center-1,ymax=y_center+1,exclude=[x_center])
(t,c/(t-x_center)+y_center)
Z3 = polygon([(x_center-1,c+y_center), (x_center-1,-c+y_center), (x_center,y_center)],fill=True,color='gray',alpha=0.5)
Z4 = polygon([(x_center+1,c+y_center), (x_center+1,-c+y_center), (x_center,y_center)],fill=True,color='gray',alpha=0.5)

counter=0
H = 7
P = [(k/r, l/r) for r in srange(1,H+1) for l in srange(r+1) for k in srange(r+1)]
Q=uniq(P)
l=len(Q)
print(l)
W=points(Q, size=3, aspect_ratio=1, figsize=(9,9), axes=False)
t = var('t')
c = 0.025
for i in range(0,l):
x_center = Q[i][0]
y_center = Q[i][1]
Z = Z1+Z2+Z3+Z4
W += Z


157
W.show(xmin=-0.2,xmax=1.2,ymin=-0.2,ymax=1.2)

Q

[(0, 0), (0, 1/7), (0, 1/6), (0, 1/5), (0, 1/4), (0, 2/7), (0, 1/3), (0, 2/5), (0, 3/7), (0, 1/2), (0, 4/7), (0, 3/5), (0, 2/3), (0, 5/7), (0, 3/4), (0, 4/5), (0, 5/6), (0, 6/7), (0, 1), (1/7, 0), (1/7, 1/7), (1/7, 2/7), (1/7, 3/7), (1/7, 4/7), (1/7, 5/7), (1/7, 6/7), (1/7, 1), (1/6, 0), (1/6, 1/6), (1/6, 1/3), (1/6, 1/2), (1/6, 2/3), (1/6, 5/6), (1/6, 1), (1/5, 0), (1/5, 1/5), (1/5, 2/5), (1/5, 3/5), (1/5, 4/5), (1/5, 1), (1/4, 0), (1/4, 1/4), (1/4, 1/2), (1/4, 3/4), (1/4, 1), (2/7, 0), (2/7, 1/7), (2/7, 2/7), (2/7, 3/7), (2/7, 4/7), (2/7, 5/7), (2/7, 6/7), (2/7, 1), (1/3, 0), (1/3, 1/6), (1/3, 1/3), (1/3, 1/2), (1/3, 2/3), (1/3, 5/6), (1/3, 1), (2/5, 0), (2/5, 1/5), (2/5, 2/5), (2/5, 3/5), (2/5, 4/5), (2/5, 1), (3/7, 0), (3/7, 1/7), (3/7, 2/7), (3/7, 3/7), (3/7, 4/7), (3/7, 5/7), (3/7, 6/7), (3/7, 1), (1/2, 0), (1/2, 1/6), (1/2, 1/4), (1/2, 1/3), (1/2, 1/2), (1/2, 2/3), (1/2, 3/4), (1/2, 5/6), (1/2, 1), (4/7, 0), (4/7, 1/7), (4/7, 2/7), (4/7, 3/7), (4/7, 4/7), (4/7, 5/7), (4/7, 6/7), (4/7, 1), (3/5, 0), (3/5, 1/5), (3/5, 2/5), (3/5, 3/5), (3/5, 4/5), (3/5, 1), (2/3, 0), (2/3, 1/6), (2/3, 1/3), (2/3, 1/2), (2/3, 2/3), (2/3, 5/6), (2/3, 1), (5/7, 0), (5/7, 1/7), (5/7, 2/7), (5/7, 3/7), (5/7, 4/7), (5/7, 5/7), (5/7, 6/7), (5/7, 1), (3/4, 0), (3/4, 1/4), (3/4, 1/2), (3/4, 3/4), (3/4, 1), (4/5, 0), (4/5, 1/5), (4/5, 2/5), (4/5, 3/5), (4/5, 4/5), (4/5, 1), (5/6, 0), (5/6, 1/6), (5/6, 1/3), (5/6, 1/2), (5/6, 2/3), (5/6, 5/6), (5/6, 1), (6/7, 0), (6/7, 1/7), (6/7, 2/7), (6/7, 3/7), (6/7, 4/7), (6/7, 5/7), (6/7, 6/7), (6/7, 1), (1, 0), (1, 1/7), (1, 1/6), (1, 1/5), (1, 1/4), (1, 2/7), (1, 1/3), (1, 2/5), (1, 3/7), (1, 1/2), (1, 4/7), (1, 3/5), (1, 2/3), (1, 5/7), (1, 3/4), (1, 4/5), (1, 5/6), (1, 6/7), (1, 1)]