@@ -0,0 +1,1024 @@
+# strategy.py - Strategies for producing arguments to model commands%0A# author: Ben Simner %0A%0Afrom strategy import *%0A%0Aclass Nat:%0A    def __init__(self, suc):%0A        self.suc = suc%0A%0A    def __repr__(self):%0A        if self.suc == None:%0A            return 'Z'%0A        else:%0A            return repr(self.suc) + '+'%0A%0A    def to_int(self):%0A        if self == Z:%0A            return 0%0A        return 1 + self.suc.to_int()%0A%0A    @staticmethod%0A    def from_int(i):%0A        if i == 0:%0A            return Z%0A        else:%0A            return S(Nat.from_int(i - 1))%0A%0AZ = Nat(None)%0AS = lambda n: Nat(n)%0A%0Aclass NatS(Strategy%5BNat%5D):%0A    def generate(depth, partial=0):%0A        k = Nat.from_int(partial)%0A        yield partial+1, %5Bk%5D%0A%0A@map_strategy(int, Strategy%5BNat%5D)%0Adef IntStrat(nat):%0A    def nat_to_int(n):%0A        if n.suc is None:%0A            return 0%0A        return 1 + nat_to_int(n.suc)%0A%0A    yield nat_to_int(nat)%0A    yield - nat_to_int(nat)%0A%0A# generat partial = generate(int, ...)%0Aprint(list(values(Nat, 5)))%0Aprint(list(values(int, 3)))%0A

Add example: Natural numbers