-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphaConversion.pl
108 lines (82 loc) · 3.36 KB
/
alphaConversion.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*************************************************************************
File: alphaConversion.pl
Copyright (C) 2004,2005,2006 Patrick Blackburn & Johan Bos
This file is part of BB1, version 1.3 (November 2006).
BB1 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
BB1 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with BB1; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*************************************************************************/
:- module(alphaConversion,[alphaConvert/2,
alphabeticVariants/2]).
:- use_module(comsemPredicates,[compose/3,
memberList/2]).
/*========================================================================
Alpha Conversion (introducing substitutions)
========================================================================*/
alphaConvert(F1,F2):-
alphaConvert(F1,[],[]-_,F2).
/*========================================================================
Alpha Conversion
========================================================================*/
alphaConvert(X,Sub,Free1-Free2,Y):-
var(X),
(
memberList(sub(Z,Y),Sub),
X==Z, !,
Free2=Free1
;
Y=X,
Free2=[X|Free1]
).
alphaConvert(Expression,Sub,Free1-Free2,some(Y,F2)):-
nonvar(Expression),
Expression = some(X,F1),
alphaConvert(F1,[sub(X,Y)|Sub],Free1-Free2,F2).
alphaConvert(Expression,Sub,Free1-Free2,all(Y,F2)):-
nonvar(Expression),
Expression = all(X,F1),
alphaConvert(F1,[sub(X,Y)|Sub],Free1-Free2,F2).
alphaConvert(Expression,Sub,Free1-Free2,lam(Y,F2)):-
nonvar(Expression),
Expression = lam(X,F1),
alphaConvert(F1,[sub(X,Y)|Sub],Free1-Free2,F2).
alphaConvert(Expression,Sub,Free1-Free3,que(Y,F3,F4)):-
nonvar(Expression),
Expression = que(X,F1,F2),
alphaConvert(F1,[sub(X,Y)|Sub],Free1-Free2,F3),
alphaConvert(F2,[sub(X,Y)|Sub],Free2-Free3,F4).
alphaConvert(F1,Sub,Free1-Free2,F2):-
nonvar(F1),
\+ F1 = some(_,_),
\+ F1 = all(_,_),
\+ F1 = lam(_,_),
\+ F1 = que(_,_,_),
compose(F1,Symbol,Args1),
alphaConvertList(Args1,Sub,Free1-Free2,Args2),
compose(F2,Symbol,Args2).
/*========================================================================
Alpha Conversion (listwise)
========================================================================*/
alphaConvertList([],_,Free-Free,[]).
alphaConvertList([X|L1],Sub,Free1-Free3,[Y|L2]):-
alphaConvert(X,Sub,Free1-Free2,Y),
alphaConvertList(L1,Sub,Free2-Free3,L2).
/*========================================================================
Alphabetic Variants
========================================================================*/
alphabeticVariants(Term1,Term2):-
alphaConvert(Term1,[],[]-Free1,Term3),
alphaConvert(Term2,[],[]-Free2,Term4),
Free1==Free2,
numbervars(Free1,0,N),
numbervars(Term3,N,M),
numbervars(Term4,N,M),
Term3=Term4.