def setUp(self): self.type_point = UnnamedOpetopicSet.Type( UnnamedOpetopicSet.PastingDiagram.point(), None) self.a = UnnamedOpetopicSet.Variable("a", UnnamedOpetope.Point()) self.b = UnnamedOpetopicSet.Variable("b", UnnamedOpetope.Point()) self.c = UnnamedOpetopicSet.Variable("c", UnnamedOpetope.Point()) self.d = UnnamedOpetopicSet.Variable("d", UnnamedOpetope.Point()) self.ab = UnnamedOpetopicSet.Variable("ab", UnnamedOpetope.Arrow()) self.ac = UnnamedOpetopicSet.Variable("ac", UnnamedOpetope.Arrow()) self.bc = UnnamedOpetopicSet.Variable("bc", UnnamedOpetope.Arrow()) self.cd = UnnamedOpetopicSet.Variable("cd", UnnamedOpetope.Arrow()) self.seq = UnnamedOpetopicSet.Sequent() self.seq.context = UnnamedOpetopicSet.Context() + \ UnnamedOpetopicSet.Typing(self.a, self.type_point) + \ UnnamedOpetopicSet.Typing(self.b, self.type_point) + \ UnnamedOpetopicSet.Typing(self.c, self.type_point) + \ UnnamedOpetopicSet.Typing(self.d, self.type_point) + \ UnnamedOpetopicSet.Typing( self.ab, self.type_arrow("a", self.b)) + \ UnnamedOpetopicSet.Typing( self.ac, self.type_arrow("a", self.c)) + \ UnnamedOpetopicSet.Typing( self.bc, self.type_arrow("b", self.c)) + \ UnnamedOpetopicSet.Typing( self.cd, self.type_arrow("c", self.d))
def test_shapeTarget(self): self.assertEqual(self.a.shapeTarget(), UnnamedOpetope.Point().eval().source) self.assertEqual(self.b.shapeTarget(), UnnamedOpetope.Point().eval().source) self.assertEqual(self.i1.shapeTarget(), UnnamedOpetope.Arrow().eval().source) self.assertEqual(self.i2.shapeTarget(), UnnamedOpetope.Arrow().eval().source) self.assertEqual(self.i3.shapeTarget(), UnnamedOpetope.Arrow().eval().source) self.assertEqual(self.c.shapeTarget(), UnnamedOpetope.OpetopicInteger(3).eval().source)
def point(seq: Sequent, name: Union[str, List[str]]) -> Sequent: """ The :math:`\\textbf{OptSet${}^?$}` :math:`\\texttt{point}` rule. * If argument ``name`` is a ``str``, creates a new point with that name (this is just the :math:`\\texttt{point}`); * if it is a list of ``str``, then creates as many points. """ if isinstance(name, list): res = seq for n in name: res = point(res, n) return res elif isinstance(name, str): if seq.pastingDiagram is not None: raise DerivationError("point rule", "Sequent cannot have a pasting diagram") var = Variable(name, UnnamedOpetope.Point()) if var in seq.context: raise DerivationError( "point rule", "Point shaped variable {name} is already typed in context " "{ctx}", name=name, ctx=str(seq.context)) res = deepcopy(seq) res.context = res.context + Typing(var, Type(PastingDiagram.point(), None)) return res else: raise DerivationError( "point rule", "Argument name is expected to be a str or list of str")
def setUp(self): self.p = UnnamedOpetopicSet.Typing( UnnamedOpetopicSet.Variable("p", UnnamedOpetope.Point()), UnnamedOpetopicSet.Type(UnnamedOpetopicSet.PastingDiagram.point(), None)) self.a = UnnamedOpetopicSet.Typing( UnnamedOpetopicSet.Variable("a", UnnamedOpetope.OpetopicInteger(0)), UnnamedOpetopicSet.Type( UnnamedOpetopicSet.PastingDiagram.degeneratePastingDiagram( UnnamedOpetope.OpetopicInteger(0), "p"), UnnamedOpetopicSet.Variable("p", UnnamedOpetope.Arrow()))) self.b = UnnamedOpetopicSet.Typing( UnnamedOpetopicSet.Variable("b", UnnamedOpetope.OpetopicInteger(0)), UnnamedOpetopicSet.Type( UnnamedOpetopicSet.PastingDiagram.degeneratePastingDiagram( UnnamedOpetope.OpetopicInteger(0), "p"), UnnamedOpetopicSet.Variable("p", UnnamedOpetope.Arrow()))) self.c = UnnamedOpetopicSet.Typing( UnnamedOpetopicSet.Variable("c", UnnamedOpetope.OpetopicInteger(2)), UnnamedOpetopicSet.Type( UnnamedOpetopicSet.PastingDiagram.nonDegeneratePastingDiagram( UnnamedOpetope.OpetopicInteger(2), { UnnamedOpetope.Address.epsilon(1): "x", UnnamedOpetope.Address.epsilon(0).shift(): "y" }), UnnamedOpetopicSet.Variable("z", UnnamedOpetope.Arrow()))) self.ctx = UnnamedOpetopicSet.Context() + self.p + self.a + self.c
def test___init__(self): UnnamedOpetopicSet.Type( self.s, UnnamedOpetopicSet.Variable("t", UnnamedOpetope.Arrow())) with self.assertRaises(DerivationError): UnnamedOpetopicSet.Type( self.s, UnnamedOpetopicSet.Variable("t", UnnamedOpetope.Point())) UnnamedOpetopicSet.Type(UnnamedOpetopicSet.PastingDiagram.point(), None) with self.assertRaises(DerivationError): UnnamedOpetopicSet.Type(self.s, None)
def target(self, name: str) -> str: """ Returns the target of the variable whose name is ``name``. """ res = self[name].type.target if self[name].type.source.shape == \ UnnamedOpetope.Point().eval().source: raise DerivationError( "Context, target of variable", "Variable {var} is a point, and do not have a target", var=name) elif res is None: raise RuntimeError( "[Context, target of variable] Variable {var} " "is not a point, but has no target. In valid " "derivations, this should not happen".format(var=name)) return res.name
def __init__(self, source: PastingDiagram, target: Optional[Variable]) -> None: if target is None: if source.shape != UnnamedOpetope.Point().eval().source: raise DerivationError( "Type, creation", "Source pasting diagram is not a point, but target is " "unspecified") elif source.shapeTarget() != target.shape: raise DerivationError( "Type, creation", "Target variable {var} has shape {shape}, should have " "{should}", var=str(target), shape=target.shape, should=source.shapeTarget()) self.source = source self.target = target
def test_ProofTree(self): self.assertEqual( UnnamedOpetope.ProofTree({}).eval(), UnnamedOpetope.Point().eval()) self.assertEqual( UnnamedOpetope.ProofTree({ UnnamedOpetope.address('*'): {} }).eval(), UnnamedOpetope.Arrow().eval()) self.assertEqual( UnnamedOpetope.ProofTree({ None: {} }).eval(), UnnamedOpetope.OpetopicInteger(0).eval()) self.assertEqual( UnnamedOpetope.ProofTree({ UnnamedOpetope.address([], 1): { UnnamedOpetope.address('*'): {} }, UnnamedOpetope.address(['*']): { UnnamedOpetope.address('*'): {} } }).eval(), UnnamedOpetope.OpetopicInteger(2).eval()) with self.assertRaises(DerivationError): UnnamedOpetope.ProofTree({ UnnamedOpetope.address(['*']): { UnnamedOpetope.address('*'): {} } }) with self.assertRaises(DerivationError): UnnamedOpetope.ProofTree({ UnnamedOpetope.address([], 1): { UnnamedOpetope.address('*'): {} }, UnnamedOpetope.address(['*', '*']): { UnnamedOpetope.address('*'): {} } }).eval()
def point(): """ Creates the trivial pasting diagram with shape the point """ return PastingDiagram.nonDegeneratePastingDiagram( UnnamedOpetope.Point(), {})