def __mul__(self, other): d = Application(multiplication, self) d = Application(d, other) d = d.fullreduce() dummy = lambnumber(0) dummy.head = d.head dummy.body = d.body dummy.number = self.number * other.number return dummy
# this implements ((λx.((λq.q) (λi.x)) (λu.z)), should print to (λi.(λu.z)) print( "------------------------- complicated example (application as body of abstraction)" ) VB1abs = Abstraction(q, q) VB2abs = Abstraction(i, x) VB3abs = absuz VB1app = Application(VB1abs, VB2abs) VB4abs = Abstraction(x, VB1app) VB2app = Application(VB4abs, VB3abs) print(VB2app) print(VB2app.fullreduce()) # (reduced twice) print("------------------------- abstraction reduce") print(VB4abs) print(VB4abs.reduce()) print("-------------------------") print("Alpha-Conversion") print("------------------------- ") print("------------------------- identity") print(identity) print(identity.alphaconv([identity.head, z])) # the following implements ((λx.λy.x) y), this should be reduced to (λz.y) or some other variable than z (but not y) print("------------------------- exception")