| 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 | (** The purpose of the solver is to generate *all* the integer solutions |
| 12 | of a system of linear equations of the following form: |
| 13 | 1- all the variables are positive |
| 14 | 2- all the coefficients are positive |
| 15 | |
| 16 | We expect the systems and the number of solutions to be small. |
| 17 | This motivates a simple solver which performs |
| 18 | 1 - interval analysis |
| 19 | 2 - substitutions |
| 20 | 3 - enumeration |
| 21 | *) |
| 22 | |
| 23 | |
| 24 | (** [system] represents a system of equation. |
| 25 | Each equation is indexed by a unique identifier [id] (an integer). |
| 26 | *) |
| 27 | |
| 28 | type system |
| 29 | |
| 30 | (** [var] is the type of variables *) |
| 31 | type var = int |
| 32 | |
| 33 | (** [id] are used to identify equations in a system *) |
| 34 | type id = int |
| 35 | |
| 36 | (** An equation [eqn] is of the form a1.x1 + ... + an.xn = a0 |
| 37 | where the ai are integer coefficients and xi are variables. |
| 38 | *) |
| 39 | type eqn |
| 40 | |
| 41 | (** [output_equations o l] prints the list of equations *) |
| 42 | val output_equations : out_channel -> eqn list -> unit |
| 43 | |
| 44 | (** [empty] is the system with no equation *) |
| 45 | val empty : system |
| 46 | |
| 47 | (** [set_constant i c s] returns the equation [i] |
| 48 | of the system [s] where the constant a0 is set to [c] *) |
| 49 | val set_constant : id -> int -> system -> eqn |
| 50 | |
| 51 | (** [make_mon i x a s] augments the system [s] |
| 52 | with the equation a.x = 0 indexed by i *) |
| 53 | val make_mon : id -> var -> int -> system -> system |
| 54 | |
| 55 | (** [merge s1 s2] returns a system [s] such that |
| 56 | the equation i is obtained by adding |
| 57 | of the equations s1(i) and s2(i) i.e. |
| 58 | s(i) = s1(i) + s2(i) |
| 59 | NB: the operation is only well-defined if |
| 60 | the variables in s1(i) and s2(i) is disjoint |
| 61 | *) |
| 62 | val merge : system -> system -> system |
| 63 | |
| 64 | (** [solution] assigns a value to each variable *) |
| 65 | type solution = (var * int) list |
| 66 | |
| 67 | (** [output_solutions o l] outputs the list of solutions *) |
| 68 | val output_solutions : out_channel -> solution list -> unit |
| 69 | |
| 70 | (** [solve_and_enum l] solves the system of equations |
| 71 | and enumerate all the solutions *) |
| 72 | val solve_and_enum : eqn list -> solution list |