Skip to content

Commit

Permalink
Eval notation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Dec 17, 2024
1 parent 324f85c commit 218a3df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions Juvix/Core/Main.lean
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import Juvix.Core.Main.Language
import Juvix.Core.Main.Semantics
import Juvix.Core.Main.Evaluator
11 changes: 7 additions & 4 deletions Juvix/Core/Main/Semantics.lean
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ inductive Eval (P : Program) : Context → Expr → Value → Prop where
| eval_unit {ctx} :
Eval P ctx Expr.unit Value.unit

theorem Eval.deterministic {P ctx e v₁ v₂} (h₁ : Eval P ctx e v₁) (h₂ : Eval P ctx e v₂) : v₁ = v₂ := by
notation "[" P "] " ctx " ⊢ " e " ↦ " v:40 => Eval P ctx e v

-- The evaluation relation is deterministic.
theorem Eval.deterministic {P ctx e v₁ v₂} (h₁ : [P] ctx ⊢ e ↦ v₁) (h₂ : [P] ctx ⊢ e ↦ v₂) : v₁ = v₂ := by
induction h₁ generalizing v₂ with
| eval_var =>
cases h₂ <;> cc
Expand Down Expand Up @@ -112,19 +115,19 @@ inductive Value.Terminating (P : Program) : Value → Prop where
Value.Terminating P (Value.constr_app ctr_name args_rev)
| closure {ctx body} :
(∀ v v',
Eval P (v :: ctx) body v' →
[P] (v :: ctx) body v' →
Value.Terminating P v') →
Value.Terminating P (Value.closure ctx body)
| unit : Value.Terminating P Value.unit

def Expr.Terminating (P : Program) (ctx : Context) (e : Expr) : Prop :=
(∃ v, Eval P ctx e v ∧ Value.Terminating P v)
(∃ v, [P] ctx ⊢ e ↦ v ∧ Value.Terminating P v)

def Program.Terminating (P : Program) : Prop :=
Expr.Terminating P [] P.main

lemma Eval.Expr.Terminating {P ctx e v} :
Expr.Terminating P ctx e → Eval P ctx e v → Value.Terminating P v := by
Expr.Terminating P ctx e → [P] ctx ⊢ e ↦ v → Value.Terminating P v := by
intro h₁ h₂
rcases h₁ with ⟨v', hval, hterm⟩
rewrite [Eval.deterministic h₂ hval]
Expand Down

0 comments on commit 218a3df

Please sign in to comment.