def _arc(p, q, s, **kwds):
    #rewrite this to use polar_plot and get points to do filled triangles
    from sage.misc.functional import det
    from sage.plot.line import line
    from sage.misc.functional import norm
    from sage.symbolic.all import pi
    from sage.plot.arc import arc

    p, q, s = map(lambda x: vector(x), [p, q, s])

    # to avoid running into division by 0 we set to be colinear vectors that are
    # almost colinear
    if abs(det(matrix([p - s, q - s]))) < 0.01:
        return line((p, q), **kwds)

    (cx, cy) = var('cx', 'cy')
    equations = [
        2 * cx * (s[0] - p[0]) + 2 * cy * (s[1] - p[1]) == s[0]**2 + s[1]**2 -
        p[0]**2 - p[1]**2, 2 * cx * (s[0] - q[0]) + 2 * cy *
        (s[1] - q[1]) == s[0]**2 + s[1]**2 - q[0]**2 - q[1]**2
    ]
    c = vector([
        solve(equations, (cx, cy), solution_dict=True)[0][i] for i in [cx, cy]
    ])

    r = norm(p - c)

    a_p, a_q, a_s = map(lambda x: atan2(x[1], x[0]), [p - c, q - c, s - c])
    a_p, a_q = sorted([a_p, a_q])
    if a_s < a_p or a_s > a_q:
        return arc(c, r, angle=a_q, sector=(0, 2 * pi - a_q + a_p), **kwds)
    return arc(c, r, angle=a_p, sector=(0, a_q - a_p), **kwds)
def _arc(p,q,s,**kwds):
    #rewrite this to use polar_plot and get points to do filled triangles
    from sage.misc.functional import det
    from sage.plot.line import line
    from sage.misc.functional import norm
    from sage.symbolic.all import pi
    from sage.plot.arc import arc
     
    p,q,s = map( lambda x: vector(x), [p,q,s])
     
    # to avoid running into division by 0 we set to be colinear vectors that are
    # almost colinear
    if abs(det(matrix([p-s,q-s])))<0.01:
        return line((p,q),**kwds)
     
    (cx,cy)=var('cx','cy')
    equations=[
            2*cx*(s[0]-p[0])+2*cy*(s[1]-p[1]) == s[0]**2+s[1]**2-p[0]**2-p[1]**2,
            2*cx*(s[0]-q[0])+2*cy*(s[1]-q[1]) == s[0]**2+s[1]**2-q[0]**2-q[1]**2
            ]
    c = vector( [solve( equations, (cx,cy), solution_dict=True )[0][i] for i in [cx,cy]] )
     
    r = norm(p-c)
     
    a_p,a_q,a_s = map( _to_angle, [p-c,q-c,s-c])
    angles = [a_p,a_q,a_s]
    angles.sort()
     
    if a_s == angles[0]:
        return arc( c, r, angle=angles[2], sector=(0,2*pi-angles[2]+angles[1]), **kwds)
    if a_s == angles[1]:
        return arc( c, r, angle=angles[0], sector=(0,angles[2]-angles[0]), **kwds)
    if a_s == angles[2]:
        return arc( c, r, angle=angles[1], sector=(0,2*pi-angles[1]+angles[0]), **kwds)
示例#3
0
def dcoeff(l,m,N):	
    """Returns the 'D' coefficient for partitions l, m having exactly N parts. See 
	   \cite{Fulton:Intersection_Theory}"""
    # make padded copies of l, m
    l1 = copy(l)
    m1 = copy(m)
    l1.extend([0]*(N-len(l)))
    m1.extend([0]*(N-len(m)))
    # for the defining matrix
    M = Matrix( [ [ binomial(l1[i]+N-(i+1), m1[j]+N-(j+1)) for j in range(N) ] for i in range(N) ])
    return det(M)
示例#4
0
def frieze_dict_quid(quiddity_row=(2,1,4,2,3),leftstart = 0,width = 5,friezerow = 4, flag_rectangle=True):
    """
    def frieze_dict_quid(quiddity_row=(2,1,4,2,3),leftstart = 0,width = 5,friezerow = 4,   flag_rectangle=True)
    quiddity_row - give at least one complete period of the quiddity row of your frieze. The program assumes this periodicity. Give this as a list or a tuple.
    leftstart - Assuming the first entry of the inputted quiddity row exists at index (0,2), give i such that the leftmost quiddity row entry is (i,i+2).
    width - desired width of each row of the frieze when passing to the print feature
    friezerow - The index of the last row we want in the frieze.

    We begin indexing the rows of our frieze pattern at the row of all 0's, so
    the row of 0s is at "frieze row" = 0,
    the row of 1s is at "frieze row" = 1
    and the quiddity row is at "frieze row"=2
    
    WARNING - inputting 0's or a mix of positive and negative integers may result in a computation that involves dividing by 0.
    
    Return a dictionary of frieze patterns indexed by (i,j)
    following the convention of Gunawan-Musiker-Volgel: Cluster Algebraic Interpretations of Infinite Friezes
    
    To view as matrix, as in Bessenrodt-Holm-Jorgensen, use matrix(frieze_dict_quid())

    """
    n=len(quiddity_row)
    if leftstart < 0:
    	leftstart = Integer(mod(leftstart,n))    
    m=dict()
    matrixwidth = friezerow + width+1
  
   #Check whether quiddity row could produce finite frieze pattern, using check as in Morier-Genoud's paper https://arxiv.org/abs/1503.05049 although originally in Coxeter's original frieze pattern paper.
   #We make continuants in terms of quiddity row entries. Given a quiddity sequence of length n, These will check whether rows n-1 and n are boundary rows. 
   #Of course, as in the case of 3,1,3,1,3,1, one could just input quiddity_row = (3,1), which will give the right frieze pattern but will fail this test. 
    checkdict1 = dict()
    checkdict2 = dict()
    checkdict3 = dict()
    for i in range(n-1):
        checkdict1[(i,i)] = quiddity_row[i]
        checkdict2[(i,i)] = quiddity_row[i+1]
    for i in range(n-2):
        checkdict1[(i,i+1)] = 1
        checkdict1[(i+1,i)] = 1
        checkdict2[(i,i+1)] = 1
        checkdict2[(i+1,i)] = 1
        checkdict3[(i,i)] = quiddity_row[i+1]
    for i in range(n-3):
        checkdict3[(i,i+1)] = 1
        checkdict3[(i+1,i)] = 1   
    check1 = matrix(checkdict1)
    check2 = matrix(checkdict2)
    check3 = matrix(checkdict3)
    if det(check1) != 0 or det(check2)!= 0 or det(check3)!= 1:
            print('This is not the quiddity row of a finite frieze pattern, although it could be subsequence of a periodic quiddity row which does produce a finite frieze pattern')

   

    # Fill in 0s at position (1,1), (2,2), (3,3), until (inputrow,inputrow)
    #i.e. we fill in the "frieze row" = 0
    for col in range(matrixwidth-1):
        if m.has_key((col,col)):
            raise ValueError('There is a bug. This key {} should not have been assigned.'.format((col,col)))
        m[(col,col)]=0
        #print m[(col,col)]
	#print (col, col)

    # Fill in the 1s at position (i,j) where |i - j| = 1 until (inputrow,inputrow +/- 1)
    # i.e. we fill in the "frieze row" =1
    for col in range(1,matrixwidth):
        if m.has_key((col,col-1)):
            raise ValueError('There is a bug. This key {} should not have been assigned.'.format((col,col-1)))
        m[(col,col-1)]=1
      #  print m[(col,col-1)]
        #print (col,col-1)
    for col in range(1,matrixwidth):
        if m.has_key((col-1,col)):
            raise ValueError('There is a bug. This key {} should not have been assigned.'.format((col-1,col)))
        m[(col-1,col)]=1

   
    #Fill in quiddity row for (i,j) where |i - j| = 2
    for col in range(0,matrixwidth-2):
        if m.has_key((col+2,col)):
	    raise ValueError('There is a bug. This key {} should not have been assigned.'.format((col+2,col)))
        m[(col+2,col)]=quiddity_row[((col+leftstart) % n)]
        #print m[(col+2,col)]
    for col in range(0,matrixwidth-2):
        if m.has_key((col,col+2)):
            raise ValueError('There is a bug. This key {} should not have been assigned.'.format((col,col+2)))
        m[(col,col+2)]=quiddity_row[(col+leftstart)%n]

    # Fill in the rest of the "frieze rows" below the quiddity row using the quiddity row
    for row in range(3, matrixwidth-(leftstart+1)):
        for col in range(0,matrixwidth-row):
            i,j=col,col+row
            if m.has_key((i,j)):
                raise ValueError('There is a bug. This key {} should not exist'.format((i,j)))
            if m[(i+1,j-1)]<1:
                break
            #print (i,(j-1)%n+1)
            #print (i+1,j%n+1)
            #print m.keys()
            m[(i,j)] = (m[(i,(j-1))]*m[(i+1,j)]-1)/m[(i+1,(j-1))]
            if type(m[(i,j)]) == type(sqrt(2)):
                m[(i,j)] = m[(i,j)].full_simplify()
            #print m[(i,j)]
	for col in range(0,matrixwidth-row):
            i,j=col+row,col
            if m.has_key((i,j)):
                raise ValueError('There is a bug. This key {} should not exist'.format((i,j)))
            if m[(i-1,j+1)]<1:
                break
            #print (i,(j-1)%n+1)
            #print (i+1,j%n+1)
            #print m.keys()
            m[(i,j)] = (m[((i-1),j)]*m[(i,(j+1))]-1)/m[((i-1),(j+1))]
            if type(m[(i,j)]) == type(sqrt(2)):
                m[(i,j)] = m[(i,j)].full_simplify()
            #print m[(i,j)]
        if m[(leftstart+row,leftstart)]<1:
            break
        #print '\n'
    return m