Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
4c7edb7e
Commit
4c7edb7e
authored
9 years ago
by
Regis Blanc
Committed by
Ravi
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
working guess number example
parent
a5b1437b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testcases/verification/xlang/GuessNumberInteractive.scala
+12
-16
12 additions, 16 deletions
testcases/verification/xlang/GuessNumberInteractive.scala
with
12 additions
and
16 deletions
testcases/verification/xlang/GuessNumberInteractive.scala
+
12
−
16
View file @
4c7edb7e
...
@@ -5,35 +5,31 @@ import leon.io.StdIn
...
@@ -5,35 +5,31 @@ import leon.io.StdIn
import
leon.annotation._
import
leon.annotation._
object
GuessNumberInteractive
{
object
GuessNumberInteractive
{
//def pickRandomly(min: BigInt, max: BigInt): BigInt = {
// require(min >= 0 && max >= min)
// StdIn.readBigInt
//}
@extern
def
pickBetween
(
bot
:
BigInt
,
top
:
BigInt
)
:
BigInt
=
{
def
pickBetween
(
bot
:
BigInt
,
top
:
BigInt
)
:
BigInt
=
{
require
(
bot
<=
top
)
require
(
bot
<=
top
)
bot
+
(
top
-
bot
)/
2
bot
+
(
top
-
bot
)/
2
//works for execution
}
ensuring
(
res
=>
res
>=
bot
&&
res
<=
top
)
}
ensuring
(
res
=>
res
>=
bot
&&
res
<=
top
)
def
guessNumber
(
choice
:
Option
[
BigInt
])(
implicit
state
:
StdIn.State
)
:
BigInt
=
{
def
guessNumber
(
choice
:
Option
[
BigInt
])(
implicit
state
:
StdIn.State
)
:
BigInt
=
{
require
(
choice
match
{
case
Some
(
c
)
=>
c
>=
0
&&
c
<=
10
case
None
()
=>
true
})
require
(
choice
match
{
case
Some
(
c
)
=>
c
>=
0
&&
c
<=
10
case
None
()
=>
true
})
var
top
:
BigInt
=
10
var
bot
:
BigInt
=
0
var
bot
:
BigInt
=
0
var
guess
:
BigInt
=
pickBetween
(
bot
,
top
)
var
top
:
BigInt
=
10
(
while
(
bot
<
top
)
{
(
while
(
bot
<
top
)
{
if
(
isGreater
(
guess
,
choice
))
{
val
prevDec
=
top
-
bot
top
=
guess
-
1
if
(
bot
<=
top
)
val
guess
=
pickBetween
(
bot
,
top
-
1
)
//never pick top, wouldn't learn anyting if pick top and if guess >= choice
guess
=
pickBetween
(
bot
,
top
)
if
(
isSmaller
(
guess
,
choice
))
{
bot
=
guess
+
1
}
else
{
}
else
{
bot
=
guess
top
=
guess
if
(
bot
<=
top
)
guess
=
pickBetween
(
bot
,
top
)
}
}
val
dec
=
top
-
bot
assert
(
dec
>=
0
&&
dec
<
prevDec
)
})
invariant
(
choice
match
{
})
invariant
(
choice
match
{
case
Some
(
c
)
=>
guess
>=
bot
&&
guess
<=
top
&&
bot
>=
0
&&
top
<=
10
&&
bot
<=
top
&&
c
>=
bot
&&
c
<=
top
case
Some
(
c
)
=>
bot
>=
0
&&
top
<=
10
&&
bot
<=
top
&&
c
>=
bot
&&
c
<=
top
case
None
()
=>
true
case
None
()
=>
true
})
})
bot
bot
...
...
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