root/trunk/examples/logic/SCRIPT.txt

Revision 4662, 2.9 KB (checked in by pmoura, 5 days ago)

Updated copyright notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1================================================================
2Logtalk - Open source object-oriented logic programming language
3Release 2.35.0
4
5Copyright (c) 1998-2009 Paulo Moura.        All Rights Reserved.
6Logtalk is free software.  You can redistribute it and/or modify
7it under the terms of the "Artistic License 2.0" as published by
8The 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).
21r :- p.
22k :- p.
23q; r :- .
24q; k :- .
25
26
27Cs = [cl([r],[p]),cl([k],[p]),cl([q,r],[]),cl([q,k],[])]
28yes
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
35Processing 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
45Clauses in Prolog-like notation:
46r :- p.
47k :- p.
48q; r :- .
49q; k :- .
50
51
52Cs = [cl([r],[p]),cl([k],[p]),cl([q,r],[]),cl([q,k],[])]
53yes
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
60Processing 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
70Clauses in Prolog-like notation:
71r(X, f1(X)) :- p(X).
72q(X); r(X, f1(X)) :- .
73
74
75X = X
76Y = f1(X)
77Cs = [cl([r(X, f1(X))], [p(X)]), cl([q(X), r(X, f1(X))], [])]
78yes
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
85Processing 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
95Clauses in Prolog-like notation:
96mortal(X) :- men(X).
97
98
99X = X
100Cs = [cl([mortal(X)], [men(X)])]
101yes
Note: See TracBrowser for help on using the browser.