Skip to content

Commit

Permalink
WIP: prove the parallel reduction is a series of regular
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatolay committed Aug 16, 2024
1 parent 76e3b49 commit 87039fe
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 21 deletions.
41 changes: 41 additions & 0 deletions Extended/Record.lean
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,45 @@ def insert
then Record.cons k not_in a tail
else Record.cons k not_in a' (insert tail key a)

def consequtive_insert
{keys : List String}
{record : Record Ī± keys}
{key : String}
{a b : Ī±}
: insert (insert record key a) key b
= insert record key b
:= match record with
| nil => by rfl
| cons cur_key not_in elem tail => by
simp [insert]
exact dite
(key = cur_key)
(Ī» eq => by
simp [eq]
exact _
)
(Ī» neq => by
simp [neq]
exact _
)

end Record

namespace Contains

def contains_after_insert
{keys : List String}
{record : Record Ī± keys}
{key : String}
{a b : Ī±}
(contains : Contains record key a)
: Contains (Record.insert record key b) key b
:= match contains with
| head _ _ => by
simp [Record.insert]
exact head _ _
| tail cur_key _ neq _ contains_tail => by
simp [Record.insert, neq]
exact tail _ _ neq _ (contains_after_insert contains_tail)

end Contains
24 changes: 24 additions & 0 deletions Extended/Reduction/Parallel/Properties.lean
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,27 @@ def single
exact FormationPremise.consAttached prefl (single bnds_tail attr pred contains_tail)

end FormationPremise

namespace ApplicationPremise

def single
{ctx : Ctx}
{t t' : Term}
{attrs : Attrs}
(apps : Record Term attrs)
(attr : Attr)
(preduce : PReduce ctx t t')
(contains : Contains apps attr t)
: ApplicationPremise ctx apps (Record.insert apps attr t')
:= match attrs with
| [] => match apps with | Record.nil => ApplicationPremise.nil
| _ :: attrs_tail => match apps with
| Record.cons _ not_in term bnds_tail => match contains with
| Contains.head _ _ => by
simp [Record.insert]
exact ApplicationPremise.cons preduce prefl_app_premise
| Contains.tail _ _ neq _ contains_tail => by
simp [Record.insert, neq]
exact ApplicationPremise.cons prefl (single bnds_tail attr preduce contains_tail)

end ApplicationPremise
126 changes: 120 additions & 6 deletions Extended/Reduction/Regular/Confluence.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ set_option autoImplicit false

/-! ### Equivalence of `ā‡›` and `ā‡` -/

/-- Equivalence of `ā‡›` and `ā‡` [KS22, Proposition 3.4 (1)] -/
def reg_to_par
: {ctx : Ctx}
ā†’ {t t' : Term}
ā†’ Reduce ctx t t'
ā†’ PReduce ctx t t'
-- := Ī» { ctx t t' } reduce => match reduce with
:= Ī» { _ _ _ } reduce => match reduce with
:= Ī» reduce => match reduce with
-- Dispatch
| .r_dot is_attached => .pr_dot prefl is_attached
| .r_Ļ† attr_absent Ļ†_present => .pr_Ļ† prefl attr_absent Ļ†_present
Expand All @@ -32,11 +30,127 @@ def reg_to_par
| .r_dc => .pr_dc
-- Congruence
| .r_cong_appā‚— app_bnds t_t' => .pr_cong_app prefl_app_premise (reg_to_par t_t')
| .r_cong_appįµ£ app_bnds u_u' =>
| .r_cong_appįµ£ _ contains u_u' =>
.pr_cong_app
(ApplicationPremise.cons (reg_to_par u_u') prefl_app_premise)
(ApplicationPremise.single _ _ (reg_to_par u_u') contains)
prefl
-- | .r_cong_appįµ£ app_bnds contains u_u' =>
-- .pr_cong_app
-- (ApplicationPremise.cons (reg_to_par u_u') prefl_app_premise)
-- prefl
| .r_cong_dot t_t' => .pr_cong_dot (reg_to_par t_t')
-- TODO
| .r_cong_obj contains t_t' =>
.pr_cong_obj (FormationPremise.single _ _ (reg_to_par t_t') contains)

inductive R : Ctx ā†’ Term ā†’ Term ā†’ Type where
| refl : {ctx : Ctx} ā†’ {t : Term} ā†’ R ctx t t
| head
: {ctx : Ctx}
ā†’ {t s u : Term}
ā†’ Reduce ctx t s
ā†’ R ctx s u
ā†’ R ctx t u

def trans_R
{ctx : Ctx}
{t u s : Term}
(r1 : R ctx t u)
(r2 : R ctx u s)
: R ctx t s
:= match r1 with
| .refl => r2
| .head reduce r_tail =>
.head reduce (trans_R r_tail r2)

def congr_dot_R
{attr : Attr}
{ctx : Ctx}
{t t' : Term}
(r : R ctx t t')
: R ctx (dot t attr) (dot t' attr)
:= match r with
| .refl => .refl
| .head reduce r' => .head (.r_cong_dot reduce) (congr_dot_R r')

def congr_appā‚—_R
{attrs : Attrs}
{apps : Record Term attrs}
{ctx : Ctx}
{t t' : Term}
(r : R ctx t t')
: R ctx (app t apps) (app t' apps)
:= match r with
| .refl => .refl
| .head reduce r' => .head (.r_cong_appā‚— _ reduce) (congr_appā‚—_R r')

def congr_appįµ£_R
{attr : Attr}
{attrs : Attrs}
{apps : Record Term attrs}
{ctx : Ctx}
{t u u' : Term}
(r : R ctx u u')
(contains : Contains apps attr u)
: R ctx (app t apps) (app t (Record.insert apps attr u'))
:= match r with
| .refl => _ -- TODO .refl
| .head reduce r' =>
.head (.r_cong_appįµ£ _ contains reduce) (congr_appįµ£_R r' contains.contains_after_insert)

def par_to_reg
: {ctx : Ctx}
ā†’ {t t' : Term}
ā†’ PReduce ctx t t'
ā†’ R ctx t t'
:= Ī» preduces => match preduces with
| .pr_dot preduce attr_attached =>
let reduces := par_to_reg preduce
trans_R (congr_dot_R reduces) (.head (.r_dot attr_attached) .refl)
| .pr_Ļ† preduce attr_absent Ļ†_in =>
let reduces := par_to_reg preduce
trans_R (congr_dot_R reduces) (.head (.r_Ļ† attr_absent Ļ†_in) .refl)
| .pr_stop preduce attr_absent Ļ†_absent lam_absent => _
| .pr_empty preduce =>
let reduces := par_to_reg preduce
trans_R (congr_appā‚—_R reduces) (.head .r_empty .refl)
| .pr_copy preduce_t preduce_u attr_void => _
| .pr_over preduce attr_attached => _
| .pr_miss preduce attr_absent Ļ†_absent lam_absent => _
| .pr_Ī¦ => .head .r_Ī¦ .refl
| .pr_Ī¾ => .head .r_Ī¾ .refl
| .pr_dd => .head .r_dd .refl
| .pr_dc => .head .r_dc .refl
| .pr_cong_app premise preduce => _
| .pr_cong_dot preduce =>
let reduces := par_to_reg preduce
congr_dot_R reduces
| .pr_cong_obj premise => _
| .pr_termination_refl => .refl
| .pr_Ī¾_refl => .refl
| .pr_Ī¦_refl => .refl


-- def par_to_reg
-- : {t t' : Term}
-- ā†’ PReducesTo t t'
-- ā†’ ReducesToMany t t'
-- := Ī» preduces => match preduces with
-- | .pr_dot preduce attr_attached => _
-- | .pr_Ļ† preduce attr_absent Ļ†_in => _
-- | .pr_stop preduce attr_absent Ļ†_absent lam_absent => _
-- | .pr_empty preduce => _
-- | .pr_copy preduce_t preduce_u attr_void => _
-- | .pr_over preduce attr_attached => _
-- | .pr_miss preduce attr_absent Ļ†_absent lam_absent => _
-- | .pr_Ī¦ => .head .r_Ī¦ .refl
-- | .pr_Ī¾ => .head .r_Ī¾ .refl
-- | .pr_dd => .head .r_dd .refl
-- | .pr_dc => .head .r_dc .refl
-- | .pr_cong_app premise preduce => _
-- | .pr_cong_dot preduce =>
-- let reduce := par_to_reg preduce
-- _
-- | .pr_cong_obj premise => _
-- | .pr_termination_refl => .refl
-- | .pr_Ī¾_refl => .refl
-- | .pr_Ī¦_refl => .refl
30 changes: 15 additions & 15 deletions Extended/Reduction/Regular/Definition.lean
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,27 @@ inductive Reduce : Ctx ā†’ Term ā†’ Term ā†’ Type where
-- This would simplify the rules. On the other hand, from the point of view of "intermediate
-- representation for optimizations", it would make sence to allow congruence for any term of
-- the application.
-- | r_cong_appįµ£ -- congruence of arbitrary app term
-- : { ctx : Ctx }
-- ā†’ {t u u' : Term}
-- ā†’ {attr : Attr}
-- ā†’ {app_attrs : Attrs}
-- ā†’ (app_bnds : Record Term app_attrs)
-- ā†’ Contains app_bnds attr u
-- ā†’ Reduce ctx u u'
-- ā†’ Reduce ctx (app t app_bnds) (app t (Record.insert app_bnds attr u'))
| r_cong_appįµ£ -- congruence of the first app term
| r_cong_appįµ£ -- congruence of arbitrary app term
: { ctx : Ctx }
ā†’ {t u u' : Term}
ā†’ {attr : Attr}
ā†’ {app_attrs : Attrs}
ā†’ {not_in : attr āˆ‰ app_attrs}
ā†’ (app_bnds : Record Term app_attrs)
ā†’ Contains app_bnds attr u
ā†’ Reduce ctx u u'
ā†’ Reduce
ctx
(app t (Record.cons attr not_in u app_bnds))
(app t (Record.cons attr not_in u' app_bnds))
ā†’ Reduce ctx (app t app_bnds) (app t (Record.insert app_bnds attr u'))
-- | r_cong_appįµ£ -- congruence of the first app term
-- : { ctx : Ctx }
-- ā†’ {t u u' : Term}
-- ā†’ {attr : Attr}
-- ā†’ {app_attrs : Attrs}
-- ā†’ {not_in : attr āˆ‰ app_attrs}
-- ā†’ (app_bnds : Record Term app_attrs)
-- ā†’ Reduce ctx u u'
-- ā†’ Reduce
-- ctx
-- (app t (Record.cons attr not_in u app_bnds))
-- (app t (Record.cons attr not_in u' app_bnds))
| r_cong_dot
: { ctx : Ctx }
ā†’ {t t' : Term}
Expand Down

0 comments on commit 87039fe

Please sign in to comment.