summaryrefslogtreecommitdiff
path: root/Test/dafny0/Parallel.dfy
blob: 0928c070f8b1ce48d48a345ca1b22bfc3a2411ca (plain)
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
80
81
82
83
84
/*
method ParallelStatement_Syntax()
{
  parallel (i: int | 0 <= i < a.Length && i % 2 == 0) {
    a[i] := a[(i + 1) % a.Length] + 3;
  }

  parallel (o | o in spine) {
    o.f := o.f + Repr;
  }

  parallel (x, y | x in S && 0 <= y+x < 100) {
    Lemma(x, y);
  }

  parallel (p | 0 <= p)
    ensures F(p) <= Sum(p) * (p-1) + 100;
  {
    assert G(p);
    ghost var t;
    if (p % 2 == 0) {
      assert G(p) == F(p+2);
      t := p*p;
    } else {
      assume H(p, 20) < 100;  // don't know how to justify this
      t := p;
    }
    PowerLemma(p, t);
    t := t + 1;
    PowerLemma(p, t);
  }
}
*/

class C {
  var f: set<object>;
}

method ParallelStatement_Resolve(
    a: array<int>,
    spine: set<C>,
    Repr: set<object>,
    S: set<int>
  )
  requires a != null;
  modifies a, spine;
{
  parallel (i: int | 0 <= i < a.Length && i % 2 == 0) {
    a[i] := a[(i + 1) % a.Length] + 3;
  }

  parallel (o | o in spine) {
    o.f := o.f + Repr;
  }

  parallel (x, y | x in S && 0 <= y+x < 100) {
    Lemma(x, y);
  }

  parallel (p | 0 <= p)
    ensures F(p) <= Sum(p) * (p-1) + 100;
  {
    assert 0 <= G(p);
    ghost var t;
    if (p % 2 == 0) {
      assert G(p) == F(p+2);
      t := p*p;
    } else {
      assume H(p, 20) < 100;  // don't know how to justify this
      t := p;
    }
    PowerLemma(p, t);
    t := t + 1;
    PowerLemma(p, t);
  }
}

method Lemma(x: int, y: int)
ghost method PowerLemma(x: int, y: int)

function F(x: int): int
function G(x: int): int
function H(x: int, y: int): int
function Sum(x: int): int