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
d7391f63
Commit
d7391f63
authored
9 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
Put these files together
parent
9971a4fa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
testcases/verification/proof/measure/Meas.scala
+177
-0
177 additions, 0 deletions
testcases/verification/proof/measure/Meas.scala
testcases/verification/proof/measure/Rational.scala
+0
-182
0 additions, 182 deletions
testcases/verification/proof/measure/Rational.scala
with
177 additions
and
182 deletions
testcases/verification/proof/measure/Meas.scala
+
177
−
0
View file @
d7391f63
...
@@ -6,6 +6,181 @@ import leon.annotation._
...
@@ -6,6 +6,181 @@ import leon.annotation._
import
leon.collection._
import
leon.collection._
import
leon.lang._
import
leon.lang._
import
leon.proof._
import
leon.proof._
import
scala.language.implicitConversions
object
Rational
{
implicit
def
bigInt2Rational
(
x
:
BigInt
)
=
Rational
(
x
,
1
)
}
/**
* Represents rational number 'n / d', where 'n' is the numerator and
* 'd' the denominator.
*/
case
class
Rational
(
n
:
BigInt
,
d
:
BigInt
)
{
def
+
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
)
Rational
(
n
*
that
.
d
+
that
.
n
*
d
,
d
*
that
.
d
)
}
ensuring
{
res
=>
res
.
isRational
&&
((
this
.
isPositive
==
that
.
isPositive
)
==>
(
res
.
isPositive
==
this
.
isPositive
))
}
def
-
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
)
Rational
(
n
*
that
.
d
-
that
.
n
*
d
,
d
*
that
.
d
)
}
ensuring
{
res
=>
res
.
isRational
&&
((
this
.
isPositive
!=
that
.
isPositive
)
==>
(
res
.
isPositive
==
this
.
isPositive
))
}
def
*
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
)
Rational
(
n
*
that
.
n
,
d
*
that
.
d
)
}
ensuring
{
res
=>
res
.
isRational
&&
(
res
.
isNonZero
==
(
this
.
isNonZero
&&
that
.
isNonZero
))
&&
(
res
.
isPositive
==
(!
res
.
isNonZero
||
this
.
isPositive
==
that
.
isPositive
))
}
def
/
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
&&
that
.
isNonZero
)
Rational
(
n
*
that
.
d
,
d
*
that
.
n
)
}
ensuring
{
res
=>
res
.
isRational
&&
(
res
.
isNonZero
==
this
.
isNonZero
)
&&
(
res
.
isPositive
==
(!
res
.
isNonZero
||
this
.
isPositive
==
that
.
isPositive
))
}
def
<=
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
if
(
that
.
d
*
d
>
0
)
n
*
that
.
d
<=
d
*
that
.
n
else
n
*
that
.
d
>=
d
*
that
.
n
}
def
<
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
if
(
that
.
d
*
d
>
0
)
n
*
that
.
d
<
d
*
that
.
n
else
n
*
that
.
d
>
d
*
that
.
n
}
def
>=
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
that
<=
this
}
def
>
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
that
<
this
}
// Equivalence of two rationals, true if they represent the same real number
def
~
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
n
*
that
.
d
==
that
.
n
*
d
}
def
isRational
=
d
!=
0
def
isPositive
=
isRational
&&
(
n
*
d
>=
0
)
def
isNonZero
=
isRational
&&
(
n
!=
0
)
}
object
RationalSpecs
{
def
equivalenceOverAddition
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
)
(
a1
+
b1
)
~
(
a2
+
b2
)
}.
holds
def
equivalenceOverSubstraction
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
)
(
a1
-
b1
)
~
(
a2
-
b2
)
}.
holds
def
equivalenceOverMultiplication
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
)
(
a1
*
b1
)
~
(
a2
*
b2
)
}.
holds
def
equivalenceOverDivision
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
&&
b1
.
isNonZero
// in addition to the usual requirements
)
(
a1
/
b1
)
~
(
a2
/
b2
)
}.
holds
def
additionPreservesOrdering
(
a
:
Rational
,
b
:
Rational
,
c
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
&&
c
.
isRational
)
(
a
<=
b
)
==>
(
a
+
c
<=
b
+
c
)
&&
(
a
<=
b
)
==>
(
c
+
a
<=
c
+
b
)
}.
holds
def
orderingTransitivity
(
a
:
Rational
,
b
:
Rational
,
c
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
&&
c
.
isRational
)
((
a
<
b
)
&&
(
b
<
c
))
==>
(
a
<
c
)
&&
(((
a
<=
b
)
&&
(
b
<=
c
))
==>
(
a
<=
c
))
}.
holds
def
orderingAntisymmetry
(
a
:
Rational
,
b
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
)
(
a
<=
b
&&
b
<=
a
)
==>
a
~
b
}.
holds
def
orderingReflexivity
(
a
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
)
a
<=
a
}.
holds
def
orderingIrreflexivity
(
a
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
)
!(
a
<
a
)
}.
holds
def
orderingExtra
(
a
:
Rational
,
b
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
)
((
a
<
b
)
==
!(
b
<=
a
))
&&
((
a
<
b
)
==
(
a
<=
b
&&
!(
a
~
b
)))
}.
holds
def
plusAssoc
(
a
:
Rational
,
b
:
Rational
,
c
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
&&
c
.
isRational
)
(
a
+
b
)
+
c
==
a
+
(
b
+
c
)
}.
holds
def
plusComm
(
a
:
Rational
,
b
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
)
a
+
b
==
b
+
a
}.
holds
}
/**
/**
* Measures on discrete probability spaces.
* Measures on discrete probability spaces.
...
@@ -18,6 +193,7 @@ import leon.proof._
...
@@ -18,6 +193,7 @@ import leon.proof._
* principle, the class could be re-implemented using 'Real' instead
* principle, the class could be re-implemented using 'Real' instead
* of 'Rational'.
* of 'Rational'.
*/
*/
sealed
abstract
class
Meas
[
A
]
{
sealed
abstract
class
Meas
[
A
]
{
/** Compute the value of this measure on the space 'A'. */
/** Compute the value of this measure on the space 'A'. */
...
@@ -262,3 +438,4 @@ object MeasSpecs {
...
@@ -262,3 +438,4 @@ object MeasSpecs {
}
}
}.
holds
}.
holds
}
}
This diff is collapsed.
Click to expand it.
testcases/verification/proof/measure/Rational.scala
deleted
100644 → 0
+
0
−
182
View file @
9971a4fa
/* Copyright 2009-2015 EPFL, Lausanne */
package
leon.testcases.verification.proof.measure
import
leon.proof._
import
leon.lang._
import
scala.language.implicitConversions
object
Rational
{
implicit
def
bigInt2Rational
(
x
:
BigInt
)
=
Rational
(
x
,
1
)
}
/**
* Represents rational number 'n / d', where 'n' is the numerator and
* 'd' the denominator.
*/
case
class
Rational
(
n
:
BigInt
,
d
:
BigInt
)
{
def
+
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
)
Rational
(
n
*
that
.
d
+
that
.
n
*
d
,
d
*
that
.
d
)
}
ensuring
{
res
=>
res
.
isRational
&&
((
this
.
isPositive
==
that
.
isPositive
)
==>
(
res
.
isPositive
==
this
.
isPositive
))
}
def
-
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
)
Rational
(
n
*
that
.
d
-
that
.
n
*
d
,
d
*
that
.
d
)
}
ensuring
{
res
=>
res
.
isRational
&&
((
this
.
isPositive
!=
that
.
isPositive
)
==>
(
res
.
isPositive
==
this
.
isPositive
))
}
def
*
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
)
Rational
(
n
*
that
.
n
,
d
*
that
.
d
)
}
ensuring
{
res
=>
res
.
isRational
&&
(
res
.
isNonZero
==
(
this
.
isNonZero
&&
that
.
isNonZero
))
&&
(
res
.
isPositive
==
(!
res
.
isNonZero
||
this
.
isPositive
==
that
.
isPositive
))
}
def
/
(
that
:
Rational
)
:
Rational
=
{
require
(
isRational
&&
that
.
isRational
&&
that
.
isNonZero
)
Rational
(
n
*
that
.
d
,
d
*
that
.
n
)
}
ensuring
{
res
=>
res
.
isRational
&&
(
res
.
isNonZero
==
this
.
isNonZero
)
&&
(
res
.
isPositive
==
(!
res
.
isNonZero
||
this
.
isPositive
==
that
.
isPositive
))
}
def
<=
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
if
(
that
.
d
*
d
>
0
)
n
*
that
.
d
<=
d
*
that
.
n
else
n
*
that
.
d
>=
d
*
that
.
n
}
def
<
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
if
(
that
.
d
*
d
>
0
)
n
*
that
.
d
<
d
*
that
.
n
else
n
*
that
.
d
>
d
*
that
.
n
}
def
>=
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
that
<=
this
}
def
>
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
that
<
this
}
// Equivalence of two rationals, true if they represent the same real number
def
~
(
that
:
Rational
)
:
Boolean
=
{
require
(
isRational
&&
that
.
isRational
)
n
*
that
.
d
==
that
.
n
*
d
}
def
isRational
=
d
!=
0
def
isPositive
=
isRational
&&
(
n
*
d
>=
0
)
def
isNonZero
=
isRational
&&
(
n
!=
0
)
}
object
RationalSpecs
{
def
equivalenceOverAddition
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
)
(
a1
+
b1
)
~
(
a2
+
b2
)
}.
holds
def
equivalenceOverSubstraction
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
)
(
a1
-
b1
)
~
(
a2
-
b2
)
}.
holds
def
equivalenceOverMultiplication
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
)
(
a1
*
b1
)
~
(
a2
*
b2
)
}.
holds
def
equivalenceOverDivision
(
a1
:
Rational
,
a2
:
Rational
,
b1
:
Rational
,
b2
:
Rational
)
:
Boolean
=
{
require
(
a1
.
isRational
&&
a2
.
isRational
&&
b1
.
isRational
&&
b2
.
isRational
&&
a1
~
a2
&&
b1
~
b2
&&
b1
.
isNonZero
// in addition to the usual requirements
)
(
a1
/
b1
)
~
(
a2
/
b2
)
}.
holds
def
additionPreservesOrdering
(
a
:
Rational
,
b
:
Rational
,
c
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
&&
c
.
isRational
)
(
a
<=
b
)
==>
(
a
+
c
<=
b
+
c
)
&&
(
a
<=
b
)
==>
(
c
+
a
<=
c
+
b
)
}.
holds
def
orderingTransitivity
(
a
:
Rational
,
b
:
Rational
,
c
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
&&
c
.
isRational
)
((
a
<
b
)
&&
(
b
<
c
))
==>
(
a
<
c
)
&&
(((
a
<=
b
)
&&
(
b
<=
c
))
==>
(
a
<=
c
))
}.
holds
def
orderingAntisymmetry
(
a
:
Rational
,
b
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
)
(
a
<=
b
&&
b
<=
a
)
==>
a
~
b
}.
holds
def
orderingReflexivity
(
a
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
)
a
<=
a
}.
holds
def
orderingIrreflexivity
(
a
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
)
!(
a
<
a
)
}.
holds
def
orderingExtra
(
a
:
Rational
,
b
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
)
((
a
<
b
)
==
!(
b
<=
a
))
&&
((
a
<
b
)
==
(
a
<=
b
&&
!(
a
~
b
)))
}.
holds
def
plusAssoc
(
a
:
Rational
,
b
:
Rational
,
c
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
&&
c
.
isRational
)
(
a
+
b
)
+
c
==
a
+
(
b
+
c
)
}.
holds
def
plusComm
(
a
:
Rational
,
b
:
Rational
)
:
Boolean
=
{
require
(
a
.
isRational
&&
b
.
isRational
)
a
+
b
==
b
+
a
}.
holds
}
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