User talk:ButterBookie/sandbox

Prolog article
This sandbox could be used for experimenting with edits to the Prolog article. Alternatively, proposed edits could be posted directly on the talk page of the Prolog article itself. Robert Kowalski (talk) 17:43, 19 February 2024 (UTC)


 * I'm not sure how to add a "reply" in the right place, but this comment refers to the relationship between the common-sense meaning of "true" and the logical meaning. This might be easily clarified by mentioning that a set of clauses represents a given world as the programmer understands it, and WITHIN THAT WORLD, logical inferences from what's deemed to be true are also deemed true. That way if an inexistent (in the real world) Samuel is a child of somebody in an existent Prolog database, truths about him will hold in that world view, whether it exists in reality or not. 187.252.206.150 (talk) 15:16, 22 February 2024 (UTC)
 * Yes, that is true (pun intended:-). What you are doing is beginning to explain the logical meaning of true, as a correspondence theory between a statement and a world state.  But in this introduction, that long explanation would be distracting, I would think, and could be confusing.  My proposal is to give the precise meaning of the Prolog fact as stating membership of a pair in a relation.  That is, of course, the essential aspect of the first-order semantics of that statement (a model defining a relations for the binary predicate/verb), but it doesn't require the distraction of worlds and states.  It reduces the meaning to its essence, and should be understandable by anyone with no idea of logic, but just simple basic set theory. ButterBookie (talk) 18:05, 22 February 2024 (UTC)

Logic and English
It is interesting that your proposed reading of Prolog clauses focuses on the relationship between the Prolog syntax and the relational semantics, but omits the relationship between the Prolog syntax and the intended English reading of the syntax. My intuition is that most readers and writers of Prolog programs will understand Prolog programs in terms of the correspondence between the programs and the natural language reading of the programs. Of course, this reflects my Logical English bias.

But I have been encouraged in this bias by the treatment in the Russell-Norvig AI book, which starts with English sentences, translates them into FOL logical syntax, and then discusses the different semantics that can be given to the syntax. They contrast the standard Tarskian semantics with the "database" semantics used by logic programming and Prolog, and they suggest that sometimes it is more natural to understand English sentences using Tarskian semantics, and sometimes it is more natural to understand English sentences using database semantics. But in any case, they start with the English sentences, and then move on to logical syntax and semantics. Robert Kowalski (talk) 09:35, 21 February 2024 (UTC)


 * Good points. I would push back slightly on your use of "database semantics" being a special case of "Tarskian semantics."  In my mind Tarskian semantics does not include the possibility of a closed world assumption.  I think what you call "Tarskian semantics," I might call model-based semantics.  But that is minor.
 * Come to think about it, I guess my approach is very radical, for a logic programmer. I would like Prolog programmers to be able to understand precisely what their Prolog programs do without having to understand all of first-order logic and model theory.  If they do understand all that logic, then that's great, and even better.  But if they don't, I'd like them to be able to understand Prolog programming anyway.  And I do believe that's possible, by understanding Prolog programs as defining relations.  I have more things to say along these lines, but I've got zoom meetings for the next several hours.  I'll be back... ButterBookie (talk) 16:26, 21 February 2024 (UTC)
 * To continue... Having to understand first-order logic before being able to understand Prolog programming is too high a hurdle, I believe.  To understand a programming language, one has to understand precisely what it does when you program something.  To say "it's just like natural language" is clearly a non-starter.  Even talking about "true" sentences can be confusing to students.  Maybe I add to our mother_child relation the fact mother_child(elizabeth,samuel).  As an undergraduate student, I would have said, "But that's wrong.  It's not true that the former queen of England had a child named Samuel.  You can't say that."  The word "true" has an common-sense meaning that is not the meaning that logic gives it.  Yes, once you have a good understanding of logic, you can see the relationship between the common-sense meaning of "true" and the logical meaning.  But that is a rather sophisticated understanding.  (Think what pre-20th century philosophers thought about the word "true".)  But if I say I'm just defining a different relation, then that confusion doesn't arise.
 * Maybe another way to argue this is that I think more undergraduate students would understand the precise meaning of "the pair  is in the relation p" than would understand the precise meaning of "p(a,b) is true."
 * Students learning functional languages don't need to understand lattice theory to be able to program well in a functional language. And similarly a student shouldn't have to understand all of first-order logic to be able to program in Prolog.  And, of course, Prolog is *not* classical first-order logic.  Prolog has the closed world assumption, and uses only Herbrand models.
 * So I think the better way to teach Prolog is to teach it as a relational programming language. And then after it is understood that way, then introduce what FO logic is and how Prolog relates to it.  Philosophers and logicians think the way to understand Prolog is to first understand logic and then specialize it to understand Prolog.  Programmers think the way to understand logic is first to understand Prolog programming and then see how it relates to logic.  (I'm clearly a programmer...). ButterBookie (talk) 20:31, 21 February 2024 (UTC)
 * I'd caution us regarding the use of "English" where what we really mean is "natural language". Granted that most wikipedia contributors, AI and CS main actors in general, books, materials, etc. are English-dominated, but taking the part for the whole is (unless we clealy refer specifically to
 * English) incorrect, let alone exclusive. 187.252.206.150 (talk) 15:11, 22 February 2024 (UTC)
 * Why don´t we just replace:
 * mother_child(elizabeth, charles).
 * expresses that the mother_child relation contains the pair elizabeth and charles. This can also be expressed by saying that mother_child(elizabeth,charles) is true.
 * by something like:
 * mother_child(elizabeth, charles).
 * expresses that elizabeth is the mother of charles.
 * I don´t think Bob wanted us to discuss Tarskian semantics. Jacinto Dávila (talk) 15:37, 22 February 2024 (UTC)
 * I wanted to be more precise than is achieved with just a natural language gloss. The English statement "elizabeth is the mother of charles" is not as clear as you might think.  In Montague grammar, it is given a meaning as a complex expression in a rather complex intensional type theory.  Also, "mother" can mean biological mother, step mother, female adult raising a child regardless of legal relationship, etc.  I don't want the reader to have to consider all these options and realize they are not included here, or don't matter here, or however they come to the "right" conclusion.  Saying pair membership in a set short circuits all those considerations, and it is precise.
 * (And to Michael's comment that we should avoid functions in the example to emphasize relations, I would note that "mother_child" is not a function. Its inverse is a function, if we're talking biological mother, maybe.  Google "has two mothers" for situations in which even the inverse may not be a function...) ButterBookie (talk) 18:18, 22 February 2024 (UTC)


 * Yes, I'm sorry that my comments about Tarskian versus database semantics gave the wrong impression that I was suggesting that the introduction should mention anything about semantics. In fact, I wanted to suggest the opposite, that there is no need to refer to semantics in the introduction at all, but that a paraphrase along the lines that Jacinto has suggested would be sufficient. Robert Kowalski (talk) 18:09, 22 February 2024 (UTC)
 * I can't believe you think that "there is no need to refer to semantics in the introduction at all." You must mean "formal semantics."  A "paraphrase" is, of course, an attempt to give an informal semantics.  I was going to say we all agree with this, but then I realized that I actually am proposing mentioning a kind of formal semantics, when I want to say "membership in a set."  I do want to say something rather precise.  And I have a hard time thinking about how to describe a programming language rather precisely to someone who doesn't understand such basic set theory.
 * But I want to go back to what I was trying to say concerning Bob's use of the terms: Tarskian and database semantics. I first thought this was a good idea, but now I'm not so sure.  Every logician I know of means Bob's Tarskian semantics when they say "the semantics of first-order logic(FOL)."  But saying there is another "database semantics" for FOL implies that this semantics gives a meaning for every first-order formula of FOL.  But we know that is false.  It gives a semantics to only a small subset of FOL: implications with atomic consequences and conjunctions of literals as conditions.  Reiter showed that the CWA can't be consistently extended to all formulas.  So saying "db semantics for FOL" is misleading.  It seems much more reasonable to me to say that these implications are actually inductive definitions.  That's what gives them their semantics (and of course it is well-known and the right one).  So they are not first-order formulas with a new and different semantics; they are inductive definitions with the well-known semantics that comes with inductive definitions.
 * Of course, I'm not proposing any of this for the Prolog lead. This is just thinking I've been doing, prompted by Bob's thought provoking comments. ButterBookie (talk) 18:57, 22 February 2024 (UTC)
 * This is getting deeper and deeper, and straying into the territory of how to introduce a formal/symbolic logic in general. I think the usual approach, when teaching an introduction to formal logic, is to focus on the translation of natural language sentences into formal logic. Formal semantics, if it comes into an introductory course at all, comes later.
 * But even restricting attention to this relationship between natural language sentences and formal logic, there is the further complication of going in the opposite direction: from sentences in formal logic into sentences in natural language. For example, p(X,Y) :- q(X,Y) could be interpreted as "X is a parent of Y if X is a mother of Y",  or as "there is a path from X to Y if there is a step from X to Y". Translating from natural language to formal language is more straight-forward than translating from formal to natural language.
 * In contrast, the usual Prolog definition of plus in Peano arthmetic does not suffer from this problem of translation, because it is a stipulative definition of a unique intended interpretation, both at the formal semantic level, and more importantly at the natural language level.
 * None of this should go in an introduction to Prolog, of course.
 * On the other hand, it does suggest that saying:
 * mother_child(elizabeth, charles).
 * expresses that elizabeth is the mother of charles.
 * may be the wrong way around. Better to say, perhaps:
 * the English sentence "Elizabeth is the mother of Charles"
 * can be represented by the Prolog fact mother_child(elizabeth, charles).
 * Robert Kowalski (talk) 21:09, 22 February 2024 (UTC)
 * Yes, going from formal language to natural language is different from going the other way. However, I doubt that many (any?) linguists would say that going from natural language to formal language is the easier direction.  Linguists argue (ad nauseam, I might even say) about what sentences in natural language mean.  Ambiguity is everywhere.  Context is incredibly important. Etc.  I think your example of a formal language sentence, p(X,Y) :- q(X,Y), is quite easy to express clearly in natural language: "The binary relation q is a subset of the binary relation p." ButterBookie (talk) 16:27, 23 February 2024 (UTC)


 * One of the problems with explaining that mother_child(elizabeth, charles) expresses that the mother_child relation contains the pair elizabeth and charles is that it does not rule out the possibility that its intended meaning in natural language is that charles is the mother of elizabeth. Robert Kowalski (talk) 09:27, 23 February 2024 (UTC)
 * That is definitely correct. I should say "... contains the ordered pair elizabeth and charles with elizabeth as the mother." ButterBookie (talk) 16:16, 23 February 2024 (UTC)

Define vs Represent (predicates and relations)
Regarding the first two sentences:

"Prolog is a general-purpose logic programming language in which a program consist of facts and rules that define predicates representing relations. Given a set of definitions, the programmer poses a query to invoke the system to deduce members of the defined relations."

Since the first sentence says "define predicates representing relations", perhaps the end of the second sentence could be:

".. to deduce representations of members of the defined relations."

(BTW, there is typo in the first sentence: a program consist -> consists.)

A justification for this is likely not needed, but I'm giving some explanation (not intended to be included in the Prolog lead).

The answers to a query can be considered representations of (subsets of) tuples of the defined relation, which can contain variables and (equality) constraints among such variables. A query can be seen as a representation of the set of tuples of a relation meeting some "constraints," that the programmer wants the system to infer from the program (the answer can express more constraints than the ones given by the query). For example, the query without variables:

restricts the possible answers to the only pair elizabeth and charles (in this order) of the parent_child relation. If the system answers "yes", it means that the answer is exactly the same as the query. If the system answers no, it means that no tuple represented by the query can be inferred. The query with a variable:

is constraining the first element of the pairs of the parent_child relation to be "elizabeth", and the query:

is constraining the two elements of the pairs to be the same. The answer will be "no" for the sample program.

Given a program consisting of the clause:

The answer to the query

will be:

which is equivalent to, and represents all the 3-tuples (triples) of the "p" relation such as the three components of the triple are the same. Variable A can take any value.

A conjunctive query such a:

is actually doing two things:

1. Defining an "unnamed" predicate consisting of the rule:

and "adding" it to the program.

2. Posing the query: Pedro.Lz.Ga (talk) 20:14, 24 February 2024 (UTC)

Indentation of resolvents
In this example:

"Prolog finds the answers to query using goal-directed (or subgoal reduction or backward chaining) reasoning, as follows: [...] Alternative matches to the same subgoal appear at the same level of indentation."

Shouldn't the last "resolvent" be at the same indentation level than the second one ? The same happens for the 5th and 6th resolvents. Also, the bindings such as (Z = charles) could go after the resolvent. A possible indentation could be: Bob also suggested to include a search tree here. It could be a good idea to include the tree in addition to this indented representation, or to include a link to another section in the article where the tree is depicted, for conciseness (perhaps the "Execution" Section). Pedro.Lz.Ga (talk) 11:03, 26 February 2024 (UTC)

What to say in the first paragraph of the Prolog article
As this is probably the most important paragraph of the article, it should convey in a concise way what we want the reader to grasp as a first impression, without delving into details. I guess it should mention:

1. The features that characterize Prolog (unification, builtin search, DCGs, ...)

2. Some applications.

3. Origins (giving credits to people).

A possibility could be to start with the sentence proposed by David and moving the paragraph that starts "Prolog has its roots ..." (or a shorter version) to the beginning. Also mention "Turing-complete" at the beginning.

For example (to be rewritten/completed/refined, citations added, ...):

" Prolog is a Turing-complete, general-purpose logic programming language in which a program consists of facts and rules that define predicates representing relations. It is well-suited, and has been used for artificial intelligence applications, such as natural language processing, (its original intended field of use), theorem proving,  expert systems, automated planning and intelligent knowledge-processing in general. Additionally, it supports term rewriting, type systems, and more. Prolog is rooted in first-order logic, serving primarily as a declarative programming language. Its strength lies in distinctive features such as unification, providing a uniform mechanism for parameter passing, data selection, and construction; built-in search capabilities for handling non-determinism and obtaining multiple results; and definite clause grammars (DCGs), facilitating language processing, whether natural or computer-oriented."

Then, start with:

"Given a Prolog program representing a set of relation definitions, the programmer poses a query to invoke the system to deduce representations of members of the defined relations...." Pedro.Lz.Ga (talk) 13:47, 26 February 2024 (UTC)