| 1 | ================================================================ |
|---|
| 2 | Logtalk - Open source object-oriented logic programming language |
|---|
| 3 | Release 2.35.0 |
|---|
| 4 | |
|---|
| 5 | Copyright (c) 1998-2009 Paulo Moura. All Rights Reserved. |
|---|
| 6 | Logtalk is free software. You can redistribute it and/or modify |
|---|
| 7 | it under the terms of the "Artistic License 2.0" as published by |
|---|
| 8 | The Perl Foundation. Consult the "LICENSE.txt" file for details. |
|---|
| 9 | ================================================================ |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | % start by loading the example: |
|---|
| 13 | |
|---|
| 14 | | ?- logtalk_load(logic(loader)). |
|---|
| 15 | ... |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | % translate a single logic proposition: |
|---|
| 19 | |
|---|
| 20 | | ?- translator::translate((p v ~q) => (r & k), Cs). |
|---|
| 21 | r :- p. |
|---|
| 22 | k :- p. |
|---|
| 23 | q; r :- . |
|---|
| 24 | q; k :- . |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | Cs = [cl([r],[p]),cl([k],[p]),cl([q,r],[]),cl([q,k],[])] |
|---|
| 28 | yes |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | % translate a single logic proposition printing each translation step: |
|---|
| 32 | |
|---|
| 33 | | ?- translator::step_by_step((p v ~q) => (r & k), Cs). |
|---|
| 34 | |
|---|
| 35 | Processing proposition: p v ~q=>r&k |
|---|
| 36 | |
|---|
| 37 | 1. Remove implications: ~ (p v ~q) v r&k |
|---|
| 38 | 2. Distribute negation: ~p&q v r&k |
|---|
| 39 | 3. Remove existential quantifiers: ~p&q v r&k |
|---|
| 40 | 4. Convert to prenex normal form: ~p&q v r&k |
|---|
| 41 | 5. Remove universal quantifiers: ~p&q v r&k |
|---|
| 42 | 6. Convert to conjunctive normal form: (~p v r)&(~p v k)&((q v r)&(q v k)) |
|---|
| 43 | 7. Convert to clauses: [cl([r],[p]),cl([k],[p]),cl([q,r],[]),cl([q,k],[])] |
|---|
| 44 | |
|---|
| 45 | Clauses in Prolog-like notation: |
|---|
| 46 | r :- p. |
|---|
| 47 | k :- p. |
|---|
| 48 | q; r :- . |
|---|
| 49 | q; k :- . |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | Cs = [cl([r],[p]),cl([k],[p]),cl([q,r],[]),cl([q,k],[])] |
|---|
| 53 | yes |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | % translate a single logic proposition printing each translation step: |
|---|
| 57 | |
|---|
| 58 | | ?- translator::step_by_step(all(X, exists(Y, p(X) v ~q(X) => r(X, Y))), Cs). |
|---|
| 59 | |
|---|
| 60 | Processing proposition: all(X, exists(Y, p(X)v~q(X)=>r(X, Y))) |
|---|
| 61 | |
|---|
| 62 | 1. Remove implications: all(X, exists(Y, ~ (p(X)v~q(X))v r(X, Y))) |
|---|
| 63 | 2. Distribute negation: all(X, exists(Y, ~p(X)&q(X)v r(X, Y))) |
|---|
| 64 | 3. Remove existential quantifiers: all(X, ~p(X)&q(X)v r(X, f1(X))) |
|---|
| 65 | 4. Convert to prenex normal form: all(X, ~p(X)&q(X)v r(X, f1(X))) |
|---|
| 66 | 5. Remove universal quantifiers: ~p(X)&q(X)v r(X, f1(X)) |
|---|
| 67 | 6. Convert to conjunctive normal form: (~p(X)v r(X, f1(X)))& (q(X)v r(X, f1(X))) |
|---|
| 68 | 7. Convert to clauses: [cl([r(X, f1(X))], [p(X)]), cl([q(X), r(X, f1(X))], [])] |
|---|
| 69 | |
|---|
| 70 | Clauses in Prolog-like notation: |
|---|
| 71 | r(X, f1(X)) :- p(X). |
|---|
| 72 | q(X); r(X, f1(X)) :- . |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | X = X |
|---|
| 76 | Y = f1(X) |
|---|
| 77 | Cs = [cl([r(X, f1(X))], [p(X)]), cl([q(X), r(X, f1(X))], [])] |
|---|
| 78 | yes |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | % translate a single logic proposition printing each translation step: |
|---|
| 82 | |
|---|
| 83 | | ?- translator::step_by_step(all(X, men(X) => mortal(X)), Cs). |
|---|
| 84 | |
|---|
| 85 | Processing proposition: all(X, men(X)=>mortal(X)) |
|---|
| 86 | |
|---|
| 87 | 1. Remove implications: all(X, ~men(X)v mortal(X)) |
|---|
| 88 | 2. Distribute negation: all(X, ~men(X)v mortal(X)) |
|---|
| 89 | 3. Remove existential quantifiers: all(X, ~men(X)v mortal(X)) |
|---|
| 90 | 4. Convert to prenex normal form: all(X, ~men(X)v mortal(X)) |
|---|
| 91 | 5. Remove universal quantifiers: ~men(X)v mortal(X) |
|---|
| 92 | 6. Convert to conjunctive normal form: ~men(X)v mortal(X) |
|---|
| 93 | 7. Convert to clauses: [cl([mortal(X)], [men(X)])] |
|---|
| 94 | |
|---|
| 95 | Clauses in Prolog-like notation: |
|---|
| 96 | mortal(X) :- men(X). |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | X = X |
|---|
| 100 | Cs = [cl([mortal(X)], [men(X)])] |
|---|
| 101 | yes |
|---|