<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Fcl_expr.html"> <link rel="next" href="Fcl_interval.html"> <link rel="Up" href="index.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="Fcl_genesis" rel="Chapter" href="Fcl_genesis.html"> <link title="Fcl_debug" rel="Chapter" href="Fcl_debug.html"> <link title="Fcl_misc" rel="Chapter" href="Fcl_misc.html"> <link title="Fcl_float" rel="Chapter" href="Fcl_float.html"> <link title="Fcl_stak" rel="Chapter" href="Fcl_stak.html"> <link title="Fcl_domain" rel="Chapter" href="Fcl_domain.html"> <link title="Fcl_setDomain" rel="Chapter" href="Fcl_setDomain.html"> <link title="Fcl_data" rel="Chapter" href="Fcl_data.html"> <link title="Fcl_cstr" rel="Chapter" href="Fcl_cstr.html"> <link title="Fcl_var" rel="Chapter" href="Fcl_var.html"> <link title="Fcl_reify" rel="Chapter" href="Fcl_reify.html"> <link title="Fcl_invariant" rel="Chapter" href="Fcl_invariant.html"> <link title="Fcl_boolean" rel="Chapter" href="Fcl_boolean.html"> <link title="Fcl_alldiff" rel="Chapter" href="Fcl_alldiff.html"> <link title="Fcl_linear" rel="Chapter" href="Fcl_linear.html"> <link title="Fcl_nonlinear" rel="Chapter" href="Fcl_nonlinear.html"> <link title="Fcl_expr" rel="Chapter" href="Fcl_expr.html"> <link title="Fcl_arith" rel="Chapter" href="Fcl_arith.html"> <link title="Fcl_interval" rel="Chapter" href="Fcl_interval.html"> <link title="Fcl_gcc" rel="Chapter" href="Fcl_gcc.html"> <link title="Fcl_fdArray" rel="Chapter" href="Fcl_fdArray.html"> <link title="Fcl_conjunto" rel="Chapter" href="Fcl_conjunto.html"> <link title="Fcl_sorting" rel="Chapter" href="Fcl_sorting.html"> <link title="Fcl_goals" rel="Chapter" href="Fcl_goals.html"> <link title="Fcl_opti" rel="Chapter" href="Fcl_opti.html"> <link title="Facile" rel="Chapter" href="Facile.html"><link title="Basics" rel="Section" href="#2_Basics"> <link title="Construction of Arithmetic Expressions" rel="Section" href="#2_ConstructionofArithmeticExpressions"> <link title="Access" rel="Section" href="#2_Access"> <link title="Arithmetic Constraints on Expressions" rel="Section" href="#2_ArithmeticConstraintsonExpressions"> <link title="Reification" rel="Section" href="#2_Reification"> <link title="Boolean sums setting" rel="Section" href="#2_Booleansumssetting"> <title>Fcl_arith</title> </head> <body> <div class="navbar"><a href="Fcl_expr.html">Previous</a> <a href="index.html">Up</a> <a href="Fcl_interval.html">Next</a> </div> <center><h1>Module <a href="type_Fcl_arith.html">Fcl_arith</a></h1></center> <br> <pre><span class="keyword">module</span> Fcl_arith: <code class="code">sig</code> <a href="Fcl_arith.html">..</a> <code class="code">end</code></pre><a name="1_ArithmeticExpressionsandConstraints"></a> <h1>Arithmetic Expressions and Constraints</h1><br> <hr width="100%"> <br> <br> <br> This module provides functions and operators to build arithmetic expressions and state (in/dis)equation constraints on them.<br> <br> <a name="2_Basics"></a> <h2>Basics</h2><br> <pre><span class="keyword">type</span> <a name="TYPEt"></a><code class="type"></code>t </pre> <div class="info"> Type of arithmetic expressions over variables of type <code class="code">Var.Fd.t</code> and integers.<br> </div> <pre><span class="keyword">val</span> <a name="VALi2e"></a>i2e : <code class="type">int -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> <code class="code">i2e n</code> returns an expression which evaluates to <code class="code">n</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALfd2e"></a>fd2e : <code class="type">Fcl_var.Fd.t -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> <code class="code">fd2e v</code> returns an expression which evaluates to <code class="code">n</code> if the variable <code class="code">v</code> is instantiated to <code class="code">n</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALe2fd"></a>e2fd : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> Fcl_var.Fd.t</code></pre><div class="info"> <code class="code">e2fd e</code> creates and returns a new variable <code class="code">v</code> and posts the constraint <code class="code">fd2e v =~ e</code>.<br> </div> <br> <a name="2_ConstructionofArithmeticExpressions"></a> <h2>Construction of Arithmetic Expressions</h2><br> <br> <b>Only</b> if compiled in bytecode (using <code class="code">facile.cma</code>), the arithmetic operators check whether any integer overflow (i.e. the result of an arithmetic operation on integers is less than <code class="code">min_int</code> or greater than <code class="code">max_int</code>) occurs during constraints internal computations and raise an assert failure. Arithmetic operations are taken modulo otherwise (or on 64-bit processors, see the OCaml reference manual), thus incomplete failures may happen with native code compiled programs.<br> <pre><span class="keyword">val</span> <a name="VAL(+~)"></a>(+~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(-~)"></a>(-~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL( *~ )"></a>( *~ ) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> Addition, substraction, multiplication on expressions.<br> </div> <pre><span class="keyword">val</span> <a name="VAL( **~ )"></a>( **~ ) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> int -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> Exponentiation of an expression to an integer value.<br> </div> <pre><span class="keyword">val</span> <a name="VAL(/~)"></a>(/~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(%~)"></a>(%~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> Division and modulo on expressions. The exception <code class="code">Division_by_zero</code> is raised whenever the second argument evaluates to 0.<br> </div> <pre><span class="keyword">val</span> <a name="VALabs"></a>abs : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> Absolute value on expressions.<br> </div> <pre><span class="keyword">val</span> <a name="VALsum"></a>sum : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> array -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VALsum_fd"></a>sum_fd : <code class="type">Fcl_var.Fd.t array -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> <code class="code">sum exps</code> (resp. <code class="code">sum_fd vars</code>) returns the sum of all the elements of an array of expressions (resp. variables). Returns an expression that evaluates to 0 if the array is empty.<br> </div> <pre><span class="keyword">val</span> <a name="VALscalprod"></a>scalprod : <code class="type">int array -> <a href="Fcl_arith.html#TYPEt">t</a> array -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VALscalprod_fd"></a>scalprod_fd : <code class="type">int array -> Fcl_var.Fd.t array -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> <code class="code">scalprod coeffs exps</code> (resp. <code class="code">scalprod_fd coeffs vars</code>) returns the scalar product of an array of integers and an array of expressions (resp. variables). Returns an expression that evaluates to 0 if both arrays are empty. Raises <code class="code">Invalid_argument</code> if the arrays don't have the same length.<br> </div> <pre><span class="keyword">val</span> <a name="VALprod"></a>prod : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> array -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VALprod_fd"></a>prod_fd : <code class="type">Fcl_var.Fd.t array -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> <code class="code">prod exps</code> (resp. <code class="code">prod_fd vars</code>) returns the product of all the elements of an array of expressions (resp. variables). Returns an expression that evaluates to 1 if the array is empty.<br> </div> <br> <a name="2_Access"></a> <h2>Access</h2><br> <pre><span class="keyword">val</span> <a name="VALfprint"></a>fprint : <code class="type">Pervasives.out_channel -> <a href="Fcl_arith.html#TYPEt">t</a> -> unit</code></pre><div class="info"> <code class="code">fprint chan e</code> prints expression <code class="code">e</code> on channel <code class="code">chan</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALeval"></a>eval : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> int</code></pre><div class="info"> <code class="code">eval e</code> returns the integer numerical value of a fully instantiated expression <code class="code">e</code>. Raises <code class="code">Invalid_argument</code> if <code class="code">e</code> is not instantiated.<br> </div> <pre><span class="keyword">val</span> <a name="VALmin_of_expr"></a>min_of_expr : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> int</code></pre><pre><span class="keyword">val</span> <a name="VALmax_of_expr"></a>max_of_expr : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> int</code></pre><div class="info"> <code class="code">min_of_expr e</code> (resp. <code class="code">max_of_expr e</code>) returns the minimal (resp. maximal) possible value of expression <code class="code">e</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALmin_max_of_expr"></a>min_max_of_expr : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> int * int</code></pre><div class="info"> <code class="code">min_max_of_expr e</code> is equivalent to <code class="code">(min_of_expr e, max_of_expr e)</code>.<br> </div> <br> <a name="2_ArithmeticConstraintsonExpressions"></a> <h2>Arithmetic Constraints on Expressions</h2><br> <br> FaCiLe processes arithmetic constraints to try to simplify and factorize common subexpressions. Furthermore, auxilliary variables are created to handle non-linear expressions and substituted to the original terms. So printing an arithmetic constraint may produce something quite different from the user's input.<br> <pre><span class="keyword">val</span> <a name="VAL(<~)"></a>(<~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_cstr.html#TYPEt">Fcl_cstr.t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(<=~)"></a>(<=~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_cstr.html#TYPEt">Fcl_cstr.t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(=~)"></a>(=~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_cstr.html#TYPEt">Fcl_cstr.t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(>=~)"></a>(>=~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_cstr.html#TYPEt">Fcl_cstr.t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(>~)"></a>(>~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_cstr.html#TYPEt">Fcl_cstr.t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(<>~)"></a>(<>~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_cstr.html#TYPEt">Fcl_cstr.t</a></code></pre><div class="info"> Strictly less, less or equal, equal, greater or equal, strictly greater and different constraints on expressions.<br> </div> <pre><span class="keyword">val</span> <a name="VALshift"></a>shift : <code class="type">Fcl_var.Fd.t -> int -> Fcl_var.Fd.t</code></pre><div class="info"> <code class="code">shift x d</code> returns a finite domain variable constrained to be equal to <code class="code">x+d</code>.<br> </div> <br> <a name="2_Reification"></a> <h2>Reification</h2><br> <br> The following operators are shortcuts to lighten the writing of reified expressions. They replace the corresponding constraint by an expression equal to a boolean variable that is instantiated to <code class="code">1</code> when the constraint is satisfied and to <code class="code">0</code> if it is violated. See module <code class="code">Reify</code> .<br> <pre><span class="keyword">val</span> <a name="VAL(<~~)"></a>(<~~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> <code class="code">e1 op~~ e2</code> is equivalent to <code class="code">fd2e (Reify.boolean (e1 op~ e2))</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VAL(<=~~)"></a>(<=~~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(=~~)"></a>(=~~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(>=~~)"></a>(>=~~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(>~~)"></a>(>~~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><pre><span class="keyword">val</span> <a name="VAL(<>~~)"></a>(<>~~) : <code class="type"><a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a> -> <a href="Fcl_arith.html#TYPEt">t</a></code></pre><div class="info"> Reified strictly less, less or equal, equal, greater or equal, strictly greater and different.<br> </div> <br> <a name="2_Booleansumssetting"></a> <h2>Boolean sums setting</h2> <p> FaCiLe tries to automatically optimize the processing of boolean (0-1 variables) sums whenever their sizes are large enough.<br> <pre><span class="keyword">val</span> <a name="VALget_boolsum_threshold"></a>get_boolsum_threshold : <code class="type">unit -> int</code></pre><div class="info"> Returns the minimum size for boolean sums optimization. (Default: 5)<br> </div> <pre><span class="keyword">val</span> <a name="VALset_boolsum_threshold"></a>set_boolsum_threshold : <code class="type">int -> unit</code></pre><div class="info"> Set the minimum size for boolean sums optimization. <code class="code">boolsum_threshold max_int</code> disables it.<br> </div> </body></html>