UNPKG

@ciao-lang/ts-ciao-interface

Version:

Simple Ciao interface for node.

108 lines (92 loc) 7.48 kB
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#273f79"/><link rel="stylesheet" href="lpdoc.css" type="text/css"/><script type="text/javascript" src="lpdoc.js"></script><title>Constraint programming over reals &mdash; The Ciao System v1.22</title></head><body><div class="lpdoc-page fixleftbar"><a href="#" id="sidebar-toggle-button" class="lpdoc-navbutton"><span id="sidebar-button-arrow">&#9776;</span></a><div id="sidebar" class="lpdoc-sidebar"><div style="height: 40px; margin-left: auto; margin-right: auto"><img src="ciao-logo_autofig.png" width=auto height=100%></div><div class="lpdoc-nav"><span class="lpdoc-on-right"><a class="lpdoc-navbutton" href="ExtendLang.html">&#x2191;</a><a class="lpdoc-navbutton" href="clpq_doc.html">&#x2190;</a><a class="lpdoc-navbutton" href="clpfd_doc.html">&#x2192;</a><a class="lpdoc-navbutton" href="ciaosearch.html">&#x1F50D;</a></span><span><a href="ciaofulltoc.html">TOC</a></span></div><hr></hr><ul class="lpdoc-itemize-sectpath"><li><a href="ciao.html">The Ciao System</a> &raquo;<br/> </li><li><a href="ExtendLang.html">PART IV - Language extensions</a> &raquo;<br/> </li><li><a href=""><strong>Constraint programming over reals</strong></a></li></ul><hr></hr><em>ON THIS PAGE</em><ul><li><a href="#Usage and interface">Usage and interface</a></li><li><a href="#Other information">Other information</a></li><ul><li><a href="#Some CLP(R) examples">Some CLP(R) examples</a></li><li><a href="#Meta-programming with CLP(R)">Meta-programming with CLP(R)</a></li></ul></ul></div><div class="lpdoc-main"><div id=""><h1>Constraint programming over reals</h1><a class="lpdoc-idx-anchor" href="ciaosearch.html#clpr"></a> <strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="Christian Holzbaur" href="ciaosearch.html#Christian Holzbaur">Christian Holzbaur</a>, <a class="lpdoc-idx-anchor" id="Daniel Cabeza" href="ciaosearch.html#Daniel Cabeza">Daniel Cabeza</a>, <a class="lpdoc-idx-anchor" id="Samir Genaim" href="ciaosearch.html#Samir Genaim">Samir Genaim (Meta-programming predicates)</a>.<p> <div class="lpdoc-alert"> <strong>Warning</strong>: This package is currently being adapted to the new characteristics of the Ciao module system. This new version now works right now to some extent, but it under further development at the moment. Use with (lots of) caution. </div> <br/><div id="Usage and interface"><h2>Usage and interface</h2><div class="lpdoc-cartouche"><ul><li><strong>Library usage:</strong><br/><tt>:- use_package(clpr).</tt> or <tt>:- module(...,...,[clpr]).</tt><li><strong>New operators defined:</strong><br/><a class="lpdoc-idx-anchor" id="0" href="ciaosearch.html#.=./2"><tt>.=./2</tt></a> [700,xfx], <a class="lpdoc-idx-anchor" id="1" href="ciaosearch.html#.&lt;&gt;./2"><tt>.&lt;&gt;./2</tt></a> [700,xfx], <a class="lpdoc-idx-anchor" id="2" href="ciaosearch.html#.&lt;./2"><tt>.&lt;./2</tt></a> [700,xfx], <a class="lpdoc-idx-anchor" id="3" href="ciaosearch.html#.=&lt;./2"><tt>.=&lt;./2</tt></a> [700,xfx], <a class="lpdoc-idx-anchor" id="4" href="ciaosearch.html#.&gt;./2"><tt>.&gt;./2</tt></a> [700,xfx], <a class="lpdoc-idx-anchor" id="5" href="ciaosearch.html#.&gt;=./2"><tt>.&gt;=./2</tt></a> [700,xfx]. <li><strong>Implicit imports:</strong><br/><ul class="lpdoc-itemize-minus"><li><em>Packages:</em><br/><a class="lpdoc-idx-anchor" id="6" href="ciaosearch.html#prelude"><tt>prelude</tt></a>, <a class="lpdoc-idx-anchor" id="7" href="ciaosearch.html#initial"><tt>initial</tt></a>, <a class="lpdoc-idx-anchor" id="8" href="condcomp_doc.html"><tt>condcomp</tt></a>, <a class="lpdoc-idx-anchor" id="9" href="assertions_doc.html"><tt>assertions</tt></a>, <a class="lpdoc-idx-anchor" id="10" href="ciaosearch.html#assertions/assertions_basic"><tt>assertions/assertions_basic</tt></a>. </ul></ul></div></div><div id="Other information"><h2>Other information</h2> <p><div id="Some CLP(R) examples"><h3>Some CLP(R) examples</h3> <p>(Other examples can be found in the source and library directories.)<p><ul> <li>&apos;Reversible&apos; Fibonacci (clpr): </ul> <p><pre class="lpdoc-codeblock">:- module(_, [fib/2], []). :- use_package(clpr). fib(X,Y):- X .=. 0, Y .=. 0. fib(X,Y):- X .=. 1, Y .=. 1. fib(N,F) :- N .&gt;. 1, N1 .=. N - 1, N2 .=. N - 2, fib(N1, F1), fib(N2, F2), F .=. F1+F2. </pre> <p><ul> <li>Dirichlet problem for Laplace&apos;s equation (clpr): </ul> <p><pre class="lpdoc-codeblock"> % % Solve the Dirichlet problem for Laplace&apos;s equation using % Leibman&apos;s five-point finit-differenc approximation. % The goal ?- go1 is a normal example, while the goal ?- go2 % shows output constraints for a small region where the boundary conditions % are not specified. % :- use_package(clpq). :- use_module(library(format)). laplace([_, _]). laplace([H1, H2, H3|T]):- laplace_vec(H1, H2, H3), laplace([H2, H3|T]). laplace_vec([_, _], [_, _], [_, _]). laplace_vec([_TL, T, TR|T1], [ML, M, MR|T2], [_BL, B, BR|T3]):- B + T + ML + MR - 4 * M .=. 0, laplace_vec([T, TR|T1], [M, MR|T2], [B, BR|T3]). printmat([]). printmat([H|T]):- printvec(H), printmat(T). printvec([]):- nl. printvec([H|T]):- printrat(H), printvec(T). printrat(rat(N,D)) :- !, X is N/D, format(&quot; ~2f&quot;,X). printrat(N) :- X is N*100, format(&quot; ~2d&quot;,X). go1:- X = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, _, _, _, _, _, _, _, _, _, 100], [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100] ], laplace(X), printmat(X). % Answer: % 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 % 100.00 51.11 32.52 24.56 21.11 20.12 21.11 24.56 32.52 51.11 100.00 % 100.00 71.91 54.41 44.63 39.74 38.26 39.74 44.63 54.41 71.91 100.00 % 100.00 82.12 68.59 59.80 54.97 53.44 54.97 59.80 68.59 82.12 100.00 % 100.00 87.97 78.03 71.00 66.90 65.56 66.90 71.00 78.03 87.97 100.00 % 100.00 91.71 84.58 79.28 76.07 75.00 76.07 79.28 84.58 91.71 100.00 % 100.00 94.30 89.29 85.47 83.10 82.30 83.10 85.47 89.29 94.30 100.00 % 100.00 96.20 92.82 90.20 88.56 88.00 88.56 90.20 92.82 96.20 100.00 % 100.00 97.67 95.59 93.96 92.93 92.58 92.93 93.96 95.59 97.67 100.00 % 100.00 98.89 97.90 97.12 96.63 96.46 96.63 97.12 97.90 98.89 100.00 % 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 100.0 go2([B31, M32, M33, B34, B42, B43, B12, B13, B21, M22, M23, B24]) :- laplace([ [_B11, B12, B13, _B14], [B21, M22, M23, B24], [B31, M32, M33, B34], [_B41, B42, B43, _B44] ]). % Answer: % % B34.=. -4*M22+B12+B21+4*M33-B43, % M23.=.4*M22-M32-B12-B21, % B31.=. -M22+4*M32-M33-B42, % B24.=.15*M22-4*M32-4*B12-4*B21-M33-B13 ? </pre> <p></div><div id="Meta-programming with CLP(R)"><h3>Meta-programming with CLP(R)</h3> <p>see <a href="clpq_doc.html#Meta-programming with CLP(Q)">Meta-programming with CLP(Q)</a> <p></div><br/></div></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>