<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Expr (libabsolute.Libabsolute.Expr)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../odoc.support/odoc.css"/><meta name="generator" content="odoc 2.4.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../odoc.support/highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> â€“ <a href="../../index.html">libabsolute</a> &#x00BB; <a href="../index.html">Libabsolute</a> &#x00BB; Expr</nav><header class="odoc-preamble"><h1>Module <code><span>Libabsolute.Expr</span></code></h1><p>This module defines the numerical language and some basic operations over it</p></header><nav class="odoc-toc"><ul><li><a href="#errors">Errors</a></li><li><a href="#constructors">Constructors</a><ul><li><a href="#constants">Constants</a></li><li><a href="#expression-constructors">Expression Constructors</a></li></ul></li><li><a href="#predicates">Predicates</a></li><li><a href="#operations">Operations</a></li><li><a href="#printing">Printing</a></li></ul></nav><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-binop"><a href="#type-binop" class="anchor"></a><code><span><span class="keyword">type</span> binop</span><span> = </span></code><ol><li id="type-binop.ADD" class="def variant constructor anchored"><a href="#type-binop.ADD" class="anchor"></a><code><span>| </span><span><span class="constructor">ADD</span></span></code></li><li id="type-binop.SUB" class="def variant constructor anchored"><a href="#type-binop.SUB" class="anchor"></a><code><span>| </span><span><span class="constructor">SUB</span></span></code></li><li id="type-binop.MUL" class="def variant constructor anchored"><a href="#type-binop.MUL" class="anchor"></a><code><span>| </span><span><span class="constructor">MUL</span></span></code></li><li id="type-binop.DIV" class="def variant constructor anchored"><a href="#type-binop.DIV" class="anchor"></a><code><span>| </span><span><span class="constructor">DIV</span></span></code></li><li id="type-binop.POW" class="def variant constructor anchored"><a href="#type-binop.POW" class="anchor"></a><code><span>| </span><span><span class="constructor">POW</span></span></code></li></ol></div><div class="spec-doc"><p>binary arithmetic operators</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span><span> = </span></code><ol><li id="type-t.Funcall" class="def variant constructor anchored"><a href="#type-t.Funcall" class="anchor"></a><code><span>| </span><span><span class="constructor">Funcall</span> <span class="keyword">of</span> string * <span><a href="#type-t">t</a> list</span></span></code></li><li id="type-t.Neg" class="def variant constructor anchored"><a href="#type-t.Neg" class="anchor"></a><code><span>| </span><span><span class="constructor">Neg</span> <span class="keyword">of</span> <a href="#type-t">t</a></span></code></li><li id="type-t.Binary" class="def variant constructor anchored"><a href="#type-t.Binary" class="anchor"></a><code><span>| </span><span><span class="constructor">Binary</span> <span class="keyword">of</span> <a href="#type-binop">binop</a> * <a href="#type-t">t</a> * <a href="#type-t">t</a></span></code></li><li id="type-t.Var" class="def variant constructor anchored"><a href="#type-t.Var" class="anchor"></a><code><span>| </span><span><span class="constructor">Var</span> <span class="keyword">of</span> string</span></code></li><li id="type-t.Cst" class="def variant constructor anchored"><a href="#type-t.Cst" class="anchor"></a><code><span>| </span><span><span class="constructor">Cst</span> <span class="keyword">of</span> <a href="../Q/index.html#type-t">Q.t</a></span></code></li></ol></div><div class="spec-doc"><p>numeric expressions (function call, unary negation, binary operations, variables and constants)</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-annot"><a href="#type-annot" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a annot</span></span><span> = </span></code><ol><li id="type-annot.AFuncall" class="def variant constructor anchored"><a href="#type-annot.AFuncall" class="anchor"></a><code><span>| </span><span><span class="constructor">AFuncall</span> <span class="keyword">of</span> string * <span><span><span class="type-var">'a</span> <a href="#type-annot_t">annot_t</a></span> list</span></span></code></li><li id="type-annot.ANeg" class="def variant constructor anchored"><a href="#type-annot.ANeg" class="anchor"></a><code><span>| </span><span><span class="constructor">ANeg</span> <span class="keyword">of</span> <span><span class="type-var">'a</span> <a href="#type-annot_t">annot_t</a></span></span></code></li><li id="type-annot.ABinary" class="def variant constructor anchored"><a href="#type-annot.ABinary" class="anchor"></a><code><span>| </span><span><span class="constructor">ABinary</span> <span class="keyword">of</span> <a href="#type-binop">binop</a> * <span><span class="type-var">'a</span> <a href="#type-annot_t">annot_t</a></span> * <span><span class="type-var">'a</span> <a href="#type-annot_t">annot_t</a></span></span></code></li><li id="type-annot.AVar" class="def variant constructor anchored"><a href="#type-annot.AVar" class="anchor"></a><code><span>| </span><span><span class="constructor">AVar</span> <span class="keyword">of</span> string</span></code></li><li id="type-annot.ACst" class="def variant constructor anchored"><a href="#type-annot.ACst" class="anchor"></a><code><span>| </span><span><span class="constructor">ACst</span> <span class="keyword">of</span> <a href="../Q/index.html#type-t">Q.t</a></span></code></li></ol></div><div class="spec-doc"><p>generic type for annotated expressions</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-annot_t"><a href="#type-annot_t" class="anchor"></a><code><span><span class="keyword">and</span> <span>'a annot_t</span></span><span> = <span><span class="type-var">'a</span> <a href="#type-annot">annot</a></span> * <span class="type-var">'a</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span><span class="keyword">val</span> compare : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> int</span></code></div></div><h2 id="errors"><a href="#errors" class="anchor"></a>Errors</h2><div class="odoc-spec"><div class="spec exception anchored" id="exception-Division_by_zero"><a href="#exception-Division_by_zero" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">Division_by_zero</span></span></code></div><div class="spec-doc"><p>raised by evaluation functions</p></div></div><div class="odoc-spec"><div class="spec exception anchored" id="exception-Non_integer_exposant"><a href="#exception-Non_integer_exposant" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">Non_integer_exposant</span></span></code></div><div class="spec-doc"><p>raised by evaluation functions</p></div></div><h2 id="constructors"><a href="#constructors" class="anchor"></a>Constructors</h2><h3 id="constants"><a href="#constants" class="anchor"></a>Constants</h3><div class="odoc-spec"><div class="spec value anchored" id="val-one"><a href="#val-one" class="anchor"></a><code><span><span class="keyword">val</span> one : <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-zero"><a href="#val-zero" class="anchor"></a><code><span><span class="keyword">val</span> zero : <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-two"><a href="#val-two" class="anchor"></a><code><span><span class="keyword">val</span> two : <a href="#type-t">t</a></span></code></div></div><h3 id="expression-constructors"><a href="#expression-constructors" class="anchor"></a>Expression Constructors</h3><div class="odoc-spec"><div class="spec value anchored" id="val-of_int"><a href="#val-of_int" class="anchor"></a><code><span><span class="keyword">val</span> of_int : <span>int <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>builds an expression from an integer</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_float"><a href="#val-of_float" class="anchor"></a><code><span><span class="keyword">val</span> of_float : <span>float <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>builds an expression from an float</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-of_mpqf"><a href="#val-of_mpqf" class="anchor"></a><code><span><span class="keyword">val</span> of_mpqf : <span><a href="../Q/index.html#type-t">Q.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>builds an expression from an Mpqf.t</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-var"><a href="#val-var" class="anchor"></a><code><span><span class="keyword">val</span> var : <span>string <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>variables constructor</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add"><a href="#val-add" class="anchor"></a><code><span><span class="keyword">val</span> add : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>addition</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-sub"><a href="#val-sub" class="anchor"></a><code><span><span class="keyword">val</span> sub : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>substraction</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-mul"><a href="#val-mul" class="anchor"></a><code><span><span class="keyword">val</span> mul : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>multiplication</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-div"><a href="#val-div" class="anchor"></a><code><span><span class="keyword">val</span> div : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>multiplication</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pow"><a href="#val-pow" class="anchor"></a><code><span><span class="keyword">val</span> pow : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>given an expression <code>e</code> builds the expresspion for <code>e1^e2</code></p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-square"><a href="#val-square" class="anchor"></a><code><span><span class="keyword">val</span> square : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>given an expression <code>e</code> builds the expresspion for <code>e*e</code></p></div></div><h2 id="predicates"><a href="#predicates" class="anchor"></a>Predicates</h2><div class="odoc-spec"><div class="spec value anchored" id="val-has_variable"><a href="#val-has_variable" class="anchor"></a><code><span><span class="keyword">val</span> has_variable : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>checks if an expression contains a variable</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_linear"><a href="#val-is_linear" class="anchor"></a><code><span><span class="keyword">val</span> is_linear : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p>checks if an expression is linear:</p><ul><li>is_linear (2*x + 4*y) = true</li><li>is_linear (2*x*z + y) = false</li></ul></div></div><h2 id="operations"><a href="#operations" class="anchor"></a>Operations</h2><div class="odoc-spec"><div class="spec value anchored" id="val-op_to_fun"><a href="#val-op_to_fun" class="anchor"></a><code><span><span class="keyword">val</span> op_to_fun : <span><a href="#type-binop">binop</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Q/index.html#type-t">Q.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Q/index.html#type-t">Q.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Q/index.html#type-t">Q.t</a></span></code></div><div class="spec-doc"><p>convert a binary operator to a rational function. The resulting function may raise Division_by_zero or Non_integer_exposant when the binary operator is respectivelly DIV or POW</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-constant_propagation"><a href="#val-constant_propagation" class="anchor"></a><code><span><span class="keyword">val</span> constant_propagation : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>bottom-up partial evaluation of expressions when operations involving only constants are involved:</p><ul><li>constant_propagation (x+2) = (x+2)</li><li>constant_propagation (2+2)*x = (4*x)</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-collect_vars"><a href="#val-collect_vars" class="anchor"></a><code><span><span class="keyword">val</span> collect_vars : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>int <a href="../Tools/VarMap/index.html#type-t">Tools.VarMap.t</a></span></span></code></div><div class="spec-doc"><p>Returns all the variables appearing in an expression as a map where to each variable is associated the integer number of its occurences</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-replace"><a href="#val-replace" class="anchor"></a><code><span><span class="keyword">val</span> replace : <span><span class="optlabel">?simplify</span>:bool <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>replace expr var value</code> builds a new expression identical to <code>expr</code> where all the occurences of the variable <code>var</code> are replaced by the expression <code>value</code>.</p><p>if simplify is true (default behaviour), a round of constant propagation is applied on the resulting expression</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-fix_var"><a href="#val-fix_var" class="anchor"></a><code><span><span class="keyword">val</span> fix_var : <span><span class="optlabel">?simplify</span>:bool <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> <span><a href="../Q/index.html#type-t">Q.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>fix_var expr var cst</code> builds a new expression identical to <code>expr</code> where all the occurences of the variable <code>var</code> are replaced by the constant <code>cst</code></p><p>if simplify is true (default behaviour), a round of constant propagation is applied on the resulting expression</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-eval"><a href="#val-eval" class="anchor"></a><code><span><span class="keyword">val</span> eval : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Instance/index.html#type-t">Instance.t</a> <span class="arrow">&#45;&gt;</span></span> <a href="../Q/index.html#type-t">Q.t</a></span></code></div><div class="spec-doc"><p>Evaluates the expression at the given point.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>[Invalid_arg]</code> <p>if a division by zero occurs of if an exponentitation by a non integer exposant is made.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-deannot"><a href="#val-deannot" class="anchor"></a><code><span><span class="keyword">val</span> deannot : <span><span><span class="type-var">'a</span> <a href="#type-annot_t">annot_t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>removes annotations from an annotated expression</p></div></div><h2 id="printing"><a href="#printing" class="anchor"></a>Printing</h2><div class="odoc-spec"><div class="spec value anchored" id="val-pp_var"><a href="#val-pp_var" class="anchor"></a><code><span><span class="keyword">val</span> pp_var : <span><span class="xref-unresolved">Stdlib</span>.Format.formatter <span class="arrow">&#45;&gt;</span></span> <span>string <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>variables printing</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pp_binop"><a href="#val-pp_binop" class="anchor"></a><code><span><span class="keyword">val</span> pp_binop : <span><span class="xref-unresolved">Stdlib</span>.Format.formatter <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-binop">binop</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>binary operators printing</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-print"><a href="#val-print" class="anchor"></a><code><span><span class="keyword">val</span> print : <span><span class="xref-unresolved">Stdlib</span>.Format.formatter <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>expression printer</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_string"><a href="#val-to_string" class="anchor"></a><code><span><span class="keyword">val</span> to_string : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Conversion to a string</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Operators"><a href="#module-Operators" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Operators/index.html">Operators</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Classic infix operators are redefined on <code>t</code>.</p></div></div></div></body></html>
