def test_generic_sort(self): sort = Sort('sort') sort.operation('op_generic', (GenericSort(), )) sort2 = Sort('sort2') sort2.variable('x') t = sort.op_generic(sort2.x()) self.assertEqual(type(t), Term) self.assertEqual(t.args[0].sort, sort2)
def test_generic_sort(self): generic = GenericSort() generic.variable('x') sort = Sort('sort') sort.operation('op_gen', (generic, generic)) sort.operation('const', ()) sort2 = Sort('sort2') sort2.operation('const', ()) r = RewriteRule(sort.op_gen(generic.x(), generic.x()), generic.x()) t1 = r.apply(sort.op_gen(sort2.const(), sort2.const())) self.assertEqual(t1, sort2.const()) t2 = r.apply(sort.op_gen(sort2.const(), sort.const())) self.assertEqual(t2, sort.op_gen(sort2.const(), sort.const()))
""" Adt for the Map Sort. """ # Aurelien Coet, 2018. from alpyne.adt import Sort, GenericSort from alpyne.adts.boolean import boolean # Sort Definition. kv_map = Sort('map') generic = GenericSort() # ---------- Operations on maps ---------- # # Generators. kv_map.operation('empty', ()) kv_map.operation('add', (kv_map, generic, generic)) # Observers. kv_map.operation('get', (kv_map, generic)) kv_map.operation('isempty', (kv_map, ), boolean) # Modifiers. kv_map.operation('delete', (kv_map, generic)) # Operations for the generic sort. generic.operation('equal', (generic, generic)) # ---------- Variables ---------- # kv_map.variable('m') kv_map.variable('n')
def test_variable(self): generic = GenericSort() generic.variable('x') self.assertEqual(type(generic.x), Variable) self.assertEqual(type(generic.x()), Term)
def test_str_representation(self): self.assertEqual(str(GenericSort()), "anysort")
# ---------- Variables ---------- # boolean.variable('b') boolean.variable('c') # ---------- Rewrite rules ---------- # # not(true) -> false. boolean.rewrite_rule(boolean.not_(boolean.true()), boolean.false()) # not(false) -> true. boolean.rewrite_rule(boolean.not_(boolean.false()), boolean.true()) # and(b, false) -> false. boolean.rewrite_rule(boolean.and_(boolean.b(), boolean.false()), boolean.false()) # and(b, true) -> b. boolean.rewrite_rule(boolean.and_(boolean.b(), boolean.true()), boolean.b()) # or(b, false) -> b. boolean.rewrite_rule(boolean.or_(boolean.b(), boolean.false()), boolean.b()) # or(b, true) -> true. boolean.rewrite_rule(boolean.or_(boolean.b(), boolean.true()), boolean.true()) generic = GenericSort() generic.operation('equal', (generic, generic)) boolean.rewrite_rule(generic.equal(boolean.b(), boolean.c()), boolean.equal(boolean.b(), boolean.c()))
# equal(empty, append(s, c)) -> false. string.rewrite_rule( string.equal(string.empty(), string.append(string.s(), char.c1())), boolean.false()) # equal(append(s, c), empty) -> false. string.rewrite_rule( string.equal(string.append(string.s(), char.c1()), string.empty()), boolean.false()) # equal(append(s, c), append(t, c)) -> equal(s, t). string.rewrite_rule( string.equal(string.append(string.s(), char.c1()), string.append(string.t(), char.c1())), string.equal(string.s(), string.t())) # equal(c, d) == false => equal(append(s, c), append(t, d)) -> false. string.rewrite_rule( string.equal(string.append(string.s(), char.c1()), string.append(string.t(), char.c2())), boolean.false(), [(char.equal(char.c1(), char.c2()), boolean.false())]) generic = GenericSort() generic.operation('equal', (generic, generic)) string.rewrite_rule(generic.equal(string.s(), string.t()), string.equal(string.s(), string.t())) # TODO: concat rewrite rules.