File size: 2,035 Bytes
6851d40 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | // RUN: %verify "%s"
/*******************************************************************************
* Copyright by the contributors to the Dafny Project
* SPDX-License-Identifier: MIT
*******************************************************************************/
include "../src/dafny/Relations.dfy"
module {:options "-functionSyntax:4"} RelationsExamples {
import opened Dafny.Relations
lemma BuiltInIntLTIsStrictTotalOrdering()
ensures StrictTotalOrdering((x: int, y: int) => x < y)
{}
lemma BuiltInIntLEIsTotalOrdering()
ensures TotalOrdering((x: int, y: int) => x <= y)
{}
function Modulo(n: nat): (R: (int, int) -> bool)
requires n >= 1
ensures EquivalenceRelation(R)
{
(x, y) => (x % n == y % n)
}
lemma BuiltInIntEqIsEquivalenceRelation()
ensures EquivalenceRelation((x: int, y: int) => (x == y))
{}
lemma BuiltInIntGeIsAntiSymmetricRelation()
ensures AntiSymmetric((x: int, y: int) => (x >= y))
{}
lemma BuiltInIntLtIsAsymmetricRelation()
ensures Asymmetric((x: int, y: int) => (x < y))
{
}
lemma AlwaysTrueIsNotAntiSymmetric()
ensures !AntiSymmetric((x: int, y: int) => true)
{
var f := (x: int, y: int) => true;
assert f(2,3) && f(3,2) && 3 != 2;
assert !AntiSymmetric(f);
}
lemma BuiltInIntLtIsNotReflexiveRelation()
ensures !Reflexive((x: int, y: int) => (x < y))
{
var f := (x: int, y: int) => (x < y);
assert !f(0,0);
assert !forall x: int :: f(x,x);
assert !Reflexive(f);
}
lemma BuiltInIntLtIsIrreflexiveRelation()
ensures Irreflexive((x: int, y: int) => (x < y))
{}
lemma BuiltInIntEqIsNotIrreflexiveRelation()
ensures !Irreflexive((x: int, y: int) => (x == y))
{
var f := (x: int, y: int) => (x == y);
assert f(0,0);
assert !Irreflexive(f);
}
lemma AsymmetricIsAntiSymmetric<T>(f: (T,T)->bool)
ensures Asymmetric(f) ==> AntiSymmetric(f)
{}
lemma AsymmetricIsIrreflexive<T>(f: (T,T)->bool)
ensures Asymmetric(f) ==> Irreflexive(f)
{}
}
|