Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jscoq-light
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Rousselin
jscoq-light
Commits
22be8235
Commit
22be8235
authored
3 years ago
by
Karl Palmskog
Browse files
Options
Downloads
Patches
Plain Diff
fix sqrt2 deprecations and modernize some proof scripts
parent
2a3c3455
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/sqrt2.v
+21
-23
21 additions, 23 deletions
examples/sqrt2.v
with
21 additions
and
23 deletions
examples/sqrt2.v
+
21
−
23
View file @
22be8235
...
...
@@ -7,13 +7,11 @@ which reduces to considering an isosceles right triangle.
Below
,
we
prove
a
statement
in
Coq
of
the
irrationality
of
the
square
root
of
two
that
is
expressed
only
in
terms
of
natural
numbers
(
Coq
'
s
<<
nat
>>
).
The
proof
is
a
simplified
version
of
a
#
<
a
href
=
"https://github.com/coq-community/qarith-stern-brocot/blob/master/theories/sqrt2.v"
>
proof
by
Milad
Niqui
</
a
>
#.
*
)
of
natural
numbers
(
Coq
'
s
<<
nat
>>
).
The
proof
is
a
simplified
version
of
a
#
<
a
href
=
"https://github.com/coq-community/qarith-stern-brocot/blob/master/theories/sqrt2.v"
>
proof
by
Milad
Niqui
</
a
>
#.
(
**
We
begin
by
loading
results
on
arithmetic
on
natural
numbers
,
and
the
lia
arithmetic
proof
tactic
.
We
begin
by
loading
results
on
arithmetic
on
natural
numbers
,
and
the
lia
arithmetic
solver
tactic
.
*
)
From
Coq
Require
Import
Arith
Lia
.
...
...
@@ -25,8 +23,8 @@ Lemma lt_monotonic_inverse :
forall
x
y
:
nat
,
f
x
<
f
y
->
x
<
y
.
Proof
.
intros
f
Hmon
x
y
Hlt
;
case
(
le_gt_dec
y
x
);
auto
.
intros
Hle
;
case
(
le_lt_or_eq
_
_
Hle
).
intros
Hlt
'
;
case
(
lt_asym
_
_
Hlt
);
apply
Hmon
;
auto
.
intros
Hle
;
case
(
proj1
(
Nat
.
lt_eq_cases
_
_
)
Hle
).
intros
Hlt
'
;
case
(
Nat
.
lt_asym
m
_
_
Hlt
);
apply
Hmon
;
auto
.
intros
Heq
;
case
(
Nat
.
lt_neq
_
_
Hlt
);
rewrite
Heq
;
auto
.
Qed
.
...
...
@@ -34,7 +32,7 @@ Lemma sub_square_identity :
forall
a
b
:
nat
,
b
<=
a
->
(
a
-
b
)
*
(
a
-
b
)
=
a
*
a
+
b
*
b
-
2
*
(
a
*
b
).
Proof
.
intros
a
b
H
.
rewrite
(
le_plus_minus
b
a
H
);
lia
.
rewrite
<-
(
Nat
.
sub_add
b
a
H
);
lia
.
Qed
.
Lemma
root_monotonic
:
forall
x
y
:
nat
,
x
*
x
<
y
*
y
->
x
<
y
.
...
...
@@ -60,13 +58,13 @@ Proof. lia. Qed.
(
**
We
define
a
local
custom
proof
tactic
.
*
)
Local
Ltac
solve_comparison
:=
apply
root_monotonic
;
repeat
rewrite
square_recompose
;
rewrite
hyp_sqrt
;
rewrite
(
mul
t
_assoc
_
2
_
);
apply
mul
t
_lt_
compat
_r
;
rewrite
(
Nat
.
mul_assoc
_
2
_
);
apply
Nat
.
mul_lt_
mono_pos
_r
;
auto
using
sqrt_q_non_zero
with
arith
.
Lemma
comparison1
:
q
<
p
.
Proof
.
replace
q
with
(
1
*
q
)
;
tr
y
lia
.
replace
p
with
(
1
*
p
)
;
tr
y
lia
.
replace
q
with
(
1
*
q
)
b
y
lia
.
replace
p
with
(
1
*
p
)
b
y
lia
.
solve_comparison
.
Qed
.
...
...
@@ -78,12 +76,12 @@ Proof. solve_comparison. Qed.
Lemma
comparison4
:
3
*
q
-
2
*
p
<
q
.
Proof
.
apply
plus_lt_reg
_l
with
(
2
*
p
).
rewrite
<-
le_plus_minus
;
try
(
simple
apply
lt_le_
weak
;
auto
using
comparison2
with
arith
).
replace
(
3
*
q
)
with
(
2
*
q
+
q
)
;
tr
y
lia
.
apply
plus
_lt_le_
compat
;
auto
.
repeat
rewrite
(
mul
t
_comm
2
);
apply
mul
t
_lt_
compat
_r
;
apply
Nat
.
add_lt_mono
_l
with
(
2
*
p
).
rewrite
Nat
.
add_comm
,
Nat
.
sub_add
;
try
(
simple
apply
Nat
.
lt_le_
incl
;
auto
using
comparison2
with
arith
).
replace
(
3
*
q
)
with
(
2
*
q
+
q
)
b
y
lia
.
apply
Nat
.
add
_lt_le_
mono
;
auto
.
repeat
rewrite
(
Nat
.
mul_comm
2
);
apply
Nat
.
mul_lt_
mono_pos
_r
;
auto
using
comparison1
with
arith
.
Qed
.
...
...
@@ -107,18 +105,18 @@ End sqrt2_decrease.
We
apply
the
induction
hypothesis
with
the
numbers
<<
3
*
q
-
2
*
q
>>
and
<<
3
*
p
-
4
*
q
>>
.
This
leaves
two
key
proof
goals
:
-
<<
3
*
q
-
2
*
p
<>
0
>>
,
which
we
prove
using
arithmetic
and
the
[
comparison2
]
lemma
above
.
[
comparison2
]
lemma
above
-
<<
(
3
*
p
-
4
*
q
)
*
(
3
*
p
-
4
*
q
)
=
2
*
((
3
*
q
-
2
*
p
)
*
(
3
*
q
-
2
*
p
))
>>
,
which
we
prove
using
the
[
new_equality
]
lemma
above
.
which
we
prove
using
the
[
new_equality
]
lemma
above
*
)
Theorem
sqrt2_not_rational
:
forall
p
q
:
nat
,
q
<>
0
->
p
*
p
=
2
*
(
q
*
q
)
->
False
.
Proof
.
intros
p
q
;
generalize
p
;
clear
p
;
elim
q
using
(
well_founded_ind
lt_wf
).
clear
q
;
intros
q
Hrec
p
Hneq
.
generalize
(
neq_
O
_lt
_
(
sym_not_equal
Hneq
)
)
;
intros
Hlt_O_q
Heq
.
generalize
(
proj1
(
Nat
.
neq_
0
_lt
_0
_
)
Hneq
);
intros
Hlt_O_q
Heq
.
apply
(
Hrec
(
3
*
q
-
2
*
p
)
(
comparison4
_
_
Hlt_O_q
Heq
)
(
3
*
p
-
4
*
q
)).
-
apply
sym_not_equal
;
apply
Nat
.
lt_neq
;
apply
plus_lt_reg
_l
with
(
2
*
p
).
rewrite
<-
plus_n_O
;
rewrite
<-
le_plus_minus
;
auto
using
lt_le_
weak
,
comparison2
.
-
apply
sym_not_equal
;
apply
Nat
.
lt_neq
;
apply
Nat
.
add_lt_mono
_l
with
(
2
*
p
).
rewrite
<-
plus_n_O
,
Nat
.
add_comm
,
Nat
.
sub_add
;
auto
using
Nat
.
lt_le_
incl
,
comparison2
.
-
apply
new_equality
;
auto
.
Qed
.
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