-
Notifications
You must be signed in to change notification settings - Fork 0
/
Values.fs
66 lines (59 loc) · 2.35 KB
/
Values.fs
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
// Values can be ⊤, ⊥ either an interval of values [a,b]
// the interval is a sound overapproximation of RIC, such that (a,b,c,d) = (1,ab+d, ac+d, 0) = [ab+d, ac+d]
// ⊤ = [NegativeInf, PositiveInf], ⊥ = empty set (0,0)
type Values =
| Bottom
| Interval of left : Endpoint * right : Endpoint
| Top
// ⊤ + ⊥ = ⊥; ⊤ + ⊤ = ⊤; ⊤ + I = ⊤;
// ⊥ + ⊥ = ⊥; ⊥ + I = ⊥;
// I1 : [a,b] + I2 : [c,d] = [a+c,b+d]
with static member (+) (v1 : Values, v2 : Values) =
match v1,v2 with
|Interval(l1,r1),Interval(l2,r2) -> Interval(l1+l2,r1+r2)
|Bottom,_
|_,Bottom -> Bottom
|Top,_
|_,Top -> Top
// VS1 * VS2 :
// ⊤ * ⊥ = ⊥; ⊤ * ⊤ = ⊤; ⊤ * I = ⊤;
// ⊥ * ⊥ = ⊥; ⊥ * I = ⊥;
// I1 : [a,b] * I2 : [c,d] = [a*c,b*d]
static member (*) (v1 : Values, v2 : Values) =
match v1,v2 with
|Interval(l1,r1),Interval(l2,r2) -> Interval(l1*l2,r1*r2)
|Bottom,_
|_,Bottom -> Bottom
|Top,_
|_,Top -> Top
and Endpoint =
| NegativeInf
| Int of int
| PositiveInf
with static member (+) (e1 : Endpoint, e2 : Endpoint) =
match e1,e2 with
|Int(x),Int(y) -> Int(x+y)
|NegativeInf,PositiveInf
|PositiveInf,NegativeInf -> failwith("Undefined sum")
|_,PositiveInf
|PositiveInf,_ -> PositiveInf
|_,NegativeInf
|NegativeInf,_ -> NegativeInf
static member (*) (e1 : Endpoint, e2 : Endpoint) =
match e1,e2 with
|Int(x),Int(y) -> Int(x*y)
|Int(x),PositiveInf when x=0 -> failwith("Undefined product")
|Int(x),NegativeInf when x=0 -> failwith("Undefined product")
|PositiveInf,Int(x) when x=0 -> failwith("Undefined product")
|NegativeInf,Int(x) when x=0 -> failwith("Undefined product")
|Int(x),PositiveInf when x<0 -> NegativeInf
|PositiveInf,Int(x) when x<0 -> NegativeInf
|Int(x),NegativeInf when x<0 -> PositiveInf
|NegativeInf,Int(x) when x<0 -> PositiveInf
|NegativeInf,PositiveInf
|PositiveInf,NegativeInf -> NegativeInf
|PositiveInf,_
|_,PositiveInf -> PositiveInf
|NegativeInf,_
|_,NegativeInf -> NegativeInf
;;