Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
why3_2018
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
why3_2018
Commits
d259aaa2
Commit
d259aaa2
authored
6 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
peano_nat.mlw
+177
-0
177 additions, 0 deletions
peano_nat.mlw
with
177 additions
and
0 deletions
peano_nat.mlw
0 → 100644
+
177
−
0
View file @
d259aaa2
module Nat
type nat = O | S nat
function add (n1 n2 : nat) : nat =
match n1 with
| O -> n2
| S n -> S (add n n2)
end
function (+) (a b : nat) : nat = add a b
use int.Int
goal g:
forall x. x = 1 -> x > 0
end
module TestAdd
use Nat
goal g_0_0: (* 0 + 0 = 0 *)
O + O = O
(* solved by "compute_in_goal" *)
goal g_0_1: (* 0 + 1 = 1 *)
O + S O = S O
(* solved by "compute_in_goal" *)
goal g_2_1: (* 2 + 1 = 3 *)
S (S O) + S O = S (S (S O))
(* solved by "compute_in_goal" *)
end
module Inconsistency
lemma introduce: true -> false (* <-- introduces inconsistency *)
lemma exposed: true -> false (* <-- exposed to inconsistency *)
(*
incosisitency applies in this scope,
and all scopes the "use" this module (transitively)
*)
end
module Add
use import Nat
goal plus_ol:
forall n. O + n = n
(* solved by "compute_in_goal" *)
goal plus_o_right:
forall n. n + O = n
(* solved by numerous transformations *)
goal plus_o_right_altergo:
forall n. n + O = n
(* solved by two simple transofrmations and SMT solver
"inline_goal"
"induction_ty_lex"
"altergo"
*)
(* we want to prove commutativity *)
(* facilitates plus_comm *)
lemma plus_o_right_lemma:
forall n. n + O = n
(* solved by two simple transofrmations and SMT solver
"inline_goal"
"induction_ty_lex"
"altergo"
*)
(* not required to solve plus_comm *)
(* but might be useful to other proofs *)
lemma plus_Snm_nSm : forall n m:nat. (S n) + m = n + (S m)
(* solved by two simple transofrmations and SMT solver
"inline_goal"
"induction_ty_lex"
"altergo"
*)
(* facilitates plus_comm *)
lemma plus_S: forall n m:nat. S (n + m) = n + (S m)
(* solved by two simple transofrmations and SMT solver
"inline_goal"
"induction_ty_lex"
"altergo"
*)
(* our final goal *)
goal plus_comm:
forall n m. n + m = m + n
(* solved by two simple transofrmations and SMT solver
"inline_goal"
"induction_ty_lex"
"altergo"
*)
end
module Compare
use import Nat
(* use import Add *)
(* use import Inconsistency *)
inductive le nat nat =
| Le_n : forall n:nat. le n n
| Le_S : forall n m:nat. le n m -> le n (S m)
predicate (<=) (x y:nat) = le x y
predicate (<) (x y:nat) = (S x) <= y
function f (x : nat) : nat = x + (S O)
goal f_proof:
forall x. x < f x
function g (x y: nat) : nat = x + y
goal g_proof:
forall x y [@induction]. x <= g x y
end
module Sub
use import Nat
use import Compare
function sub (n m:nat) : nat =
match n, m with
| S k, S l -> sub k l
| _, _ -> n
end
(*
(* Assignment 3a *)
inductive sub_pr nat nat nat =
| (* your code here *)
(*
show the correspondence in between the
inductive predicate sub_pr and the
function sub
*)
lemma sub_equivalence:
forall n m l. l = sub n m <-> sub_pr n m l
(* Assignment 3b *)
lemma sub_le_nm:
forall n m. sub n m <= n
(* Assignment 3c *)
predicate (>=) (x y:nat) = (* your code here *)
lemma sub_ge_nm:
forall n m. n >= sub n m
(* Assignment 3d *)
predicate (<) (x y:nat) = le (S x) y
lemma sub_lt_nm:forall n m. ... -> sub n m < n
*)
end
\ No newline at end of file
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