Fil-C on Nix

Filnix wiki

the formal campaign

rocq/backend/NfbProof.v

What NFB's Gallina reader and writer (NfbTerm.v, Nfb.v) are proved to do (docs/nfb.md, Relation to the term form and the Rocq model).

From Stdlib Require Import String ZArith List Bool Lia
From Nanofil Require Import Term Syntax Transport Cfg
From Backend Require Import NfbTerm Nfb NfbRead NfbTransport
Import ListNotations
Open Scope Z_scope

Canonical form

Whether the reader finds a NAMES section in ws.

24Definition names_ofws : listZ : bool ≔
match read_termws with
Some_, b
⇒
b
None
⇒
false

The words decode takes are exactly the words encode_with writes for the module it gives, with NAMES if they have it: no other spelling of a module is read.

30Theorem decode_canonical
∀ ws m
decodews = Somem
Proof 12 steps Qed
intros ws m H
unfold decode , names_of in *
destruct read_termws as t b | ; try discriminate
simpl in H
destruct decode_modulet as m0 | ; try discriminate
destruct encode_withb m0 as ws1 | eqn: E1 ; try discriminate
destruct module_wordsws as ws2 | ; try discriminate
destruct words_eqbws1 ws2 eqn: E3 ; try discriminate
injection H as ←
apply words_eqb_eq in E3
subst
exact E1

Two lists of words that decode reads as the same module, both with NAMES or both without, are the same words once CONTEXT and tools' sections are set aside: the module id the document defines over them is sound.

46Corollary decode_identity
∀ ws1 ws2 m
decodews1 = Somem
decodews2 = Somem
Proof 3 steps Qed
intros ws1 ws2 m H1 H2 E
rewrite <- decode_canonical_ _ H1 , <- decode_canonical_ _ H2 , E
reflexivity

Round trip

A list of words is equal to itself by words_eqb.

57Lemma words_eqb_refl
∀ xs
words_eqbxs xs = true
Proof 3 steps Qed
induction xs as | x xs IH ; simpl ; reflexivity |
rewrite Z.eqb_refl
exact IH

A module that decode_module reads from a term, once written as words, is read back as itself, NAMES included.

62Theorem round_trip
∀ t m ws
decode_modulet = Somem
encodem = Somews
decodews = Somem
Proof 10 steps Qed
intros t m ws Hd He
unfold encode , encode_with in He
destruct read_encode_term_ _ He as b Hr Hb Hw
unfold decode
rewrite Hr
cbn [ fst snd ]
rewrite decode_enc_module_ _ Hd
rewrite Hb , Hw , words_eqb_refl
reflexivity

decode_input, the reader without decode's check, reads a module back as itself too.

74Theorem input_round_trip
∀ t m ws
decode_modulet = Somem
encodem = Somews
decode_inputws = Somem
Proof 7 steps Qed
intros t m ws Hd He
unfold encode , encode_with in He
destruct read_encode_term_ _ He as b Hr _
rewrite Hr
cbn [ fst ]
exact decode_enc_module_ _ Hd