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
.
Also, what exactly are the non-obvious advantages of Horn clauses?
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 .
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With