Fil-C on Nix

Filnix wiki

the formal campaign

rocq/theories/ValidFast.v

The validator with its single definitions found through a name map, and the proof that it answers as Validate.v's valid does.

single_definitions asks, for each definition of a function, how many definitions share its name, and answers by walking the list of all of them: time that grows with the square of their number. Three functions of SQLite have 6,000 to 14,800 definitions, and that walk was 7 of the 18 seconds valid took on its module. single_definitions_fast counts every name once, in a name map, and then keeps the definitions whose name counts one.

valid stays the specification: the proofs of the reuse forms read single_definitions, and nothing in them changes. valid_fast is what an extracted program runs, and valid_fast_eq says the two are one function. The definitions from stage_sources_fast down to valid_fast repeat Validate.v's with the one name replaced; each equality is proved by unfolding both sides, so a change to one side that the other lacks stops the build here.

From Stdlib Require Import String ZArith List Bool Lia
From Nanofil Require Import Term Maps Syntax Cfg Validate
Import ListNotations
Open Scope string_scope
Open Scope Z_scope
Open Scope list_scope

Counting definitions

How many of the definitions ds define the name n: the length single_definitions compares with one.

33Definition def_countn : name ds : listname × def : nat ≔
lengthfilterλd′ ⇒ name_eqbn fstd′ ds

The map from each name the definitions ds define to how many of them define it, built in one pass over ds.

38Definition def_countsds : listname × def : nmapnat ≔
fold_left
λ m d  ⇒
nm_addfstd
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1%nat
m
ds

As single_definitions: the temporaries of the function f with exactly one definition, each with it, in the same order.

45Definition single_definitions_fastf : func : listname × def ≔
let ds ≔ all_defsf in
let counts ≔ def_countsds in
filter
λ d  ⇒
match nm_findfstd counts with
Somec
⇒
c =? 1%nat
None
⇒
false
ds

Counting the definitions ds into a map m adds, to what m held for the name n, the number of them that define n.

55Lemma def_counts_fold
∀ n ds m
fold_left
λ m d  ⇒
nm_addfstd
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1%nat
m
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
Explore proof 14 tactics

Initial goal

⊢
∀ n : name ds : listname × def m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds

intros n ds

n :
ds :
listname × def
⊢
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds

induction ds as | d ds IH ; intros m

2 open

n :
m :
nmapnat
⊢
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
[ ]
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn [ ]%nat
None
⇒
def_countn [ ] =? 0%nat
→
None
else
Somedef_countn [ ]
focused goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
⊢
fold_left
λ m0 : nmapnat d0 : name × def  ⇒
nm_addfstd0
match nm_findfstd0 m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
d :: ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn d :: ds%nat
None
⇒
def_countn d :: ds =? 0%nat
→
None
else
Somedef_countn d :: ds

–simpl

2 open

n :
m :
nmapnat
⊢
=
let* c ≔ nm_findn m in
Somec + def_countn [ ]%nat
deferred goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
⊢
fold_left
λ m0 : nmapnat d0 : name × def  ⇒
nm_addfstd0
match nm_findfstd0 m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
d :: ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn d :: ds%nat
None
⇒
def_countn d :: ds =? 0%nat
→
None
else
Somedef_countn d :: ds

destruct nm_findn m ; rewrite Nat.add_0_r | ; reflexivity

deferred goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
⊢
fold_left
λ m0 : nmapnat d0 : name × def  ⇒
nm_addfstd0
match nm_findfstd0 m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
d :: ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn d :: ds%nat
None
⇒
def_countn d :: ds =? 0%nat
→
None
else
Somedef_countn d :: ds

–cbn [ fold_left ]

n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
⊢
fold_left
λ m0 : nmapnat d0 : name × def  ⇒
nm_addfstd0
match nm_findfstd0 m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
nm_addfstd
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1%nat
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn d :: ds%nat
None
⇒
def_countn d :: ds =? 0%nat
→
None
else
Somedef_countn d :: ds

rewrite IH , nm_find_add

n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
⊢
match if name_eqbn fstd then Somematch nm_findfstd m with Somec ⇒ Sc | None ⇒ 1%nat end else nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
=
match nm_findn m with
Somec
⇒
Somec + def_countn d :: ds%nat
None
⇒
def_countn d :: ds =? 0%nat
→
None
else
Somedef_countn d :: ds

unfold def_count

n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
⊢
match if name_eqbn fstd then Somematch nm_findfstd m with Somec ⇒ Sc | None ⇒ 1%nat end else nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ d :: ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ d :: ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ d :: ds

cbn [ filter ]

n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
⊢
match if name_eqbn fstd then Somematch nm_findfstd m with Somec ⇒ Sc | None ⇒ 1%nat end else nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Some
c
+
Datatypes.length
name_eqbn fstd
→
d :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds
else
filterλd′ : name × def ⇒ name_eqbn fstd′ ds
None
⇒
Datatypes.length
name_eqbn fstd
→
d :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds
else
filterλd′ : name × def ⇒ name_eqbn fstd′ ds
=?
0
→
None
else
Some
Datatypes.length
name_eqbn fstd
→
d :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds
else
filterλd′ : name × def ⇒ name_eqbn fstd′ ds

destruct name_eqbn fstd eqn: E

2 open

n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
E :
name_eqbn fstd = true
⊢
Some
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1
+
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds
focused goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
E :
name_eqbn fstd = false
⊢
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds

+apply term_eqb_eq in E

2 open

n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
E :
n = fstd
⊢
Some
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1
+
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbn fstd′ ds
deferred goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
E :
name_eqbn fstd = false
⊢
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds

subst n

2 open

d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findfstd m with
Somec
⇒
Somec + def_countfstd ds%nat
None
⇒
def_countfstd ds =? 0%nat
→
None
else
Somedef_countfstd ds
m :
nmapnat
⊢
Some
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1
+
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ ds
=
match nm_findfstd m with
Somec
⇒
Somec + Datatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbfstd fstd′ ds%nat
None
⇒
Datatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbfstd fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthd :: filterλd′ : name × def ⇒ name_eqbfstd fstd′ ds
deferred goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
E :
name_eqbn fstd = false
⊢
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds

cbn [ length ]

2 open

d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findfstd m with
Somec
⇒
Somec + def_countfstd ds%nat
None
⇒
def_countfstd ds =? 0%nat
→
None
else
Somedef_countfstd ds
m :
nmapnat
⊢
Some
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1
+
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ ds
=
match nm_findfstd m with
Somec
⇒
Somec + SDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ ds%nat
None
⇒
SDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ ds =? 0%nat
→
None
else
SomeSDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ ds
deferred goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
E :
name_eqbn fstd = false
⊢
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds

destruct nm_findfstd m ; simpl ; f_equal ; lia

deferred goal
n :
d :
name × def
ds :
listname × def
IH :
∀ m : nmapnat  ,
fold_left
λ m0 : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m0 with
Somec
⇒
Sc
None
⇒
1%nat
m0
ds
m
=
match nm_findn m with
Somec
⇒
Somec + def_countn ds%nat
None
⇒
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
m :
nmapnat
E :
name_eqbn fstd = false
⊢
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds
=
match nm_findn m with
Somec
⇒
Somec + Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds%nat
None
⇒
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds =? 0%nat
→
None
else
SomeDatatypes.lengthfilterλd′ : name × def ⇒ name_eqbn fstd′ ds

+reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros n ds
induction ds as | d ds IH ; intros m
–simpl
destruct nm_findn m ; rewrite Nat.add_0_r | ; reflexivity
–cbn [ fold_left ]
rewrite IH , nm_find_add
unfold def_count
cbn [ filter ]
destruct name_eqbn fstd eqn: E
+apply term_eqb_eq in E
subst n
cbn [ length ]
destruct nm_findfstd m ; simpl ; f_equal ; lia
+reflexivity

The map of counts answers, for a name n, the number of definitions of n when there is one, and nothing otherwise.

77Lemma def_counts_find
∀ n ds
=
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
Explore proof 4 tactics

Initial goal

⊢
∀ n : name ds : listname × def  ,
=
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds

intros n ds

n :
ds :
listname × def
⊢
=
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds

unfold def_counts

n :
ds :
listname × def
⊢
fold_left
λ m : nmapnat d : name × def  ⇒
nm_addfstd
match nm_findfstd m with
Somec
⇒
Sc
None
⇒
1%nat
m
ds
=
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds

rewrite def_counts_fold , nm_find_empty

n :
ds :
listname × def
⊢
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds
=
def_countn ds =? 0%nat
→
None
else
Somedef_countn ds

reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros n ds
unfold def_counts
reflexivity

The single definitions found through the map are those single_definitions finds, as one list.

86Theorem single_definitions_fast_eq
Explore proof 7 tactics

Initial goal

intros f

unfold single_definitions_fast , single_definitions

f :
⊢
filter
λ d : name × def  ⇒
match nm_findfstd def_countsall_defsf with
Somec
⇒
c =? 1%nat
None
⇒
false
=
filterλd : name × def ⇒ Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ all_defsf =? 1%nat all_defsf

apply filter_ext

f :
⊢
∀ a : name × def  ,
match nm_findfsta def_countsall_defsf with
Somec
⇒
c =? 1%nat
None
⇒
false
=
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbfsta fstd′ all_defsf =? 1%nat

intros d

f :
d :
name × def
⊢
match nm_findfstd def_countsall_defsf with
Somec
⇒
c =? 1%nat
None
⇒
false
=
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ all_defsf =? 1%nat

rewrite def_counts_find

f :
d :
name × def
⊢
match if def_countfstd all_defsf =? 0%nat then None else Somedef_countfstd all_defsf with
Somec
⇒
c =? 1%nat
None
⇒
false
=
Datatypes.lengthfilterλd′ : name × def ⇒ name_eqbfstd fstd′ all_defsf =? 1%nat

fold def_countfstd all_defsf

f :
d :
name × def
⊢
match if def_countfstd all_defsf =? 0%nat then None else Somedef_countfstd all_defsf with
Somec
⇒
c =? 1%nat
None
⇒
false
=
def_countfstd all_defsf =? 1%nat

destruct def_countfstd all_defsf as | c ; reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros f
apply filter_ext
intros d
destruct def_countfstd all_defsf as | c ; reflexivity

The validator over them

97Definition stage_sources_fastmd : module f : func doms : nmapZ × Z : src ≔
→
mkSrc[ ] [ ] [ ] [ ]
else
let once ≔ single_definitions_fastf in
flat_map
λ b  ⇒
flat_map
λ i  ⇒
match renew_sourceonce i with
Somer
⇒
r
None
⇒
[ ]
once
repeated_gettersmd f doms once
107Definition stage_func_fastmd : module f : func doms : nmapZ × Z : bool ≔
111Definition valid_func_fastmd : module f : func : bool ≔
let bs ≔ fn_blocksf in
let defs ≔ temp_defsf in
match bs, block_intervalsbs with
[ ], _ | _, None
⇒
false
entry :: _, Somedoms
⇒
match fn_linkagef with
TAtom"export" | "local" | "weak"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
lengthks =? 2%nat && forallbλk ⇒ existsbclass_eqbk L; P; Single; Double ks
⇒
true
&&
&&
&&
&&
negbexistsbλb ⇒ memb_labelentry succ_labelsb_jumpb bs
&&
&&
&&
&&
forallbvalid_blockmd f defs bs
&&
negbmodule_checkedmd || stage_func_fastmd f doms
137Definition valid_items_fastmd : module : bool ≔
&&
forallb
λ it  ⇒
match it with
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
⇒
true
md

As valid, with valid_items_fast: what an extracted program runs.

148Definition valid_fastmd : module : optionbool ≔
existsb
λ it  ⇒
match it with
⇒
true
_
⇒
false
md
→
None

They are the validator

154Lemma stage_sources_fast_eq
∀ md f doms
stage_sources_fastmd f doms = stage_sourcesmd f doms
Explore proof 4 tactics

Initial goal

⊢
∀md : module f : func doms : nmapZ × Z, stage_sources_fastmd f doms = stage_sourcesmd f doms

intros md f doms

md :
f :
doms :
nmapZ × Z
⊢
stage_sources_fastmd f doms = stage_sourcesmd f doms

unfold stage_sources_fast , stage_sources

md :
f :
doms :
nmapZ × Z
⊢
→
s_renews ≔ [ ]; s_once ≔ [ ]; s_ahead ≔ [ ]; s_getters ≔ [ ]
else
s_renews ≔ flat_mapλb : block ⇒ flat_mapλi : inst ⇒ match renew_sourcesingle_definitions_fastf i with Somer ⇒ r | None ⇒ [ ] end b_instsb fn_blocksf; s_once ≔ single_definitions_fastf; s_ahead ≔ ahead_justifiedf single_definitions_fastf; s_getters ≔ repeated_gettersmd f doms single_definitions_fastf
=
→
s_renews ≔ [ ]; s_once ≔ [ ]; s_ahead ≔ [ ]; s_getters ≔ [ ]
else
s_renews ≔ flat_mapλb : block ⇒ flat_mapλi : inst ⇒ match renew_sourcesingle_definitionsf i with Somer ⇒ r | None ⇒ [ ] end b_instsb fn_blocksf; s_once ≔ single_definitionsf; s_ahead ≔ ahead_justifiedf single_definitionsf; s_getters ≔ repeated_gettersmd f doms single_definitionsf

rewrite single_definitions_fast_eq

md :
f :
doms :
nmapZ × Z
⊢
→
s_renews ≔ [ ]; s_once ≔ [ ]; s_ahead ≔ [ ]; s_getters ≔ [ ]
else
s_renews ≔ flat_mapλb : block ⇒ flat_mapλi : inst ⇒ match renew_sourcesingle_definitionsf i with Somer ⇒ r | None ⇒ [ ] end b_instsb fn_blocksf; s_once ≔ single_definitionsf; s_ahead ≔ ahead_justifiedf single_definitionsf; s_getters ≔ repeated_gettersmd f doms single_definitionsf
=
→
s_renews ≔ [ ]; s_once ≔ [ ]; s_ahead ≔ [ ]; s_getters ≔ [ ]
else
s_renews ≔ flat_mapλb : block ⇒ flat_mapλi : inst ⇒ match renew_sourcesingle_definitionsf i with Somer ⇒ r | None ⇒ [ ] end b_instsb fn_blocksf; s_once ≔ single_definitionsf; s_ahead ≔ ahead_justifiedf single_definitionsf; s_getters ≔ repeated_gettersmd f doms single_definitionsf

reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros md f doms
reflexivity
161Lemma stage_func_fast_eq
∀ md f doms
stage_func_fastmd f doms = stage_funcmd f doms
Explore proof 4 tactics

Initial goal

⊢
∀md : module f : func doms : nmapZ × Z, stage_func_fastmd f doms = stage_funcmd f doms

intros md f doms

md :
f :
doms :
nmapZ × Z
⊢
stage_func_fastmd f doms = stage_funcmd f doms

unfold stage_func_fast , stage_func

rewrite stage_sources_fast_eq

reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros md f doms
reflexivity

One function is judged alike.

169Theorem valid_func_fast_eq
∀ md f
Explore proof 6 tactics

Initial goal

⊢
∀md : module f : func, valid_func_fastmd f = valid_funcmd f

intros md f

unfold valid_func_fast , valid_func

md :
f :
⊢
match fn_blocksf with
[ ]
⇒
false
entry :: l
⇒
match block_intervalsentry :: l with
Somedoms
⇒
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb fn_blocksf
&&
&&
&&
&&
&&
negbmodule_checkedmd || stage_func_fastmd f doms
None
⇒
false
=
match fn_blocksf with
[ ]
⇒
false
entry :: l
⇒
match block_intervalsentry :: l with
Somedoms
⇒
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb fn_blocksf
&&
&&
&&
&&
&&
negbmodule_checkedmd || stage_funcmd f doms
None
⇒
false

destruct fn_blocksf as | entry bs ; reflexivity |

md :
f :
entry :
bs :
listblock
⊢
match block_intervalsentry :: bs with
Somedoms
⇒
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
no_dupsmapb_label entry :: bs
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb entry :: bs
&&
&&
&&
&&
forallbvalid_blockmd f temp_defsf entry :: bs
&&
negbmodule_checkedmd || stage_func_fastmd f doms
None
⇒
false
=
match block_intervalsentry :: bs with
Somedoms
⇒
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
no_dupsmapb_label entry :: bs
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb entry :: bs
&&
&&
&&
&&
forallbvalid_blockmd f temp_defsf entry :: bs
&&
negbmodule_checkedmd || stage_funcmd f doms
None
⇒
false

destruct block_intervalsentry :: bs as doms | ; | reflexivity

md :
f :
entry :
bs :
listblock
doms :
nmapZ × Z
⊢
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
no_dupsmapb_label entry :: bs
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb entry :: bs
&&
&&
&&
&&
forallbvalid_blockmd f temp_defsf entry :: bs
&&
negbmodule_checkedmd || stage_func_fastmd f doms
=
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
no_dupsmapb_label entry :: bs
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb entry :: bs
&&
&&
&&
&&
forallbvalid_blockmd f temp_defsf entry :: bs
&&
negbmodule_checkedmd || stage_funcmd f doms

rewrite stage_func_fast_eq

md :
f :
entry :
bs :
listblock
doms :
nmapZ × Z
⊢
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
no_dupsmapb_label entry :: bs
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb entry :: bs
&&
&&
&&
&&
forallbvalid_blockmd f temp_defsf entry :: bs
&&
negbmodule_checkedmd || stage_funcmd f doms
=
match fn_linkagef with
TAtom"weak" | TAtom"export" | TAtom"local"
⇒
true
_
⇒
false
&&
match fn_retf with
⇒
true
⇒
Datatypes.lengthks =? 2%nat && forallbλk : class ⇒ existsbclass_eqbk L; P; Single; Double ks
&&
&&
no_dupsmapb_label entry :: bs
&&
&&
negbexistsbλb : block ⇒ memb_labelentry succ_labelsb_jumpb entry :: bs
&&
&&
&&
&&
forallbvalid_blockmd f temp_defsf entry :: bs
&&
negbmodule_checkedmd || stage_funcmd f doms

reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros md f
destruct fn_blocksf as | entry bs ; reflexivity |
destruct block_intervalsentry :: bs as doms | ; | reflexivity
reflexivity
177Lemma valid_items_fast_eq
Explore proof 9 tactics

Initial goal

⊢

intros md

unfold valid_items_fast , valid_items

md :
⊢
&&
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md
=
&&
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md

f_equal

md :
⊢
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md

assert H : ∀its, forallbλit ⇒ match it with IFuncf ⇒ valid_func_fastmd f | IDatan lk al its ⇒ valid_datamd n lk al its | IAliasn lk t ⇒ valid_aliasmd n lk t | IOutside_ _ ⇒ true end its = forallbλit ⇒ match it with IFuncf ⇒ valid_funcmd f | IDatan lk al its ⇒ valid_datamd n lk al its | IAliasn lk t ⇒ valid_aliasmd n lk t | IOutside_ _ ⇒ true end its

2 open

md :
⊢
∀ its : listitem  ,
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
focused goal
md :
H :
∀ its : listitem  ,
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md

{induction its as | it its IH ; reflexivity |

2 open

md :
it :
its :
listitem
IH :
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
forallb
λ it0 : item  ⇒
match it0 with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
it :: its
=
forallb
λ it0 : item  ⇒
match it0 with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
it :: its
deferred goal
md :
H :
∀ its : listitem  ,
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md

cbn [ forallb ]

2 open

md :
it :
its :
listitem
IH :
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
&&
forallb
λ it0 : item  ⇒
match it0 with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
&&
forallb
λ it0 : item  ⇒
match it0 with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
deferred goal
md :
H :
∀ its : listitem  ,
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md

rewrite IH

2 open

md :
it :
its :
listitem
IH :
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
&&
forallb
λ it0 : item  ⇒
match it0 with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
&&
forallb
λ it0 : item  ⇒
match it0 with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
deferred goal
md :
H :
∀ its : listitem  ,
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md

destruct it ; try rewrite valid_func_fast_eq ; reflexivity

deferred goal
md :
H :
∀ its : listitem  ,
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its0
⇒
valid_datamd n lk al its0
IAliasn lk t
⇒
valid_aliasmd n lk t
its
⊢
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md
=
forallb
λ it : item  ⇒
match it with
⇒
true
IDatan lk al its
⇒
valid_datamd n lk al its
IAliasn lk t
⇒
valid_aliasmd n lk t
md

apply H

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros md
f_equal
assert H : ∀its, forallbλit ⇒ match it with IFuncf ⇒ valid_func_fastmd f | IDatan lk al its ⇒ valid_datamd n lk al its | IAliasn lk t ⇒ valid_aliasmd n lk t | IOutside_ _ ⇒ true end its = forallbλit ⇒ match it with IFuncf ⇒ valid_funcmd f | IDatan lk al its ⇒ valid_datamd n lk al its | IAliasn lk t ⇒ valid_aliasmd n lk t | IOutside_ _ ⇒ true end its
{induction its as | it its IH ; reflexivity |
cbn [ forallb ]
rewrite IH
destruct it ; try rewrite valid_func_fast_eq ; reflexivity
apply H

valid_fast accepts, refuses and declines to judge exactly the modules valid does.

200Theorem valid_fast_eq
∀ md
Explore proof 4 tactics

Initial goal

⊢
∀md : module, valid_fastmd = validmd

intros md

md :
⊢

unfold valid_fast , valid

md :
⊢
existsb
λ it : item  ⇒
match it with
⇒
true
_
⇒
false
md
→
None
=
existsb
λ it : item  ⇒
match it with
⇒
true
_
⇒
false
md
→
None
else

rewrite valid_items_fast_eq

md :
⊢
existsb
λ it : item  ⇒
match it with
⇒
true
_
⇒
false
md
→
None
else
=
existsb
λ it : item  ⇒
match it with
⇒
true
_
⇒
false
md
→
None
else

reflexivity

No remaining goals.

Qed

✓ Proof checked and closed by Rocq.

Source script
intros md
unfold valid_fast , valid
reflexivity