• No results found

Minlog’s normalization is done by means of the technique of NbE. The implementation is based on Section 2.2.4. The idea is that a term in T+ is first sent to its denotation, and then we retrieve from the denotational object a term which is in normal form. The

representation of a semantic object in Minlog is a pair of a type and a native Scheme procedure. We call such a pair an NbE object, and call a native Scheme procedure in an NbE object anNbE value. Minlog has procedures to deal with NbE objects. Corresponding to term families mentioned in Section 2.2.4 we also introduce procedures to send a term to a term family and vice versa. Proof normalization is also done by NbE through the correspondence between proofs and terms. Note that the extracted term from a proof carries less information than the proof, since non-computational information is thrown away due to the realizability. In order to recover the Curry-Howard correspondence, Minlog regards non-computational parts of formulas in the same way as computational ones in the case of proof normalization. Minlog uses the NbE algebras instead of the associated algebras of the defined predicate constants. In contrast to associated algebras, NbE algebras are defined with regard to non-computational universal quantifiers and implications in the same way as computational ones. Moreover, constants as recursion operators are allowed to carry reproduction data, which are used to reproduce the formula of the axiom from which these constants are extracted.

In this section, we describe technical details of the implementation of NbE in Minlog system.

A.1.1.1 Term Family

In order to implement NbE, we have to deal with bound variables in in reifying an NbE object of higher type. A term family is used to implement the way to create bound variables. There is a procedure to form a term family.

(nbe-make-termfam type proc)

The internal representation of term families is of the form (’termfam type proc) where the type, type, is an internal representation of a type and the NbE value, proc, is a native Scheme function procedure from a natural number k to an internal representation of terms. The following procedure applies a term family termfam :N→Λρ to a natural numberk:N

to get a term of Λρ.

(nbe-fam-apply termfam k)

This procedure applies the NbE value of termfam of the form (lambda (k) ...) to k. The following procedures sends a term to a term family and vice versa.

(nbe-term-to-termfam term) (nbe-extract termfam)

The procedure nbe-term-to-termfam gives the term family by making a case distinction on the construction of the given term. In any case the type is computed by term-to-type. If the outermost construction of term is a variable or a constant, the NbE value of the result is (lambda (k) term). If term is an abstraction λxt, the term family is given by

Listing A.1: Abstraction case in nbe-term-to-termfam 1 ( let * (( var ( t e r m - i n - a b s t - f o r m - t o - v a r t e r m ) ) 2 ( t y p e ( v a r - t o - t y p e var ) ) 3 ( k e r n e l ( t e r m - i n - a b s t - f o r m - t o - k e r n e l t e r m ) ) ) 4 ( n b e - m a k e - t e r m f a m 5 ( t e r m - t o - t y p e t e r m ) 6 ( l a m b d a ( k )

7 ( let (( v a r - k ( m a k e - v a r t y p e k ( v a r - t o - t - d e g var ) ( v a r - t o - n a m e var ) ) ) ) 8 ( m a k e - t e r m - i n - a b s t - f o r m 9 v a r - k 10 ( n b e - f a m - a p p l y 11 ( n b e - t e r m - t o - t e r m f a m 12 ( t e r m - s u b s t k e r n e l var ( m a k e - t e r m - i n - v a r - f o r m v a r - k ) ) ) 13 (+ 1 k ) ) ) ) ) ) )

Listing A.2: Application case in nbe-term-to-termfam

1 ( let (( op ( t e r m - i n - a p p - f o r m - t o - f i n a l - o p t e r m ) ) 2 ( a r g s ( t e r m - i n - a p p - f o r m - t o - a r g s t e r m ) ) ) 3 ( n b e - m a k e - t e r m f a m 4 ( t e r m - t o - t y p e t e r m ) 5 ( l a m b d a ( k ) 6 ( a p p l y m k - t e r m - i n - a p p - f o r m 7 ( map ( l a m b d a ( x ) ( n b e - f a m - a p p l y ( n b e - t e r m - t o - t e r m f a m x ) k ) ) 8 ( c o n s op a r g s ) ) ) ) ) )

the following code snippet. Let term be the given term. For the given term λxt, var

and kernel in lines 1 and 3 correspond to x and t, respectively. The variable name x

of abstraction is renamed to xk, i.e., var-k, then the body of the function procedure is

λxk(t[x/xk]

(k+ 1)). If term is an application t~s, where |~s| ≥1, the term family is given by the following code snippet. Letterm be the given term. For the given t~s, op and args correspond to t and ~s, respectively. Then, the body of the function (lines 6–8) constructs

t∞(k)s∞(k).

For a term familyr the procedurenbe-extractfirst computes the least natural number

k which is larger than any index of a variable in r(0), then the term r(k) is returned. A.1.1.2 Reflect and Reify

There are two (simultaneous) procedures which translate from a term family into an NbE object and vice versa.

(nbe-reflect termfam) (nbe-reify object)

A term family is sent to an NbE object by nbe-reflectand the opposite direction is done by nbe-reify. The procedure nbe-reflect makes a case distinction on the type of the term family. If it is a type variable or an algebra, the NbE value is the term family, a native Scheme procedure. If it is an arrow type, the NbE value of the result is computed by the

Listing A.3: Arrow type case in nbe-reflect 1 ( l a m b d a ( obj ) 2 ( n b e - r e f l e c t ( n b e - m a k e - t e r m f a m 3 ( a r r o w - f o r m - t o - v a l - t y p e t y p e ) 4 ( l a m b d a ( k ) 5 ( m a k e - t e r m - i n - a p p - f o r m 6 ( n b e - f a m - a p p l y t e r m f a m k ) 7 ( n b e - f a m - a p p l y ( n b e - r e i f y obj ) k ) ) ) ) ) )

Listing A.4: Algebra case in nbe-reify

1 ( let (( a r g s ( n b e - c o n s t r - v a l u e - t o - a r g s v a l u e ) ) ) 2 ( n b e - m a k e - t e r m f a m 3 t y p e 4 ( l a m b d a ( k ) 5 ( a p p l y m k - t e r m - i n - a p p - f o r m 6 ( c o n s ( m a k e - t e r m - i n - c o n s t - f o r m 7 ( n b e - c o n s t r - v a l u e - t o - c o n s t r v a l u e ) ) 8 ( map ( l a m b d a ( obj ) 9 ( n b e - f a m - a p p l y ( n b e - r e i f y obj ) k ) ) 10 a r g s ) ) ) ) ) )

following code snippet. Let typebe the type of the given term family. Let a term family

λxt∞ be given tonbe-reflect. The outermost(lambda (obj) ...) is a representation

of the abstraction λx. . . as a native Scheme procedure. Intuitively the body is given by

applying t∞ to obj. Formally, it first constructs a term family ↓ obj by reifying, then the body t∞(k)(↓obj)(k) is computed. Finally,nbe-make-termfam is applied to the body abstracted by k. At the end, we apply nbe-reflectwhich is corresponding to ↑.

The procedure nbe-reify takes an NbE object and retrieves a term family. A term family is built by induction on the type of the NbE object. If the type is a type variable, it returns the NbE value of the NbE object. If the type is an algebra, it checks by means of nbe-constr-value? whether this NbE object expresses C~t, a constructor C with arguments ~t. If this is the case, it makes a term family by the following code snippet. Assume type and value are the type and the NbE value of the given term family. Assume arguments args are prepared as NbE objects corresponding to~tin line 1. They become reified terms in lines 8–10, then are given to the constructor to be an NbE value. If this is not the case, e.g. it is a variable, then it returns the NbE value of the NbE object. The next case is the arrow type. The following code snippet gives a term family from the NbE object. The procedure nbe-object-applyis for function application of NbE objects. Let type be the type of the given term family. The variable var-k is created with the index k which is abstracted by the native Scheme function abstraction. The NbE object obtained by applying the given NbE object obj to the NbE object of var-k is reified to the term family ↓ (obj(↑ (var-k))). Further applying this term family to k+1 and abstracting by var-k, we obtain the very term in Definition 2.2.47.

Listing A.5: Arrow type case in nbe-reify 1 ( let (( t y p e 1 ( a r r o w - f o r m - t o - a r g - t y p e t y p e ) ) ) 2 ( n b e - m a k e - t e r m f a m 3 t y p e 4 ( l a m b d a ( k ) 5 ( let (( v a r - k ( m a k e - v a r t y p e 1 k 1 ( d e f a u l t - v a r - n a m e t y p e 1 ) ) ) ) 6 ( m a k e - t e r m - i n - a b s t - f o r m 7 v a r - k ( n b e - f a m - a p p l y 8 ( n b e - r e i f y 9 ( n b e - o b j e c t - a p p l y 10 obj 11 ( n b e - r e f l e c t ( n b e - t e r m - t o - t e r m f a m 12 ( m a k e - t e r m - i n - v a r - f o r m v a r - k ) ) ) ) ) 13 (+ k 1) ) ) ) ) ) )