{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from sage.structure.parent import Parent\n", "from sage.structure.element import Element\n", "#from sage.structure.unique_representation import UniqueRepresentation\n", "#from sage.categories.rings import Rings\n", "from sage.structure.richcmp import rich_to_bool, op_EQ, op_NE, op_LT, op_LE, op_GT, op_GE\n", "#from sage.categories.morphism import Morphism\n", "#from sage.rings.rational_field import QQ\n", "#from sage.algebras.commutative_dga import GradedCommutativeAlgebra\n", "#from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing\n", "#from sage.functions.other import factorial\n", "import itertools\n", "import copy\n", "import random" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Simplicial Complex" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def cohomology_gens(S,n):\n", " gens = {}\n", " basis = S.cohomology_ring().basis()\n", " for k in basis.keys():\n", " if k[0] == n:\n", " gens[k] = basis[k]\n", " return gens" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def lift_cohomology_generator(S, g):\n", " cycle = g.to_cycle()\n", " cochain = {}\n", " for n in range(S.dimension()+1):\n", " for simplex in S._n_cells_sorted(n):\n", " cochain[simplex.tuple()] = 0\n", " for i in cycle:\n", " #print(type(i[0].tuple()))\n", " cochain[i[0].tuple()] = i[1]\n", " return cochain" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def sublist(lst1, lst2):\n", " return set(lst1) <= set(lst2)\n", "\n", "def sublist_of_lists(list1,list_of_lists):\n", " is_sublist = False\n", " for list2 in list_of_lists:\n", " if sublist(list1,list2):\n", " is_sublist = True\n", " break\n", " return is_sublist\n", "\n", "def random_simplicial_complex(num_vertices,max_num_facets):\n", " vertices = list(range(num_vertices))\n", " simplices = []\n", " partitions = []\n", " for length in range(num_vertices):\n", " partitions += [tuple(e) for e in powerset(vertices) if len(e)==length and e]\n", " for i in range(max_num_facets+1):\n", " r = randint(0,len(partitions)-1)\n", " candidate = partitions[r]\n", " if not sublist_of_lists(candidate,simplices):\n", " simplices.append(candidate)\n", " return SimplicialComplex(simplices,is_mutable=False)\n", "\n", "def random_cochain(S):\n", " dim = S.dimension()\n", " cochain = {}\n", " for n in range(dim+1):\n", " for s in S._n_cells_sorted(n):\n", " cochain[s.tuple()] = randint(-100,100)\n", " return cochain" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{(2, 4), (0, 1, 3, 4)}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S = random_simplicial_complex(5,4)\n", "S.facets()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Apln" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "class Apln(UniqueRepresentation):\n", "\n", " def __init__(self,n):\n", " self.n = n\n", " self.algebras = []\n", " self.relations = []\n", " for i in range(n+1):\n", " [cdga, relations] = self._cdga(i)\n", " self.algebras.append(cdga)\n", " self.relations.append(relations)\n", " \n", " def _cdga(self,n):\n", " ts = ['t'+str(t) for t in range(n+1)]\n", " ys = ['y'+str(t) for t in range(n+1)]\n", " degrees = tuple((n+1)*[(0,2)])+tuple((n+1)*[(1,2)])\n", " gca = GradedCommutativeAlgebra(QQ, names=ts+ys, degrees=degrees)\n", " t_relation = -1\n", " y_relation = 0\n", " #t_relation = sum(self.gca.gens()[:n])-1\n", " #y_relation = sum(self.gca.gens()[n:])\n", " for i in range(n+1):\n", " t_relation += gca.gens()[i]\n", " y_relation += gca.gens()[n+1+i]\n", " #gca_with_relations = self.gca.quotient(self.gca.ideal(t_relation,y_relation),check=False)\n", " dfs = {gca.gens_dict()[ts[i]]:gca.gens_dict()[ys[i]] for i in range(n+1)}\n", " return [gca.cdg_algebra(dfs),[t_relation,y_relation]]\n", " \n", " def __repr__(self):\n", " return \"Simplicial algebra of dimension %s\" % self.n\n", " \n", " def inject_variables(self, n):\n", " self.algebras[n].inject_variables()\n", " \n", " def generators(self, n):\n", " return self.algebras[n].gens()\n", " \n", " def face(self,i,n):\n", "\n", " if(self.n==0):\n", " return 0\n", " domain = self.algebras[n]\n", " codomain = self.algebras[n-1]\n", " tImages = []\n", " yImages = []\n", " n = len(domain.gens())//2\n", " for k in range(n):\n", " if(ki):\n", " tImages.append(codomain.gens()[k-1])\n", " yImages.append(codomain.gens()[n+k-2])\n", " images = tImages+yImages\n", " return domain.hom(codomain=codomain,im_gens=images)\n", "\n", " def reduce_polynomial(self,p):\n", " ## Input:\n", " # - p: polynomial in variables t_0,..t_n,y_0,...,y_n\n", " ## Output:\n", " # - The polynomial after applying the corresponding relations to reduce the variables t_0, y_0\n", " apl = p.parent()\n", " dim = len(apl.gens())//2-1\n", " return p.reduce(self.relations[dim])\n", " \n", " def _convert_integrable_polynomial(self,p):\n", " ## Input:\n", " # - p: polynomial in variables t_1,..t_n,y_1,...,y_n\n", " ## Output:\n", " # - A polynomial in the ring Q.\n", " # (After reducing the variables t_{0},y_{0} by the corresponding relations, \n", " # the algorithm removes the variables y_{1},..,y_{n}). \n", " \n", " apl = p.parent()\n", " n = len(apl.gens())//2\n", " pol = self.reduce_polynomial(p)\n", " relations = []\n", " for i in range(n): \n", " relations.append(apl.gens()[n+i]-1)\n", " return pol.reduce(relations)\n", " \n", " def integral(self,p):\n", " ## Input:\n", " # - p: polynomial in variables t_0,..t_n,y_0,...,y_n\n", " ## Output:\n", " # - the integral of the polynomial after reducing the variables t_0, y_0 by the corresponding relations \n", " #\n", " apl = p.parent()\n", " n = len(apl.gens())//2-1\n", " pol = self._convert_integrable_polynomial(p)\n", " result = 0\n", " for k in pol.dict().keys(): # k is a monomial\n", " numerator = 1\n", " denominator = n\n", " for e in k: # e is an exponents\n", " numerator *= factorial(e)\n", " denominator += e\n", " coef = pol.dict()[k]\n", " result += coef*numerator/factorial(denominator)\n", " return ((-1)**(n*(n-1)/2))*result\n", " \n", " def lift(self, value, n): \n", " apl = self.algebras[n]\n", " gens = apl.gens()\n", " return value*((-1)**(n*(n-1)/2))*factorial(n)*prod(gens[n+2:])\n", " \n", " def homogeneous_part(self,pol,degree):\n", " parts = [pol.homogeneous_parts()[k] for k in pol.homogeneous_parts() if list(k)[0]==degree]\n", " return sum(parts)\n", " \n", " def propagate(self, face_list, n):\n", " \"\"\"\n", " - face_list: indexes of the elements that form the face of the simplex we want to propagate\n", " - EXAMPLE: p = a.propagate([0,3,4],5)\n", " t4*y0*y3 - t3*y0*y4 + t0*y3*y4\n", " \"\"\"\n", " simplex_dim = len(face_list)-1\n", " indexes = list(range(simplex_dim+1))\n", " apl = self.algebras[n]\n", " y_gens = [apl.gens()[n+1+i] for i in face_list]\n", " t_gens = [apl.gens()[i] for i in face_list]\n", " result = apl(0)\n", " for i in reversed(indexes):\n", " t = t_gens[i]\n", " y_prod = copy.deepcopy(y_gens)\n", " del y_prod[i]\n", " y_prod = prod(y_prod)\n", " result += ((-1)**i)*t*y_prod#((-1)**(simplex_dim+i))*t*y_prod\n", " return result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Apl(K)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "class AplK(UniqueRepresentation, Parent):\n", " \n", " def __init__(self,K, category=None):\n", " self.K = K\n", " self.n = K.dimension()\n", " self.apln = Apln(K.dimension())\n", " Parent.__init__(self,category=category )\n", " f = MorphismFromQQToAplK(self)\n", " self.register_coercion(f)\n", " \n", " def _repr_(self):\n", " return \"Algebra AplK over %s\" % self.K\n", " \n", " def _element_constructor_(self,values):\n", " return self.element_class(self,values)\n", " \n", " def dimension(self):\n", " return self.K.dimension()\n", " \n", " def simplicialComplex(self):\n", " return self.K\n", " \n", " def _n_cells_sorted(self,n):\n", " return self.K._n_cells_sorted(n)\n", " \n", " def lift(self, cochain):\n", " \n", " # first we find polynomials compatible with the integration value\n", " values = {}\n", " max_n = 0\n", " for k in cochain.keys():\n", " n = len(k)-1\n", " if n > max_n:\n", " max_n = n\n", " apl = self.apln.algebras[n]\n", " if n>0:\n", " values[k] = self.apln.lift(cochain[k],n)\n", " else:\n", " values[k]= apl(cochain[k])\n", " \n", " # second, we propagate the simplicial information\n", " simplicial_structure = {}\n", " for n in reversed(range(max_n+1)):\n", " keys = [k for k in values.keys() if len(k) == n+1] # keys of the n-simplices\n", " for k in keys:\n", " simplicial_structure[k] = values[k] + self._propagate(cochain, k) \n", " #print(simplicial_structure)\n", " return AplKElement(self,simplicial_structure)\n", "\n", " def _faces_of_length(self, simplex, length):\n", " return [tuple(e) for e in powerset(simplex) if len(e)==length]\n", " \n", " def _propagate(self, cochain, simplex):\n", " \n", " dim = len(simplex)-1\n", " apl = self.apln.algebras[dim]\n", " propagation = apl(0)\n", " for n in reversed(range(dim+1)):\n", " faces = self._faces_of_length(simplex, n)\n", " for f in faces:\n", " if f in cochain.keys():\n", " dim_face = len(f)-1\n", " value = cochain[f]\n", " face_indexes = [simplex.index(i) for i in f]\n", " propagation += value*((-1)**(dim_face*(dim_face-1)/2))*factorial(dim_face)*self.apln.propagate(face_indexes, dim)\n", " return propagation\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Apl(K) Element" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "class AplKElement(Element):\n", "\n", " def __init__(self, parent, values):\n", " Element.__init__(self,parent)\n", " self.apln = Apln(parent.dimension())\n", " self.elements = self.reduce(values) \n", " self.check()\n", " \n", " def reduce(self, values):\n", " reduced_values = {}\n", " for k in values.keys():\n", " n = len(k)-1\n", " apl = self.apln.algebras[n]\n", " reduced_values[k] = self.apln.reduce_polynomial(apl(values[k]))\n", " return reduced_values\n", " \n", " def _repr_(self):\n", " return str(self.elements)\n", " \n", " def dimension(self):\n", " return self.parent().dimension()\n", " \n", " def nullElement(self):\n", " C = self.__class__\n", " values = {}\n", " for k in self.elements.keys():\n", " values[k]=0\n", " return C(self.parent(),values) \n", " \n", " def _add_(self,other):\n", " C = self.__class__\n", " if(self.elements.keys()!=other.elements.keys()):\n", " raise ValueError(\"error: keys do not match\")\n", " newValues = {}\n", " for k in self.elements.keys():\n", " newValues[k] = self.elements[k]+other.elements[k]\n", " return C(self.parent(),newValues)\n", " \n", " def _sub_(self,other):\n", "\n", " C = self.__class__\n", " if(self.elements.keys()!=other.elements.keys()):\n", " raise ValueError(\"error: keys do not match\")\n", " newValues = {}\n", " for k in self.elements.keys():\n", " newValues[k] = self.elements[k]-other.elements[k]\n", " return C(self.parent(),newValues)\n", " \n", " def _mul_(self,other):\n", "\n", " C = self.__class__\n", " if(self.elements.keys()!=other.elements.keys()):\n", " raise ValueError(\"error: keys do not match\")\n", " newValues = {}\n", " for k in self.elements.keys():\n", " newValues[k] = self.elements[k]*other.elements[k]\n", " return C(self.parent(),newValues)\n", " \n", " def _richcmp_(self, other, op):\n", "\n", " if(op==op_EQ):\n", " if(self.elements.keys()!=other.elements.keys()):\n", " return False\n", " for k in self.elements.keys():\n", " if(self.elements[k]!=other.elements[k]):\n", " return False\n", " return True\n", " elif(op==op_NE):\n", " return not self._richcmp_(other,op_EQ)\n", " else:\n", " raise NotImplementedError(\"operation not implemented for this element class\")\n", " \n", " def differential(self):\n", " C = self.__class__\n", " newValues = {}\n", " for k in self.elements.keys():\n", " newValues[k] = self.elements[k].differential()\n", " return C(self.parent(),newValues)\n", " \n", " def check(self):\n", "\n", " S = self.parent().simplicialComplex()\n", " dim = S.dimension()\n", " for n in range(1,dim+1):\n", " #print(\"Checking dimension \" + str(n))\n", " for simplex in S._n_cells_sorted(n):\n", " for f in range(n+1):\n", " sFace = tuple(S.face(simplex,f))\n", " aFace = self.apln.face(f,n)(self.elements[simplex.tuple()])\n", " aFace = self.apln.reduce_polynomial(aFace)\n", " #print(\"face: \" + str(f),\"simplex: \" + str(simplex),\"sFace: \" + str(self.elements[sFace]), \"aFace: \" + str(aFace))\n", " if(self.elements[sFace] != aFace):\n", " raise ValueError(\"the assignation is not valid\")\n", " \n", " def homogeneous_part(self,degree):\n", " C = self.__class__\n", " part = {}\n", " for k in self.elements.keys():\n", " part[k] = self.apln.homogeneous_part(self.elements[k],degree)\n", " return C(self.parent(),part)\n", " \n", " def homogeneous_parts(self):\n", " parts = {}\n", " for n in range(self.dimension()+1):\n", " parts[n] = self.homogeneous_part(n)\n", " return parts\n", " \n", " def is_homogeneous(self):\n", " isHomogeneous = True\n", " for k in self.elements.keys():\n", " isHomogeneous = isHomogeneous and self.elements[k].is_homogeneous()\n", " return isHomogeneous\n", " \n", " def is_closed(self):\n", " diff = self.differential()\n", " if(diff == self.nullElement()):\n", " return True\n", " else:\n", " return False\n", " \n", " def _integrable_component(self):\n", " C = self.__class__\n", " component = {}\n", " for k in self.elements.keys():\n", " degree = len(k)-1\n", " component[k] = self.apln.homogeneous_part(self.elements[k],degree)\n", " #component[k] = self.homogeneous_component(dim).elements[k]\n", " return component\n", " \n", " def integral(self):\n", " component = self._integrable_component()\n", " cochain = {}\n", " #integration of each polynomial\n", " for k in component.keys():\n", " n = len(k)-1\n", " apl = self.apln.algebras[n]\n", " cochain[k] = self.apln.integral(apl(component[k]))\n", " return cochain\n", " \n", "#####################################################################\n", "\n", "class MorphismFromQQToAplK(Morphism):\n", "\n", " def __init__(self, codomain):\n", " self.simplicialComplex= codomain.K\n", " Morphism.__init__(self, QQ, codomain)\n", "\n", " def _call_(self, x):\n", " S = self.simplicialComplex\n", " params1 = {}\n", " for d in range(S.dimension()+1):\n", " for c in S._n_cells_sorted(d):\n", " params1[tuple(c)]=x\n", " A = AplK(S)\n", " return AplKElement(A, params1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Test lift == integral" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def test(max_vertices, verbose=False):\n", " success = True\n", " data = []\n", " for i in range(10):\n", " v = randint(2,max_vertices)\n", " f = randint(1,v)\n", " S = random_simplicial_complex(num_vertices=v,max_num_facets=f)\n", " A = AplK(S)\n", " cochain = random_cochain(S)\n", " #print(cochain)\n", " data = [S, cochain]\n", " if verbose:\n", " print(\"iteration: \" + str(i), \"num_vertices: \" + str(v), \"max_num_facets: \" + str(f), \"facets: \" + str(S.facets()))\n", " p = A.lift(cochain)\n", " if verbose:\n", " print(p)\n", " if not p.integral()==cochain:\n", " success = False\n", " print(\"Error\")\n", " break\n", " if success:\n", " print(\"success: \" + str(success))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "iteration: 0 num_vertices: 6 max_num_facets: 4 facets: {(1, 2, 5), (0, 3, 4, 5), (0, 1, 3), (1, 3, 4)}\n", "{(0, 3, 4, 5): 288*y1*y2*y3 + 84*t3*y1*y2 - 84*t2*y1*y3 + 84*t1*y2*y3 - 174*y1*y2 - 112*y1*y3 + 124*y2*y3 + 43*t2*y1 + 225*t3*y1 - 43*t1*y2 + 3*t3*y2 - 225*t1*y3 - 3*t2*y3 - 63*y1 + 37*y2 + 81*y3 - 86*t1 - 69*t2 - 114*t3 + 97, (0, 1, 3): 200*y1*y2 + 13*t2*y1 - 13*t1*y2 + 18*y1 - 63*y2 - 178*t1 - 86*t2 + 97, (0, 3, 4): -174*y1*y2 + 43*t2*y1 - 43*t1*y2 - 63*y1 + 37*y2 - 86*t1 - 69*t2 + 97, (0, 3, 5): -112*y1*y2 + 225*t2*y1 - 225*t1*y2 - 63*y1 + 81*y2 - 86*t1 - 114*t2 + 97, (0, 4, 5): 124*y1*y2 + 3*t2*y1 - 3*t1*y2 + 37*y1 + 81*y2 - 69*t1 - 114*t2 + 97, (1, 2, 5): 160*y1*y2 + 83*t2*y1 - 83*t1*y2 + 20*y1 + 57*y2 + 64*t1 + 64*t2 - 81, (1, 3, 4): 14*y1*y2 + 9*t2*y1 - 9*t1*y2 - 94*y1 - 28*y2 + 92*t1 + 109*t2 - 81, (3, 4, 5): 146*y1*y2 - 179*t2*y1 + 179*t1*y2 + 57*y1 - 81*y2 + 17*t1 - 28*t2 + 11, (0, 1): 18*y1 - 178*t1 + 97, (0, 3): -63*y1 - 86*t1 + 97, (0, 4): 37*y1 - 69*t1 + 97, (0, 5): 81*y1 - 114*t1 + 97, (1, 2): 20*y1 + 64*t1 - 81, (1, 3): -94*y1 + 92*t1 - 81, (1, 4): -28*y1 + 109*t1 - 81, (1, 5): 57*y1 + 64*t1 - 81, (2, 5): -46*y1 - 17, (3, 4): 57*y1 + 17*t1 + 11, (3, 5): -81*y1 - 28*t1 + 11, (4, 5): 41*y1 - 45*t1 + 28, (0,): 97, (1,): -81, (2,): -17, (3,): 11, (4,): 28, (5,): -17}\n", "iteration: 1 num_vertices: 5 max_num_facets: 2 facets: {(0, 2, 3, 4), (1, 3, 4)}\n", "{(0, 2, 3, 4): 6*y1*y2*y3 + 506*t3*y1*y2 - 506*t2*y1*y3 + 506*t1*y2*y3 - 196*y1*y2 + 6*y1*y3 - 106*y2*y3 - 56*t2*y1 - 75*t3*y1 + 56*t1*y2 - 23*t3*y2 + 75*t1*y3 + 23*t2*y3 - 38*y1 - 86*y2 - 16*y3 - 50*t1 - 54*t2 - 3*t3 + 65, (0, 2, 3): -196*y1*y2 - 56*t2*y1 + 56*t1*y2 - 38*y1 - 86*y2 - 50*t1 - 54*t2 + 65, (0, 2, 4): 6*y1*y2 - 75*t2*y1 + 75*t1*y2 - 38*y1 - 16*y2 - 50*t1 - 3*t2 + 65, (0, 3, 4): -106*y1*y2 - 23*t2*y1 + 23*t1*y2 - 86*y1 - 16*y2 - 54*t1 - 3*t2 + 65, (1, 3, 4): -2*y1*y2 + 4*t2*y1 - 4*t1*y2 - 37*y1 + 60*y2 - 13*t1 + 38*t2 + 24, (2, 3, 4): 198*y1*y2 - 4*t2*y1 + 4*t1*y2 + 8*y1 + 97*y2 - 4*t1 + 47*t2 + 15, (0, 2): -38*y1 - 50*t1 + 65, (0, 3): -86*y1 - 54*t1 + 65, (0, 4): -16*y1 - 3*t1 + 65, (1, 3): -37*y1 - 13*t1 + 24, (1, 4): 60*y1 + 38*t1 + 24, (2, 3): 8*y1 - 4*t1 + 15, (2, 4): 97*y1 + 47*t1 + 15, (3, 4): 93*y1 + 51*t1 + 11, (0,): 65, (1,): 24, (2,): 15, (3,): 11, (4,): 62}\n", "iteration: 2 num_vertices: 3 max_num_facets: 2 facets: {(0, 2), (1,)}\n", "{(0, 2): 89*y1 + 2*t1 - 26, (0,): -26, (1,): -60, (2,): -24}\n", "iteration: 3 num_vertices: 6 max_num_facets: 4 facets: {(1, 3), (2, 3), (0, 3, 5), (0, 1, 2, 4, 5)}\n", "{(0, 1, 2, 4, 5): -1704*y1*y2*y3*y4 - 534*t4*y1*y2*y3 + 534*t3*y1*y2*y4 - 534*t2*y1*y3*y4 + 534*t1*y2*y3*y4 - 558*y1*y2*y3 - 444*y1*y2*y4 + 192*y1*y3*y4 - 132*y2*y3*y4 - 90*t3*y1*y2 + 238*t4*y1*y2 + 90*t2*y1*y3 + 236*t4*y1*y3 - 90*t1*y2*y3 + 198*t4*y2*y3 - 238*t2*y1*y4 - 236*t3*y1*y4 + 238*t1*y2*y4 - 198*t3*y2*y4 + 236*t1*y3*y4 + 198*t2*y3*y4 - 112*y1*y2 - 36*y1*y3 + 8*y2*y3 + 146*y1*y4 + 94*y2*y4 - 24*y3*y4 - 55*t2*y1 - 41*t3*y1 + 23*t4*y1 + 55*t1*y2 - 121*t3*y2 - 60*t4*y2 + 41*t1*y3 + 121*t2*y3 - 23*t4*y3 - 23*t1*y4 + 60*t2*y4 + 23*t3*y4 + 38*y1 + 73*y2 + 31*y3 + 85*y4 - 88*t1 - 115*t2 - 74*t3 - 63*t4 + 85, (0, 1, 2, 4): -558*y1*y2*y3 - 90*t3*y1*y2 + 90*t2*y1*y3 - 90*t1*y2*y3 - 112*y1*y2 - 36*y1*y3 + 8*y2*y3 - 55*t2*y1 - 41*t3*y1 + 55*t1*y2 - 121*t3*y2 + 41*t1*y3 + 121*t2*y3 + 38*y1 + 73*y2 + 31*y3 - 88*t1 - 115*t2 - 74*t3 + 85, (0, 1, 2, 5): -444*y1*y2*y3 + 238*t3*y1*y2 - 238*t2*y1*y3 + 238*t1*y2*y3 - 112*y1*y2 + 146*y1*y3 + 94*y2*y3 - 55*t2*y1 + 23*t3*y1 + 55*t1*y2 - 60*t3*y2 - 23*t1*y3 + 60*t2*y3 + 38*y1 + 73*y2 + 85*y3 - 88*t1 - 115*t2 - 63*t3 + 85, (0, 1, 4, 5): 192*y1*y2*y3 + 236*t3*y1*y2 - 236*t2*y1*y3 + 236*t1*y2*y3 - 36*y1*y2 + 146*y1*y3 - 24*y2*y3 - 41*t2*y1 + 23*t3*y1 + 41*t1*y2 - 23*t3*y2 - 23*t1*y3 + 23*t2*y3 + 38*y1 + 31*y2 + 85*y3 - 88*t1 - 74*t2 - 63*t3 + 85, (0, 2, 4, 5): -132*y1*y2*y3 + 198*t3*y1*y2 - 198*t2*y1*y3 + 198*t1*y2*y3 + 8*y1*y2 + 94*y1*y3 - 24*y2*y3 - 121*t2*y1 - 60*t3*y1 + 121*t1*y2 - 23*t3*y2 + 60*t1*y3 + 23*t2*y3 + 73*y1 + 31*y2 + 85*y3 - 115*t1 - 74*t2 - 63*t3 + 85, (1, 2, 4, 5): 324*y1*y2*y3 + 290*t3*y1*y2 - 290*t2*y1*y3 + 290*t1*y2*y3 - 158*y1*y2 + 74*y1*y3 + 30*y2*y3 - 135*t2*y1 - 138*t3*y1 + 135*t1*y2 - 87*t3*y2 + 138*t1*y3 + 87*t2*y3 + 90*y1 + 34*y2 + 24*y3 - 27*t1 + 14*t2 + 25*t3 - 3, (0, 1, 2): -112*y1*y2 - 55*t2*y1 + 55*t1*y2 + 38*y1 + 73*y2 - 88*t1 - 115*t2 + 85, (0, 1, 4): -36*y1*y2 - 41*t2*y1 + 41*t1*y2 + 38*y1 + 31*y2 - 88*t1 - 74*t2 + 85, (0, 1, 5): 146*y1*y2 + 23*t2*y1 - 23*t1*y2 + 38*y1 + 85*y2 - 88*t1 - 63*t2 + 85, (0, 2, 4): 8*y1*y2 - 121*t2*y1 + 121*t1*y2 + 73*y1 + 31*y2 - 115*t1 - 74*t2 + 85, (0, 2, 5): 94*y1*y2 - 60*t2*y1 + 60*t1*y2 + 73*y1 + 85*y2 - 115*t1 - 63*t2 + 85, (0, 3, 5): -146*y1*y2 + 167*t2*y1 - 167*t1*y2 - 46*y1 + 85*y2 - 13*t1 - 63*t2 + 85, (0, 4, 5): -24*y1*y2 - 23*t2*y1 + 23*t1*y2 + 31*y1 + 85*y2 - 74*t1 - 63*t2 + 85, (1, 2, 4): -158*y1*y2 - 135*t2*y1 + 135*t1*y2 + 90*y1 + 34*y2 - 27*t1 + 14*t2 - 3, (1, 2, 5): 74*y1*y2 - 138*t2*y1 + 138*t1*y2 + 90*y1 + 24*y2 - 27*t1 + 25*t2 - 3, (1, 4, 5): 30*y1*y2 - 87*t2*y1 + 87*t1*y2 + 34*y1 + 24*y2 + 14*t1 + 25*t2 - 3, (2, 4, 5): 88*y1*y2 - 84*t2*y1 + 84*t1*y2 + 79*y1 + 72*y2 + 41*t1 + 52*t2 - 30, (0, 1): 38*y1 - 88*t1 + 85, (0, 2): 73*y1 - 115*t1 + 85, (0, 3): -46*y1 - 13*t1 + 85, (0, 4): 31*y1 - 74*t1 + 85, (0, 5): 85*y1 - 63*t1 + 85, (1, 2): 90*y1 - 27*t1 - 3, (1, 3): -88*y1 + 75*t1 - 3, (1, 4): 34*y1 + 14*t1 - 3, (1, 5): 24*y1 + 25*t1 - 3, (2, 3): -68*y1 + 102*t1 - 30, (2, 4): 79*y1 + 41*t1 - 30, (2, 5): 72*y1 + 52*t1 - 30, (3, 5): -36*y1 - 50*t1 + 72, (4, 5): 77*y1 + 11*t1 + 11, (0,): 85, (1,): -3, (2,): -30, (3,): 72, (4,): 11, (5,): 22}\n", "iteration: 4 num_vertices: 4 max_num_facets: 3 facets: {(0, 1, 2), (0, 3)}\n", "{(0, 1, 2): -128*y1*y2 + 102*t2*y1 - 102*t1*y2 - 83*y1 - 17*y2 - 3*t1 + 23*t2 + 1, (0, 1): -83*y1 - 3*t1 + 1, (0, 2): -17*y1 + 23*t1 + 1, (0, 3): -98*y1 - 21*t1 + 1, (1, 2): -36*y1 + 26*t1 - 2, (0,): 1, (1,): -2, (2,): 24, (3,): -20}\n", "iteration: 5 num_vertices: 3 max_num_facets: 2 facets: {(0, 2), (1,)}\n", "{(0, 2): 91*y1 - 45*t1 - 46, (0,): -46, (1,): -75, (2,): -91}\n", "iteration: 6 num_vertices: 4 max_num_facets: 1 facets: {(0, 1, 2)}\n", "{(0, 1, 2): 106*y1*y2 + 100*t2*y1 - 100*t1*y2 - 83*y1 + 50*y2 - 60*t1 + 7*t2 - 20, (0, 1): -83*y1 - 60*t1 - 20, (0, 2): 50*y1 + 7*t1 - 20, (1, 2): 33*y1 + 67*t1 - 80, (0,): -20, (1,): -80, (2,): -13}\n", "iteration: 7 num_vertices: 5 max_num_facets: 1 facets: {(0, 1, 4), (1, 3)}\n", "{(0, 1, 4): -36*y1*y2 + 72*t2*y1 - 72*t1*y2 - 88*y1 + 25*y2 - 12*t1 + 77*t2 - 1, (0, 1): -88*y1 - 12*t1 - 1, (0, 4): 25*y1 + 77*t1 - 1, (1, 3): 52*y1 + 43*t1 - 13, (1, 4): 41*y1 + 89*t1 - 13, (0,): -1, (1,): -13, (3,): 30, (4,): 76}\n", "iteration: 8 num_vertices: 5 max_num_facets: 2 facets: {(0, 3, 4), (0, 2, 4), (1, 2)}\n", "{(0, 2, 4): 198*y1*y2 - 84*t2*y1 + 84*t1*y2 - 68*y1 - 75*y2 - 129*t1 - 5*t2 + 46, (0, 3, 4): 152*y1*y2 + 57*t2*y1 - 57*t1*y2 - 100*y1 - 75*y2 - 40*t1 - 5*t2 + 46, (0, 2): -68*y1 - 129*t1 + 46, (0, 3): -100*y1 - 40*t1 + 46, (0, 4): -75*y1 - 5*t1 + 46, (1, 2): -86*y1 - 66*t1 - 17, (2, 4): 77*y1 + 124*t1 - 83, (3, 4): -32*y1 + 35*t1 + 6, (0,): 46, (1,): -17, (2,): -83, (3,): 6, (4,): 41}\n", "iteration: 9 num_vertices: 2 max_num_facets: 2 facets: {(1,), (0,)}\n", "{(0,): -75, (1,): -70}\n", "success: True\n" ] } ], "source": [ "test(max_vertices=6, verbose=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Minimal model (sin terminar)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class MinimalModel():\n", "\n", " def __init__(self, S):\n", " self.K = S\n", " self.Phi = {}\n", " gens = self.first_non_trivial_cohomology_group()\n", " [self.cdga, self.cohomology_dict] = self.createModel(gens)\n", " \n", " def first_non_trivial_cohomology_group(self, max_iter=20):\n", " # busco el primer grupo de cohomología no trivial\n", " i=1\n", " gens = self.cohomology_gens(i)\n", " while(len(gens)==0 and i