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
4039f20e
Commit
4039f20e
authored
8 years ago
by
Regis Blanc
Committed by
Ravi
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
interactive leon program
parent
51a4db48
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
library/lang/package.scala
+9
-0
9 additions, 0 deletions
library/lang/package.scala
testcases/verification/xlang/GuessNumberInteractive.scala
+77
-0
77 additions, 0 deletions
testcases/verification/xlang/GuessNumberInteractive.scala
with
86 additions
and
0 deletions
library/lang/package.scala
+
9
−
0
View file @
4039f20e
...
...
@@ -82,4 +82,13 @@ package object lang {
}
}
}
@extern
def
print
(
x
:
String
)
:
Unit
=
{
scala
.
Predef
.
print
(
x
)
}
@extern
def
println
(
x
:
String
)
:
Unit
=
{
scala
.
Predef
.
println
(
x
)
}
}
This diff is collapsed.
Click to expand it.
testcases/verification/xlang/GuessNumberInteractive.scala
0 → 100644
+
77
−
0
View file @
4039f20e
import
leon.lang._
import
leon.lang.xlang._
import
leon.io.StdIn
import
leon.annotation._
object
GuessNumberInteractive
{
//def pickRandomly(min: BigInt, max: BigInt): BigInt = {
// require(min >= 0 && max >= min)
// StdIn.readBigInt
//}
def
pickBetween
(
bot
:
BigInt
,
top
:
BigInt
)
:
BigInt
=
{
require
(
bot
<=
top
)
bot
+
(
top
-
bot
)/
2
}
ensuring
(
res
=>
res
>=
bot
&&
res
<=
top
)
def
guessNumber
(
choice
:
Option
[
BigInt
])(
implicit
state
:
StdIn.State
)
:
BigInt
=
{
require
(
choice
match
{
case
Some
(
c
)
=>
c
>=
0
&&
c
<=
10
case
None
()
=>
true
})
var
top
:
BigInt
=
10
var
bot
:
BigInt
=
0
var
guess
:
BigInt
=
pickBetween
(
bot
,
top
)
(
while
(
bot
<
top
)
{
if
(
isGreater
(
guess
,
choice
))
{
top
=
guess
-
1
if
(
bot
<=
top
)
guess
=
pickBetween
(
bot
,
top
)
}
else
{
bot
=
guess
if
(
bot
<=
top
)
guess
=
pickBetween
(
bot
,
top
)
}
})
invariant
(
choice
match
{
case
Some
(
c
)
=>
guess
>=
bot
&&
guess
<=
top
&&
bot
>=
0
&&
top
<=
10
&&
bot
<=
top
&&
c
>=
bot
&&
c
<=
top
case
None
()
=>
true
})
bot
}
ensuring
(
answer
=>
choice
match
{
case
Some
(
c
)
=>
c
==
answer
case
None
()
=>
true
})
@extern
def
isGreater
(
guess
:
BigInt
,
choice
:
Option
[
BigInt
])(
implicit
state
:
StdIn.State
)
:
Boolean
=
(
choice
match
{
case
None
()
=>
print
(
"Is it (strictly) smaller than "
+
guess
+
": "
)
StdIn
.
readBoolean
case
Some
(
c
)
=>
guess
>
c
})
ensuring
(
res
=>
choice
match
{
case
Some
(
c
)
=>
res
==
guess
>
c
case
None
()
=>
true
})
@extern
def
isSmaller
(
guess
:
BigInt
,
choice
:
Option
[
BigInt
])(
implicit
state
:
StdIn.State
)
:
Boolean
=
(
choice
match
{
case
None
()
=>
print
(
"Is it (strictly) greater than "
+
guess
+
": "
)
StdIn
.
readBoolean
case
Some
(
c
)
=>
guess
<
c
})
ensuring
(
res
=>
choice
match
{
case
Some
(
c
)
=>
res
==
guess
<
c
case
None
()
=>
true
})
def
guessNumberValid
(
choice
:
BigInt
)
:
BigInt
=
{
require
(
choice
>=
0
&&
choice
<=
10
)
implicit
val
ioState
=
StdIn
.
newState
guessNumber
(
Some
(
choice
))
}
ensuring
(
_
==
choice
)
@extern
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
implicit
val
ioState
=
StdIn
.
newState
println
(
"Think of a number between 0 and 10..."
)
println
(
"Leon will try to guess it..."
)
val
answer
=
guessNumber
(
None
())
println
(
"Found: "
+
answer
)
println
(
"Goodbye"
)
}
}
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