Download Matita Tutorial - Dipartimento di Informatica
Transcript
Matita Tutorial
·
145
n ≤ m ↔ leb n m = true
Then, we could reduce the verification of 2 ≤ 3! to that of of leb 2 3! = true that
just requires a mere computation!
5.8
Finite Sets
A finite set is a record consisting of a DeqSet A, a list of elements of type A enumerating all the elements of the set, and the proofs that the enumeration does not
contain repetitions and is complete (memb is the membership operation on lists, defined in the obvious way, and uniqueb is the function that returns true if its third
argument is an enumeration without repetitions).
record FinSet : Type[1] :=
{ FinSetcarr:> DeqSet
; enum: list FinSetcarr
; enum_unique: uniqueb FinSetcarr enum = true
; enum_complete : ∀x:FinSetcarr. memb ? x enum = true}.
The standard library of Matita provides many operations for building new FinSets
by composing existing ones: for example, if A and B have type FinSet, then option A,
A×B, A+B are finite sets too. In all these cases, unification hints are used to suggest
the intended finite set structure associated with them, that makes their use quite
transparent to the user.
A particularly interesting case is that of the arrow type A → B. We may define
the graph of f:A → B, as the set (sigma type) of all pairs ha,bi such that f a = b.
definition graph_of :=λA,B.λf:A→ B. Σp:A×B.f (\fst p) = \snd p.
When the equality on B is decidable, we can effectively enumerate all elements of the
graph by simply filtering from pairs in A×B those satisfying the test
λp.f (\fst p) == \snd p, as expressed by the following definition:
definition graph_enum :=λA,B:FinSet.λf:A→ B.
filter ? (λp.f (\fst p) == \snd p) (enum (FinProd A B)).
The proofs that this enumeration does not contain repetitions and is complete are
straightforward.
5.9
Vectors
A vector of length n of elements of type A is simply defined in Matita as a record
composed by a list of elements of type A, plus a proof that the list has the expected
length. Vectors are a paradigmatic example of dependent type, that is of a type
whose definition depends on a term.
record Vector (A:Type[0]) (n:nat): Type[0] :=
{ vec :>list A
; len: length ? vec = n }.
Given a list l we may trivially turn it into a vector of length |l|; we just need to
prove that |l|=|l|, which follows from the reflexivity of equality.
Journal of Formalized Reasoning Vol. 7, No. 2, 2014.