in reply to Theorem proving and Unit testing

Mathematical induction is as follows. Suppose you want to prove some property holds for all x, where x is a member of some sequence, e.g., the natural numbers. Then prove Then by repreatedly applying the second result, you have shown by induction that it holds for all elements.

Scientific induction, a part of the scientific method, is a looser version of this. It says that if you (even better, others as well) try an experiment a bunch of times under the same conditions and get the same result, that result is likely to be a solid 'fact' upon which you can build theories and reason about other experiments. The more times you and others try it, the more confidence you build.

Your procedure above is more akin to scientific induction than mathematical induction. Which is fine, but it isn't really a formal method in that you are not proving anything, just building evidence that code seems to work.

-Mark

Replies are listed 'Best First'.
Re^2: Theorem proving and Unit testing
by stvn (Monsignor) on Aug 25, 2004 at 21:41 UTC
    Your procedure above is more akin to scientific induction than mathematical induction.

    I am sorry if I wasn't clear, but I am not talking about doing mathematical induction, but more structural induction. Which is a more generalized version of mathematical induction. Which to my understanding says that to prove P(x) you must test P with both a empty and non-empty value of x.

    Which is fine, but it isn't really a formal method in that you are not proving anything, just building evidence that code seems to work.

    I am not hoping it to be a truely formal method, but more a basis to build good unit tests off of. It seems to me that testing arbitrary data against manually calculated results (which is commonly how people built unit tests), is not as good as some kind of (possibly) provable statement which can be translated into a unit test.

    -stvn

      Structural induction is not only possible, but fun and easy (well, possibly for grad-student values thereof). What you want to do is remember that induction consists of a base and a recursive case -- for mathematical induction, this comes from the fact that every natural number but zero is the successor of another nat.

      For a binary tree, you'd prove theorems inductively by proving them on leaf nodes, then proving that if both of an interior node's children satisfy the theorem, the interior node must as well. (It's a bit more difficult with lazy languages, but that's not your problem here.)

      Nice job on the root node, btw.

      --
      F o x t r o t U n i f o r m
      Found a typo in this node? /msg me
      % man 3 strfry

        For a binary tree, you'd prove theorems inductively by proving them on leaf nodes, then proving that if both of an interior node's children satisfy the theorem, the interior node must as well.

        Do you see any value though in the 'random' structure part? Or do you think that to prove it on a leaf, then on a interior node would suffice to say that it works? I can see the theoretical beauty of that, but real-world exp. tells me that edge cases are not that easily revealed and running it through several random iterations would be a good idea.

        Nice job on the root node, btw.

        Thanks.

        -stvn
      Alternative way (to that by FoxtrotUniform) of structural induction for binary tress would be:
      • to prove it for a tree build of only one node
      • to prove it that if it is true for two binary trees than it is true for a tree build from those two trees connected with a node
      The hard part is the 'if it is true ... then ...' - the induction step, I don't see how this can be achieved with random generated trees.