From d60e2a736b3a227351f4d02b47d695ec3eaad79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sun, 22 Apr 2018 22:26:17 +0200 Subject: [PATCH] Update examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This updates the examples to showcase the scope of anthem’s feature set. New examples are added concerning placeholders, hiding predicates, and simplifications related to integer variables. --- examples/choice-rules.lp | 2 ++ examples/graph-coloring.lp | 20 ++++++++++++++------ examples/letters.lp | 11 +++++++++++ examples/permutations.lp | 4 ++-- examples/schur-numbers.lp | 4 ++-- examples/simple-external-show.lp | 9 +++++++++ examples/simple-external.lp | 5 +++++ 7 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 examples/choice-rules.lp create mode 100644 examples/letters.lp create mode 100644 examples/simple-external-show.lp create mode 100644 examples/simple-external.lp diff --git a/examples/choice-rules.lp b/examples/choice-rules.lp new file mode 100644 index 0000000..7cba339 --- /dev/null +++ b/examples/choice-rules.lp @@ -0,0 +1,2 @@ +p(a). +{q(a)}. diff --git a/examples/graph-coloring.lp b/examples/graph-coloring.lp index 53fef3b..670e8b5 100644 --- a/examples/graph-coloring.lp +++ b/examples/graph-coloring.lp @@ -1,10 +1,18 @@ -#external color(1). -#external edge(2). -#external vertex(1). -#show color/2. - +% assign a set of colors to each vertex {color(V, C)} :- vertex(V), color(C). + +% at most one color per vertex +:- color(V, C1), color(V, C2), C1 != C2. + +% at least one color per vertex covered(V) :- color(V, _). :- vertex(V), not covered(V). + +% adjacent vertices don’t share the same color :- color(V1, C), color(V2, C), edge(V1, V2). -:- color(V, C1), color(V, C2), C1 != C2. + +#show color/2. + +#external vertex(1). +#external edge(2). +#external color(1). diff --git a/examples/letters.lp b/examples/letters.lp new file mode 100644 index 0000000..6dc4e14 --- /dev/null +++ b/examples/letters.lp @@ -0,0 +1,11 @@ +letter(a). +letter(b). +letter(c). + +{p(1..3, Y)} :- letter(Y). +:- p(X1, Y), p(X2, Y), X1 != X2. + +q(X) :- p(X, _). +:- X = 1..3, not q(X). + +#show p/2. diff --git a/examples/permutations.lp b/examples/permutations.lp index 844d6e0..ac911b4 100644 --- a/examples/permutations.lp +++ b/examples/permutations.lp @@ -1,3 +1,5 @@ +#show p/2. + {p(1..n, 1..n)}. :- p(X, Y1), p(X, Y2), Y1 != Y2. @@ -8,5 +10,3 @@ q2(Y) :- p(_, Y). :- not q1(X), X = 1..n. :- not q2(Y), Y = 1..n. - -#show p/2. diff --git a/examples/schur-numbers.lp b/examples/schur-numbers.lp index cdbbca9..5c4e63a 100644 --- a/examples/schur-numbers.lp +++ b/examples/schur-numbers.lp @@ -1,7 +1,7 @@ +#show in/2. + {in(1..n, 1..r)}. covered(I) :- in(I, S). :- I = 1..n, not covered(I). :- in(I, S), in(J, S), in(I + J, S). - -#show in/2. diff --git a/examples/simple-external-show.lp b/examples/simple-external-show.lp new file mode 100644 index 0000000..3739bb2 --- /dev/null +++ b/examples/simple-external-show.lp @@ -0,0 +1,9 @@ +s(X) :- p(X). +s(X) :- q(X). +u(X) :- r(X), not s(X). + +#show u/1. + +#external p(1). +#external q(1). +#external r(1). diff --git a/examples/simple-external.lp b/examples/simple-external.lp new file mode 100644 index 0000000..ed9a3dd --- /dev/null +++ b/examples/simple-external.lp @@ -0,0 +1,5 @@ +s(X) :- p(X). +s(X) :- q(X). + +#external p(1). +#external q(1).