Note that there are some explanatory texts on larger screens.

plurals
  1. POProlog: how to do "check(a++b++c++d equals d++a++c++b) -> yes"
    primarykey
    data
    text
    <p>Let's define custom operators - let it be <code>++</code>,<code>equals</code></p> <pre><code>:- op(900, yfx, equals). :- op(800, xfy, ++). </code></pre> <p>And fact:</p> <pre><code>check(A equals A). </code></pre> <p>I try to make predicate, let it be <code>check/1</code>, that will return true in all following situations:</p> <pre><code>check( a ++ b ++ c ++ d equals c ++ d ++ b ++ a ), check( a ++ b ++ c ++ d equals d ++ a ++ c ++ b), check( a ++ b ++ c ++ d equals d ++ b ++ c ++ a ), % and all permutations... of any amount of atoms check( a ++ ( b ++ c ) equals (c ++ a) ++ b), % be resistant to any type of parentheses </code></pre> <p>return</p> <pre><code>yes </code></pre> <p><strong>How to implement this in Prolog?</strong> (Code snippet, please. Is it possible? Am I missing something?)</p> <p>Gnu-Prolog is preferred, but SWI-Prolog is acceptable as well.</p> <p>P.S. Please treat code, as draft "pseudocode", and don't care for small syntax issues.</p> <p>P.P.S '++' is just beginning. I'd like to add more operators. That's why I'm afraid that putting stuff into list might be not good solution.</p> <h3>Additionally</h3> <p>Additionally, would be nice, if queries would be possible (but, this part <strong>is not required</strong>, if you are able to answer to first part, it's great and enough)</p> <pre><code>check( a ++ (b ++ X) equals (c ++ Y) ++ b) ) </code></pre> <p>one of possible results (thanks @mat for showing others)</p> <pre><code>X=c, Y=a </code></pre> <p>I am looking mostly for solution for first part of question - "yes/no" checking.</p> <p>Second part with X,Y would be nice addition. In it X,Y should be simple atoms. For above example domains for X,Y are specified: <code>domain(X,[a,b,c]),domain(Y,[a,b,c])</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload