Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining the material conditional in Prolog

Tags:

logic

prolog

I have been trying to acclimate to Prolog and Horn clauses, but the transition from formal logic still feels awkward and forced. I understand there are advantages to having everything in a standard form, but:

What is the best way to define the material conditional operator --> in Prolog, where A --> B succeeds when either A = true and B = true OR B = false? That is, an if->then statement that doesn't fail when if is false without an else.

truth table

Also, what exactly are the non-obvious advantages of Horn clauses?

like image 636
QuietThud Avatar asked Nov 26 '12 19:11

QuietThud


People also ask

What is the material conditional?

In propositional logic and various other logics, the Material Conditional is the logical connective and binary truth operation represented symbolically as and outputs false whenever is true and is false. They are often expressed in natural language as a conditional sentence, even though they often differ in function from indictive conditionals .

What are the constants of Prolog?

Another variation of constants is the Numbers. So integer numbers can be represented as 100, 4, -81, 1202. In Prolog, the normal range of integers is from -16383 to 16383. Prolog also supports real numbers, but normally the use-case of floating point number is very less in Prolog programs, because Prolog is for symbolic, non-numeric computation.

What are the basic operations on Prolog?

Basic operations on prolog such as Insert, delete, update, append. Repositioning operators such as permutation, combination, etc. Set operations like set union, set intersection, etc. The list is a simple data structure that is widely used in non-numeric programming. List consists of any number of items, for example, red, green, blue, white, dark.

What is Prolog language?

The first Prolog was the Marseille Prolog based on the work by Colmerauer in the year 1970. The manual of this Marseille Prolog interpreter (Roussel, 1975) was the first detailed description of the Prolog language. Prolog is also considered as a fourth generation programming language supporting the declarative programming paradigm.


1 Answers

What is the best way to define the material conditional operator --> in Prolog

When A and B are just variables to be bound to the atoms true and false, this is easy:

cond(false, _).
cond(_, true).

But in general, there is no best way because Prolog doesn't offer proper negation, only negation as failure, which is non-monotonic. The closest you can come with actual propositions A and B is often

(\+ A ; B)

which tries to prove A, then goes on to B if A cannot be proven (which does not mean that it is false due to the closed-world assumption).

Negation, however, should be used with care in Prolog.

Also, what exactly are the non-obvious advantages of Horn clauses?

That they have a straightforward procedural reading. Prolog is a programming language, not a theorem prover. It's possible to write programs that have a clear logical meaning, but they're still programs.

To see the difference, consider the classical problem of sorting. If L is a list of numbers without duplicates, then

sort(L, S) :-
    permutation(L, S),
    sorted(S).
sorted([]).
sorted([_]).
sorted([X,Y|L]) :-
    X < Y,
    sorted([Y|L]).

is a logical specification of what it means for S to contain the elements of L in sorted order. However, it also has a procedural meaning, which is: try all the permutations of L until you have one that it sorted. This procedure, in the worst case, runs through all n! permutations, even though sorting can be done in O(n lg n) time, making it a very poor sorting program.

See also this question.

like image 68
Fred Foo Avatar answered Sep 30 '22 14:09

Fred Foo