Debian Codegraph @

plugins/micromega/itv.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open NumCompat
12 open Q.Notations
13
14 (** Intervals (extracted from mfourier.ml) *)
15
16 (** The type of intervals is *)
17 type interval = Q.t option * Q.t option
18 (** None models the absence of bound i.e. infinity
19 As a result,
20 - None , None -> \]-oo,+oo\[
21 - None , Some v -> \]-oo,v\]
22 - Some v, None -> \[v,+oo\[
23 - Some v, Some v' -> \[v,v'\]
24 Intervals needs to be explicitly normalised.
25 *)
26
27 let pp o (n1, n2) =
28 ( match n1 with
29 | None -> output_string o "]-oo"
30 | Some n -> Printf.fprintf o "[%s" (Q.to_string n) );
31 output_string o ",";
32 match n2 with
33 | None -> output_string o "+oo["
34 | Some n -> Printf.fprintf o "%s]" (Q.to_string n)
35
36 (** if then interval [itv] is empty, [norm_itv itv] returns [None]
37 otherwise, it returns [Some itv] *)
38
39 let norm_itv itv =
40 match itv with
41 | Some a, Some b -> if a <=/ b then Some itv else None
42 | _ -> Some itv
43
44 (** [inter i1 i2 = None] if the intersection of intervals is empty
45 [inter i1 i2 = Some i] if [i] is the intersection of the intervals [i1] and [i2] *)
46 let inter i1 i2 =
47 let l1, r1 = i1 and l2, r2 = i2 in
48 let inter f o1 o2 =
49 match (o1, o2) with
50 | None, None -> None
51 | Some _, None -> o1
52 | None, Some _ -> o2
53 | Some n1, Some n2 -> Some (f n1 n2)
54 in
55 norm_itv (inter Q.max l1 l2, inter Q.min r1 r2)
56
57 let range = function
58 | None, _ | _, None -> None
59 | Some i, Some j -> Some (Q.floor j -/ Q.ceiling i +/ Q.one)
60
61 let smaller_itv i1 i2 =
62 match (range i1, range i2) with
63 | None, _ -> false
64 | _, None -> true
65 | Some i, Some j -> i <=/ j
66
67 (** [in_bound bnd v] checks whether [v] is within the bounds [bnd] *)
68 let in_bound bnd v =
69 let l, r = bnd in
70 match (l, r) with
71 | None, None -> true
72 | None, Some a -> v <=/ a
73 | Some a, None -> a <=/ v
74 | Some a, Some b -> a <=/ v && v <=/ b