Example #1
0
 def test_reduce(self):
     sort = Sort('sort')
     sort.operation('const', ())
     sort.operation('reduce', (sort, ))
     sort.operation('merge', (sort, sort))
     sort.variable('x')
     sort.rewrite_rule(sort.reduce(sort.x()), sort.x())
     sort.rewrite_rule(sort.merge(sort.x(), sort.x()),
                       sort.reduce(sort.x()))
     t = sort.reduce(sort.merge(sort.reduce(sort.const()), sort.const()))
     t2 = t.reduce(sort.rewrite_rules)
     self.assertEqual(t2, sort.const())
Example #2
0
# ---------- Variables ---------- #
kv_map.variable('m')
kv_map.variable('n')

# Generic variables for map keys.
generic.variable('k')
generic.variable('l')

# Generic variables for map values.
generic.variable('v')
generic.variable('w')

# ---------- Rewrite rules ---------- #
# isempty(empty) -> true.
kv_map.rewrite_rule(
    kv_map.isempty(kv_map.empty()),
    # ->
    boolean.true())

# isempty(empty, add(m, k, v)) -> false.
kv_map.rewrite_rule(
    kv_map.isempty(kv_map.add(kv_map.m(), generic.k(), generic.v())),
    # ->
    boolean.false())

# add(add(m, k, v), k, w) -> add(m, k, w).
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()))
Example #3
0
# Modifiers.
boolean.operation('not_', (boolean, ))
boolean.operation('and_', (boolean, boolean))
boolean.operation('or_', (boolean, boolean))

# Observers.
boolean.operation('equal', (boolean, boolean))

# ---------- 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.
Example #4
0
    if i < 26:
        c_upper = c.upper()
    else:
        c_upper = None

    for j, c2 in enumerate(chars):
        if j < 26:
            c2_upper = c2.upper()
        else:
            c2_upper = None

        if c == c2:
            rhs = boolean.true()
        else:
            rhs = boolean.false()
        char.rewrite_rule(char.equal(char.__dict__[c](), char.__dict__[c2]()),
                          rhs)

        if c_upper:
            if c_upper == c2:
                rhs = boolean.true()
            else:
                rhs = boolean.false()
            char.rewrite_rule(
                char.equal(char.__dict__[c_upper](), char.__dict__[c2]()), rhs)

        if c2_upper:
            if c == c2_upper:
                rhs = boolean.true()
            else:
                rhs = boolean.false()
            char.rewrite_rule(