A union of a conditions

81 Views Asked by At

i'm pretty new to prolog and now only the very basics and i ran into a problem

i need to write a statement line this: <cond.1> and (<cond.2> or <cond.3>)

in languages like c++ it would look something like this:

if(<cond.1> && (<cond.2> || <cond.3>)) { /*...*/ }

And i tried this in prolog:

statement(X, Y, Z, W):-condition(X,Y,Z,W), !, X <> Z or Y <> W.

And this

statement(X, Y, Z, W):-condition(X,Y,Z,W) and (X <> Z or Y <> W).

And more things that google told me. Nothing worked, and i know that this logical statement would look like this in expanded form: <cond.1> and <cond.2> or <cond.1> and <cond.3>

But this is creates a frick ton of code and makes it unreadable. i just feel there has to be a way to implement these conditions inside a parentheses. But i just dont know how and i can't find any way to do it.

1

There are 1 best solutions below

6
On

The "logical or" is denoted with a semicolon (;). So your predicate would likely look like:

statement(X, Y, Z, W) :-
    condition(X,Y,Z,W),
    (X \= Z; Y \= W).

Here the \=/2 predicate [swi-doc] succeeds if it can not unify X with Z (or Y with W).