Exemplo n.º 1
0
 def apply(self, r: RewriteRule):
     """Apply a rewrite rule to the current step."""
     if not isinstance(r, RewriteRule):
         raise ValueError("apply must be given a RewriteRule")
     x_new = r.apply(self.premise)
     if x_new is None:
         return
     self.current_step = x_new
     self.steps.append(r)
     return x_new
Exemplo n.º 2
0
#!/usr/bin/env python3
from symcollab.algebra import Constant, Function, Variable
from symcollab.rewrite import RewriteRule

a = Constant("a")
b = Constant("b")
c = Constant("c")
x = Variable("x")
y = Variable("y")
f = Function("f", 2)
g = Function("g", 2)

r = RewriteRule(f(y, g(x, a)), g(y, a))

term = f(b, g(c, a))
print("Applying " + str(r) + " to " + str(term))
print("Result:", r.apply(term))

print("Now to show what happens when you can't apply a term...")
term = f(a, b)
print("Applying " + str(r) + " to " + str(term))
print("Result:", r.apply(term))

print("Applying f(x, x) -> x to f(f(x, x), f(x, x))")
term = f(f(x, x), f(x, x))
r = RewriteRule(f(x, x), x)
print("Result:", r.apply(term))

print("Applying f(x, x) -> x to f(f(x, x), f(x,x)) at position 2")
print("Result:", r.apply(term, '2'))