]>
Witch of Git - mukan/blob - src/main.rs
1 use mukan
::{all
, and
, call_fresh
, delay
, eq
, fresh
, or
, reify
, reify_vars
, Goal
, State
, Term
};
5 let term
= call_fresh(|a
| call_fresh(move |b
| or(and(eq(a
, b
), eq(a
, 1)), eq(b
, 2))));
6 for soln
in term
.search(State
::new()) {
7 println
!("{:?}", reify(soln
));
11 let term
= fresh
!((p
, a
, b
, c
, d
) => {
19 for soln
in term
.search(State
::new()) {
20 println
!("{:?}", reify(soln
));
24 let term
= fresh
!((a
, b
) => eq(a
, b
));
25 for soln
in term
.search(State
::new()) {
26 println
!("{:?}", reify(soln
));
30 fn peano(n
: impl Into
<Term
>) -> impl Goal
+ Clone
{
34 fresh
!((r
) => and(eq(n
.clone(), (1, r
)), delay(move || peano(r
)))),
37 let term
= fresh
!((n
) => peano(n
));
38 for soln
in term
.search(State
::new()).take(5) {
39 println
!("{:?}", reify(soln
));
42 fn make_nat(n
: u32) -> Term
{
46 (1, make_nat(n
- 1)).into
()
50 fn less(n
: impl Into
<Term
>, m
: impl Into
<Term
>) -> impl Goal
+ Clone
{
54 eq((1, n
.clone()), m
.clone()),
56 eq(m
.clone(), (1, x
)),
59 delay(move || less(n
.clone(), x
.clone()))
65 fn sums_to(n
: impl Into
<Term
>, m
: impl Into
<Term
>, s
: impl Into
<Term
>) -> impl Goal
+ Clone
{
70 and(eq(n
.clone(), 0), eq(m
.clone(), s
.clone())),
72 eq(n
.clone(), (1, x
)),
77 less(m
.clone(), s
.clone()),
78 sums_to(x
, (1, m
.clone()), s
.clone()),
85 println
!("Peano addition!");
86 let (vars
, state
) = State
::with_vars(2);
87 let term
= sums_to(vars
[0], vars
[1], make_nat(10));
88 for soln
in term
.search(state
) {
89 println
!("= {:?}", reify_vars(&vars
, soln
));