Hi,<br><br> I'm trying to make a predicate that converts a formula with complex literals into a formula with primitive literals. For example, using the facts informed in predicate "definition" (in module defs.m), I could convert the complex formula <br>
<br> and(literal("A"), literal("G"))<br><br>into <br><br> and(and(literal("B"),<br> not(or(literal("D"),<br> literal("E")))),<br>
or(literal("H", literal("J"))))<br><br>Each complex literal can only be defined one time, so the predicate "definition" can provide, at most, one answer. Similarly, the predicate "expand" can only provide <span id="result_box" class="short_text" lang="en"><span title="Clique para mostrar traduções alternativas" class="hps">exactly </span></span>one expansion for each formula.<br>
<br>But when I try to compile the module defs.m (defined at end of this message) I get the following errors:<br>$ mmc --make defs<br>Making Mercury/int3s/defs.int3<br>Making Mercury/ints/<a href="http://defs.int">defs.int</a><br>
Making Mercury/cs/defs.c<br>defs.m:021: In `definition'(out):<br>defs.m:021: error: determinism declaration not satisfied.<br>defs.m:021: Declared `semidet', inferred `multi'.<br>defs.m:023: Disjunction has multiple clauses with solutions.<br>
** Error making `Mercury/cs/defs.c'.<br><br>What am I doing wrong?<br><br>------------------------- defs.m -----------------------------------<br>:- module defs.<br>:- interface. <br>:- import_module io.<br><br>:- pred main(io::di, io::uo) is det.<br>
<br>:- implementation.<br>:- import_module string.<br><br>:- type formula<br> ---> and(formula, formula)<br> ; or(formula, formula)<br> ; not(formula)<br> ; literal(string).<br><br><br>
:- type query<br> ---> equiv(formula, formula)<br> ; formula(formula).<br><br>:- pred definition(query::out) is semidet.<br><br>definition(equiv(literal("A"), and(literal("B"), not(literal("C"))))).<br>
definition(equiv(literal("C"), or(literal("D"), literal("E")))).<br>definition(equiv(literal("G"), or(literal("H"), literal("J")))).<br><br><br>:- func expand(formula) = formula.<br>
<br>expand(F) = ExF :-<br> ( F = and(A,B), ExF = and(expand(A), expand(B))<br> ; F = or(A,B), ExF = or(expand(A), expand(B))<br> ; F = not(A), ExF = not(expand(A))<br> ; F = literal(X),<br> ( if definition(equiv(literal(X),X1))<br>
then X1 = X2, ExF = expand(X2)<br> else ExF = literal(X)<br> )<br> ).<br><br>main(!IO) :-<br> X = and(literal("A"), literal("G")),<br> io.print(expand(X),!IO),<br> <a href="http://io.nl">io.nl</a>(!IO).<br>
<br><br>-----------------------------------------------------------------------<br><br clear="all"> Thanks in advance for any answer.<br><br>Regards,<br>Alex<br>