{"id":208,"date":"2004-07-05T20:07:13","date_gmt":"2004-07-06T03:07:13","guid":{"rendered":"http:\/\/northgare.net\/blah\/?p=208"},"modified":"2018-07-20T14:03:29","modified_gmt":"2018-07-20T21:03:29","slug":"on-clean-dishes-and-being-positive","status":"publish","type":"post","link":"http:\/\/northgare.net\/blog\/2004\/07\/on-clean-dishes-and-being-positive\/","title":{"rendered":"On Clean Dishes, and Being Positive"},"content":{"rendered":"<p>About our new dishwasher&#8230;<\/p>\n<p>A couple of years ago I taught a course called &#8216;Introduction to Artificial Intelligence Programming&#8217; \u2014 largely because I was available when no-one else was. It turned out to be great fun, and not least because I&#8217;d been through the same course one year as a student, and another as a Teaching Assistant, and could finally teach it the way I wanted to.<\/p>\n<p>The course had been moving towards trendy-but-hardly-AI stuff like Java, so I was happy to yank it back to the delights of Prolog, and basic AI techniques like state-space search.<\/p>\n<p>Prolog is a fantastic way to approach programming, for various reasons. You can&#8217;t help but learn about logic too \u2014 you&#8217;re basically programming with a subset of first-order predicate logic. You absolutely can&#8217;t hack it, the way that you can with most procedural languages. If you&#8217;re not exactly sure what a piece of code you&#8217;ve written means, it&#8217;ll bite back, hard. It&#8217;s a perverse joy to see students go through the Three Stages of Prolog. The First Stage is: &#8216;Bah. This is just a toy. It couldn&#8217;t possibly be actually useful for anything.&#8217; The Second Stage is: &#8216;SHIT. This suddenly got hard and I don&#8217;t understand it any more.&#8217; (The Second Stage only really exists because of the First Stage, which gives them a lethally false sense of security.) The Third Stage, which most (but not all) reach, is: &#8216;Oh, <em>I<\/em> get it.&#8217; That light-bulb moment is wonderful to see, when it happens. It&#8217;ll never be unclear to them again.<\/p>\n<p>Prolog is to AI programming as Latin is to natural language. You don&#8217;t just learn the language \u2014 indeed, in some ways that&#8217;s the least thing that you learn. Latin teaches you about language itself. Prolog teaches you about AI: formal logics, knowledge representation and inference, search strategies.<\/p>\n<p>Anyway, about our new dishwasher&#8230;<\/p>\n<p>One of the small-but-important rules of thumb that I tried to teach the students on the course was not to define some predicate in terms of the conditions under which it <em>isn&#8217;t<\/em> true. A Prolog clause might look like this:<\/p>\n<blockquote><p>\nmortal(X) :- man(X).\n<\/p><\/blockquote>\n<p>\u2014 which says that some property, &#8216;mortal&#8217;, is true of some thing, &#8216;X&#8217;, if some other property, &#8216;man&#8217;, is also true of that thing. &#8216;Every man is mortal&#8217;, in other words. And that&#8217;s fine. On the other hand:<\/p>\n<blockquote><p>\nnot_immortal(X) :- man(X).\n<\/p><\/blockquote>\n<p>Logically, this is completely equivalent, since (one assumes):<\/p>\n<blockquote><p>\nnot_immortal(X) :- mortal(X).\n<\/p><\/blockquote>\n<p>But clarity, which is every bit as important as logical soundness, goes flying out of the window. Consider how we might define &#8216;immortal&#8217; using our original definition of &#8216;mortal&#8217;:<\/p>\n<blockquote><p>\nimmortal(X) :- \\+ mortal(X).\n<\/p><\/blockquote>\n<p>The \\+ symbol is the typical Prolog symbol to represent a logical &#8216;not&#8217;, so this reads: &#8216;Something is immortal if it isn&#8217;t mortal&#8217; (assuming a closed world), and that&#8217;s clear enough. Consider now how we&#8217;d define &#8216;immortal&#8217; using our second definition of mortality:<\/p>\n<blockquote><p>\nimmortal(X) :- \\+ not_immortal(X).\n<\/p><\/blockquote>\n<p>That&#8217;s: &#8216;Something is immortal if it isn&#8217;t not immortal&#8217;, and it&#8217;s entirely boneheaded. We&#8217;ve defined mortality in terms of the <em>absence<\/em> of immortality. Start sprinkling such double-negatives in Prolog \u2014 as in any representational system \u2014 and you&#8217;re very quickly lost. The mistake is right at the beginning, where we defined &#8216;not_immortal&#8217;. It has no place in logic programming.<\/p>\n<p>Anyway, about our new dishwasher&#8230;<\/p>\n<p>Apart from the program settings on our new portable dishwasher, there are two &#8216;options&#8217; settings. The first, when selected, causes the dishwasher to increase the water temperature to 140 degrees before it begins to clean. It&#8217;s labelled: &#8216;Water Heat&#8217;. The second option is labelled:<\/p>\n<blockquote><p>\nNo Heat Dry\n<\/p><\/blockquote>\n<p>Can you guess what it does? That&#8217;s right. When selected, it <em>disables<\/em> the application of heat at the end of the cycle to dry the dishes. I could easily <a href=\"http:\/\/northgare.net\/blog\/2004\/05\/software_and_so\/\">talk about confusing defaults<\/a>, but today I&#8217;m yakking on about logic, and I&#8217;m sure you can see how I got here. One option setting is defined in terms of the conditions under which it&#8217;s true:<\/p>\n<blockquote><p>\nwater_heat :- button_1_depressed.\n<\/p><\/blockquote>\n<p>But the second is defined in terms of the conditions under which it&#8217;s <em>not<\/em> true:<\/p>\n<blockquote><p>\nno_heat_dry :- button_2_depressed.\n<\/p><\/blockquote>\n<p>There&#8217;s even a <em>third<\/em> option button labelled &#8216;Reset Options&#8217;, at which point things start to get mind-bending. What does it reset to? &#8216;No Heat Dry&#8217;? Or &#8216;No No Heat Dry&#8217;? (I&#8217;m guessing that the designer isn&#8217;t a Prolog programmer.) The result is a throughly confusing user interface, and a long and tedious blog entry. Blame Kenmore, not me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About our new dishwasher&#8230; A couple of years ago I taught a course called &#8216;Introduction to Artificial Intelligence Programming&#8217; \u2014 largely because I was available when no-one else was. It turned out to be great fun, and not least because I&#8217;d been through the same course one year as a student, and another as a &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-208","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/posts\/208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/comments?post=208"}],"version-history":[{"count":5,"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/posts\/208\/revisions"}],"predecessor-version":[{"id":1034,"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/posts\/208\/revisions\/1034"}],"wp:attachment":[{"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/media?parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/categories?post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/northgare.net\/blog\/wp-json\/wp\/v2\/tags?post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}