def test_degen(self): s = UnnamedOpetope.degen(UnnamedOpetope.point()) self.assertEqual( s.context, UnnamedOpetope.Context(2) + (UnnamedOpetope.Address.epsilon(1), UnnamedOpetope.Address.epsilon(0))) self.assertEqual( s.source, UnnamedOpetope.Preopetope.degenerate( UnnamedOpetope.Preopetope.point())) self.assertEqual(s.target, UnnamedOpetope.shift(UnnamedOpetope.point()).source)
def __str__(self) -> str: srcstr = str() if self.source.degeneracy is None: if self.source.nodes is None: raise RuntimeError("[Pasting diagram, to string] Both the " "degeneracy and node dict of the pasting " "diagram are None. In valid derivations, " "this should not happen") if self.source.shape == UnnamedOpetope.point().source: srcstr = "⧫" else: lines = [] # type: List[str] for addr in self.source.nodes.keys(): if self.isSourceUniversal(addr): lines += [ str(addr) + " ← ∀" + str(self.source.nodes[addr]) ] else: lines += [ str(addr) + " ← " + str(self.source.nodes[addr]) ] srcstr = "{" + ", ".join(lines) + "}" else: srcstr = "{{" + str(self.source.degeneracy) + "}}" if self.isTargetUniversal(): return srcstr + " → ∀" + str(self.target) else: return srcstr + " → " + str(self.target)
def toTex(self) -> str: if self.degeneracy is None: if self.nodes is None: raise RuntimeError("[Pasting diagram, to TeX] Both the " "degeneracy and node dict of the pasting " "diagram are None. In valid derivations, " "this should not happen") if self.shape == UnnamedOpetope.point().source: return "\\optZero" else: lines = [ addr.toTex() + " \\sep " + self.nodes[addr] for addr in self.nodes.keys() ] return "\\opetope{" + " \\\\ ".join(lines) + "}" else: return "\\degenopetope{" + self.degeneracy + "}"
def __str__(self) -> str: if self.degeneracy is None: if self.nodes is None: raise RuntimeError("[Pasting diagram, to string] Both the " "degeneracy and node dict of the pasting " "diagram are None. In valid derivations, " "this should not happen") if self.shape == UnnamedOpetope.point().source: return "⧫" else: lines = [ str(addr) + " ← " + str(self.nodes[addr]) for addr in self.nodes.keys() ] return "{" + ", ".join(lines) + "}" else: return "{{" + str(self.degeneracy) + "}}"
def test_shift(self): s1 = UnnamedOpetope.shift(UnnamedOpetope.point()) s2 = UnnamedOpetope.shift(s1) self.assertEqual( s2.context, UnnamedOpetope.Context(2) + (UnnamedOpetope.Address.epsilon(0).shift(), UnnamedOpetope.Address.epsilon(0))) p = UnnamedOpetope.Preopetope.point() a = UnnamedOpetope.Preopetope(1) a.nodes[UnnamedOpetope.Address.epsilon(0)] = p g = UnnamedOpetope.Preopetope(2) g.nodes[UnnamedOpetope.Address.epsilon(1)] = a self.assertEqual(s1.source, a) self.assertEqual(s1.target, p) self.assertEqual(s2.source, g) self.assertEqual(s2.target, a)
def test_point(self): s = UnnamedOpetope.point() self.assertEqual(s.context, UnnamedOpetope.Context(0)) self.assertEqual(s.source, UnnamedOpetope.Preopetope.point()) self.assertEqual(s.target, UnnamedOpetope.Preopetope.empty())