/*************************************************************************

         name: betaConversion.pl
      version: May 2002
  description: Predicates for beta-reduction
      authors: Johan Bos, Patrick Blackburn

*************************************************************************/
  
:- module(betaConversion,[betaConvert/2]).
:- use_module(semconHelpers,[compose/3,substitute/4]).
:- [semconOperators].

betaConvert(Functor@Arg,Result):-
        betaConvert(Functor,lambda(X,Formula)),
        !,
        substitute(Arg,X,Formula,BetaConverted),
        betaConvert(BetaConverted,Result).
  
betaConvert(Formula,Result):-
	compose(Formula,Functor,Formulas),
	betaConvertList(Formulas,ResultFormulas),
	compose(Result,Functor,ResultFormulas).
  
betaConvertList([],[]).

betaConvertList([Formula|Others],[Result|ResultOthers]):-
	betaConvert(Formula,Result),
	betaConvertList(Others,ResultOthers).



