def test___eq__(self):
     self.assertEqual(self.tw, self.tw)
     self.assertEqual(self.tx, self.tx)
     self.assertEqual(self.ty, self.ty)
     self.assertEqual(self.tz, self.tz)
     self.assertNotEqual(self.tx, self.tz)
     self.assertNotEqual(self.tw, NamedOpetope.Term(self.w))
     self.assertNotEqual(NamedOpetope.Term(NamedOpetope.Variable("x", 0)),
                         NamedOpetope.Term(NamedOpetope.Variable("x", 1)))
 def test___init__(self):
     NamedOpetope.Typing(NamedOpetope.Term(NamedOpetope.Variable("a", 0)),
                         NamedOpetope.Type([NamedOpetope.Term()]))
     NamedOpetope.Typing(
         NamedOpetope.Term(NamedOpetope.Variable("f", 1)),
         NamedOpetope.Type([
             NamedOpetope.Term(NamedOpetope.Variable("a", 0)),
             NamedOpetope.Term()
         ]))
     with self.assertRaises(DerivationError):
         NamedOpetope.Typing(
             NamedOpetope.Term(NamedOpetope.Variable("a", 1)),
             NamedOpetope.Type([NamedOpetope.Term()]))
     with self.assertRaises(DerivationError):
         NamedOpetope.Typing(
             NamedOpetope.Term(NamedOpetope.Variable("f", 2)),
             NamedOpetope.Type([
                 NamedOpetope.Term(NamedOpetope.Variable("a", 0)),
                 NamedOpetope.Term()
             ]))
     with self.assertRaises(DerivationError):
         NamedOpetope.Typing(
             NamedOpetope.Term(NamedOpetope.Variable("f", 0)),
             NamedOpetope.Type([
                 NamedOpetope.Term(NamedOpetope.Variable("a", 0)),
                 NamedOpetope.Term()
             ]))
 def test___add__(self):
     with self.assertRaises(DerivationError):
         self.ctx5 + NamedOpetope.Typing(self.term1, self.typing1)
     with self.assertRaises(DerivationError):
         self.ctx5 + NamedOpetope.Typing(self.term2, self.typing2)
     with self.assertRaises(DerivationError):
         self.ctx5 + NamedOpetope.Typing(self.term3, self.typing3)
     with self.assertRaises(DerivationError):
         self.ctx5 + NamedOpetope.Typing(self.term4, self.typing4)
     term = NamedOpetope.Term(NamedOpetope.Variable("x", 2))
     term[NamedOpetope.Variable("a", 1)] = NamedOpetope.Term(
         NamedOpetope.Variable("y", 2))
     typing = NamedOpetope.Typing(term, self.typing3)
     with self.assertRaises(DerivationError):
         self.ctx5 + typing
 def test___contains__(self):
     self.assertNotIn(self.a, self.t0)
     self.assertNotIn(self.f, self.t0)
     self.assertNotIn(self.alpha, self.t0)
     self.assertIn(self.a, self.t1)
     self.assertNotIn(self.f, self.t1)
     self.assertNotIn(self.alpha, self.t1)
     self.assertIn(self.a, self.t2)
     self.assertIn(self.f, self.t2)
     self.assertNotIn(self.alpha, self.t2)
     self.assertIn(self.a, self.t3)
     self.assertIn(self.f, self.t3)
     self.assertIn(self.alpha, self.t3)
     self.assertNotIn(NamedOpetope.Variable("β", 2), self.t3)
     self.assertNotIn(NamedOpetope.Variable("a", 2), self.t3)
 def setUp(self):
     self.a1 = NamedOpetope.Variable("a1", 0)
     self.b1 = NamedOpetope.Variable("b1", 0)
     self.c1 = NamedOpetope.Variable("c1", 0)
     self.a2 = NamedOpetope.Variable("a2", 0)
     self.b2 = NamedOpetope.Variable("b2", 0)
     self.c2 = NamedOpetope.Variable("c2", 0)
     self.f = NamedOpetope.Variable("f", 1)
     self.g = NamedOpetope.Variable("g", 1)
     self.h = NamedOpetope.Variable("h", 1)
     self.i = NamedOpetope.Variable("h", 1)
     ctx = NamedOpetope.Context() + \
         NamedOpetope.Typing(
             NamedOpetope.Term(self.a1),
             NamedOpetope.Type([NamedOpetope.Term()])) + \
         NamedOpetope.Typing(
             NamedOpetope.Term(self.b1),
             NamedOpetope.Type([NamedOpetope.Term()])) + \
         NamedOpetope.Typing(
             NamedOpetope.Term(self.c1),
             NamedOpetope.Type([NamedOpetope.Term()])) + \
         NamedOpetope.Typing(
             NamedOpetope.Term(self.f),
             NamedOpetope.Type(
                 [NamedOpetope.Term(self.a2),
                  NamedOpetope.Term()])) + \
         NamedOpetope.Typing(
             NamedOpetope.Term(self.g),
             NamedOpetope.Type(
                 [NamedOpetope.Term(self.b2), NamedOpetope.Term()])) + \
         NamedOpetope.Typing(
             NamedOpetope.Term(self.h),
             NamedOpetope.Type(
                 [NamedOpetope.Term(self.c2), NamedOpetope.Term()]))
     eqth = NamedOpetope.EquationalTheory() + \
         (self.b1, self.b2) + \
         (self.c1, self.c2) + \
         (self.h, self.i)
     self.sequent = NamedOpetope.Sequent(eqth, ctx, None)
     self.fg = self.sequent.graft(NamedOpetope.Term(self.g), self.b2,
                                  NamedOpetope.Term(self.f))
     self.gh = self.sequent.graft(NamedOpetope.Term(self.h), self.c2,
                                  NamedOpetope.Term(self.g))
     self.fgh1 = self.sequent.graft(self.gh, self.b2,
                                    NamedOpetope.Term(self.f))
     self.fgh2 = self.sequent.graft(NamedOpetope.Term(self.h), self.c2,
                                    self.fg)
 def test___init__(self):
     with self.assertRaises(DerivationError):
         NamedOpetope.Type([
             NamedOpetope.Term(NamedOpetope.Variable("α", 3)),
             NamedOpetope.Term(self.f),
             NamedOpetope.Term(self.a),
             NamedOpetope.Term()
         ])
     with self.assertRaises(DerivationError):
         NamedOpetope.Type([
             NamedOpetope.Term(self.alpha),
             NamedOpetope.Term(self.f),
             NamedOpetope.Term(NamedOpetope.Variable("a", 1)),
             NamedOpetope.Term()
         ])
     with self.assertRaises(DerivationError):
         NamedOpetope.Type([])
示例#7
0
def point(name: str) -> NamedOpetope.OCMT:
    """
    The :math:`\\textbf{OptSet${}^!_m$}` :math:`\\texttt{point}` rule.
    Introduces a :math:`0`-variable with name ``x``.
    """
    t = NamedOpetope.Typing(NamedOpetope.Term(NamedOpetope.Variable(name, 0)),
                            NamedOpetope.Type([NamedOpetope.Term()]))
    return NamedOpetope.OCMT(NamedOpetope.EquationalTheory(),
                             NamedOpetope.Context() + t)
 def setUp(self):
     self.term1 = NamedOpetope.Term(NamedOpetope.Variable("a", 0))
     self.term2 = NamedOpetope.Term(NamedOpetope.Variable("f", 1))
     self.term3 = NamedOpetope.Term(NamedOpetope.Variable("α", 2))
     self.term4 = NamedOpetope.Term(NamedOpetope.Variable("A", 3))
     self.typing1 = NamedOpetope.Type([NamedOpetope.Term()])
     self.typing2 = NamedOpetope.Type([self.term1, NamedOpetope.Term()])
     self.typing3 = NamedOpetope.Type(
         [self.term2, self.term1,
          NamedOpetope.Term()])
     self.typing4 = NamedOpetope.Type(
         [self.term3, self.term2, self.term1,
          NamedOpetope.Term()])
     self.ctx1 = NamedOpetope.Context()
     self.ctx2 = self.ctx1 + NamedOpetope.Typing(self.term1, self.typing1)
     self.ctx3 = self.ctx2 + NamedOpetope.Typing(self.term2, self.typing2)
     self.ctx4 = self.ctx3 + NamedOpetope.Typing(self.term3, self.typing3)
     self.ctx5 = self.ctx4 + NamedOpetope.Typing(self.term4, self.typing4)
 def test_degen(self):
     s = NamedOpetope.point("x")
     s = NamedOpetope.degen(s)
     self.assertEqual(
         s.typing.term,
         NamedOpetope.Term(NamedOpetope.Variable("x", 0), True))
     self.assertEqual(len(s.context), 1)
     with self.assertRaises(DerivationError):
         NamedOpetope.degen(s)
示例#10
0
 def setUp(self):
     self.a = NamedOpetope.Variable("a", 0)
     self.f = NamedOpetope.Variable("f", 1)
     self.alpha = NamedOpetope.Variable("α", 2)
     self.t0 = NamedOpetope.Type([NamedOpetope.Term()])
     self.t1 = NamedOpetope.Type(
         [NamedOpetope.Term(self.a),
          NamedOpetope.Term()])
     self.t2 = NamedOpetope.Type([
         NamedOpetope.Term(self.f),
         NamedOpetope.Term(self.a),
         NamedOpetope.Term()
     ])
     self.t3 = NamedOpetope.Type([
         NamedOpetope.Term(self.alpha),
         NamedOpetope.Term(self.f),
         NamedOpetope.Term(self.a),
         NamedOpetope.Term()
     ])
 def test_pd(self):
     s = NamedOpetopicSetM.point("x")
     with self.assertRaises(DerivationError):
         NamedOpetopicSetM.pd(s, "y")
     s = NamedOpetopicSetM.pd(s, "x")
     self.assertTrue(isinstance(s, NamedOpetope.Sequent))
     self.assertEqual(len(s.context), 1)
     self.assertEqual(len(s.theory.classes), 0)
     self.assertEqual(
         s.typing.term, NamedOpetope.Term(
             NamedOpetope.Variable("x", 0), False))
示例#12
0
 def setUp(self):
     self.w = NamedOpetope.Variable("w", 2)
     self.x = NamedOpetope.Variable("x", 2)
     self.y = NamedOpetope.Variable("y", 2)
     self.z = NamedOpetope.Variable("z", 2)
     self.a = NamedOpetope.Variable("a", 1)
     self.b = NamedOpetope.Variable("b", 1)
     self.c = NamedOpetope.Variable("c", 1)
     self.d = NamedOpetope.Variable("d", 1)
     self.e = NamedOpetope.Variable("e", 1)
     # t = w (a <- x, b <- y (c <- z, d <- _e_))
     self.tw = NamedOpetope.Term(self.w)
     self.tx = NamedOpetope.Term(self.x)
     self.ty = NamedOpetope.Term(self.y)
     self.tz = NamedOpetope.Term(self.z)
     self.ty[self.c] = self.tz
     self.ty[self.d] = NamedOpetope.Term(self.e, True)
     self.tw[self.a] = self.tx
     self.tw[self.b] = self.ty
示例#13
0
 def setUp(self):
     self.a0 = NamedOpetope.Variable("a", 0)
     self.b0 = NamedOpetope.Variable("b", 0)
     self.c0 = NamedOpetope.Variable("c", 0)
     self.d0 = NamedOpetope.Variable("d", 0)
     self.e0 = NamedOpetope.Variable("e", 0)
     self.a1 = NamedOpetope.Variable("a", 1)
     self.th1 = NamedOpetope.EquationalTheory()
     self.th2 = self.th1 + (self.a0, self.b0)
     self.th3 = self.th2 + (self.c0, self.d0)
     self.th4 = self.th3 + (self.c0, self.e0)
     self.th5 = self.th4 + (self.b0, self.a0)
     self.th6 = self.th5 + (self.a0, self.e0)
示例#14
0
 def test_typeOf(self):
     with self.assertRaises(DerivationError):
         self.ctx1.typeOf(NamedOpetope.Variable("a", 0))
     with self.assertRaises(DerivationError):
         self.ctx2.typeOf(NamedOpetope.Variable("b", 0))
     self.assertEqual(
         self.ctx5.typeOf(NamedOpetope.Variable("a", 0)).terms,
         self.typing1.terms)
     self.assertEqual(
         self.ctx5.typeOf(NamedOpetope.Variable("f", 1)).terms,
         self.typing2.terms)
     self.assertEqual(
         self.ctx5.typeOf(NamedOpetope.Variable("α", 2)).terms,
         self.typing3.terms)
     self.assertEqual(
         self.ctx5.typeOf(NamedOpetope.Variable("A", 3)).terms,
         self.typing4.terms)
示例#15
0
def shift(seq: NamedOpetope.Sequent, name: str) -> NamedOpetope.OCMT:
    """
    The :math:`\\textbf{OptSet${}^!_m$}` :math:`\\texttt{shift}` rule.
    Takes a sequent ``seq`` typing a term ``t`` and introduces
    a new variable ``x`` having ``t`` as :math:`1`-source.
    """
    n = seq.typing.term.dimension
    var = NamedOpetope.Variable(name, n + 1)
    if var in seq.context:
        raise DerivationError(
            "shift rule",
            "NamedOpetope.Variable {var} already typed in context",
            var=name)
    typing = NamedOpetope.Typing(
        NamedOpetope.Term(var),
        NamedOpetope.Type([seq.typing.term] + seq.typing.type.terms))
    res = NamedOpetope.OCMT(deepcopy(seq.theory),
                            deepcopy(seq.context) + typing)
    # targets of new variable
    for i in range(1, n + 2):
        res.context += NamedOpetope.Typing(
            NamedOpetope.Term(res.target(var, i)),
            NamedOpetope.Type(typing.type.terms[i:]))
    # additional theory
    termVar = seq.typing.term.variable
    if termVar is None:
        raise RuntimeError(
            "[shift rule] Premiss sequent types an invalid term. In valid "
            "proof trees, this should not happen")
    if seq.typing.term.degenerate:
        for i in range(n):
            res.theory += (res.target(var, i + 2), res.target(termVar, i))
    elif n >= 1:
        seq.theory += (res.target(var, 2), res.target(termVar))
        for gt in seq.typing.term.graftTuples():
            seq.theory += (res.target(gt[1]), gt[0])
    return res
 def test_repres(self):
     with self.assertRaises(DerivationError):
         NamedOpetopicSet.repres(
             NamedOpetope.Degen(NamedOpetope.Point("x")).eval())
     aseq = NamedOpetopicSet.repres(NamedOpetope.Arrow().eval())
     self.assertEqual(len(aseq.context), 3)
     self.assertEqual(len(aseq.theory.classes), 0)
     self.assertIn(NamedOpetope.Variable("a", 0), aseq.context)
     self.assertIn(NamedOpetope.Variable("tf", 0), aseq.context)
     self.assertIn(NamedOpetope.Variable("f", 1), aseq.context)
     i3seq = NamedOpetopicSet.repres(NamedOpetope.OpetopicInteger(3).eval())
     self.assertEqual(len(i3seq.context), 12)
     self.assertEqual(len(i3seq.theory.classes), 3)
     self.assertIn(NamedOpetope.Variable("a_1", 0), i3seq.context)
     self.assertIn(NamedOpetope.Variable("a_2", 0), i3seq.context)
     self.assertIn(NamedOpetope.Variable("a_3", 0), i3seq.context)
     self.assertIn(NamedOpetope.Variable("f_1", 1), i3seq.context)
     self.assertIn(NamedOpetope.Variable("f_2", 1), i3seq.context)
     self.assertIn(NamedOpetope.Variable("f_3", 1), i3seq.context)
     self.assertIn(NamedOpetope.Variable("A", 2), i3seq.context)
     self.assertTrue(
         i3seq.theory.equal(NamedOpetope.Variable("a_1", 0),
                            NamedOpetope.Variable("tf_2", 0)))
     self.assertTrue(
         i3seq.theory.equal(NamedOpetope.Variable("a_2", 0),
                            NamedOpetope.Variable("tf_3", 0)))
     self.assertTrue(
         i3seq.theory.equal(NamedOpetope.Variable("tf_1", 0),
                            NamedOpetope.Variable("ttA", 0)))
示例#17
0
 def test___init__(self):
     with self.assertRaises(DerivationError):
         NamedOpetope.Variable("x", -1)
     NamedOpetope.Variable("x", 0)
示例#18
0
 def setUp(self):
     self.a0 = NamedOpetope.Variable("a", 0)
     self.b0 = NamedOpetope.Variable("b", 0)
     self.c1 = NamedOpetope.Variable("c", 1)
     self.a1 = NamedOpetope.Variable("a", 1)
示例#19
0
 def test_source(self):
     with self.assertRaises(DerivationError):
         self.ctx5.source(NamedOpetope.Variable("A", 3), -1)
     with self.assertRaises(DerivationError):
         self.ctx5.source(NamedOpetope.Variable("A", 3), 5)
     self.assertEqual(self.ctx5.source(NamedOpetope.Variable("A", 3), 0),
                      NamedOpetope.Term(NamedOpetope.Variable("A", 3)))
     self.assertEqual(self.ctx5.source(NamedOpetope.Variable("A", 3), 1),
                      NamedOpetope.Term(NamedOpetope.Variable("α", 2)))
     self.assertEqual(self.ctx5.source(NamedOpetope.Variable("A", 3), 2),
                      NamedOpetope.Term(NamedOpetope.Variable("f", 1)))
     self.assertEqual(self.ctx5.source(NamedOpetope.Variable("A", 3), 3),
                      NamedOpetope.Term(NamedOpetope.Variable("a", 0)))
     self.assertEqual(self.ctx5.source(NamedOpetope.Variable("A", 3), 4),
                      NamedOpetope.Term())
示例#20
0
 def test_point(self):
     s = NamedOpetope.point("x")
     self.assertEqual(s.typing.term,
                      NamedOpetope.Term(NamedOpetope.Variable("x", 0)))
     self.assertEqual(len(s.context), 1)