% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % File: pascal.dtr % % Purpose: illustrate Pascal's triangle % % Author: Lionel Moser, December 1991 % % Email: moser@bnr.ca % % Documentation: Cognitive Science Research Paper CSRP 215, Univ. Sussex % % Related files: arglists.dtr, arglogic.dtr, decimadd.dtr % % Version: 2.01 % % % % Copyright (c) University of Sussex 1991. All rights reserved. % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % # load 'arglists.dtr'. # load 'arglogic.dtr'. # load 'decimadd.dtr'. % Moser, Lionel, "DATR paths as arguments," Cognitive Science % Research Paper CSRP 215, University of Sussex, Brighton, % 1992. % % DATR is a lexical knowledge representation language which is % designed to support the lexicon in an NLP system. Its syntax % and semantics are designed to support the types of inference % required in computational lexicography. It was not a design % intention of the language to support general logic % programming, yet in this paper we show that the types of % inference permitted in the language do support a general % type of logical inference. Drawing an analogy with Prolog, % both are declarative languages, and each has its own % inference engine or theorem prover, which are quite % different. DATR allows at least a subset of Prolog- % definable logic programs to be encoded. # vars $terminal: [ ] 0 1 2 3 4 5 6 7 8 9. # vars $;: ;. # vars $!: !. % Pascal's triangle looks like this: % % 1 % 1 1 % 1 2 1 % 1 3 3 1 % 1 4 6 4 1 % 1 5 10 10 5 1 % Successor computes the (n+1)th line of the triangle as a function of the % nth line. Successor: <1 ; ]> == 1 ; ] <[ 1 ; > == [ 1 ; <1 ;> <> == Add0: ; . Line6: <> == Successor:>>>>. % Some example theorems: % % Successor: % <[ 1 ; ]> = [ 1 ; 1 ; ] % <[ 1 ; 1 ; ]> = [ 1 ; 2 ; 1 ; ] % <[ 1 ; 2 ; 1 ; ]> = [ 1 ; 3 ; 3 ; 1 ; ] % <[ 1 ; 3 ; 3 ; 1 ; ]> = [ 1 ; 4 ; 6 ; 4 ; 1 ; ] % <[ 1 ; 4 ; 6 ; 4 ; 1 ; ]> = [ 1 ; 5 ; 1 0 ; 1 0 ; 5 ; 1 ; ]. % % Line6: % <> = [ 1 ; 5 ; 1 0 ; 1 0 ; 5 ; 1 ; ]. % To define a procedure which returns the first N lines of Pascal's triangle, % we strip down the For loop to just look at the first two arguments, and pass % an arbitrary number of following args as the arg list to Body. What For % computes is: % % For: == Body:<{Body(0)}> ; % Body:<{Body(1)}> ; % Body:<{Body(2)}> ; % .... % Body:<{Body(N-1)}> ; . % But it is defined recursively: % % For: == % if I = N: % otherwise: Body: ; For:. % Argument names I: <> == Arg1. N: <> == Arg2. PrevBody: <> == Pop_arg:. % args 3, 4, ..., ! For: <> == > % (I = N?) pass entire arglist; % Equal uses only first two. == % stop == Body: !> ; For: ; > ; N:<> ; Body: !> ; ! >. % Wire up Successor as the body. Body: <> == Successor. % Some example theorems: % % For:<0 ; 1 ; [ 1 ; ] ;> = [ 1 ; 1 ; ] ;. % % For:<0 ; 2 ; [ 1 ; ] ;> = [ 1 ; 1 ; ] ; [ 1 ; 2 ; 1 ; ] ;. % Make a pretty interface, and insert top line (Body(0)) of the triangle. % Pascal: == first (n+1) lines of Pascal's triangle. Pascal: <> == [ 1 ; ] ; For:<0 ; Arg1 ; [ 1 ; ] ; !>. % Some example theorems: % % Pascal: <0 ;> = [ 1 ; ] ; . % % Pascal: <1 ;> = [ 1 ; ] ; % [ 1 ; 1 ; ] ; . % % Pascal: <2 ;> = [ 1 ; ] ; % [ 1 ; 1 ; ] ; % [ 1 ; 2 ; 1 ; ] ; . % % Pascal: <3 ;> = [ 1 ; ] ; % [ 1 ; 1 ; ] ; % [ 1 ; 2 ; 1 ; ] ; % [ 1 ; 3 ; 3 ; 1 ; ] ; . % % Pascal: <6 ;> = [ 1 ; ] ; % [ 1 ; 1 ; ] ; % [ 1 ; 2 ; 1 ; ] ; % [ 1 ; 3 ; 3 ; 1 ; ] ; % [ 1 ; 4 ; 6 ; 4 ; 1 ; ] ; % [ 1 ; 5 ; 1 0 ; 1 0 ; 5 ; 1 ; ] ; % [ 1 ; 6 ; 1 5 ; 2 0 ; 1 5 ; 6 ; 1 ; ] ; . % % Pascal: <7 ;> = [ 1 ; ] ; % [ 1 ; 1 ; ] ; % [ 1 ; 2 ; 1 ; ] ; % [ 1 ; 3 ; 3 ; 1 ; ] ; % [ 1 ; 4 ; 6 ; 4 ; 1 ; ] ; % [ 1 ; 5 ; 1 0 ; 1 0 ; 5 ; 1 ; ] ; % [ 1 ; 6 ; 1 5 ; 2 0 ; 1 5 ; 6 ; 1 ; ] ; % [ 1 ; 7 ; 2 1 ; 3 5 ; 3 5 ; 2 1 ; 7 ; 1 ; ] ; . % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % # show <0 ;> <1 ;> <2 ;> <3 ;> <6 ;> <7 ;>. % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % The next line is the Revision Control System Archive Id: do not delete it. % $Id: archive.dtr,v 1.1 1997/04/09 20:40:33 root Exp $