Normalization

Description

Normalizing plus expressions.

Source: The Art of Prolog

Download

Program source code: normalization.pl

Listing

/*	
    normalize(Sum,NormalisedSum) :-
	NormalizedSum is the result of normalizing the sum expression Sum.
 
*/
	:- op(50,xfx,++).
 
	normalize(Exp,Norm) :- normalize_ds(Exp,Norm++0).
 
	normalize_ds(A+B,Norm++Space) :-
	   normalize_ds(A,Norm++NormB), normalize_ds(B,NormB++Space).
	normalize_ds(A,(A+Space)++Space) :-
	   constant(A).
 
%	Program 15.7 :	Normalizing plus expressions.

Comments

pl/prolog/pllib/normalization.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0