rocq/theories/Term.v
Ground Prolog terms, the shape every nanofil product has before it means anything: an integer, an atom, a compound of a name and arguments, or a proper list.
The model uses them twice. The names of nanofil's intermediate representation (IR), its temporaries, block labels, symbols and named locals, are ground terms, compared only for equality, as ir.pl says: "Temps are ground names". And a module or an outcome crosses between Prolog and the extracted model as a term, which Transport.v decodes into the syntax of Syntax.v and encodes back.
A ground Prolog term, one constructor per form. A proper list is its own form rather than nested '[|]'/2 compounds, so that decoding a list of blocks or instructions is a map.
| | | TInt | n : Z | the integer n |
| | | TAtom | a : string | the atom a, [ ] included |
| | | TApp | the compound f(A1, ..., An), with at least one argument | |
| | | TList | ts : listterm | the proper list [T1, ..., Tn] |
Term equality, structural, as Prolog's ==/2 on ground terms.
term_eqb is sound: two terms t and u it calls equal are the same term, so a name found by comparing is the very name asked for.
Explore proof 22 tactics
Initial goal
fix IH 1
intros t u H
destruct t as n | a | f ts | ts , u as n′ | a′ | f′ us | us ; simpl in H ; try discriminate H
4 openfocused goal
–f_equal
4 opendeferred goal
apply Z.eqb_eq
4 opendeferred goal
exact H
3 opendeferred goal
–f_equal
3 openapply String.eqb_eq
3 openexact H
2 open–apply andb_true_iff in H as Hf Hl
2 openapply String.eqb_eq in Hf
2 opensubst f′
2 openf_equal
2 openrevert us Hl
2 openinduction ts as | t ts IHl ; intros | u us Hl ; simpl in Hl ; try discriminate Hl ; auto
2 openapply andb_true_iff in Hl as H1 H2
2 openf_equal ; apply IH ; exact H1 | apply IHl ; exact H2
–f_equal
revert us H
induction ts as | t ts IHl ; intros | u us Hl ; simpl in Hl ; try discriminate Hl ; auto
apply andb_true_iff in Hl as H1 H2
f_equal ; apply IH ; exact H1 | apply IHl ; exact H2
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
Every term t is term_eqb-equal to itself, as Prolog's ==/2 holds of a term and itself.
Explore proof 13 tactics
Initial goal
fix IH 1
intros t
destruct t as n | a | f ts | ts ; simpl
4 openfocused goal
–apply Z.eqb_refl
3 opendeferred goal
–apply String.eqb_refl
2 opendeferred goal
–rewrite String.eqb_refl
2 opensimpl
2 openinduction ts as | t ts IHl ; simpl ; auto
2 openrewrite IH
2 openexact IHl
–induction ts as | t ts IHl ; simpl ; auto
rewrite IH
exact IHl
No remaining goals.
Qed
✓ Proof checked and closed by Rocq.
Source script
Equality of names, which is term_eqb.
As memberchk(Key-V, Pairs): the value of the first pair of the association list ps whose key is k, if any. Prolog's library(assoc) and the association lists here agree on every lookup: a key is put once, or replaced.
As put_assoc(Key, Assoc0, V, Assoc): the association list ps with k now mapped to v, in front, and k's old pair dropped.
The code of t, a one-character atom, as char_code/2 gives it, for the codes 0 to 2047: one byte below 128, or a two-byte UTF-8 sequence. Any other term, or an atom of another code, has none.