Friday, June 10, 2016

Matryoshka Dolls

Elon Musk plans to send people to Mars, and I would love to show how FFAS can be used to specify such a system, but for now I will stick with a simpler example, making matryoshka dolls, with the hope that this can be scaled up.

Matryoshka is a set of Russian wooden dolls of decreasing size placed one inside another. Traditionally the outer layer is a woman. The figures inside may be of either gender. The smallest, innermost doll is typically a baby turned from a single piece of wood.  Here are some pictures:



The example is simple but contains sufficient difficulty to demonstrate what FFAS is about and, hopefully, point the way to using it for more complex systems. The parameters of the problem are:
  • Create a series of dolls.
    • Each doll except the largest fits inside a larger doll.
    • All but the smallest are hollow.
    • All but the smallest open at the waist.
  • After a doll is carved, paint the doll.
    • The largest doll is a female.
    • The smallest doll is a baby.
  • When the paint is dry, assemble the dolls.

Introduction

Elon Musk has called for us to "get super good at making large complex objects", which I take to mean "large complex systems".  I believe that the reason we are not already "super good" at this has mostly to do with the problem of system specification.  Current methods of specifying large, complex systems suffer from the following conundrum:
  • A specification which is complete and unambiguous is necessarily incomprehensible.
  • A specification which is comprehensible is necessarily incomplete and ambiguous.
  • All such specifications are incorrect in that they fail to match the actual implementation.
"Functional Flat Active Specification" (FFAS for short) refers to a method of specifying systems which seeks to address the Elon Musk challenge. Unlike current specification methods, I believe that the simplifications imposed by the rules of FFAS methodology enable a specification to be all things--complete, unambiguous, comprehensible and correct.

FFAS has the following characteristics:
  • It is functional, in a sense such as that used in computer science, by which I mean that a specification module
    • ...is stateless, which in the computer science sense means it does not use variables.
    • ...does not have "side effects", which means that the explicit result is the only effect.
    • ...does not use iteration or recursion.
    • ...does not imply the order of operations.
  • It is flat, meaning that the input of a module is a list of simple elements and the output is a single simple element.
  • It is active, meaning that the specification "drives" or "controls" the system in some way.


Blockly Visual Programming

A visual programming language is any programming language that lets users create programs by manipulating program elements graphically rather than by specifying them textually. Blockly, a project of Google, is a library for creating visual block programming editors. It runs in a web browser and resembles MIT's Scratch application for teaching children to program.

Visual programming needs to be used with FFAS because functional programming is only practical when implemented with visual programming. A characteristic of text-based functional programming is that modules end up being one line of very opaque code. The following example of quicksort written in the Haskell language illustrates this:

      qsort (x:xs) = (qsort (filter (<x) xs)) ++ [x] ++ (qsort (filter (>=x) xs))

Programmers call these "one-liners" and they have a bad reputation. As you try to do more and more the line just gets longer and longer. The great thing about functional programming is that it's much easier to prove that the program is correct, but reading and writing it in text form is difficult at least, and probably impossible unless you have an IQ above a certain level.