From: Enrico Tassi Date: Fri, 17 Oct 2008 14:01:02 +0000 (+0000) Subject: ... X-Git-Tag: make_still_working~4674 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=e9111f50a843ffe4d8dd2ba81dc849ef382d72b0;p=helm.git ... --- diff --git a/helm/software/matita/contribs/didactic/induction.ma b/helm/software/matita/contribs/didactic/induction.ma index c9c165218..2ae94646d 100644 --- a/helm/software/matita/contribs/didactic/induction.ma +++ b/helm/software/matita/contribs/didactic/induction.ma @@ -21,8 +21,7 @@ account è mrossi deve salvare il file in /public/linguaggi_mrossi.ma *) -(*DOCBEGIN - +(* Come scrivere i simboli ======================= @@ -52,31 +51,72 @@ La sintassi 'ℕ → ℕ' è il tipo delle funzioni che preso un numero naturale restituiscono un numero naturale. - LA sintassi .. - ============== - * applicazione - * match - * min/max a b - * sottrazione + La sintassi di Matita + ===================== + + Il linguaggio di Matita si basa sul λ-calcolo CIC, la cui sintassi si + differenzia in vari aspetti da quella che solitamente viene utilizzata + per fare matematica, e ricorda quella di Scheme che state vedendo nel corso + di programmazione. - I comandi per le definizioni - ============================ + * applicazione - Esistono due tipi di definizioni: definizioni ricorsive tramite sintassi - simile a BNF, definizione di funzioni per ricorsione strutturale. + Se 'f' è una funzione che si aspetta due argomenti, l'applucazione di 'f' + agli argomenti 'x' e 'y' si scrive '(f x y)' e non 'f(x,y)'. Le parentesi + possono essere omesse se il senso è chiaro dal contesto. In particolare + vengono omesse quando l'applicazione è argomento di un operatore binario. + Esempio: 'f x y + f y x' si legge '(f x y) + (f y x)'. + + * minimo e massimo - Definire una nuova sintassi astratta - ------------------------------------ + Le funzioni 'min' e 'max' non fanno eccezione, per calcolare il + massimo tra 'x' e 'y' si scrive '(max x y)' e non 'max{x,y}' - Definizione + * Le funzioni definite per ricorsione strutturale utilizzano il costrutto + 'let rec' (ricorsione) e il costrutto 'match' (analisi per casi). -DOCEND*) + Ad esempio la funzione count definita a lezione come + + count ⊤ ≝ 1 + count (F1 ∧ F2) ≝ 1 + count F1 + count F2 + ... + + la si esprime come + + let rec count F on F ≝ + match F with + [ ⊤ ⇒ 1 + | F1 ∧ F2 ⇒ 1 + count F1 + count F2 + ... + ]. + + * Per dare la definizione ricorsiva (di un linguaggio) si usa una sintassi + simile a BNF. Per esempio per definire + + ::= "+" | "*" | "0" | "1" + + si usa il seguente comando + + inductive A : Type ≝ + | Plus : A → A → A + | Times : A → A → A + | Zero : A + | One : A + . + + La ratio è che 'Plus' prende due argomenti di tipo A per darmi un A, + mentre 'Zero' non prende nessun argomento per darmi un A. Al posto di usare + operatori infissi (0 + 0) la definizione crea operatori prefissi (funzioni). + Quindi (0+0) si scriverà come (Plus Zero Zero). + +*) (* non modificare le seguenti tre righe *) include "nat/minus.ma". definition max : nat → nat → nat ≝ λa,b:nat.let rec max n m on n ≝ match n with [ O ⇒ b | S n ⇒ match m with [ O ⇒ a | S m ⇒ max n m]] in max a b. definition min : nat → nat → nat ≝ λa,b:nat.let rec min n m on n ≝ match n with [ O ⇒ a | S n ⇒ match m with [ O ⇒ b | S m ⇒ min n m]] in min a b. + (* Esercizio 1: Definire l'albero di sintassi astratta delle formule *) inductive Formula : Type ≝ | FBot: Formula @@ -88,6 +128,7 @@ inductive Formula : Type ≝ | FNot: (*BEGIN*)Formula → Formula(*END*) . + (* Esercizio 2: Data la funzione di valutazione per gli atomi 'v', definire la funzione 'sem' per una generica formula 'F' che vi associa la semantica (o denotazione) *) @@ -107,6 +148,7 @@ let rec sem (v: nat → nat) (F: Formula) on F ≝ ] . + (* I comandi che seguono definiscono la seguente notazione: if e then risultato1 else risultato2 @@ -124,16 +166,30 @@ let rec sem (v: nat → nat) (F: Formula) on F ≝ Non modificare le linee seguenti, saltare all'esercizio 3 *) -definition if_then_else ≝ λe,t,f.match e return λ_.Formula with [ true ⇒ t | false ⇒ f]. +definition if_then_else ≝ λT:Type.λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f]. notation > "'if' term 19 e 'then' term 19 t 'else' term 90 f" non associative with precedence 90 for @{ 'if_then_else $e $t $f }. -notation < "'if' \nbsp term 19 e \nbsp 'then' \nbsp term 19 t \nbsp 'else' \nbsp term 90 f \nbsp" non associative with precedence 90 for @{ 'if_then_else $e $t $f }. -interpretation "Formula if_then_else" 'if_then_else e t f = (if_then_else e t f). +notation < "'if' \nbsp term 19 e \nbsp 'then' \nbsp term 19 t \nbsp 'else' \nbsp term 90 f \nbsp" non associative with precedence 90 for @{ 'if_then_else _ $e $t $f }. +interpretation "Formula if_then_else" 'if_then_else e t f = (if_then_else _ e t f). notation < "[[ \nbsp term 19 a \nbsp ]] \nbsp \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }. notation > "[[ term 19 a ]] \sub term 90 v" non associative with precedence 90 for @{ 'semantics $v $a }. notation > "[[ term 19 a ]]_ term 90 v" non associative with precedence 90 for @{ sem $v $a }. interpretation "Semantic of Formula" 'semantics v a = (sem v a). +(* TESTARE LA DEFINIZIONE DI SEM *) +definition v110 ≝ λx. + if eqb x 0 then 1 (* Atom 0 ↦ 1 *) + else if eqb x 1 then 1 (* Atom 1 ↦ 1 *) + else if eqb x 2 then 0 (* Atom 2 ↦ 0 *) + else 0. (* Atom _ ↦ 0 *) + + +definition formula1 ≝ (FAnd (FAtom 1) (FAtom 0)). + + +eval normalize on [[ formula1 ]]_v110. + + (* Esercizio 3: Definire la funzione di sostituzione di una formula 'G' al posto degli atomi uguali a 'x' in una formula 'F'. *) let rec subst (x:nat) (G: Formula) (F: Formula) on F ≝ @@ -149,6 +205,9 @@ let rec subst (x:nat) (G: Formula) (F: Formula) on F ≝ | FNot F ⇒ FNot (subst x G F) ]. +(* AGGIUNGERE ALCUNI TEST *) + + (* I comandi che seguono definiscono la seguente notazione: * F [ G / x ] @@ -172,6 +231,8 @@ notation "hvbox(a \nbsp break mstyle color #0000ff (≡) \nbsp b)" non associat notation > "a ≡ b" non associative with precedence 50 for @{ equiv $a $b }. interpretation "equivalence for Formulas" 'equivF a b = (equiv a b). + + (* Esercizio 4: Prove the substitution theorem *) theorem substitution: ∀G1,G2,F,x. G1 ≡ G2 → F[G1/x] ≡ F[G2/x]. assume G1 : Formula. @@ -296,6 +357,9 @@ case FNot. (*END*) done. qed. + +eval normalize on + (substitution (FAtom 1) (FAtom 1) formula1 1 (λ_.refl_eq ??) v110). (* Questionario