@@ -327,34 +327,33 @@ spelled the same as some global name `x`.
327
327
328
328
Here is the definition, informally...
329
329
330
- ` x : =s` x = s
331
- ` x : =s` y = y if x <> y
332
- ` x : =s` (\x:T11. t12) = \x:T11. t12
333
- ` x : =s` (\y:T11. t12) = \y:T11. ` x:=s` t12 if x <> y
334
- ` x : =s` (t1 t2) = (` x:=s` t1) (` x:=s` t2)
335
- ` x : =s` true = true
336
- ` x : =s` false = false
337
- ` x : =s` (if t1 then t2 else t3) =
338
- if ` x : =s` t1 then ` x:=s` t2 else ` x:=s` t3
330
+ [ x : =s] x = s
331
+ [ x : =s] y = y if x <> y
332
+ [ x : =s] (\x:T11. t12) = \x:T11. t12
333
+ [ x : =s] (\y:T11. t12) = \y:T11. [ x:=s] t12 if x <> y
334
+ [ x : =s] (t1 t2) = ([ x:=s] t1) ([ x:=s] t2)
335
+ [ x : =s] true = true
336
+ [ x : =s] false = false
337
+ [ x : =s] (if t1 then t2 else t3) =
338
+ if [ x : =s] t1 then [ x:=s] t2 else [ x:=s] t3
339
339
340
340
... and formally :
341
341
342
- > mutual
343
- >
344
342
> subst : String -> Tm -> Tm -> Tm
345
- > subst x s t =
346
- > case t of
347
- > Tvar x' => if x == x' then s else t
348
- > Tabs x' ty t1 =>
349
- > Tabs x' ty (if x == x' then t1 else subst x s t1)
350
- > t1 # t2 => subst x s t1 # subst x s t2
351
- > Ttrue => Ttrue
352
- > Tfalse => Tfalse
353
- > Tif t1 t2 t3 => Tif (subst x s t1) (subst x s t2) (subst x s t3)
354
-
355
- > infixl 5 :=
356
- > (:= ) : String -> Tm -> Tm -> Tm
357
- > (:= ) x s = subst x s
343
+ > subst x s (Tvar x') =
344
+ > case decEq x x' of
345
+ > Yes _ => s
346
+ > No _ => (Tvar x')
347
+ > subst x s (Tabs x' ty t1) =
348
+ > Tabs x' ty (case decEq x x' of
349
+ > Yes p => t1
350
+ > No p => subst x s t1)
351
+ > subst x s (t1 # t2) = subst x s t1 # subst x s t2
352
+ > subst x s Ttrue = Ttrue
353
+ > subst x s Tfalse = Tfalse
354
+ > subst x s (Tif t1 t2 t3) = Tif (subst x s t1) (subst x s t2) (subst x s t3)
355
+
356
+ > syntax " [" [p] " :=" [q] " ]" [r] = subst p q r
358
357
359
358
_Technical note_ : Substitution becomes trickier to define if we
360
359
consider the case where `s` , the term being substituted for a
@@ -375,9 +374,9 @@ been "captured" by the binder at the beginning of `t`.
375
374
Why would this be bad? Because it violates the principle that the
376
375
names of bound variables do not matter. For example, if we rename
377
376
the bound variable in `t` , e. g. , let `t' = \ w : Bool . z`, then
378
- `` x : =s`t'` is `\w:Bool . \x:Bool . r`, which does not behave the
379
- same as `` x : =s` t = \r:Bool . \x:Bool . r`. That is, renaming a
380
- bound variable changes how `t` behaves under substitution. * )
377
+ `` x : =s[t'] is `\w:Bool . \x:Bool . r`, which does not behave the
378
+ same as `[ x : =s] t = \r:Bool . \x:Bool . r`. That is, renaming a
379
+ bound variable changes how `t` behaves under substitution.
381
380
382
381
See , for example, `Aydemir 2008 ` for further discussion
383
382
of this issue.
@@ -392,25 +391,22 @@ one of the constructors; your job is to fill in the rest of the
392
391
constructors and prove that the relation you've defined coincides
393
392
with the function given above.
394
393
395
- -- > data substi : Tm -> Tm -> Type where -- (s:Tm) (x:string) : :=
396
- -- > S_Var1 : (s:Tm) -> (x:string) -> substi s x (Tvar x) s
397
- -- > S_Var1 : (s:Tm) -> (x:string) -> substi s x (Tvar x) s
398
- --
399
- --
400
- -- > Tvar x' => if x == x' then s else t
401
- -- > Tabs x' ty t1 =>
402
- -- > Tabs x' ty (if x == x' then t1 else subst x s t1)
403
- -- > t1 # t2 => subst x s t1 # subst x s t2
404
- -- > Ttrue => Ttrue
405
- -- > Tfalse => Tfalse
406
- -- > Tif t1 t2 t3 => Tif (subst x s t1) (subst x s t2) (subst x s t3)
407
-
408
-
409
- Theorem substi_correct : forall s x t t',
410
- `x : =s`t = t' <-> substi s x t t'.
411
- Proof .
412
- (* FILL IN HERE * ) Admitted .
413
- (** `` * )
394
+ > data Substi : (s :Tm) -> (x :String) -> Tm -> Tm -> Type where
395
+ > S_True : Substi s x Ttrue Ttrue
396
+ > S_False : Substi s x Tfalse Tfalse
397
+ > S_App : {l', r':Tm} -> Substi s x l l' -> Substi s x r r' -> Substi s x (l # r) (l' # r')
398
+ > S_If : {b', p',n':Tm} -> Substi s x b b' -> Substi s x p p'
399
+ > -> Substi s x n n' -> Substi s x (Tif b p n) (Tif b' p' n')
400
+ > S_Var1 : Substi s x (Tvar x) s
401
+ > S_Var2 : Substi s x (Tvar y) (Tvar y)
402
+ > S_Abs1 : Substi s x t t' -> Substi s x (Tabs x' ty t) (Tabs x' ty t')
403
+ > S_Abs2 : Substi s x (Tabs y ty t) (Tabs y ty t)
404
+
405
+
406
+ > substi_correct : (s :Tm) -> (x : String) -> (t : Tm) -> (t' : Tm) ->
407
+ > (([ x := s ] t) = t') <-> Substi s x t t'
408
+ > substi_correct s x t t' = ? substi_correct_rhs1
409
+
414
410
415
411
(* ================================================================= * )
416
412
(** ** Reduction * )
0 commit comments