Tuesday, February 21, 2017

"From Eternity to Here" - Sean Carroll

Amazon Link

Just finished Sean Carroll's 2011 book, which - after an exhaustive exploration of all other options - locates the origin of 'the arrow of time' in the quantum-fluctuation emergence of super-low-entropy 'baby universes' from a preceding high-entropy de Sitter universe.

Yes, that would be the baby universe in which I'm sitting writing this post.

This may seem extravagant, to explain why eggs produce omelettes but not the reverse, but he refutes all the simpler explanations.

It presently seems unclear, however, whether a de Sitter universe could even make baby universes, absent a better theory of quantum gravity.

Carroll's latest thinking tends in a different direction, suggesting that framing the issue within the spacetime realm may itself be a mistake; the true nature of reality may be Hilbert space with Schrödinger equation dynamics. Spacetime, with its arrow of time, may be emergent.

Strange that the weirdest ideas of modern physics - the MWI, emergent spacetime - seem to be the most plausible.

This is a fine book, and an excellent introduction for the smart non-physicist to general relativity, quantum theory (QM/QFT) and cosmology.

Monday, February 20, 2017

The deep state *is* the state

Much excitement in the States (but also in Brexit Britain) about elements of the state apparatus actively working to undermine the policies of an 'insurgent' government.

The governments in question are of the right, not the extreme left, but the founders of Marxism were clear that a truly revolutionary government cannot just take over the 'controls' of a 'neutral' state apparatus. They will be thwarted at every turn.

This is, of course, true of all bureaucracies. Successful 'turnaround' CEOs bring their own posse of senior managers - and waste no time clearing out the old regime. If they don't, their mission is toast. The political right, in order to to secure their victory, will have to purge the state of their enemies and repopulate it with supporters in their own ideological image.

Marxists, however, are seldom called out on what they think should replace the bourgeois state. Lenin and Trotsky, following the model of the Paris Commune, thought that the mobilised masses, organised in soviets (councils), would constitute a non-bureaucratic socialist state - a social formation not separate from broader society.

Marx himself never wrote much about it.

Yet the state is neither a contingent formation nor just 'bodies of armed men' safeguarding existing property relations. The state has an enormous, and under-analysed, role in social-coordination.

---

Turn now to the economy. All Marxists agree that their post-capitalist economic model will replace private decision-making about the allocation of resources with 'consciously democratic', centrally-planned directives.

Given the complex and highly-technical nature of policy-making and implementation, both as regards the state and the putative planned-economy, this is not going to something managed by the masses through their councils. Nor is it going to be that old favourite, the mere 'administration of things, not of people'.

The PDF version is here

It's hard to resist the conclusion that - until the AIs take over (and where does that leave us?) - the post-capitalist state will continue to be large, bureaucratic and unresponsive. Much like the bourgeois state.

History tends to support this view.

I would guess that Marxists would not agree, but for people proposing a radical makeover of society's fundamentals, they seem remarkably coy about their proposed replacement model.

Such studied casualness wouldn't work in engineering.

Why does the far left get a free pass on something of such fundamental importance?

Sunday, February 19, 2017

People are boring - so what chance chatbots?




The BBC's Dave Lee writes:
"It's been nearly a year since Microsoft's Satya Nadella proclaimed "bots are the new apps".

"Yet despite the promise of a revolution in how we interact with services and companies online, progress has been utterly miserable - the vast majority of chatbots are gimmicky, pointless or just flat out broken. ...

The CNN news chatbot, for example, is worse at giving you the news than any of CNN’s other products. ...

"Google's AI-powered messaging app Allo, since being launched to much fanfare last year, has failed to make even a minor dent in a messaging app market dominated by Whatsapp and Facebook Messenger.

"And that's because there's no compelling reason to bother with Allo. None of its features - like asking it for directions - provide enough of a benefit beyond what you'd get from just tapping in your request the "old fashioned" way. Users have an incredibly short fuse for chatbots not working exactly as we expect."
---

We have a special name for those few people who we (mostly) don't find boring.

Friends.

We don't much enjoy extended interactions with random folk. People who, nevertheless:
  • have been completely socialised into our culture for decades, 
  • come with detailed background knowledge of the world,
  • are endowed with common sense and full conversational abilities.
So why did the AI companies think we'd enjoy interacting with chatbots, which are cognitively impoverished in every conceivable way?

It's a good question and I'm not sure of the answer.
- Were they over-impressed by their mighty artificial neural nets? But they're only fantastic recognisers and classifiers, a far cry from artificial general intelligences (AGI).

- Did they think that we're all keen to have conversational, hands-free interaction with our pocket devices? In fact that's socially way too intrusive most of the time, plus we're talking to conversational muppets.

- Was there a belief that in some narrow, vertical and tightly-constrained domains there might be a niche for a conversational interface? There's almost certainly something to that - but we don't yet know what.
My own feeling is that the successful mass consumer chatbot can be nothing less than a truly effective virtual friend. To that end it will have to posses AGI and be malleable to your own personality and 'friend-preferences'.

We'll have starships before we have that; I haven't seen the first clue we're on that road.

---

All of the above presupposes peer-relationships, typically with kids or adults. Those conversations - most of the time! - exhibit an irreducible core of rational and relevant 'aboutness'.

So hard to replicate for an artefact.

But there are natural agents around without much cognitive competence: babies, small children and pets. The bond here is emotional .. and so is the interaction.

So if you're in the business of designing chatbots which could conceivably bond with your customers, you might want to take note .. .*

---

* In the old days, we called them 'dolls', and they came without batteries.

Saturday, February 18, 2017

Diary: my day with a Prolog interpreter in Lisp

The subject: implementing a Prolog interpreter in Common Lisp, using an excellent - if rather old-fashioned - textbook as my guide. I had copied-and-pasted the code across (it never quite works first time) and was debating this morning: finally get Peter Norvig's code to run, or strike out in my own direction?

There's a lot in Chapter 11 of "Paradigms of Artificial Intelligence programming" to be wary of:
  • For efficiency reasons he stores the clauses on clause-head-predicate property lists
  • He uses destructive operations such as nconc
  • The resolution inference step and depth-first control strategy are interwoven.
I'd prefer to keep the clause database as an explicit object to be transformed and analysed throughout the proof. I'd also like to modularise the 'which clauses to try to resolve next' strategy, trying different things such as unit preference, set-of-support, hyperresolution. And it would be good to extract a proof tree, not just the final question-answering bindings.

All these things demand a rewrite.

But I was glad I persevered, because Peter Norvig's code finally came good this afternoon and I was able to successfully run it on a serious logic puzzle - the Zebra problem.

Where it ran remarkably quickly - forty times faster than in Dr Norvig's textbook-writing days. I was reminded of AI programming back in the late 1980s, when everything was slow and hard.

I imagined him developing his code on some ancient VAX 11/780 (as I used to do).

A simple Prolog interpreter in Lisp

;;;  Prolog in Lisp:  February 14th 2017 - February 18th 2017
;;;
;;;  From Peter Norvig's book: Chapter 11
;;; "Paradigms of Artificial Intelligence Programming"
;;;
;;; Unification, Prolog, Resolution, inference control strategies
;;;
;;; Posted:
; http://interweave-consulting.blogspot.co.uk/2017/02/a-simple-prolog-interpreter-in-lisp.html
;;;
;;;  Reminder: (how to load and access files)
;;;
; (load  "C:\\Users\\HP Owner\\Google Drive\\Lisp\\Prog-Prolog\\Prolog-in-Lisp.lisp")

;;;
;;; --- Unification ---
;;;

(defconstant +fail+ nil "Indicates pat-match failure.")

(defconstant +no-bindings+ '((t . t))
"Indicates pat-match success but with no variables.")

(defun variable-p (x)    ; Symbol -> Bool
  "Is x a variable, a symbol beginning with '?'"
  (and (symbolp x) (equal (char (symbol-name x) 0) #\? )))

(defun get-binding (var bindings)
  "Find a (variable . value) pair in a binding list."
  (assoc var bindings))

(defun binding-val (binding)
  "Get the value part of a single binding."
  (cdr binding))

(defun lookup (var bindings)
  "Get the value part (for var) from a binding list."
  (binding-val (get-binding var bindings) ))

(defun extend-bindings (var val bindings)
  "Add a (var . value) pair to a binding list, remove (t . t)"
  (cons (cons var val) (if (equal bindings +no-bindings+) nil bindings)))

(defparameter *occurs-check* t "Should we do the occurs check?")

(defun unify (x y &optional (bindings +no-bindings+))   ; -> Bindings
  "See if x and y match with given bindings"
  (cond ((eq bindings +fail+) +fail+)
        ((eql x y) bindings)
        ((variable-p x) (unify-variable x y bindings))
        ((variable-p y) (unify-variable y x bindings))
        ((and (consp x) (consp y))
         (unify (rest x) (rest y)
                (unify (first x) (first y) bindings) ) )
        (t +fail+) ) )

(defun unify-variable (var x bindings)              ; -> Bindings
  "Unify var with x, using (and maybe extending) bindings"
  (cond ((get-binding var bindings)
             (unify (lookup var bindings) x bindings))
        ((and (variable-p x) (get-binding x bindings))
             (unify var (lookup x bindings) bindings))
        ((and *occurs-check* (occurs-check var x bindings))
             +fail+)
        (t (extend-bindings var x bindings))))

(defun occurs-check (var x bindings)             ; -> Bool
  "Does var occur anywhere 'inside x'?"
  (cond ((eq var x) t)
        ((and (variable-p x) (get-binding x bindings))
         (occurs-check var (lookup x bindings) bindings))
        ((consp x) (or (occurs-check var (first x) bindings)
                       (occurs-check var (rest x) bindings)))
        (t nil)))

(defun unifier (x y )
  "Return something that unifies with both x and y (or +fail+)"
  (subst-bindings (unify x y) x ) )

(defun subst-bindings (bindings x)   ; Bindings x Term -> Term
  "Substitute the value of variables in bindings into x,
taking recursively bound variables into account"
  (cond ((eql bindings +fail+) +fail+ )
        ((eql bindings +no-bindings+) x)
        ((and (variable-p x) (get-binding x bindings))
              (subst-bindings bindings (lookup x bindings) ))
        ((atom x) x)
        ( t (cons (subst-bindings bindings (car x))
                        (subst-bindings bindings (cdr x )) ) ) ) )

;;; --- Now let's try unify on some examples ---
;
; (setf b '((?Z . ?X) (?Y . 4) (?X . 3)))
; (subst-bindings b '?y)           ; => 4
; (subst-bindings b '?z)           ; => 3
; (subst-bindings b '(f ?z ?y))    ; => (F 3 4)
;
; (unify '(?x ?y a) '(?y ?x ?x))   ; =>  ((?Y . A) (? X . ?Y))
; (unify '?x '(f ?x))    ; => NIL  (occurs check nil: ((?X F ?X)))
; (unify '(?x ?y) '((f ?y) (f ?x)) ; =>  NIL  (occurs check)
; (unify '(?x ?y ?z) '((?y ?z) (?x ?z) (?x ?y))) => NIL  (occurs check)
; (unify 'a 'a)   ; => ((T . T))
;
; Finally, the function unifier calls unify and substitutes
; the resulting binding list into one of the arguments.
; The choice of x is arbitrary; an equal result would come
; from substituting the binding list into y.

; Here are some examples of unifier:
;  (unifier '(?x  ?y a) '(?y ?x ?x))  ;  =>  (A A A)
;  (unifier '((?a * ?x ^ 2) + (?b * ?x) + ?c) '(?z + (4 * 5) + 3)) ; =>
;        ((?A * 5 ^ 2) + (4 * 5) + 3)

;;;
;;; ----------------- Prolog Interpreter -----------------
;;;
#|
From Wikipedia: Clause (logic)

Every nonempty clause is logically equivalent to an implication of a head
from a body, where the head is an arbitrary literal of the clause and the
body is the conjunction of the negations of the other literals. That is,
if a truth assignment causes a clause to be true and none of the literals
of the body satisfy the clause, then the head must also be true.

This equivalence is commonly used in logic programming, where clauses are
usually written as an implication in this form. More generally, the head
may be a disjunction of literals. If b1,...,bm are the literals in the body
of a clause and h1,...,hn are those of its head, the clause is usually
written as follows:

h1,...,hn <-  b1,...,bm

If n=1 and m=0, the clause is called a (Prolog) fact.
If n=1 and m>0, the clause is called a (Prolog) rule.
If n=0 and m>0, the clause is called a (Prolog) query.
If n>1, the clause is no longer Horn.
|#

;; --- Clauses are represented as (head . body) cons cells: example ---
;
;  ( (member ?item (?item . rest))) )                                         ; fact
;  ( (member ?item (?x . ?rest)) . ((member ?item ?rest)))       ; rule

(defun clause-head (clause) (first clause))     ; Clause -> Literal

(defun clause-body (clause) (rest clause))      ; Clause -> Literal-list

;; Clauses are stored on the predicate's plist

(defun get-clauses (pred) (get pred 'clauses)) ; symbol -> Clause-list

(defun predicate (literal) (first literal))    ; Literal -> Symbol (predicate)

(defvar *db-predicates* nil
  "A list of all predicates stored in the database")

(defmacro <- (&rest clause)
  "Add a clause to the database"
  `(add-clause ',clause))

; (macroexpand-1 '(<- (likes Kim Robin)))    ; =>
; (ADD-CLAUSE (QUOTE ((LIKES KIM ROBIN))))        ; ... which is correct.

(defun replace-?-vars (exp)
  "Replace any ? within exp with a var of the form ?123"
  (cond ((eq exp '?) (gensym "?"))
        ((atom exp) exp)
        (t (cons (replace-?-vars (first exp))
                 (replace-?-vars (rest exp))) ))  )


(defun add-clause (clause)
  "Add a clause to the data base, indexed by head's predicate"
  ;; The predicate must be a non-variable symbol.
  (let* ((clause1 (replace-?-vars clause))
         (pred (predicate (clause-head clause1))))
    (assert (and (symbolp pred) (not (variable-p pred))))
    (pushnew pred *db-predicates*)
    (setf (get pred 'clauses)
          (nconc (get-clauses pred) (list clause1))) pred) )

; (setf clause '((P ?x ?y) . ((Q ?x ?y))))
; (add-clause clause)                       ; => P
; *db-predicates*                            ; => (P)
; (get 'P 'clauses)                             ; (((P ?X ?Y) (Q ?X ?Y)))


(defun clear-db ()
  "Remove all clauses (for all predicates) from the database"
  (mapc #'clear-predicate *db-predicates*))

(defun clear-predicate (predicate)
  "Remove the clauses for a single predicate"
  (setf (get predicate 'clauses) nil) )

;;; So here is an example:
;;;  clause = '((P ?x ?y) . ((Q ?x ?y)))
;;;  goal = '(P a b)
;;;
;;; ----------------------------------------------------------------------------------
;;; and here is how 'prove' works:
;;;
;;; (get-clauses (predicate goal)) finds 'clause' = '((P ?x ?y) . ((Q ?x ?y)))
;;; 'clause' would then get variable-renamed -> new-clause
;;; Get binding from (unify goal (clause-head new-clause) bindings)
;;; Using that binding, try to prove clause body literals
;;; Return bindings (via prove-all)

(defvar *countr* 0)        ; count how many times 'prove' is called

(defun count-prove-calls ()
   (setf *countr* (1+ *countr*))
   (format t "~& Call to prove = ~a" *countr*) )

(defun prove (goal bindings)    ; Literal x Bindings -> Bindings
  "Return a 1ist of possible solutions to goal"
  (count-prove-calls)
  (mapcan #'(lambda (clause)
              (let ((new-clause (rename-variables clause)))
                (prove-all (clause-body new-clause)
                           (unify goal (clause-head new-clause) bindings))))
          (get-clauses (predicate goal))))

(defun prove-all (goals bindings) ; Literal-list x Bindings -> Bindings
  "Return a list of solutions to the conjunction of goals"
  (cond ((eql bindings +fail+) +fail+)
        ((null goals) (list bindings))
        (t (mapcan #'(lambda (goal1-solution)
                       (prove-all (rest goals) goal1-solution))
                   (prove (first goals) bindings)))))


(defun rename-variables (x)       ; clause -> clause (with vars renamed)
  "Replace all variables in x with new ones"
  (sublis (mapcar #'(lambda (var) (cons var (gensym (string var))))
                  (variables-in x))
          x))

; (setf clause '((P ?X ?Y) (Q ?X ?Y)))
; (rename-variables clause)     ; => ((P #:?X932 #:?Y933) (Q #:?X932 #:?Y933))
;
; (setf clause1 '((F (G ?x (H ?y)) (J ?u ?v))))
; (rename-variables clause1)  ; => ((F (G #:?X872 (H #:?Y873)) (J #:?U874 #:?V875)))


; This version of ?- superseded by later definition below
; (defmacro ?- (&rest goals) `(prove-all ',goals +no-bindings+))

;;; --- Example ---
#|
(add-clause '((likes Kim Robin)))
(add-clause '((likes Sandy Lee)))
(add-clause '((likes Sandy Kim)))
(add-clause '((likes Robin cats)))
(add-clause '((likes Sandy ?x) (likes ?x cats)))
(add-clause '((likes Kim ?x) (likes ?x Lee) (likes ?x Kim)))
(add-clause '((likes ?x ?x)))

(prove '(likes Sandy ?who) +no-bindings+)   ; =>

; (((?WHO . LEE))
;  ((?WHO . KIM))
;  ((#:?X846 . ROBIN)
;  (?WHO . #:?X846))
;  ((#:?X850 . CATS) (#:?X847 . CATS) (#:?X846 . SANDY) (?WHO . #:?X846))
;  ((#:?X855 . CATS) (#:?X846 . #:?X855) (?WHO . #:?X846))
;  ((?WHO . SANDY) (#:?X857 . SANDY)))

; --     and here with macros <-   and ?-     ---

(<- (likes Kim Robin))
(<- (likes Sandy Lee))
(<- (likes Sandy Kim))
(<- (likes Robin cats))
(<- (likes Sandy ?x) (1ikes ?x cats))
(<- (likes Kim ?x) (likes ?x Lee) (likes ?x Kim))
(<- (likes ?x ?x)

> (?- (likes Sandy ?who))

; (((?WHO . LEE))
;  ((?WHO . KIM ) )
;  ((?X2856 . ROBIN) (?WHO . ?X2856))
;  ((?X2860 . CATS) (?X2857 . CATS) (?X2856 . SANDY) (?WHO . ?X2856))
;  ((?X2865 . CATS) (?X2856 . ?X2865) (?WHO . ?X2856))
;  ((?WHO . SANDY) (?X2867 . SANDY)))

|#

;;; --- TOP-LEVEL-PROVE ---

(defmacro ?- (&rest goals) `(top-level-prove ',(replace-?-vars goals)))

; (macroexpand-1 '(?- goals))     ; Check macro expands properly

(defun variables-in (exp)
  "Return a list of all the variables in exp"
  (unique-find-anywhere-if #'variable-p exp))

(defun unique-find-anywhere-if (predicate tree &optional found-so-far)
  "Return a list of leaves of tree satisfying predicate, with duplicates removed"
  (if (atom tree)
      (if (funcall predicate tree) (adjoin tree found-so-far) found-so-far)
      (unique-find-anywhere-if predicate (first tree)
                            (unique-find-anywhere-if predicate (rest tree) found-so-far)
 )))

(defun top-level-prove (goals)
  "Prove the goals, and print variables readably"
  (show-prolog-solutions (variables-in goals) (prove-all goals +no-bindings+)))

(defun show-prolog-solutions (vars solutions)
  "Print the variables in each of the solutions"
  (if (null solutions)
      (format t "~&No.")
      (mapc #'(lambda (solution) (show-prolog-vars vars solution)) solutions))
  (values))

(defun show-prolog-vars (vars bindings)
  "Print each variable with its binding"
  (if (null vars)
      (format t "~&Yes")
    (dolist (var vars)
      (format t "~&~a = ~a" var (subst-bindings bindings var))))
  (princ ";"))

;;; --- Examples ---

; Now let's try some queries:
;
;  (?- (likes Sandy ?who))
;
; ?WHO = LEE;
; ?WHO = KIM;
; ?WHO = ROBIN;
; ?WHO = SANDY;
; ?WHO = CATS;
; ?WHO = SANDY;
;
;
;  ( ?- (likes ?who Sandy))
;
; ?WHO = SANDY;
; ?WHO = KIM;
; ?WHO = SANDY;
;
;  ( ?- (likes Robin Lee))
;
; No.
;
;---
;
;For a more sophisticated test, try the Zebra Puzzle at:
;
;  http://interweave-consulting.blogspot.co.uk/2017/02/the-zebra-puzzle-prolog-in-lisp.html
;
;                                            ----------------- End ------------------

The Zebra Puzzle (Prolog in Lisp)

I am delighted to have got Peter Norvig's Lisp interpreter for Prolog working (in its simplest form) from Chapter 11 of his book, "Paradigms of Artificial Intelligence programming".



I tested it on his Zebra puzzle, where he states:
"This took 278 seconds, and profiling (see page 288) reveals that the function prove was called 12,825 times. A call to prove has been termed a logical inference, so our system is performing 12825/278 = 46 logical inferences per second, or LIPS.

Good Prolog systems perform at 10,000 to 100,000 LIPS or more, so this is barely limping along."
On my Windows 10 HP laptop, the computation took 7 seconds with 29,272 calls to 'prove'.

I guess that's 4,182 LIPS for compiled Lisp from LispWorks - program totally unoptimised.

His book is rather old (1992).

---

The Zebra puzzle

"Here is an example of something Prolog is very good at: a logic puzzle. There are fifteen facts, or constraints, in the puzzle:
1. Five houses in a line, each with an owner, a pet, a cigarette, a drink, and a color.
2. The Englishman lives in the red house.
3. The Spaniard owns the dog.
4. Coffee is drunk in the green house.
5. The Ukrainian drinks tea.
6. The green house is immediately to the right of the ivory house.
7. The Winston smoker owns snails.
8. Kools are smoked in the yellow house.
9. Milk is drunk in the middle house.
10. The Norwegian lives in the first house on the left.
11. The man who smokes Chesterfields lives next to the man with the fox.
12. Kools are smoked in the house next to the house with the horse.
13. The Lucky Strike smoker drinks orange juice.
14. The Japanese smokes Parliaments.
15. The Norwegian lives next to the blue house.
The questions to be answered are: who drinks water and who owns the zebra?"

The translation into Prolog in Lisp uses a Lisp-like syntax for Prolog facts and rules (both are clauses). Here's the Prolog 'program' coding the above problem.

;;; --- Lisp code follows - comments from Norvig's book  ---
;;;
;;; To solve this puzzle, we first define the relations nextto (for "next to") and
;;;  iright (for 'immediately to the right of'). They are closely related to member,
;;; which is repeated here.
;;;

(<- (member ?item (?item . ?rest )))
(<- (member ?item (?x . ?rest) ) (member ?item ?rest))

(<- (nextto ?x ?y ?list) (iright ?x ?y ?list))
(<- (nextto ?x ?y ?list) (iright ?y ?x ?list))

(<- (iright ?left ?right (?left ?right . ?rest)))
(<- (iright ?left ?right (?x . ?rest)) (iright ?left ?right ?rest))
(<- (= ?x ?x))

;;; We also defined the identity relation, =. It has a single clause that says that any x is
;;; equal to itself. One might think that this implements eq or equal. Actually, since
;;; Prolog uses unification to see if the two arguments of a goal each unify with ?x, this
;;; means that = is unification.

;;; Each house is of the form:
;;; (house nationality pet cigarette drink house-color)
;;; ?h is the variable representing the list of the five houses

(<- (zebra ?h ?w ?z)

  (= ?h  ((house norwegian ? ? ? ?) ? (house ? ? ? milk ?) ? ? ) )              ; 1, 10, 9
  (member (house englishman ? ? ? red) ?h)                                             ; 2
  (member (house spaniard dog ? ? ?) ?h)                                                 ; 3
  (member (house ? ? ? coffee green) ?h)                                                  ; 4
  (member (house ukrainian ? ? tea ?) ?h)                                                 ; 5
  (iright (house ? ? ? ? ivory)                                                                     ; 6
             (house ? ? ? ? green) ?h)
  (member (house ? snails winston ? ?) ?h)                                               ; 7
  (member (house ? ? kools ? yellow) ?h)                                                 ; 8
  (nextto (house ? ? chesterfield ? ?)                                                         ; 11
             (house ? fox ? ? ?) ?h)
  (nextto (house ? ? kools ? ?)                                                                   ; 12
              (house ? horse ? ? ?) ?h)
  (member (house ? ? luckystrike orange-juice ?) ?h)                              ; 13
  (member (house japanese ? parliaments ? ?) ?h)                                   ; 14
  (nextto (house norwegian ? ? ? ?)                                                          ; 15
              (house ? ? ? ? blue) ?h)

;; Now for the questions:

   (member (house ?w ? ? water ?) ?h)                                                     ; Q1
   (member (house ?z zebra ? ? ?)  ?h) )                                                   ; Q2

; Here's the query

  (?- (zebra ?houses ?water-drinker ?zebra-owner))

; .. and here's the result

?HOUSES = ((HOUSE NORWEGIAN FOX KOOLS WATER YELLOW)
                       (HOUSE UKRAINIAN HORSE CHESTERFIELD TEA BLUE)
                       (HOUSE ENGLISHMAN SNAILS WINSTON MILK RED)
                       (HOUSE SPANIARD DOG LUCKYSTRIKE ORANGE-JUICE IVORY)
                       (HOUSE JAPANESE ZEBRA PARLIAMENTS COFFEE GREEN))
?WATER-DRINKER = NORWEGIAN
?ZEBRA-OWNER = JAPANESE;

---

I'll publish the Lisp code for the Prolog interpreter separately (here):

http://interweave-consulting.blogspot.co.uk/2017/02/a-simple-prolog-interpreter-in-lisp.html


Friday, February 17, 2017

Le terrible dilemme de la glorieuse France



Prior to Germany's unification in the mid-nineteenth century, France had regularly been top dog in Europe for a thousand years. From Charlemagne through the Sun King to Bonaparte, the French do not forget.

After the second world war, with Germany both beaten and shamed, the French seized upon the idea of the EEC/EU. They would lead an exhausted continent, and the humiliated Germans would pay.

This vision of the EU as a greater, more glorious France endured for fifty years. It took the post-Cold War reunification of Germany and a new generation of Germans with declining guilt, to parlay Germany's economic power into European political leadership.

Who can forget those pictures of Angela Merkel, striding into power-summits with a diminutive Francois Hollande trotting beside her, as if a handbag dog?

A Germany coming into its own will have its natural satellites: Austria, parts of Eastern Europe. But France? Here is the dilemma. The EU project has become a suffocating straitjacket for France, forcing it into subservience to Germany. German-interest policies inflicted upon the whole EU have created popular discontent within France as elsewhere.

The result has been the collapse of the establishment parties in France, the Socialists and the Republicans, and the emergence of a Tony Blair-lite politician (Emmanuel Macron) along with the nationalist Front National as the main contenders for power.

The French establishment is solidly pro-EU, and as defeatist as the British powers-that-be. Its 'realistic' view is that the economic realities cannot be denied and that the best France can hope for is German satellite status with influence.

Marine Le Pen speaks for a France which, like Brexit UK, decouples from German domination.

It's not clear whether the upcoming Presidential election will coincide with a decisive rupture in the dynamics of French politics, which could hand Le Pen the victory. But the tensions between la glorieuse France and its default deferential future will only grow.

If not this time, then the next.

Thursday, February 16, 2017

Stonehenge in the February rain

Perverse to visit Stonehenge yesterday, with heavy rain forecast for most of the day. Perhaps it was only Bristol Water, turning off our supply for 8 hours for 'urgent repairs', who could have forced us out.

Anyway, a chance to see the new Visitor Centre and admire the A303 before it vanishes into a tunnel forever.

Clare approaches the new Visitor Centre - henge-themed

An ancestor of Trevor Eve was found here 5,000 years ago
(click on image to make larger and read the caption).

Never have I seen such bedraggled sheep

Traffic jams on the A303 .. oh, and some rocks

Clare was sampling something from the local druids I guess

We did have a conversation about it.



Afterwards we took a late lunch in Warminster. Much as I would like the town to be associated with the heavy military presence on the adjacent Salisbury Plain, in fact:
"The town's name has evolved over time, known as Worgemynstre in approximately 912 and it was referred to in the Domesday Book in 1086 as Guerminstre.

The town name of Warminster is thought to derive from the River Were, a tributary of River Wylye which runs through the town, and from an Anglo-Saxon minster or monastery, which existed in the area of St Denys's Church.

The river's name, "Were" may derive from the Old English "worian" to wander."

Wednesday, February 15, 2017

The problem of dialogue as regards chatbots

Me: "So here's my plan."

Clare: "OK."

Me: "I've copied Peter Norvig's chapter 11 code for a Prolog interpreter in Lisp into a Notepad file. Unfortunately copying from PDF introduces all kinds of formatting errors, so it takes a while to get it into a compilable state."

Clare: "?"

Me: "I need to work through his main functions - principally to exactly understand his unification algorithm to start with. I may modify the code a bit, make it more transparent."

Clare: "??"

Me (oblivious): "And then I'm not sure I like the way he's storing clauses as plists on the clause head predicate. I think an assoc list would be clearer, if less efficient. Also, I need to do a few paper and pen examples to understand exactly the rationale for variable-renaming between clauses during resolution."

Clare: "???"

Me: "I'll get his standard Prolog depth-first search to work first of course. But I think it would be a good idea to explicitly break out the resolution procedure as a standalone function, and then parameterise the proof procedure by a range of possible search methods including breadth-first and best-first."

Clare: "????"

Me: "Of course, all this is just to get a series of tools in place for my speech-act planner, the one that's going to make my chatbot able to steer a conversation."

Clare: "?????"

Me: "I really think this could be a stellar app. I can see it on Google Play. The trouble is, 'in the knowledge lies the power' is just as relevant here and I might need to spend way too much time just data-filling various knowledge-bases, ... hmm, unless I can get it to safely learn from users. That's where Google does have an advantage ..."

[Pause]

Clare: "Is that Mr Bullfinch I see on the fat block?"

Tuesday, February 14, 2017

The Outstanding Leader is unwell ..



The BBC website reports:
"The half-brother of North Korean leader Kim Jong-un has been killed in Malaysia, South Korean and Malaysian sources say.

Kim Jong-nam, 45, is said to have been targeted at the airport in Kuala Lumpur, the capital. A source close to the Malaysian PM's office told the BBC that Mr Kim was killed in the city, saying his body was now undergoing an autopsy. Kim Jong-nam is the eldest son of former North Korean leader Kim Jong-il."
---

The US President Mr Trump says 'something will be done' about North Korea's somewhat provocative ballistic missile tests. Perhaps one imagines a pre-emptive strike on military facilities?

Easily done, but it's hard not to see the Chinese reacting badly.

Something a little more subtle is needed. Some virus, engineered to attach to cells expressing a certain genotype. Thanks to CRISPR, that kind of virus-editing seems quite practicable. A weaponised flu variant should do it.

How to get a copy of the Dear Leader's genome? You can go a long way with a half brother.

The other half of the mission is transportation. The US authorities should not be relying on a pandemic. A long range stealth-drone delivering a miniature RPV close to the OL should do it: something disposable and wasp-like.

Send a swarm: only way to be sure.

What are the chances the CIA has this mission design in front of the President as we speak?

---

Greg Cochran was writing about jihadis, but the principle seems to apply.

Monday, February 13, 2017

"The Genome Factor" - Conley and Fletcher

Amazon link

For decades the Standard Social Science Model has dominated academic social science and mainstream elite thinking. Broadly speaking, the model states: (i) there are no innate precursors for cognitive traits such as personality, intelligence, character and interests - everything is environmental; and (ii) consequentially, there are no innate psychological differences between women and men - or between blacks, whites, east asians or the Ashkenazim.

Since everything is environmental (the 'blank slate' hypothesis) then any observed differences must be due to selective discrimination which can therefore be addressed by public policy. The consequence is a litany of discriminations with which we are all familiar: sexism, racism and various phobias.

Plainly there are differences in the physical realm. Some sports are gender-segregated, for example. But even acknowledging that makes people nervous. Physical differences are played down as inconsequential.

Less well-educated folk know that the blank-slate hypothesis is rubbish. A little experience of families, a little observation both of everyday life and of the world at large will convince most people that it is more likely that the moon truly is made of green cheese.

So what explains the astonishing durability of the SSSM?

Plainly it speaks to that powerful liberal sense of compassion and fairness highlighted in Jonathan Haidt's Moral Foundations Theory.  Most western democracies are multiracial, patchwork 'internal-empires' - the legacy of centuries of immigration and in some cases slavery. Race- and gender-blind application of legislation and social norms is considerably enhanced by taking the view that formal social and legal equality is also biological equality. Once the argument for population-genetic differences is admissible, it seems to liberals that the floodgates of discrimination would be opened once again.

The ideology of the SSSM also makes it easy to justify generic immigration: high, low and zero-skilled ('everyone is the same'). This can be very convenient for company executives who suffer few of the frequently-negative social consequences of the latter.

Recent advances in genetic sequencing over very large populations pose a grave threat to the convenient untruths of the SSSM. It is already known that almost all psychological and behavioural traits of interest to social scientists are heritable at c. 50-60%. This means that about half the trait-variation in the population is attributable to genetic differences, the rest being due to differences in contemporary shared and personal environments.

Apart from hands-on confirmation of these heritability results, genomics also adds personalisation. Once we understand how to map a person's genome to such phenotypic attributes as IQ, personality, character and a myriad of narrower traits (such as political orientation) with high precision - and correlational accuracies of 0.7-0.9 seem potentially in reach - then it seems that genome truly is life-destiny. And most likely this is the case. The life-history similarities of twins, even when raised apart, tends to show the way.

Social scientists mostly ignore the incoming tsunami of new research. But the genomic telescope has been invented, it's not going to go away. A more sophisticated strategy is deployed in "The Genome Factor" by Conley and Fletcher. The authors are sociologists by profession but research the social science implications of genomic surveys. They had a choice - to go with the trend of such research to transcend the SSSM - or to find ever more intricate arguments to preserve it.

In choosing the latter approach, their strategy is to freely accept the theoretical results of population genetics and the empirical data of GWAS (genome-wide association studies) where this does not threaten blank-slatism. They then labour to find fault in every study which might cast it into doubt while feeding plenty of slack to the many purported environment-only explanations of race and gender differences. You will see plenty of uncritical space given to: continuing discrimination and poor institutions (pp. 107 ff.); subconscious bias, priming and stereotype threat (appendix 5).

In chapter 4, the authors address the claims of Herrnstein and Murray's seminal 1994 book, The Bell Curve. The three theses they wish to 'take seriously' are (to summarise): (i) increasing genetic stratification due to cognitive meritocracy; (ii) increasing assortative mating for intelligence; (iii) cognitive dysgenics via reduced fertility in the cognitive elite.

They announce, to their evident satisfaction, that none of these theses is born out by the evidence. But how convinced should we be by their arguments? The answer is, not very. There are many confounding variables - particular the massive changes in education and employment practices over the decades relevant to analysis - as Conley and Fletcher themselves spell out. In some cases the phenotypic attributes measured do, in fact, accord with Herrnstein and Murray's theses but the authors rapidly draw our attention to their underlying genetic correlates, as derived from GWAS.

Here they find no such trends. But unfortunately, we do not yet know the genetic markers for the relevant cognitive traits. Instead, the genomic indicator the authors use is the incredibly noisy 'polygenic score' (PGS). All we can really conclude is that the effects are small, and that as far as Herrnstein and Murray's proposed theses are concerned, it's too early to be sure.

Chapter 6, 'The Wealth of Nations', engages with Ashraf and Galor's 'Goldilocks' hypothesis of correlations between degrees of genetic diversity (too much in Africa?) and higher income and growth. Yet the correlations are poor (p. 124).  I wish they had engaged with work such as Garett Jones' 'Hive Mind', which focuses on ideas that country differences in IQ and size of the 'smart fraction' have something to do with it. Jones finds remarkably high correlations. But you can see the dangers.

So this is a book with an agenda although I think it's subconscious bias. The authors take too much pleasure in 'refuting' challenges to the core doctrines of the SSSM to make me think they're just doing so to protect their positions.

There are things to learn from this book. As critics they look for every conceivable flaw in twin and GWAS studies - this is socially useful. They also explain various techniques such as GWAS well, although the book is too technical and too dry for both the general public and mainstream social science academics.

In all, I regard this book as a missed opportunity.

Sunday, February 12, 2017

Chatbots: conversation as AI planning

I just love those YouTube videos of Internet-connected dolls. They're Wifi-linked to IBM's Watson, or some similar AI-in-the-cloud.

You'd think that the conversation would be scintillating - insofar as talking to a small child might have its moments.

But no, in the clip the adorable child is always shown asking the doll, "How far away is the Moon?" and the doll shows its conversational prowess by reciting Wikipedia.

Surely we can do better.

It's good to recall that we converse in order to achieve objectives. Sometime those objectives are indeed objective - as when we wonder how far away is the Moon.

Most of the time, though, the objectives are more about our more basic human desires. The need for sympathy, approbation, bonding against a third party, humiliation and revenge.

Oh dear, I've been listening to Cersei Lannister again..

Cersei and Margaery

Conversation is composed of speech acts directed towards goals, the goals often being the alteration of emotional states. Real-life chat is therefore very dependent on the accurate reading of emotional cues: facial expressions, tone of voice or other body language. No wonder email and WhatsApp chats go awry so often.

This suggests that a chatbot (a better Eliza) should treat conversation as an AI planning task.*

Naturally I'm not the first to realise that - this 1980 article - but it's the next place to go.

This relatively recent Stanford review - Conversational Agents - is quite illuminating (PDF slides).

---

Call me an old GOFAI-nostalgic but bottom-up number-crunching the stats is subject to diminishing returns as we move to higher cognitive tasks. Which is why I'm less than impressed by the tedious Google Assistant in Allo.

---

* I mean like GPS. Most conversational chatbots - like Google Assistant - cope with the extreme difficulties of unrestricted natural language input by giving a series of response-text buttons for the user to select ("Tell me a joke").

In a formalised conversational model, the chatbot should treat the conversation as a two-person game-tree. The opponent (user) has a choice of possible conversational rejoinders ('moves') which the program has a chance of understanding, and which propel the conversation forward in some direction.

Best to look at the planner conversation 'speech-act' rule-base and list the possible responses (need a way to flag input-variables) so as to guide the user.

Example:

Chatbot>: "What's your brother's name?

[I understand best:
   1. <first-name>
   2. <first-name> <second-name>
   3. <name> but we call him <nickname>
   4. I don't have a brother.
   5. Could we move on to another topic?
You can enter the response number if there's no information to give.]

User>:  Jimmie.

"When I am dead, my dearest"

Poignant poem in The Sunday Times today: by Christina Rossetti, (1830 - 1894).


When I am dead, my dearest,
    Sing no sad songs for me;
Plant thou no roses at my head,
    Nor shady cypress tree:
Be the green grass above me
    With showers and dewdrops wet;
And if thou wilt, remember,
    And if thou wilt, forget.

I shall not see the shadows,
   I shall not feel the rain;
I shall not hear the nightingale
   Sing on, as if in pain:
And dreaming through the twilight
    That doth not rise nor set,
Haply I may remember,
    And haply may forget.

---

I think that's a realistic view of death and its aftermath, beautifully stated.