Debian Codegraph @

examples/prism-coq.html

raw symbols SCIP
1 <h2>Full example</h2>
2 <pre><code>(* Source: https://coq.inria.fr/a-short-introduction-to-coq *)
3
4 Inductive seq : nat -> Set :=
5 | niln : seq 0
6 | consn : forall n : nat, nat -> seq n -> seq (S n).
7
8 Fixpoint length (n : nat) (s : seq n) {struct s} : nat :=
9 match s with
10 | niln => 0
11 | consn i _ s' => S (length i s')
12 end.
13
14 Theorem length_corr : forall (n : nat) (s : seq n), length n s = n.
15 Proof.
16 intros n s.
17
18 (* reasoning by induction over s. Then, we have two new goals
19 corresponding on the case analysis about s (either it is
20 niln or some consn *)
21 induction s.
22
23 (* We are in the case where s is void. We can reduce the
24 term: length 0 niln *)
25 simpl.
26
27 (* We obtain the goal 0 = 0. *)
28 trivial.
29
30 (* now, we treat the case s = consn n e s with induction
31 hypothesis IHs *)
32 simpl.
33
34 (* The induction hypothesis has type length n s = n.
35 So we can use it to perform some rewriting in the goal: *)
36 rewrite IHs.
37
38 (* Now the goal is the trivial equality: S n = S n *)
39 trivial.
40
41 (* Now all sub cases are closed, we perform the ultimate
42 step: typing the term built using tactics and save it as
43 a witness of the theorem. *)
44 Qed.
45 </code></pre>