| Andrew Cooke | Contents | Latest | RSS | Twitter | Previous | Next


Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

Last 100 entries

Brandalism; Table of Shifter, Cassette and Derailleur Compatability; Lenovo Demonstrates How Bad HTTPS Is; Telegraph Owned by HSBC; Smaptop - Sunrise (Music); Equation Group (NSA); UK Torture in NI; And - A Natural Extension To Regexps; This Is The Future Of Religion; The Shazam (Music Matching) Algorithm; Tributes To Lesbian Community From AIDS Survivors; Nice Rust Summary; List of Good Fiction Books; Constructing JSON From Postgres (Part 2); Constructing JSON From Postgres (Part 1); Postgres in Docker; Why Poor Places Are More Diverse; Smart Writing on Graceland; Satire in France; Free Speech in France; MTB Cornering - Where Should We Point Our Thrusters?; Secure Secure Shell; Java Generics over Primitives; 2014 (Charlie Brooker); How I am 7; Neural Nets Applied to Go; Programming, Business, Social Contracts; Distributed Systems for Fun and Profit; XML and Scheme; Internet Radio Stations (Curated List); Solid Data About Placebos; Half of Americans Think Climate Change Is a Sign of the Apocalypse; Saturday Surf Sessions With Juvenile Delinquents; Ssh, tty, stdout and stderr; Feathers falling in a vacuum; Santiago 30m Bike Route; Mapa de Ciclovias en Santiago; How Unreliable is UDP?; SE Santiago 20m Bike Route; Cameron's Rap; Configuring libxml with Eclipse; Reducing Combinatorial Complexity With Occam - AI; Sentidos Comunes (Chilean Online Magazine); Hilary Mantel: The Assassination of Margaret Thatcher - August 6th 1983; NSA Interceptng Gmail During Delivery; General IIR Filters; What's happening with Scala?; Interesting (But Largely Illegible) Typeface; Retiring Essentialism; Poorest in UK, Poorest in N Europe; I Want To Be A Redneck!; Reverse Racism; The Lost Art Of Nomography; IBM Data Center (Photo); Interesting Account Of Gamma Hack; The Most Interesting Audiophile In The World; How did the first world war actually end?; Ky - Restaurant Santiago; The Black Dork Lives!; The UN Requires Unaninmous Decisions; LPIR - Steganography in Practice; How I Am 6; Clear Explanation of Verizon / Level 3 / Netflix; Teenage Girls; Formalising NSA Attacks; Switching Brakes (Tektro Hydraulic); Naim NAP 100 (Power Amp); AKG 550 First Impressions; Facebook manipulates emotions (no really); Map Reduce "No Longer Used" At Google; Removing RAID metadata; New Bike (Good Bike Shop, Santiago Chile); Removing APE Tags in Linux; Compiling Python 3.0 With GCC 4.8; Maven is Amazing; Generating Docs from a GitHub Wiki; Modular Shelves; Bash Best Practices; Good Emergency Gasfiter (Santiago, Chile); Readings in Recent Architecture; Roger Casement; Integrated Information Theory (Or Not); Possibly undefined macro AC_ENABLE_SHARED; Update on Charges; Sunburst Visualisation; Spectral Embeddings (Distances -> Coordinates); Introduction to Causality; Filtering To Help Colour-Blindness; ASUS 1015E-DS02 Too; Ready Player One; Writing Clear, Fast Julia Code; List of LatAm Novels; Running (for women); Building a Jenkins Plugin and a Jar (for Command Line use); Headphone Test Recordings; Causal Consistency; The Quest for Randomness; Chat Wars; Real-life Financial Co Without ACID Database...; Flexible Muscle-Based Locomotion for Bipedal Creatures; SQL Performance Explained

© 2006-2013 Andrew Cooke (site) / post authors (content).

TTFP Exercises

From: "andrew cooke" <andrew@...>

Date: Mon, 23 Jan 2006 00:27:16 -0300 (CLST)

ere's my initial attempt at the first few exercises in TTFP (Type Theory
and Functional Programming; see posts at
http://www.acooke.org/cute/MoreConstr0.html).  Hopefully I'll keep
updating this thread as I get further through the book.

- for negation
! for bottom (the uspide down T)
So -X is equivalent to X => !

1.1 Prove transivity of implication

[A]1  A => B
------------ (=> E)
     B                B => C
---------------------------- (=> E)
          ------ (=> I1)
          A => C

((A => B) => (B => C)) => (A => C)

Note that it's OK to introduce extra propositions (like A above) at the
start, as long as you eliminate them later (this is what "elimination"

1.2 Prove ((A u B) => C) => ((A => C) n (B => C))

                         (A u B) => C
             ---------------------------------------------- (n I)
             (A u B) => C        n             (A u B) => C
[A]1            .                . [B]2            .
----- (u I)     .                . ----- (u I)     .
A u B           .                . A u B           .
------------------------- (=> E) . ------------------------- (=> E)
          C                      .           C
       ------ (=> I1)            .        ------ (=> I2)
       A => C                             B => C

So ((A u B) => C) => ((A => C) n (B => C))

1.3 Prove (A => (B => C)) => ((A n B) => C)

[A n B]1
-------- (n E x 2)
 B   A
 .   .
 .   .  (A => (B => C))
 .   ------------------ (=> E)
 .           B => C
 ------------------ (=> E)
    ------------ (=> I)
    (A n B) => C

1.4 Joke question?
[later] - book author (Simon Thompson) replied saying it was a mistake!

1.5 Prove (B u C) => -(-A n -B)

This looks so much like De Morgan's law I'm going to assume it's a typo
and instead prove (A u B) => -(-A n -B)

However, I can't find a solution (looks like it needs the excldued middle?)

1.6 (a) Prove ((A => B) n (A => -B)) => -A

 [A]1  A => B         [A]1  A => (B => !)
 ------------ (=> E)  ------------------- (=> E)
      B                      (B => !)
      ------------------------------- (=> E)
                  ------ (=> I1)
                  A => !

I'm not that sure about this because it might contradict (! E):
I think it doesn't because there's "more above" than just !.

Also, there are assumptions about how the "deduction process" corresponds
to a formula:
 - n being implicit between different "tracks" in the argument (OK, I
   think, since n appears to be associative and commutative).
 - vertical steps being equivalent to =>

(b) Prove (A n -A) => B

A  (A => !)
----------- (=> E)
    --- (! E)

Question 1.7

From: "andrew cooke" <andrew@...>

Date: Tue, 24 Jan 2006 11:36:44 -0300 (CLST)

1.7 Show the equivalence of EM/DN/CC

I can't find a way to do this starting with the EM formula given and
generating the other expressions.  And I think I can explain why (see Note
at foot of this for a resolution of this problem):

The law of the excluded middle (Boolean logic; I'm not sure what the
difference is) asserts *two* things about the relationship betwen A and

 - exhaustive: A u -A is always true (EXH)
 - exclusive:  A n -A is always false (EXC)

Now, asusming that a true proposition is always valid, the EM formula can
be derived from EXH alone:

 ------ (EXH)
 A u -A

The other two relations, however, require EXC.

First, --A => A

Consider EM applied to -A and A (and commutative u):
  -A u --A = true
  -A u A = true

From EXH and EXC we can divide the universe into two mutually exclusive
regions, -A and --A.  Similarly for -A and A.  So A is identical to --A. 
So --A => A.

Second, classical contradiction

 [-A]  -A => B         [-A]  -A => -B
 ------------- (=> E)  --------------
       B                      -B
       ------------------------- (EXC)
             ----------- (=> I)
             -A => false
             ----------- (EXH)
              A => true

So in both cases EXC is required in the argument, but that doesn't appear in

 A u -A

which only requires EXH.

Note - looking at Wikipedia, it seems that EXC is the "law of
non-contradiction" (LNC).  See also EoP on Dialetheism -

So presumably intuitionistic logic includes EXC (LNC).  Hence the question.

For 1.8 I think I really need a more detailed intro to logic?  It seems
that there are a bunch of things (like LNC) that I'm not using.

Apparently 1.5 *is* possible.  Rats.

Question 1.7 (correction)

From: "andrew cooke" <andrew@...>

Date: Tue, 31 Jan 2006 17:13:31 -0300 (CLST)

Looking again at my notes, the law of non-contradiction was already
present in the rules (I hesitate to say axioms - I need to go back and see
if any were derived) I had.  In particular (A n -A) => B (! E) seems to be

However, I am still unclear on how I can derive those as a simple process,
line by line, using that forumlation.

Attacking 1.5

From: "andrew cooke" <andrew@...>

Date: Tue, 31 Jan 2006 17:18:01 -0300 (CLST)

I wrote the following to try clarify where I was.  I was also considering
posting it to lambda as a plea for help, but decided it was unsuitable.

I think that my problem is that I am missing an axiom of some kind.  I am
working through http://www.cs.kent.ac.uk/people/staff/sjt/TTFP and you can
see my previous answers at http://www.acooke.org/cute/TTFPExerci1.html. 
Proofs are of the form

----------- (Reason)

And since part of the reason I'm interested in this is that I want to
understand exactly what axioms are assumed, I'm restricting myself to that
approach as much as possible.  Now I have the following transformations
available (ie they are either axiomatic or derived more or less directly
from axioms):

A B           A n B
----- (n I)   ----- (n E)
A n B         A

[A]            A  A => B
:              --------- (=> E)
B              B
------ (=> I)
A => B

A                     [A]    [B]
----- (u I)           :      :
A u B          A u B  C      C
               --------------- (u E)

-A  =  A => ! (defn)    !
(! is bottom)           - (! E / absurdity)

[A]  [A]         A  -A
:    :           ----- (- E)
B    -B          B
-------- (- I)

So, my basic problem is that I can't see a way to introduce all the
negation present in (A u B) => -(-A n -B)

I can find plenty of proofs of DeMorgan's theorem, but they assume
classical logic (ie they include the law of the excluded middle).  And the
author of TTFP assures me that this proof (in just the one direction)
doesn't require LEM.

As I said, I feel like I'm either missing an axiom or some assumption
(like "-" being distributive or something).  It's also possible I just
don't trust myself enough when manipulating expressions that include !. 
Is it really OK to have ! in the middle of a proof, draw any conclusion,
and for the proof as a whole to be valid?  Presumably ! cannot appear in
the initial assumptions, right?

Question 1.5 (partial)

From: "andrew cooke" <andrew@...>

Date: Tue, 31 Jan 2006 17:40:02 -0300 (CLST)

Prove (A u B) => -(-A n -B)

Rather than derive this directly, it seems that a kind of "truth-table"
approach might work.  However, that raises a pile of questions.  Since
they seem like useful questions anyway, this post...

A   -(-A n -B)
-------------- (=> E)
   -(! n -B)
   --------- (n E)
    ------ (notation)
    ! => !

So assuming A gives something universally (redundantly?) true.  Same for B
and, therefore, for A u B.

Now, is this sufficient?  I can see these possible problems:

(a) The approach above is not constructive and relies on some kind of
"true" value.  However, it doesn't explicitly use the LEM (so it's not
obviously bad either).

(b) The inference from A and B to (A u B) is in words.  I can't see how to
structure the argument starting from (A u B), although I can imagine
writing the B case in parallel (but what then?).  Am I assuming (A n B) =>
(A u B)? Then I would have (A n B) => -(-A n -B) (but maybe that's OK -
see (d)).

(c) How freely can I use ! - is the inference (! n B) => ! OK?

(d) What about the case (-A n -B)?  That is missing from the implicit
"truth table" I had in mind with this approach.  But why do I need to show
this?  I have a gut feeling (no more) that is only necessary with the LEM.
 Certainly => means something weaker than "equivalence".

Question 1.5 (with help)

From: "andrew cooke" <andrew@...>

Date: Wed, 1 Feb 2006 12:34:27 -0300 (CLST)

I ended up asking for help -

Here's the result:

[A u B]2     [-A n -B]1
              --   -- (n E)
              -A   -B
--------------------- (u E)
     -------------- (=> I1)
     (-A n -B) => !
--------------------- (=> I2)
(A u B) => -(-A n -B)

Which seems depressingly trivial in retrospect.

It's probably worth etching the following onto my forehead or something:

  In general, in constructive logic, work on your proof from
  the conclusion to the premises. Look at the main connective
  of your current goal. The introduction rule for the main
  connective should be the last rule you use. Now you have
  one ore more new goals that you need to prove, and possibly
  a few new premisses.

  When your goal has no connective, then you look at the main
  connectives of your current premisses, and use the
  elimination rules to try to prove your goal from them.

  - H. J. Sander Bruggink

Question 1.8

From: "andrew cooke" <andrew@...>

Date: Wed, 1 Feb 2006 16:58:38 -0300 (CLST)

Prove ((A => B) => A) => A using LEM

Using this application of the LEM (X u -X) is "free"

[X => Y]1   X u -X
------------------ (=> E)
      Y u -X
-------------------- (=> I)
(X => Y) => (Y u -X)  (a)

(A => B) => A
-------------  (a, where X = (A => B), Y = A)
A u -(A => B)
-------------  (a, where X = A, Y = B)
A u -(B u -A)
-------------  (DeMorgan; exercise 1.5)
A u (-B n A)
------------  (n E)
  A u A

So ((A => B) => A) => A

This could be more explicit, I know.  Major thanks to the anonymous
comment on the discussion page at Wikipedia -

Question 1.8 (better reference)

From: "andrew cooke" <andrew@...>

Date: Wed, 1 Feb 2006 17:03:04 -0300 (CLST)

Better URL http://en.wikipedia.org/wiki/Peirce%27s_law (for the "talk"
page click tab at top of screen).

Questions 1.9, 1.10

From: "andrew cooke" <andrew@...>

Date: Wed, 1 Feb 2006 17:34:02 -0300 (CLST)

1.9 "Between every distinct pair of numbers there is a number"

  A x,y . (x != y) E z . ((x < z) n (z < y))


(a) One-to-one function
  (A x . E y . (f(x) = y)) n (A y . E x . (f(x) = y))

(b) Onto function
  A y . E x . (f(x) = y)

(c) f respects (preserves?) the relation <
  A x,y . (f(x) < f(y) iff x < y)
  A x,y . ({(x < y) n (f(y) < f(y))} u -(x < y))

Automated Problem Solving

From: "andrew cooke" <andrew@...>

Date: Sun, 5 Feb 2006 13:22:21 -0300 (CLST)

This may be relevant - http://lambda-the-ultimate.org/node/1285

Questions 1.11, 1.12

From: "andrew cooke" <andrew@...>

Date: Sun, 12 Feb 2006 21:59:26 -0300 (CLST)

[Correction to 10.10 (c):
  A x,y . ({(x < y) n (f(x) < f(y))} u {-(x < y) n -(f(x) < f(y))}) ]

10.11 In
  A x . {(x < y) n (A z . (y > z => E x . (x > z)))}
    1     1   f       3    f   3      2    2   3

  y is free (f)
  x is bound (twice, 1 and 2)
  z is bound (once, 3)

10.12 Rename z to y in
  A z . E y . (z < y n y < z)

y is already bound, so need to rename y to x (say):
  A z . E y . (z < y n y < z) [y/z]
    = A z . E y . (z < y n y < z) [x/y][y/z]
    = A z . E x . (z < x n x < z) [y/z]
    = A y . E x . (y < x n x < y)

Summary of New (Predicate) Rules

From: "andrew cooke" <andrew@...>

Date: Sun, 12 Feb 2006 22:13:50 -0300 (CLST)

------- (A I) side condition: x not free in any assumption of B
A x . B

A x . B(x)
---------- (A E)
B(t)                               [B]
B(t)                     E x . B   C
---------- (E I)         ----------- (E I)
E x . B(x)               C

Correction and Clarification

From: "andrew cooke" <andrew@...>

Date: Mon, 13 Feb 2006 10:49:28 -0300 (CLST)

Correction - last rule above is (E E) (ie existential elimintion).

Clarification - on page 25 the book says:

  If we adopt a backwards reading of the rule of existential
  elimination, then we see how to use an existential assumption.

  To use an existential assumption Ex.P(x) , use the instance
  P(x) and finally discharge this using the rule (E E).

What it's saying is: if you need to prove something with an existential
assumption, first start without it, using the unqualified formula.  Later,
introduce the existenctial assumption it as a *separate* assumption, via E
E, which eliminates the initial unqualified formula, leaving the qualified
one (which in turn, is used, typically by => I).

Question 1.13

From: "andrew cooke" <andrew@...>

Date: Mon, 13 Feb 2006 15:06:38 -0300 (CLST)

[Note that "A" and "E" are "ForAll" and "Exists", so I'm rewriting
functions from the text with different letters identifying formulae to
avoid A]

Given the valid proof of Ey.Ax.B(x,y) => Ax.Ey.B(x,y):

[Ax.B(x,y)] (1)
----------- (A E)
 --------- (E I)
------------ (A I) (*)
Ax.Ey.B(x,y)          [Ey.Ax.B(x,y)] (2)
------------------------------------ (E E (1))
---------------------------- (=> I (2))
Ey.Ax.B(x,y) => Ax.Ey.B(x,y)

Note that at (*) x is not free in the assumptions (it is bound by the
for-all clause).

For the corresponding proof of Ax.Ey.B(x,y) => Ey.Ax.B(x,y:

[B(x,y)] (1)
--------- (A I !!!) (**)
Ax.B(x,y)               [Ax.Ey.B(x,y)] (2)
------------ (E I)      -------------- (A E)
Ey.Ax.B(x,y)               Ey.B(x,y)
------------------------------------ (E E (1))
---------------------------- (=> I (2))
Ax.Ey.B(x,y) => Ey.Ax.B(x,y)

the step (**) is invalid because x is free in the initial assumption. 
This is the "side condition" referenced in the question.

Comment on this post