@@ -22,6 +22,9 @@ work to deal with these.
22
22
> % default total
23
23
> % hide Types . Tm
24
24
> % hide Types . Ty
25
+ > % hide Types . (->> )
26
+
27
+
25
28
26
29
27
30
@@ -162,7 +165,7 @@ We next formalize the syntax of the STLC.
162
165
163
166
==== Terms
164
167
165
- > infixl 1 #
168
+ > infixl 7 #
166
169
167
170
> data Tm : Type where
168
171
> Tvar : String -> Tm
@@ -408,112 +411,122 @@ with the function given above.
408
411
> substi_correct s x t t' = ? substi_correct_rhs1
409
412
410
413
411
- (* ================================================================= * )
412
- (** ** Reduction * )
413
-
414
- (** The small- step reduction relation for STLC now follows the
415
- same pattern as the ones we have seen before. Intuitively , to
416
- reduce a function application, we first reduce its left- hand
417
- side (the function) until it becomes an abstraction; then we
418
- reduce its right- hand side (the argument) until it is also a
419
- value; and finally we substitute the argument for the bound
420
- variable in the body of the abstraction. This last rule, written
421
- informally as
422
-
423
- (\ x : T.t12) v2 ==> `x:=v2`t12
424
-
425
- is traditionally called " beta-reduction" . * )
426
-
427
- (**
428
- value v2
429
- -- -------------------------- (ST_AppAbs)
430
- (\ x : T.t12) v2 ==> `x:=v2`t12
431
-
432
- t1 ==> t1'
433
- -- -------------- (ST_App1)
434
- t1 t2 ==> t1' t2
435
-
436
- value v1
437
- t2 ==> t2'
438
- -- -------------- (ST_App2)
439
- v1 t2 ==> v1 t2'
440
- * )
441
- (** ... plus the usual rules for conditionals :
442
-
443
- -- ------------------------------ (ST_IfTrue)
444
- (if true then t1 else t2) ==> t1
445
-
446
- -- ------------------------------- (ST_IfFalse)
447
- (if false then t1 else t2) ==> t2
448
-
449
- t1 ==> t1'
450
- -- -------------------------------------------------- (ST_If)
451
- (if t1 then t2 else t3) ==> (if t1' then t2 else t3)
452
- * )
453
-
454
- (** Formally : *)
455
-
456
- Reserved Notation " t1 '==>' t2" (at level 40 ).
457
-
458
- Inductive step : Tm -> Tm -> Prop :=
459
- | ST_AppAbs : forall x T t12 v2,
460
- value v2 ->
461
- (tapp (tabs x T t12) v2) ==> `x : =v2`t12
462
- | ST_App1 : forall t1 t1' t2,
463
- t1 ==> t1' ->
464
- tapp t1 t2 ==> tapp t1' t2
465
- | ST_App2 : forall v1 t2 t2',
466
- value v1 ->
467
- t2 ==> t2' ->
468
- tapp v1 t2 ==> tapp v1 t2'
469
- | ST_IfTrue : forall t1 t2,
470
- (tif ttrue t1 t2) ==> t1
471
- | ST_IfFalse : forall t1 t2,
472
- (tif tfalse t1 t2) ==> t2
473
- | ST_If : forall t1 t1' t2 t3,
474
- t1 ==> t1' ->
475
- (tif t1 t2 t3) ==> (tif t1' t2 t3)
476
-
477
- where " t1 '==>' t2" := (step t1 t2).
478
-
479
- Hint Constructors step.
480
-
481
- Notation multistep : = (multi step).
482
- Notation " t1 '==>*' t2" := (multistep t1 t2) (at level 40 ).
483
-
484
- (* ================================================================= * )
485
- (** ** Examples * )
486
-
487
- (** Example :
488
-
489
- (\ x : Bool -> Bool . x) (\x:Bool . x) ==>* \x:Bool . x
414
+ == Reduction
415
+
416
+ The small- step reduction relation for STLC now follows the
417
+ same pattern as the ones we have seen before. Intuitively , to
418
+ reduce a function application, we first reduce its left- hand
419
+ side (the function) until it becomes an abstraction; then we
420
+ reduce its right- hand side (the argument) until it is also a
421
+ value; and finally we substitute the argument for the bound
422
+ variable in the body of the abstraction. This last rule, written
423
+ informally as
424
+
425
+ (\ x : T.t12) v2 -> > [x:=v2] t12
426
+
427
+ is traditionally called " beta-reduction" .
428
+
429
+
430
+ \ [
431
+ \ begin{prooftree}
432
+ \ hypo{\ idr{value v2}}
433
+ \ infer1[\ idr{ST_AppAbs }]{\ idr{(\ x : T.t12) v2 -> > [x:=v2] t12}}
434
+ \ end{prooftree}
435
+ \ ]
436
+
437
+ \ [
438
+ \ begin{prooftree}
439
+ \ hypo{\ idr{t1 ->> t1'}}
440
+ \ infer1[\ idr{ST_App1 }]{\ idr{t1 t2 ->> t1' t2}
441
+ \ end{prooftree}
442
+ \ ]
443
+
444
+ \ [
445
+ \ begin{prooftree}
446
+ \ hypo{\ idr{value v1}}
447
+ \ hypo{\ idr{t2 ->> t2'}}
448
+ \ infer2[\ idr{ST_App2 }]{\ idr{v1 t2 ->> v1 t2'}
449
+ \ end{prooftree}
450
+ \ ]
451
+
452
+ ... plus the usual rules for conditionals :
453
+
454
+ \ [
455
+ \ begin{prooftree}
456
+ \ infer0[\ idr{ST_IfTrue }]{\ idr{(if true then t1 else t2) ->> t1}
457
+ \ end{prooftree}
458
+ \ ]
459
+
460
+ \ [
461
+ \ begin{prooftree}
462
+ \ infer0[\ idr{ST_IfFalse }]{\ idr{(if false then t1 else t2) ->> t2}
463
+ \ end{prooftree}
464
+ \ ]
465
+
466
+ \ [
467
+ \ begin{prooftree}
468
+ \ hypo{\ idr{t1 ->> t1'}}
469
+ \ infer1[\ idr{ST_If }]{\ idr{(if t1 then t2 else t3) ->> (if t1' then t2 else t3)}
470
+ \ end{prooftree}
471
+ \ ]
472
+
473
+ Formally :
474
+
475
+ > mutual
476
+ > infixl 6 ->>
477
+ > (->> ) : Tm -> Tm -> Type
478
+ > (->> ) = Step
479
+ >
480
+ > data Step : Tm -> Tm -> Type where
481
+ > ST_AppAbs : {x : String} -> {ty : Ty} -> {t12 : Tm} -> {v2 : Tm} ->
482
+ > Value v2 ->
483
+ > (Tabs x ty t12) # v2 -> > [ x := v2] t12
484
+ > ST_App1 : {t1, t1', t2: Tm} ->
485
+ > t1 -> > t1' ->
486
+ > t1 # t2 -> > t1' # t2
487
+ > ST_App2 : {v1, t2, t2' : Tm} ->
488
+ > Value v1 ->
489
+ > t2 -> > t2' ->
490
+ > v1 # t2 -> > v1 # t2'
491
+ > ST_IfTrue : {t1, t2: Tm} ->
492
+ > Tif Ttrue t1 t2 -> > t1
493
+ > ST_IfFalse : {t1, t2: Tm} ->
494
+ > Tif Tfalse t1 t2 -> > t2
495
+ > ST_If : {t1, t1', t2, t3: Tm} ->
496
+ > t1 -> > t1' ->
497
+ > Tif t1 t2 t3 -> > Tif t1' t2 t3
498
+
499
+ > infixl 6 ->>*
500
+ > (->>* ) : Tm -> Tm -> Type
501
+ > (->>* ) t t' = Multi Step t t'
502
+
503
+ === Examples
504
+
505
+ Example :
506
+
507
+ (\ x : Bool -> Bool . x) (\x:Bool . x) -> >* \x:Bool . x
490
508
491
509
i. e. ,
492
510
493
- idBB idB ==>* idB
494
- * )
511
+ idBB idB ->>* idB
495
512
496
- Lemma step_example1 :
497
- (tapp idBB idB) ==>* idB.
498
- Proof .
499
- eapply multi_step.
500
- apply ST_AppAbs .
501
- apply v_abs.
502
- simpl.
503
- apply multi_refl. Qed .
513
+ > step_example1 : Stlc.idBB # Stlc.idB -> >* Stlc.idB
514
+ > step_example1 =
515
+ > Multi_step (ST_AppAbs V_abs ) Multi_refl
504
516
505
- ( ** Example :
517
+ Example :
506
518
507
519
(\ x : Bool -> Bool . x) ((\x:Bool -> Bool . x) (\x:Bool . x))
508
- == >* \ x : Bool . x
520
+ -> >* \ x : Bool . x
509
521
510
522
i. e. ,
511
523
512
- (idBB (idBB idB)) ==>* idB.
513
- * )
524
+ (idBB (idBB idB)) ->>* idB.
525
+
526
+ > step_example2 : Stlc.idBB # (Stlc.idBB # Stlc.idB) -> >* Stlc.idB
527
+ > step_example2 =
528
+ > Multi_step (ST_App2 V_abs ? hole1 ) (Multi_step (ST_AppAbs V_abs ) ? hole3)
514
529
515
- Lemma step_example2 :
516
- (tapp idBB (tapp idBB idB)) ==>* idB.
517
530
Proof .
518
531
eapply multi_step.
519
532
apply ST_App2 . auto.
@@ -527,15 +540,15 @@ Proof.
527
540
(\ x : Bool -> Bool . x)
528
541
(\ x : Bool . if x then false else true)
529
542
true
530
- == >* false
543
+ -> >* false
531
544
532
545
i. e. ,
533
546
534
- (idBB notB) ttrue == >* tfalse.
547
+ (idBB notB) ttrue -> >* tfalse.
535
548
* )
536
549
537
550
Lemma step_example3 :
538
- tapp (tapp idBB notB) ttrue == >* tfalse.
551
+ tapp (tapp idBB notB) ttrue -> >* tfalse.
539
552
Proof .
540
553
eapply multi_step.
541
554
apply ST_App1 . apply ST_AppAbs . auto. simpl.
@@ -548,18 +561,18 @@ Proof.
548
561
549
562
(\ x : Bool -> Bool . x)
550
563
((\ x : Bool . if x then false else true) true)
551
- == >* false
564
+ -> >* false
552
565
553
566
i. e. ,
554
567
555
- idBB (notB ttrue) == >* tfalse.
568
+ idBB (notB ttrue) -> >* tfalse.
556
569
557
570
(Note that this term doesn't actually typecheck; even so , we can
558
571
ask how it reduces. )
559
572
* )
560
573
561
574
Lemma step_example4 :
562
- tapp idBB (tapp notB ttrue) == >* tfalse.
575
+ tapp idBB (tapp notB ttrue) -> >* tfalse.
563
576
Proof .
564
577
eapply multi_step.
565
578
apply ST_App2 . auto.
@@ -575,33 +588,33 @@ Proof.
575
588
to simplify these proofs. * )
576
589
577
590
Lemma step_example1' :
578
- (tapp idBB idB) == >* idB.
591
+ (tapp idBB idB) -> >* idB.
579
592
Proof . normalize. Qed .
580
593
581
594
Lemma step_example2' :
582
- (tapp idBB (tapp idBB idB)) == >* idB.
595
+ (tapp idBB (tapp idBB idB)) -> >* idB.
583
596
Proof . normalize. Qed .
584
597
585
598
Lemma step_example3' :
586
- tapp (tapp idBB notB) ttrue == >* tfalse.
599
+ tapp (tapp idBB notB) ttrue -> >* tfalse.
587
600
Proof . normalize. Qed .
588
601
589
602
Lemma step_example4' :
590
- tapp idBB (tapp notB ttrue) == >* tfalse.
603
+ tapp idBB (tapp notB ttrue) -> >* tfalse.
591
604
Proof . normalize. Qed .
592
605
593
606
(** **** Exercise : 2 stars (step_example5) *)
594
607
(** Try to do this one both with and without `normalize` . * )
595
608
596
609
Lemma step_example5 :
597
610
tapp (tapp idBBBB idBB) idB
598
- == >* idB.
611
+ -> >* idB.
599
612
Proof .
600
613
(* FILL IN HERE * ) Admitted .
601
614
602
615
Lemma step_example5_with_normalize :
603
616
tapp (tapp idBBBB idBB) idB
604
- == >* idB.
617
+ -> >* idB.
605
618
Proof .
606
619
(* FILL IN HERE * ) Admitted .
607
620
(** `` * )
0 commit comments