Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Code Samples

169 views
unlisted
ubuntu2204
# SO FAR only works for direct containment, not isomorphisms yet # take two complexes, matrix or otherwise # if poly, turn into matrix pls and ty # append the row [B,C,D……P] on top of each matrix # DEFINE m_a as the BIGGER matrix m1= matrix ([ #B sub [1,1,1,0,0,0,0,0,0,0,0,0,0], [1,0,0,1,1,0,0,0,0,0,0,0,0], [1,0,0,0,0,1,1,0,0,0,0,0,0], [1,0,0,0,0,0,0,1,1,0,0,0,0], [1,0,0,0,0,0,0,0,0,1,1,0,0], [1,0,0,0,0,0,0,0,0,0,0,1,1], ]) # DEFINE m_b as the SMALLER/SUBmatrix # the question is now "does A contain B?" m2= matrix ([ #C sub # containment of the following line makes m_b bigger than m_a [1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], [0,1,0,1,0,1,0,0,0,0,0,0,0,0,0], [0,1,0,0,1,0,1,0,0,0,0,0,0,0,0], [0,1,0,0,0,0,0,1,0,1,0,0,0,0,0], [0,1,0,0,0,0,0,0,1,0,1,0,0,0,0], [0,1,0,0,0,0,0,0,0,0,0,1,0,1,0], [0,1,0,0,0,0,0,0,0,0,0,0,1,0,1], ]) #the following is the modified "not" C matrix! m3= matrix ([ #C sub [1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], [0,1,0,1,0,1,0,0,0,0,0,0,0,0,0], [0,1,0,0,1,0,1,0,0,0,0,0,0,0,0], [0,1,0,0,0,0,0,1,0,1,0,0,0,0,0], [0,1,0,0,0,0,0,0,1,0,1,0,0,0,0], [0,1,0,0,0,0,0,0,0,0,0,1,0,1,0], [0,1,0,0,0,0,0,0,0,0,0,1,0,1,0] ]) #ok this is how the list works, its a TUPLE of (INCIDENCE, col# starting at 0 bc cs ppl are evil) #this is how you extract the fuckers, the first coordinate gives you the col ID which for now matches with its order as well, coordinate 2 gives you the inc value #ex: if you do col_id[0][0], it'll spit out "1". if you do [O][1], it'll spit out [5], because the first spot in the big list is (1,5). it's annoying bc the 0]0] command enumerates at 0, whereas i and the rest of civilized humanity enumerates at 1 but whatevs #RANK CHECK NEEDS TO BE MODIFIED because we're hunting for submatrices def main(m_a,m_b): if m_a.rank() < m_b.rank(): print('She submatrix too big fo she GATDAMN SELF') return elif m_a.nrows() < m_b.nrows(): print('She subgraph too big fo she GATDAMN SELF') return # import incident code # this is how you find the incidence/frequency matrix # pull the number of columns of a row_a = m_a.nrows() phi_a = matrix(QQ, 1, row_a, lambda i, j:1) inc_a = phi_a*m_a row_b = m_b.nrows() phi_b = matrix(QQ, 1, row_b, lambda i, j:1) inc_b = phi_b*m_b # no need to import the sorting bc i only need the generic one now :( inc_a_sorted = sorted(inc_a[0],reverse=True) inc_b_sorted = sorted(inc_b[0],reverse=True) # NEED TO MODIFY INCIDENT SORTING # what we're looking for is NOT that they're the same, but that they COULD be the same # that is to say, the number of nonzero incidence in m_a GEQ nonzero in m_b # more particularly, the biggest number in m_a GEQ the biggest in m_b, the 2nd biggest in m_a GEQ second biggest in m_b... for i in [0, row_b]: if inc_a_sorted[i] < inc_b_sorted[i]: print('She subincidence too big fo she gatdamn self') else: i=i+1 # THIS PART'S FUCKING *EASY* NOW # take the MOTHERFUCKING TRANSPOSE OF BOTH (we'll assign to different variables so we don't have to keep recalculating each time) a = m_a*m_a.transpose() b = m_b*m_b.transpose() bsize = b.nrows() # transpose of m_a will have m_b*m_b.transpose() in the upper left corner IF m_a contains m_b # this submatrix will be "m_b.ncols() x m_b.ncols()" # if it doesn't, then you're good # this is how we'll do it # ONLY take the m_b.ncols() x m_b.ncols(), which i named "bsize", above upper left submatrix of m_a*m_a.transpose() a_shrink = a[0:bsize, 0:bsize] # define a zero matrix of the appropriate size zerom = (QQ, bsize, bsize, lambda i, j:0) if a_shrink - b == zerom: print('Your complex has a linear redundancy of type MATRIX B (whichever polygon that is), yay!') else: print('Your complex has NO linear redundancies of any kind! Yay!') # this means we won't have to fuck around with reorganizing the actual columns and rows of m_a and m_b # comparing to zero is A LOT MORE EFFICIENT than comparing coordinate by coordinate/point by point # also avoids "for" loops which fucking SLAPS main(m1,m3) # we also don't have to use a (more intense) sort and search algorithm because m*m(t) is SYMMETRICAL so no matter how we organize things, the nice stuff will pop out and we're GUCCI
She subgraph too big fo she GATDAMN SELF