Tuesday, June 12, 2012

Using Wittgen To Do Logic

This post will continue introducing Wittgen by way of giving usage examples. However, this time, the focus is some of the components of human reason: logic and arithmetic. It also tackles the question of how a language with just two instructions that is missing almost all the elements common to all programming languages can still do anything its bigger brothers and sisters can.

One might imagine that the most basic construct that a programming language needs is the conditional branching operator: the “if” statement. It is not missing; it is simply that the retrieve can do the job on its own. Let’s say you want to terminate a loop when the variable Num is equal to 0. In a classic programming language you would write something like:

if (Num == 0) {
        do this ...
}
else {
        do that ...
}

Assume there is in Wittgen’s memory, a variable that is called “stop when 0”. If there is an assign in the loop such as: 

        Doing Now:=@stop when @Num}}}

First Wittgen evaluates @Num}. If this is “0”, the right side becomes “@stop when 0}”. If, say, Num is “2” then the right side becomes “@stop when 2}”. Now there is a variable called “stop when 0” but there is no variable called “stop when 2”. “stop when 0” might contain an assign to Doing Now that would do whatever we wanted to do if "Num" was "0". On the other hand, “stop when 2” does not exist, so any assign involving it would fail. We thus have a simple mechanism that implements the conditional execution construct. One might even argue that this memory assign operation is more fundamental than the “if” operation. Here is an interesting possibility: What we think of as “if” is just a choice between different memory access options.

The If construct is one of the most basic components of logic. Symbolic logic as a whole will be discussed in later posts but by now it should seem plausible that the remaining constructs are also implementable as Wittgen code. Now what about basic arithmetic?

How would you make Wittgen do addition of two numbers of arbitrary length? Computers do this very fast while human beings are billions of times slower. How do we human being do addition? We spend years learning some basic single digit addition. So we memorize, for example, that 3+4 is 7, that 8+5=13 etc. Then we painstakingly learn procedures that teach us to write one number on one line and the second number on the second line with the digits lined up in the correct columns. Then, starting with the first column on the right we add the digits using the single digit additions we've memorized. If the answer has two digits we write down the first digit and put the second digit in the next column in a “carry” row. We do column after column this way until there are no more digits in the current working column. It’s very slow and very inefficient but it’s the way we learn to add arbitrarily large numbers.

If you want Wittgen to do addition, the right way to go about it, is to make it do addition the way humans do it. The code can be found on the Wittgen Sourceforge web site: http://sourceforge.net/projects/wittgen/

Can Wittgen do anything any other language can do? Technically, yes. Wittgen can be used to create a Universal Turing Machine - a Turing Machine that can implement a Turing Machine. This proves the standard Computer Science theoretical capability. This says nothing about what kinds of program are easier to write in which language and certainly not whether specific programming languages create mindsets that are appropriate for creative thinking regarding tough problems. A Turing Machine implementation will hopefully be up on the Wittgen Sourceforge Web site soon.

That concludes the all-too-brief usage section for now. It may only have been a taste, but talking about why Wittgen was created in the first place has been delayed for too long. So what follows in the next few posts is some Cognitive Science and philosophy. Once that's done we can get back to expanding on the art of programming Wittgen.

No comments:

Post a Comment