Skip to content

Commit

Permalink
Add two more keys for the MonteCarlo Lock puzzle.
Browse files Browse the repository at this point in the history
  • Loading branch information
massimo-nocentini committed Jun 13, 2017
1 parent 043d36f commit 02c360d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
13 changes: 13 additions & 0 deletions docs/source/primer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ grandfather toy example:
>>> run(fresh(lambda rel, p, s: grand_father(p, s) & unify([p, s], rel)))
[['paul', 'tom'], ['jason', 'peter'], ['tom', 'brian']]

Introducing guided search:

.. doctest::

>>> def recuro(e):
... return fresh(lambda a, b: conde([unify(e, ['x']), succeed],
... [unify(e, ['b']+a), recuro(a)],
... [unify(e, ['a']+b), recuro(b)]))
...
>>> run(fresh(recuro), n=5)
[['x'], ['b', 'x'], ['b', 'b', 'x'], ['b', 'b', 'b', 'x'], ['b', 'b', 'b', 'b', 'x']]



η-inversion
~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion src/mclock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def machine(*, rules):
def M(α, β):
return condi(*[[r(α, β, machine=M), succeed] for r in rules])
return condi(*[[r(α, β, machine=M), succeed] for r in rules], dovetail=True)
return M

def nullo(l):
Expand Down
11 changes: 7 additions & 4 deletions src/mclock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,13 @@ def test_fergusson_law_chapter(self):
unify([χ, ψ], out))), n=1), []) # 6

def test_the_key_chapter(self):
self.assertEqual(run(fresh(lambda α: mcculloch___o(α, α)), n=3),
[[5, 4, 6, 4, 2, 5, 4, 6, 4, 2],
[4, 5, 6, 4, 2, 4, 5, 6, 4, 2],
[5, 4, 4, 4, 6, 4, 2, 5, 4, 4, 4, 6, 4, 2]]) # the keys!!!
with recursion_limit(100000):
self.assertEqual(run(fresh(lambda α: mcculloch___o(α, α)), n=5),
[[5, 4, 6, 4, 2, 5, 4, 6, 4, 2],
[4, 5, 6, 4, 2, 4, 5, 6, 4, 2],
[5, 4, 4, 4, 6, 4, 2, 5, 4, 4, 4, 6, 4, 2],
[4, 6, 5, 4, 2, 4, 6, 5, 4, 2, 2],
[5, 4, 6, 4, 4, 4, 2, 5, 4, 6, 4, 4, 4, 2]]) # the keys!!!



Expand Down

0 comments on commit 02c360d

Please sign in to comment.