Création de Types

Avec Inductive

Inductive jour : Set :=
lundi : jour | mardi : jour | mercredi : jour |
jeudi : jour | vendredi : jour | samedi : jour |
dimanche : jour.
Inductive fonction : Set :=
 fid: fonction
|fconst: R -> fonction
|fsin: fonction
|fcos: fonction
|fexp: fonction
|fplus: fonction -> fonction -> fonction
|fmoins: fonction -> fonction -> fonction
|fmult: fonction -> fonction -> fonction
|fcomp: fonction -> fonction -> fonction
.

Ensuite, pour concretiser (interpréter) les fonctions, on interprète en matchant le constructeur:

Fixpoint interp (f:fonction) (x:R) : R :=
 match f with 
|fid => x
|fconst r => r
|fsin => sin x
|fcos => cos x
|fexp => exp x
|fplus f g => (interp f x) + (interp g x)
|fmoins f g => (interp f x) - (interp g x)
|fmult f g => (interp f x) * (interp g x)
|fcomp f g => interp f (interp g x)
end.

TD Preuves : Types

Avec Definition

Exemple donné dans l'énoncé du projet certification (sans préciser un constructeur):

Definition paire_entiers := (nat * nat)%type.

Avec Inductive

Un seul constructeur, pour faire des couples:

Require Export ZArith.
Inductive GaussInt : Set :=
c : Z ->Z-> GaussInt.

Avec Fixpoint

Autres Créations

Avec Definition

deux fonctions jour→jour

Definition jour_suivant (j:jour) : jour :=
match j with
|lundi => mardi | mardi => mercredi | mercredi => jeudi
| jeudi => vendredi | vendredi => samedi 
| samedi => dimanche | dimanche => lundi
end.

Definition jour_precedent (j:jour) : jour :=
match j with
| mardi => lundi | mercredi => mardi | jeudi => mercredi
| vendredi => jeudi | samedi => vendredi 
| dimanche => samedi | lundi => dimanche
end.
 
m1ilc/preuves_defs.txt · Dernière modification: 2011/04/09 09:21 par suitable
 
Sauf mention contraire, le contenu de ce wiki est placé sous la licence suivante :CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki