# Revision history [back]

The following alternative code is running without errors. The Möbius transform is slightly changed, and the $\sqrt 2=|s|$ was added. (I think it is also wanted.)

K.<s> = QuadraticField( -2 )
OK    = K.ring_of_integers()
IP    = ProjectiveSpace( 1, K )

points = ( -1, 0, 1 )
def lift_point( x ):
return vector( [ x, 1 ] )

def FLT( M, z ):
"""takes the fractional linear transformation/Mobius transformation of a z in CC"""
Mz = IP( ( M * lift_point(z) ).list() )
if Mz == IP( (1,0) ):
return 'infinity'
return Mz

def components( z ):
return ( z, z*sqrt(2) )

var('a','b','r','x','y');

func_cir = (x-a)**2 + (y-b)**2 == r**2

def get_circles( number_of_circles=10, show=False ):
j = 0
circles  = []
while j < number_of_circles:

M = random_matrix( OK, 2, algorithm = 'unimodular' )
A, B, C = [ components( FLT( M, z ) ) for z in points ]

print ( "\n%s\nM is %s\nA,B,C are %s, %s, %s ."
% ( 30*'=', M.list(), A, B, C ) )
colinearityMatrix = matrix( 3,3, [ A, A, 1 ,
B, B, 1 ,
C, C, 1 ] )
colinearity = bool( colinearityMatrix.det() == 0 )
# print ( "Are A,B,C colinear? %s" % colinearity )
if colinearity:
print "!!! COLINEAR... IGNORED !!!\n"

elif 'infinity' in [ A, B, C ]:
print "!!! INFINITY... IGNORED !!!\n"

else:
j += 1

eq1 = func_cir.subs( x==A ).subs( y==A )
eq2 = func_cir.subs( x==B ).subs( y==B )
eq3 = func_cir.subs( x==C ).subs( y==C )

sol = solve( [ eq1, eq2, eq3 ], a,b,r )

print "%s\n[%s]\nSolutions:\n%s" % ( 30*'-', j, sol )
c = circle( ( sol.rhs(),
sol.rhs() ),
abs( sol.rhs() ) )
circles.append( c )

if show:
plot_object = plot( [] )
for c in circles:
plot_object += plot( c )
plot_object.show()
return circles


Now the following calls did the job for me without errors:

get_circles( 1000 );


There is a verbose, aggressive print show in between, but the message is, there are no errors.

Let us also generate three circles, and show them:

get_circles( 3, show=True  );


The following alternative code is running without errors. The Möbius transform is slightly changed, and the $\sqrt 2=|s|$ was added. (I think it is also wanted.)

K.<s> = QuadraticField( -2 )
OK    = K.ring_of_integers()
IP    = ProjectiveSpace( 1, K )

points = ( -1, 0, 1 )
def lift_point( x ):
return vector( [ x, 1 ] )

def FLT( M, z ):
"""takes the fractional linear transformation/Mobius transformation of a z in CC"""
Mz = IP( ( M * lift_point(z) ).list() )
if Mz == IP( (1,0) ):
return 'infinity'
return Mz

def components( z ):
if z == 'infinity':
return None
return ( z, z*sqrt(2) )

var('a','b','r','x','y');

func_cir = (x-a)**2 + (y-b)**2 == r**2

def get_circles( number_of_circles=10, show=False ):
j = 0
circles  = []
while j < number_of_circles:

M = random_matrix( OK, 2, algorithm = 'unimodular' )
A, B, C = [ components( FLT( M, z ) ) for z in points ]

print ( "\n%s\nM is %s\nA,B,C are %s, %s, %s ."
% ( 30*'=', M.list(), A, B, C ) )
noneOccured = bool( None in ( A, B, C ) )
colinearityMatrix = matrix( 3,3, [ A, A, 1 ,
B, B, 1 ,
C, C, 1 ] )
colinearity = ) if not noneOccured else None

if noneOccured:
print "!!! INFINITY... IGNORED !!!\n"

elif bool( colinearityMatrix.det() == 0 )
):
# print ( "Are A,B,C colinear? %s" % colinearity )
if colinearity:
print "!!! COLINEAR... IGNORED !!!\n"

elif 'infinity' in [ A, B, C ]:
print "!!! INFINITY... IGNORED !!!\n"

else:
j += 1

eq1 = func_cir.subs( x==A ).subs( y==A )
eq2 = func_cir.subs( x==B ).subs( y==B )
eq3 = func_cir.subs( x==C ).subs( y==C )

sol = solve( [ eq1, eq2, eq3 ], a,b,r )

print "%s\n[%s]\nSolutions:\n%s" % ( 30*'-', j, sol )
c = circle( ( sol.rhs(),
sol.rhs() ),
abs( sol.rhs() ) )
circles.append( c )

if show:
plot_object = plot( [] )
for c in circles:
plot_object += plot( c )
plot_object.show()
return circles


Now the following calls did the job for me without errors:

get_circles( 1000 );


There is a verbose, aggressive print show in between, but the message is, there are no errors.

Let us also generate three circles, and show them:

get_circles( 3, show=True  );