Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Coq Exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Max Ole Elliger
Coq Exercises
Commits
dcfc326d
Unverified
Commit
dcfc326d
authored
1 year ago
by
Max Ole Elliger
Browse files
Options
Downloads
Patches
Plain Diff
rm ind/OldMaterial.v
parent
ab4b26d7
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!39
New Chapter about Induction
Pipeline
#134307
passed
1 year ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ind/OldMaterial.v
+0
-324
0 additions, 324 deletions
ind/OldMaterial.v
with
0 additions
and
324 deletions
ind/OldMaterial.v
deleted
100644 → 0
+
0
−
324
View file @
ab4b26d7
(
**
In
diesem
File
m
ö
chte
ich
ein
paar
Worte
zum
Beweisprinzip
Induktion
verlieren
.
Ich
beabsichtige
hier
nicht
,
eine
komplette
Einf
ü
hrung
in
Coq
zu
geben
;
vielmehr
m
ö
chte
ich
ein
paar
(
hoffentlich
selbsterkl
ä
rende
)
Beispiele
geben
,
die
jeweils
die
Struktur
des
Induktionsbeweises
aufzeigen
sollen
.
*
)
Module
nat_playground
.
(
**
Der
typische
Fall
struktureller
Induktion
ist
die
vollst
ä
ndige
Induktion
.
Diese
baut
auf
den
nat
ü
rlichen
Zahlen
auf
.
Diese
k
ö
nnen
wir
mittels
folgender
Grammatik
angeben
:
n
::=
O
|
S
n
Solche
Strukturen
kann
man
auch
in
Coq
formalisieren
:
*
)
Inductive
my_nat
:=
|
zero
:
my_nat
|
succ
(
n
:
my_nat
)
:
my_nat
.
Check
my_nat
.
Print
my_nat
.
(
**
So
eine
Definition
gibt
es
nat
ü
rlich
schon
standardm
äß
ig
in
Coq
:
*
)
Check
nat
.
Print
nat
.
(
**
Man
kann
auf
den
nat
ü
rlichen
Zahlen
rekursive
Funktionen
definieren
,
sogenannte
Fixpunkte
.
*
)
Fixpoint
addN
(
n
m
:
my_nat
)
:
my_nat
:=
match
n
with
|
zero
=>
m
|
succ
n
'
=>
succ
(
addN
n
'
m
)
(
**
Ich
rechne
also
wie
folgt
:
(
n
+
1
)
+
m
=
1
+
(
n
+
m
)
*
)
end
.
(
**
Die
folgenden
3
Beweise
sind
mathematisch
gesehen
sehr
elementar
.
Mir
geht
es
hier
prim
ä
r
darum
,
einen
Blick
auf
das
Beweisprinzip
der
(
hier
)
vollst
ä
ndigen
Induktion
zu
lenken
;
ein
genaues
Nachvollziehen
der
einen
Unterbeweise
ist
nicht
mein
Ziel
.
Trotzdem
hoffe
ich
,
halbwegs
lesbare
Beweise
geschrieben
zu
haben
trotz
wahrscheinlich
noch
unbekannter
Taktiken
.
*
)
Lemma
addN_zero_r
:
forall
(
n
:
my_nat
),
addN
n
zero
=
n
.
Proof
.
intro
n
.
induction
n
as
[
|
n
'
IV
].
(
**
Wir
machen
also
nun
Induktion
ü
ber
n
:
Im
Induktionsanfang
nehmen
wir
n
=
0
an
,
im
Induktionsschritt
n
=
n
'
+
1
,
wobei
wir
die
Aussage
als
schon
gezeigt
f
ü
r
n
'
annehmen
.
Das
kann
man
ü
brigens
auch
sichtbar
machen
mit
der
folgenden
alternativen
Zeile
.
Einfach
mal
statt
dieser
Zeile
ausf
ü
hren
.
*
)
(
**
induction
n
as
[
|
n
'
IV
]
eqn
:
eq
.
*
)
-
(
**
IA
:
"P(0)"
bzw
.
"P(zero)"
*
)
simpl
.
reflexivity
.
-
(
**
IS
:
"P(n) ~> P(n+1)"
bzw
.
"P(n) ~> P(succ n)"
*
)
simpl
.
f_equal
.
exact
IV
.
Qed
.
Lemma
addN_n_succ_m
:
forall
(
n
m
:
my_nat
),
addN
n
(
succ
m
)
=
succ
(
addN
n
m
).
Proof
.
intro
n
.
induction
n
as
[
|
n
'
IV
].
-
(
**
IA
:
"P(0)"
bzw
.
"P(zero)"
*
)
intro
m
.
simpl
.
reflexivity
.
-
(
**
IS
:
"P(n) ~> P(n+1)"
bzw
.
"P(n) ~> P(succ n)"
*
)
intro
m
.
simpl
.
f_equal
.
apply
IV
.
Qed
.
Theorem
addN_comm
:
forall
(
n
m
:
my_nat
),
addN
n
m
=
addN
m
n
.
Proof
.
intros
n
.
induction
n
as
[
|
n
'
IV
].
-
(
**
IA
:
"P(0)"
bzw
.
"P(zero)"
*
)
intro
m
.
simpl
.
symmetry
.
apply
addN_zero_r
.
-
(
**
IS
:
"P(n) ~> P(n+1)"
bzw
.
"P(n) ~> P(succ n)"
*
)
intro
m
.
simpl
.
rewrite
IV
.
rewrite
addN_n_succ_m
.
reflexivity
.
Qed
.
(
**
Man
kann
das
Induktionsprinzip
auch
explizit
anschauen
und
anwenden
statt
der
`induction
`
-
Taktik
:
*
)
Check
my_nat_ind
.
Check
nat_ind
.
(
**
->
nat_ind
:
forall
P
:
nat
->
Prop
,
P
0
->
(
forall
n
:
nat
,
P
n
->
P
(
S
n
))
->
forall
n
:
nat
,
P
n
**
)
Theorem
addN_comm
'
:
forall
(
m
n
:
my_nat
),
addN
n
m
=
addN
m
n
.
Proof
.
intro
m
.
apply
my_nat_ind
.
-
simpl
.
symmetry
.
apply
addN_zero_r
.
-
intro
n
.
intro
IV
.
simpl
.
rewrite
IV
.
rewrite
addN_n_succ_m
.
reflexivity
.
Qed
.
End
nat_playground
.
Module
logic_vol1
.
(
**
Nun
ein
komplexeres
Beispiel
:
x
,
y
::=
bot
|
A
|
neg
x
|
conj
x
y
|
disj
x
y
|
impl
x
y
|
iff
x
y
*
)
Definition
atoms
:
Type
:=
nat
.
Inductive
form
:=
|
bot
:
form
(
**
bottom
,
Falsum
*
)
|
top
:
form
(
**
top
,
Verum
*
)
|
atom
(
A
:
atoms
)
:
form
(
**
Konstruktor
f
ü
r
ein
Atom
,
z
.
B
.
entspricht
die
logische
Aussage
"A"
einfach
"atom A"
hier
.
*
)
|
neg
(
x
:
form
)
:
form
(
**
Negation
*
)
|
conj
(
x
y
:
form
)
:
form
(
**
Konjunktion
*
)
|
disj
(
x
y
:
form
)
:
form
(
**
Disjunktion
*
)
|
impl
(
x
y
:
form
)
:
form
(
**
Implikation
*
)
|
iff
(
x
y
:
form
)
:
form
(
**
Biimplikation
*
)
.
Print
form
.
Fixpoint
evaluate
(
f
:
form
)
(
k
:
atoms
->
Prop
)
:
Prop
:=
match
f
with
|
bot
=>
False
|
top
=>
True
|
atom
A
=>
k
A
|
neg
x
=>
~
evaluate
x
k
|
conj
x
y
=>
evaluate
x
k
/
\
evaluate
y
k
|
disj
x
y
=>
evaluate
x
k
\
/
evaluate
y
k
|
impl
x
y
=>
evaluate
x
k
->
evaluate
y
k
|
iff
x
y
=>
evaluate
x
k
<->
evaluate
y
k
end
.
Fixpoint
contains
(
f
:
form
)
(
A
:
atoms
)
:
Prop
:=
match
f
with
|
bot
=>
False
|
top
=>
False
|
atom
X
=>
A
=
X
|
neg
x
=>
contains
x
A
|
conj
x
y
=>
contains
x
A
\
/
contains
y
A
|
disj
x
y
=>
contains
x
A
\
/
contains
y
A
|
impl
x
y
=>
contains
x
A
\
/
contains
y
A
|
iff
x
y
=>
contains
x
A
\
/
contains
y
A
end
.
Fixpoint
only_bot_atom_disj
(
f
:
form
)
:
Prop
:=
match
f
with
|
bot
=>
True
|
top
=>
False
|
atom
A
=>
True
|
neg
x
=>
False
|
conj
x
y
=>
False
|
disj
x
y
=>
only_bot_atom_disj
x
/
\
only_bot_atom_disj
y
|
impl
x
y
=>
False
|
iff
x
y
=>
False
end
.
Section
mini_ex
.
Variable
f
:
form
.
Variable
A
:
atoms
.
Variable
k
:
atoms
->
Prop
.
Hypothesis
H1
:
k
A
.
Hypothesis
H2
:
contains
f
A
.
Hypothesis
H3
:
only_bot_atom_disj
f
.
Theorem
disjunctive_correctness
:
evaluate
f
k
.
Proof
.
induction
f
as
[
|
|
B
|
x
IVx
|
x
IVx
y
IVy
|
x
IVx
y
IVy
|
x
IVx
y
IVy
|
x
IVx
y
IVy
].
(
**
Hier
ist
vielleicht
schon
aufgefallen
,
dass
ich
pro
Operation
jeweils
einzeln
die
Induktionsvoraussetzungen
aufschreiben
muss
.
Bei
einem
Pen
-
And
-
Paper
-
Induktionsbeweis
w
ü
rde
man
vermutlich
im
Normalfall
IV
'
s
f
ü
r
alle
Induktionsschritte
gemeinsam
verwenden
,
um
sich
Schreibarbeit
zu
sparen
.
Technisch
gesehen
hat
man
aber
offenbar
pro
Operation
eigene
IV
'
s
.
*
)
-
(
**
"P(bot)"
*
)
simpl
in
H2
.
contradiction
.
(
**
Widerspruch
:
f
enth
ä
lt
nicht
das
Atom
A
.
*
)
-
(
**
"P(top)"
*
)
simpl
in
H3
.
contradiction
.
(
**
Widerspruch
:
Formel
besteht
nicht
nur
aus
bot
,
atom
und
disj
.
*
)
-
(
**
"P(A)"
*
)
simpl
.
simpl
in
H2
,
H3
.
subst
.
(
**
Damit
das
ein
nicht
-
trivialer
Fall
wird
,
muss
A
=
B
gelten
.
Kann
man
also
vereinfachen
.
*
)
exact
H1
.
-
(
**
"P(x) ~> P(neg x)"
*
)
simpl
in
H3
.
contradiction
.
(
**
Widerspruch
:
Formel
besteht
nicht
nur
aus
bot
,
atom
und
disj
.
*
)
-
(
**
"P(x),P(y) -> P(conj x y)"
*
)
simpl
in
H3
.
contradiction
.
(
**
siehe
neg
*
)
-
(
**
"P(x),P(y) ~> P(disj x y)"
*
)
simpl
.
simpl
in
H2
,
H3
.
destruct
H3
as
[
H4
H5
].
destruct
H2
as
[
H6
|
H6
].
+
left
.
apply
IVx
.
exact
H6
.
exact
H4
.
+
right
.
apply
IVy
.
exact
H6
.
exact
H5
.
-
(
**
"P(x),P(y) ~> P(impl x y)"
*
)
simpl
in
H3
.
contradiction
.
(
**
siehe
neg
*
)
-
(
**
"P(x),P(y) ~> P(iff x y)"
*
)
simpl
in
H3
.
contradiction
.
(
**
siehe
neg
*
)
Qed
.
End
mini_ex
.
End
logic_vol1
.
Module
nat_exercises
.
(
**
Hier
nun
noch
ein
paar
Theoreme
zum
selbst
ausprobieren
.
*
)
Import
nat_playground
.
(
**
Wir
haben
vorhin
die
nat
ü
rlichen
Zahlen
neu
definiert
mittels
my_nat
:
*
)
Print
my_nat
.
(
**
Ich
m
ö
chte
nun
zeigen
,
dass
die
beiden
Mengen
nat
und
my_nat
isomorph
,
also
gleichm
ä
chtig
sind
.
Dazu
brauche
ich
eine
Bijektion
my_nat_to_nat
:
*
)
Fixpoint
my_nat_to_nat
(
x
:
my_nat
)
:
nat
:=
match
x
with
|
zero
=>
O
|
succ
x
'
=>
S
(
my_nat_to_nat
x
'
)
end
.
(
**
Was
hei
ß
t
es
f
ü
r
eine
Funktion
,
bijektiv
zu
sein
?
Sie
muss
injektiv
und
surjektiv
sein
.
*
)
Definition
inj
(
f
:
my_nat
->
nat
)
:
Prop
:=
forall
(
x
x
'
:
my_nat
),
f
x
=
f
x
'
->
x
=
x
'
.
Definition
sur
(
f
:
my_nat
->
nat
)
:
Prop
:=
forall
(
y
:
nat
),
exists
(
x
:
my_nat
),
f
x
=
y
.
Definition
bij
(
f
:
my_nat
->
nat
)
:
Prop
:=
inj
f
/
\
sur
f
.
Theorem
my_nat_iso_to_nat
:
bij
my_nat_to_nat
.
Proof
.
(
**
An
den
folgenden
3
Zeilen
sieht
man
auch
nochmal
sch
ö
n
,
dass
es
eine
gute
Beweisstrategie
ist
,
erstmal
Definitionen
"auszupacken"
:
*
)
unfold
bij
.
unfold
inj
.
unfold
sur
.
split
.
-
(
**
inj
*
)
intro
x
.
admit
.
-
(
**
sur
*
)
intro
y
.
admit
.
Admitted
.
(
**
Widmen
wir
uns
wieder
den
praktischen
Sachen
:
Assoziativit
ä
t
.
*
)
Theorem
addN_assoc
:
forall
(
x
y
z
:
my_nat
),
addN
x
(
addN
y
z
)
=
addN
(
addN
x
y
)
z
.
Proof
.
Admitted
.
(
**
Nun
wollen
wir
noch
die
Multiplikation
rekursiv
definieren
:
*
)
Fixpoint
mulN
(
n
m
:
my_nat
)
:
my_nat
:=
match
n
with
|
zero
=>
zero
|
succ
n
'
=>
addN
m
(
mulN
n
'
m
)
end
.
Lemma
mulN_zero_r
:
forall
(
n
:
my_nat
),
mulN
n
zero
=
zero
.
Proof
.
Admitted
.
Lemma
mulN_n_succ_m
:
forall
(
n
m
'
:
my_nat
),
mulN
n
(
succ
m
'
)
=
addN
(
mulN
n
m
'
)
n
.
Proof
.
Admitted
.
Theorem
mulN_comm
:
forall
(
n
m
:
my_nat
),
mulN
n
m
=
mulN
m
n
.
Proof
.
Admitted
.
Theorem
addN_mulN_distr_1
:
forall
x
y
z
,
mulN
x
(
addN
y
z
)
=
addN
(
mulN
x
y
)
(
mulN
x
z
).
Proof
.
Admitted
.
Theorem
addN_mulN_distr_2
:
forall
x
y
z
,
mulN
(
addN
x
y
)
z
=
addN
(
mulN
x
z
)
(
mulN
y
z
).
Proof
.
Admitted
.
Theorem
mulN_assoc
:
forall
(
x
y
z
:
my_nat
),
mulN
x
(
mulN
y
z
)
=
mulN
(
mulN
x
y
)
z
.
Proof
.
Admitted
.
Fixpoint
addRow
(
n
:
my_nat
)
:
my_nat
:=
match
n
with
|
zero
=>
zero
|
succ
n
'
=>
addN
n
(
addRow
n
'
)
end
.
Theorem
know_this_one
:
forall
(
n
:
my_nat
),
mulN
(
succ
(
succ
zero
))
(
addRow
n
)
=
mulN
n
(
succ
n
).
Proof
.
Admitted
.
End
nat_exercises
.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment