annotate bdtstd.pl @ 4:029b5a5ac494

*** empty log message ***
author kono
date Fri, 19 Jan 2001 02:03:27 +0900
parents 1c57a78f1d98
children 07d6c4c5654b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
1 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
2 /*
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
3 Copyright (C) 1991, Shinji Kono, Sony Computer Science Laboratory, Inc.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
4 The University, Newcastle upton Tyne
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
5
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
6 Everyone is permitted to copy and distribute verbatim copies
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
7 of this license, but changing it is not allowed. You can also
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
8 use this wording to make the terms for other programs.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
9
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
10 send your comments to kono@csl.sony.co.jp
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
11 $Id$
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
12 */
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
13 % ITL subterm standarization with BDT
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
14 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
15 % Fri Jun 21 10:32:58 BST 1991
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
16 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
17 % a standard form of ITL, based on subterm classification
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
18 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
19 %
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
20 subterm_init :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
21 abolish(sb,2),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
22 asserta((sb([],-1))),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
23 abolish(sbn,1),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
24 asserta(sbn(0)).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
25
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
26 std_check(I,J) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
27 sb(I,J),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
28 std_check(I,N1) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
29 retract(sbn(N)),N1 is N+1,asserta(sbn(N1)),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
30 assertz(sb(I,N1)),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
31
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
32 itlstd(P,List) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
33 sbdt(P,List).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
34
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
35 % BDT classification of subterm
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
36
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
37 sbdt(true,true):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
38 sbdt(false,false):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
39 sbdt(P,F) :- atomic(P),!,F= ?(P,true,false).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
40 sbdt(?(C,T,F),?(C,T,F)) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
41 sbdt(not(P),F) :- !,sbdt(P,F0),sbdt_not(F0,F),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
42 sbdt_not(true,false).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
43 sbdt_not(false,true).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
44 sbdt_not(F,?(H,A1,B1)):-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
45 arg(1,F,H),arg(2,F,A),arg(3,F,B),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
46 sbdt_not(A,A1),sbdt_not(B,B1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
47 sbdt((P,Q),F) :- !,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
48 sbdt(P,P0),sbdt(Q,Q0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
49 sbdt_and(P0,Q0,F),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
50 sbdt_and(false,_,false):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
51 sbdt_and(_,false,false):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
52 sbdt_and(true,T,T):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
53 sbdt_and(T,true,T):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
54 sbdt_and(P,Q,R) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
55 arg(1,P,PF),arg(1,Q,QF),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
56 sbdt_and(PF,QF,P,Q,R).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
57 sbdt_and(PF,QF,P,Q,R):-PF @< QF,!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
58 sbdt_and(QF,PF,Q,P,R).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
59 sbdt_and(PF,QF,P,Q,?(QF,R0,R1)):-PF @> QF,!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
60 arg(2,Q,Q0),arg(3,Q,Q1),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
61 sbdt_and(Q0,P,R0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
62 sbdt_and(Q1,P,R1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
63 sbdt_and(PF,PF,P,Q,?(PF,R0,R1)):-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
64 arg(2,P,P0),arg(3,P,P1),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
65 arg(2,Q,Q0),arg(3,Q,Q1),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
66 sbdt_and(P0,Q0,R0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
67 sbdt_and(P1,Q1,R1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
68 sbdt((P;Q),F) :- !,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
69 sbdt(P,P0),sbdt(Q,Q0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
70 sbdt_or(P0,Q0,F),!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
71 sbdt_or(true,_,true):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
72 sbdt_or(_,true,true):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
73 sbdt_or(false,T,T):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
74 sbdt_or(T,false,T):-!.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
75 sbdt_or(P,Q,R) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
76 arg(1,P,PF),arg(1,Q,QF),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
77 sbdt_or(PF,QF,P,Q,R).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
78 sbdt_or(PF,QF,P,Q,R):-PF @< QF,!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
79 sbdt_or(QF,PF,Q,P,R).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
80 sbdt_or(PF,QF,P,Q,?(QF,R0,R1)):-PF @> QF,!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
81 arg(2,Q,Q0),arg(3,Q,Q1),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
82 sbdt_or(Q0,P,R0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
83 sbdt_or(Q1,P,R1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
84 sbdt_or(PF,PF,P,Q,?(PF,R0,R1)):-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
85 arg(2,P,P0),arg(3,P,P1),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
86 arg(2,Q,Q0),arg(3,Q,Q1),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
87 sbdt_or(P0,Q0,R0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
88 sbdt_or(P1,Q1,R1).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
89 sbdt((P&Q), ?(N,true,false)) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
90 sbdt(P,P1),sbdt(Q,Q1), % projection touch later part of chop
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
91 std_check((P1&Q1),N).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
92 %sbdt(@(Q), ?(N,true,false)) :-!, % Don't check next part now
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
93 % std_check(@(Q),N). % this makes everything very slow
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
94 %sbdt(*(Q), ?(N,true,false)) :-!, % Don't check next part now
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
95 % std_check(*(Q),N). % this makes everything very slow
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
96 %sbdt(free_fin(Q), ?(N,true,false)) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
97 % std_check(free_fin(Q),N).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
98 % bottom up development is effective for quantifier
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
99 sbdt(exists(P,Q), ?(N,true,false)) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
100 sbdt(Q,QF),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
101 std_check(exists(P,QF),N).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
102 sbdt(proj(P,Q), ?(N,true,false)) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
103 sbdt(Q,QF), % P part is fixed
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
104 std_check(proj(P,QF),N).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
105 sbdt(prefix(P), ?(N,true,false)) :-!,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
106 sbdt(P,PF), % P part is fixed
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
107 std_check(prefix(PF),N).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
108 % Simple Functor including Regular variable and state
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
109 sbdt(Func,F) :- functor(Func,_,1),!,F= ?(N,true,false),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
110 std_check(Func,N).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
111 sbdt(Func,F) :- functor(Func,_,2),!,F= ?(N,true,false),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
112 std_check(Func,N).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
113 sbdt(Def,true) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
114 write('bdtstd error: '),write(Def),nl.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
115
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
116 sbterm :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
117 listing(sb/2),listing(itl_state/2).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
118
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
119
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
120 bdt2itl(B,F) :- number(B),!,sb(F0,B),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
121 bdt2itl(F0,F).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
122 bdt2itl(?(IF,THEN,ELSE),F) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
123 bdt2itl(IF,IF0),bdt2itl(THEN,THEN0),bdt2itl(ELSE,ELSE0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
124 bdt2itl_opt(IF0,THEN0,ELSE0,F).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
125 % little more readable representation
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
126 bdt2itl_opt(IF,true,false,IF) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
127 bdt2itl_opt(IF,false,true,not(IF)) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
128 bdt2itl_opt(IF,true,ELSE,(IF;ELSE)) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
129 bdt2itl_opt(IF,THEN,false,(IF,THEN)) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
130 bdt2itl_opt(IF,false,ELSE,(not(IF);ELSE)) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
131 bdt2itl_opt(IF,THEN,true,(not(IF),THEN)) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
132 bdt2itl_opt(IF,THEN,ELSE,?(IF,THEN,ELSE)) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
133 bdt2itl(B,F) :- atom(B),!,F=B.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
134 bdt2itl(B,F) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
135 functor(B,H,N),functor(F,H,N),bdt2itl_subterm(N,N,B,F).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
136 bdt2itl_subterm(0,_,_,_) :- !.
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
137 bdt2itl_subterm(N,N1,F,F0) :-
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
138 N0 is N-1,
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
139 arg(N,F,A),arg(N,F0,A0),
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
140 bdt2itl(A,A0),bdt2itl_subterm(N0,N1,F,F0).
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
141
1c57a78f1d98 Initial revision
kono
parents:
diff changeset
142 % BDT end %