Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
why3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
119
Issues
119
List
Boards
Labels
Service Desk
Milestones
Merge Requests
17
Merge Requests
17
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Why3
why3
Commits
fb3da6dc
Commit
fb3da6dc
authored
Mar 30, 2019
by
Jean-Christophe Filliâtre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new example: word common factor
parent
ab2b2058
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
0 deletions
+108
-0
examples/word_common_factor.mlw
examples/word_common_factor.mlw
+41
-0
examples/word_common_factor/why3session.xml
examples/word_common_factor/why3session.xml
+67
-0
examples/word_common_factor/why3shapes.gz
examples/word_common_factor/why3shapes.gz
+0
-0
No files found.
examples/word_common_factor.mlw
0 → 100644
View file @
fb3da6dc
(** {2 Common factor of two words}
If `a ++ b = b ++ a` then `a` and `b` are powers of a common word. *)
use int.Int
use seq.Seq
use seq.FreeMonoid
type char
type word = seq char
let rec function power (w: word) (n: int) : word
requires { n >= 0 }
variant { n }
= if n = 0 then empty else w ++ power w (n - 1)
let rec lemma power_add (w: word) (n1 n2: int)
requires { n1 >= 0 && n2 >= 0 }
variant { n1 }
ensures { power w (n1 + n2) == power w n1 ++ power w n2 }
= if n1 > 0 then power_add w (n1 - 1) n2
let rec remove_prefix (a b: word) : word
requires { length a <= length b && b[0 .. length a] == a }
ensures { b = a ++ result }
variant { length a }
= if length a = 0 then b else remove_prefix a[1..] b[1..]
let rec common_factor (a b: word) : (w: word, ka: int, kb: int)
requires { a ++ b == b ++ a }
ensures { ka >= 0 /\ a == power w ka /\ kb >= 0 /\ b == power w kb }
variant { length a, length b }
= if length a = 0 then b, 0, 1
else if length b = 0 then a, 1, 0
else if length a <= length b then begin
let c = remove_prefix a b in
let w, ka, kc = common_factor a c in
w, ka, ka + kc
end else
let w, ka, kb = common_factor b a in w, kb, ka
examples/word_common_factor/why3session.xml
0 → 100644
View file @
fb3da6dc
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE why3session PUBLIC "-//Why3//proof session v5//EN"
"http://why3.lri.fr/why3session.dtd">
<why3session
shape_version=
"6"
>
<prover
id=
"1"
name=
"Alt-Ergo"
version=
"2.2.0"
timelimit=
"1"
steplimit=
"0"
memlimit=
"1000"
/>
<prover
id=
"2"
name=
"CVC4"
version=
"1.6"
timelimit=
"1"
steplimit=
"0"
memlimit=
"1000"
/>
<file
proved=
"true"
>
<path
name=
".."
/>
<path
name=
"word_common_factor.mlw"
/>
<theory
name=
"Top"
proved=
"true"
>
<goal
name=
"VC power"
expl=
"VC for power"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.05"
/></proof>
</goal>
<goal
name=
"VC power_add"
expl=
"VC for power_add"
proved=
"true"
>
<proof
prover=
"1"
><result
status=
"valid"
time=
"0.14"
steps=
"270"
/></proof>
</goal>
<goal
name=
"VC remove_prefix"
expl=
"VC for remove_prefix"
proved=
"true"
>
<proof
prover=
"1"
><result
status=
"valid"
time=
"0.05"
steps=
"518"
/></proof>
</goal>
<goal
name=
"VC common_factor"
expl=
"VC for common_factor"
proved=
"true"
>
<transf
name=
"split_vc"
proved=
"true"
>
<goal
name=
"VC common_factor.0"
expl=
"precondition"
proved=
"true"
>
<proof
prover=
"1"
><result
status=
"valid"
time=
"0.01"
steps=
"78"
/></proof>
</goal>
<goal
name=
"VC common_factor.1"
expl=
"variant decrease"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.05"
/></proof>
</goal>
<goal
name=
"VC common_factor.2"
expl=
"precondition"
proved=
"true"
>
<transf
name=
"split_all_full"
proved=
"true"
>
<goal
name=
"VC common_factor.2.0"
expl=
"precondition"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.05"
/></proof>
</goal>
</transf>
</goal>
<goal
name=
"VC common_factor.3"
expl=
"variant decrease"
proved=
"true"
>
<transf
name=
"split_all_full"
proved=
"true"
>
<goal
name=
"VC common_factor.3.0"
expl=
"variant decrease"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.05"
/></proof>
</goal>
<goal
name=
"VC common_factor.3.1"
expl=
"variant decrease"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.05"
/></proof>
</goal>
<goal
name=
"VC common_factor.3.2"
expl=
"variant decrease"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.04"
/></proof>
</goal>
<goal
name=
"VC common_factor.3.3"
expl=
"variant decrease"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.04"
/></proof>
</goal>
<goal
name=
"VC common_factor.3.4"
expl=
"variant decrease"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.04"
/></proof>
</goal>
<goal
name=
"VC common_factor.3.5"
expl=
"variant decrease"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.03"
/></proof>
</goal>
</transf>
</goal>
<goal
name=
"VC common_factor.4"
expl=
"precondition"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.03"
/></proof>
</goal>
<goal
name=
"VC common_factor.5"
expl=
"postcondition"
proved=
"true"
>
<proof
prover=
"2"
><result
status=
"valid"
time=
"0.24"
/></proof>
</goal>
</transf>
</goal>
</theory>
</file>
</why3session>
examples/word_common_factor/why3shapes.gz
0 → 100644
View file @
fb3da6dc
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment