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
874f0484
Commit
874f0484
authored
9 years ago
by
Samuel Gruetter
Browse files
Options
Downloads
Patches
Plain Diff
make BitsTricks test more termination-friendly
counting from 31 down to 0 instead of from 0 up to 31
parent
be71561e
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
src/test/resources/regression/verification/purescala/valid/BitsTricks.scala
+11
-15
11 additions, 15 deletions
.../regression/verification/purescala/valid/BitsTricks.scala
with
11 additions
and
15 deletions
src/test/resources/regression/verification/purescala/valid/BitsTricks.scala
+
11
−
15
View file @
874f0484
...
...
@@ -47,20 +47,17 @@ object BitsTricks {
x
^
y
^
x
}
ensuring
(
res
=>
res
==
y
)
def
turnOffRightmostOneRec
(
x
:
Int
,
index
:
Int
)
:
Int
=
{
require
(
index
>=
0
&&
index
<
32
)
if
(
bitAt
(
x
,
index
))
toggleBitN
(
x
,
index
)
//(x ^ (1 << index))
else
if
(
index
==
31
)
x
else
turnOffRightmostOneRec
(
x
,
index
+
1
)
def
turnOffRightmostOneRec
(
x
:
Int
,
indexFromLeft
:
Int
)
:
Int
=
{
require
(
0
<=
indexFromLeft
&&
indexFromLeft
<
32
)
if
(
bitAt
(
x
,
31
-
indexFromLeft
))
toggleBitN
(
x
,
31
-
indexFromLeft
)
//(x ^ (1 << (31 - indexFromLeft)))
else
if
(
indexFromLeft
==
0
)
x
else
turnOffRightmostOneRec
(
x
,
indexFromLeft
-
1
)
}
/*
* loops forever on the proof
*/
// proves in 10s
def
turnOffRightmostOne
(
x
:
Int
)
:
Int
=
{
x
&
(
x
-
1
)
}
//ensuring(_ == turnOffRightmostOneRec(x,
0
))
}
//ensuring(_ == turnOffRightmostOneRec(x,
31
))
// 010100 -> 010111
def
rightPropagateRightmostOne
(
x
:
Int
)
:
Int
=
{
...
...
@@ -73,10 +70,9 @@ object BitsTricks {
}
ensuring
(
b
=>
b
)
def
isRotationLeft
(
x
:
Int
,
y
:
Int
,
n
:
Int
,
i
:
Int
)
:
Boolean
=
{
require
(
i
>=
0
&&
i
<=
32
&&
n
>=
0
&&
n
<
32
)
if
(
i
==
32
)
true
else
bitAt
(
x
,
i
)
==
bitAt
(
y
,
(
i
+
n
)
%
32
)
&&
isRotationLeft
(
x
,
y
,
n
,
i
+
1
)
require
(
0
<=
i
&&
i
<
32
&&
0
<=
n
&&
n
<
32
)
val
isOk
=
bitAt
(
x
,
i
)
==
bitAt
(
y
,
(
i
+
n
)
%
32
)
if
(
i
==
0
)
isOk
else
isOk
&&
isRotationLeft
(
x
,
y
,
n
,
i
-
1
)
}
//rotateLeft proves in 1 minute (on very powerful computer)
...
...
@@ -84,7 +80,7 @@ object BitsTricks {
require
(
n
>=
0
&&
n
<
32
)
val
front
=
x
>>>
(
32
-
n
)
(
x
<<
n
)
|
front
}
//ensuring(res => isRotationLeft(x, res, n,
0
))
}
//ensuring(res => isRotationLeft(x, res, n,
31
))
//careful with overflows, case definition, truncated
def
safeMean
(
x
:
Int
,
y
:
Int
)
:
Int
=
{
...
...
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