Exemple #1
0
# ---------- 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()))
Exemple #2
0
kv_map.rewrite_rule(
    kv_map.add(kv_map.add(kv_map.m(), generic.k(), generic.v()), generic.k(),
               generic.w()),
    # ->
    kv_map.add(kv_map.m(), generic.k(), generic.w()))

# equal(k, l) == false and isempty(m) == false
# => add(add(m, k, v), l, w) -> add(add(m, l, w), k, v).
kv_map.rewrite_rule(
    kv_map.add(kv_map.add(kv_map.m(), generic.k(), generic.v()), generic.l(),
               generic.w()),
    # ->
    kv_map.add(kv_map.add(kv_map.m(), generic.l(), generic.w()), generic.k(),
               generic.v()),
    # Conditions:
    [(generic.equal(generic.k(), generic.l()), boolean.false()),
     (kv_map.isempty(kv_map.m()), boolean.false())])

# get(add(m, k, v), k) -> v.
kv_map.rewrite_rule(
    kv_map.get(kv_map.add(kv_map.m(), generic.k(), generic.v()), generic.k()),
    # ->
    generic.v())

# equal(k, l) == false and isempty(m) == false
# => get(add(m, k, v), l) -> get(m, l).
kv_map.rewrite_rule(
    kv_map.get(kv_map.add(kv_map.m(), generic.k(), generic.v()), generic.l()),
    # ->
    kv_map.get(kv_map.m(), generic.l()),
    # Conditions:
Exemple #3
0
# 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.