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
|
%substitution_term((X,T),(Y,T),(Term,Type),(Term_final,Type)) est vrai si Term_final est le résultat de la substitution de X par Y dans Term
%le cas d'une variable
substitution_term((X,T),(Y,T),(Term,Type),(Term_final,Type)):-
is_variable_term(Term,Type),
Term==X,!,
Term_final=Y.
substitution_term((X,T),(Y,T),(Term,Type),(Term_final,Type)):-
is_variable_term(Term,Type),
Term_final=Term,!.
%le cas d'une constante
substitution_term((X,T),(Y,T),(Term,Type),(Term_final,Type)):-
is_cst_term(Term,Type),
Term_final=Term.
%le cas d'une application
substitution_term((X,T),(Y,T),(appl((M,U->T),(N,U)),T),(Term_final,Type)):-
is_type(U->T),
substitution(T,T,U->T,Type_final1),
substitution_term((X,T),(Y,T),(M,Type_final1),(Term_final1,Type1)),
substitution_term((X,T),(Y,T),(N,U),(Term_final2,Type2)),
Term_final=(appl((Term_final1,Type1),(Term_final2,Type2))).
%le cas d'une abstraction
%le cas ou X==Z
substitution_term((X,T),(Y,T),(lam((Z,T),(N,B)),(T->B)),(Term_final,Type)):-
X==Z,!,
Term_final=lam((Z,T),(N,B)).
%le cas ou X=/=Z et Z appartient a Y
substitution_term((X,T),(Y,T),(lam((Z,T),(N,B)),(T->B)),(Term_final,Type)):-
%le prob est la, comment verifier si Z appartient a Y?
member(Z,Y),!,
variables_In_Term((lam((Z,T),(N,B)),(T->B)),L),
%un autre probleme la, comment verifier que W n'appartient pas a L:
not(member((W,T),L)),
%renommer Z par W dans Term1 de Type1 pour obtenir Term2 de Type2
substitution_term((Z,T),(W,T),(Term1,Type1),(Term2,Type2)),
substitution_term((X,T),(Y,T),Term2,Type2,(Term_final,Type)). |
Partager