Saturday, December 31, 2011

DNA seen through the eyes of a coder, my take

Several years ago in 2008, a programmer researched DNA and  how the cell works. He gave a software related analogy on how it operates.  It was a great overview of the process with the biology language translated for engineers.  I constantly thought about the article and wanted to add my own spin on it.  The author didn't really do anything wrong, and it really is a great article, but I personally wish he would have given a one paragraph software analogy.  (With the core content, I am not a scientist so I can't really refute his research).

http://ds9a.nl/amazing-dna/

I enjoyed the last view paragraphs at the end, "Now, DNA is not like a computer programming language. It really isn't. But there are some whopping analogies. We can view each cell as a CPU, running its own kernel. Each cell has a copy of the entire kernel, but choses to activate only the relevant parts. Which modules or drivers it loads, so to speak. If a cell needs to do something, it whips up the right piece of the genome and transcribes it into RNA. The RNA is then translated into a sequence of amino acids, which together make up a protein the DNA coded for."

I would analogize the DNA processing of the cell like so, DNA is a special type of hardware device and storage software.  Imagine it is like a VMWare like virtual machine.   Not only does it store important information about the cell, key blueprint information about how the cell should function.  But DNA also has special software for dynamically running other applications.  VMWare virtual machine has persistent information contained within its image file.  But, the VMWare player can also execute the machine.

The DNA virtual machine has the cron task launcher and only one cron job configured.  The cron job program launches special software that makes a "web-service call to some remote server". The web-service message might be similar to mRNA and the content is based on core DNA data stored on the virtual machine.   I used the analogy of a remote web-service call because DNA can't leave the nucleus so information and functions are sent remotely.  During transcription, RNA is copied from DNA.  Eventually, proteins are created.  RNA has message information for which protein to create.

So, during the lifecycle of the cell, cron jobs are running every 5 minutes.  The cron job task launches an application reading information from DNA, then launches a web-service call.  At the back-end server, the data from the web-service call (mRNA) is used with data from the server-side (tRNA).  Some additional routines get kicked off on the back-end and eventually proteins are created.  Proteins are also molecular chains that can be used as a structural component for the cell or used to for other cell tasks.  There are sixty thousand different proteins in the human body [1].

(Note: 5 mins is an arbitrary time period for my analogy, a cell can live several months or decades).

[1] The Machinery of Life – Goodsell - 1993


Monday, December 26, 2011

Lorenz Attractor 3D View




Resources:


[1] http://jvmnotebook.googlecode.com/svn/trunk/blog/java/Lorenz

[2] http://en.wikipedia.org/wiki/Lorenz_attractor

[3] http://berlinbrown.github.com/newpages/applet2/applet2.html

[4] http://berlinbrown.github.com/ - Github projects

----

Human life faces the same alternatives that confront all other forms of life—of adapting itself to the conditions under which it must live or becoming extinct. You have an advantage over the sagebrush in that you can move from your city or state or country to another, but after all that is not much of an advantage. For though you may improve your situation slightly you will still find that in any civilized country the main elements of your problem are the same.

Friday, December 23, 2011

Ron Paul is the most racist candidate in 2012 by far

http://www.youtube.com/watch?v=eMQmInReYlI 

Summary of his remarks. 

Repeal drug laws and it will be a tremendous improvement for blacks snared in an injust system. 

Systems that are impartial will have no special punishments or rewards for people. Right no no one can deny blacks are punished by our justice system. That has to stop. Blacks are 14% of drug users, yet are 36% of those arrested for drugs. 

We must get black men out of prison. The war on drugs is responsible for this. It cost $400 billion since the 1970s fighting drugs. Prohibition is a failure. Drug addiction is a disease and should be treated medically. 

Death penalty is wrong, unjust, and racist. The rich never get it, the poor and minorities are far more likely to get the death penalty. 

Rosa Parks is one of his heros for engaging in peaceful civil disobedience against injust laws. 

Ron Paul has gotten the most black votes of any Republican candidate because he is against injustice. 

He will issue a presidential pardon to EVERYONE, black, white and otherwise convicted of non-violent drug "crimes". 

Libertarianism is about the individual, not the color of their skin. Paul is the anti-racist because he is the ONLY candidate that will protect people against vicious drug laws.


Edit: In recent news Kelly Clarkson supports Ron Paul for 2012.  And not a bad song: Stronger.

Wednesday, December 21, 2011

A Physics Example in Java: A Projectile Fired from a Cannon, 2D Particle Kinematics

Here is an example program that shows how to implement kinematic equations for projectile motion using Java and the Swing 2D graphics libraries.

Equation used to plot projectile path along the X and Y axis

The Java code for these equations are simple, here is the current implementation of the doSimulation routine. The routine calculates the X and Y positions of the projectile over time.  The project only consists of two classes, the class for rendering the simulation and initializing the application.  The other class contains logic for calculating the X and Y positions.

Java code, DoSimulation routine, see s.i and s.k for the X/Y positions





Java 2D Cannon Physics Simulation

Java Source

https://jvmnotebook.googlecode.com/svn/trunk/blog/java/SimpleCannonPhysicsJava


Based on code from: physics for game developers, David Bourg

http://berlin2research.com/dyna/berlinbrown_java_resume/

----

So today we see man a highly evolved creature who not only acts but thinks and feels. All these thoughts, feelings and emotions are interrelated.
The body and the mind of man are so closely bound together that whatever affects one affects the other. An instantaneous change of mind instantly changes the muscles of the face. A violent thought instantly brings violent bodily movements.

Sunday, December 18, 2011

Random Code Post of the Day (procedural haskell, parse file)

This is a random code post of the day, with haskell, read a log file, search for a term and then write when the term is found to another file.

Haskell Source, open a file and search for a term

Source


https://jvmnotebook.googlecode.com/svn/trunk/blog/haskell/RandomParseFile


----


It was a cloudy, sultry afternoon; the seamen were lazily lounging about the decks, or vacantly gazing over into the lead-coloured waters. Queequeg and I were mildly employed weaving what is called a sword-mat, for an additional lashing to our boat. So still and subdued and yet somehow preluding was all the scene, and such an incantation of reverie lurked in the air, that each silent sailor seemed resolved into his own invisible self.

Friday, December 16, 2011

Implementing Example One from the Machine Learning Class in Java

At the end of 2011, Stanford offered a free online machine learning course.  The course covered many aspects of machine learning including linear regression, neural networks, super vector machines, and anomaly detection.

Octave is an open software platform for numerical applications that is compatible with Matlab.  Octave was the   tool of choice for the machine learning class, all of the programming exercises required that you submit Octave source.

Overview of example one:

The first example in the course is to implement one variable linear regression.  The regression in linear regression is a regression towards a mean or moving closer towards a mean.

Partial Approach for Gradient Descent with Octave



In the example, data points are read from a file and after running the example from Octave, this plot is generated.



Overview of example one in Java:


The Java implementation as you might expect is more verbose than the Octave equivalent.  Java doesn't include a matrix library in the standard toolkit so it took 5-10 lines more code to implement basic matrix multiplication as opposed to the seamless multiplication in Octave.



Java Swing Example of MlClass Ex1, regression line and data points

Resources

http://www.gnu.org/software/octave/
http://www.ml-class.org/course/class/index

Note:  I tried not to provide a full matlab implementation from the machine learning course as that wouldn't be fair to the students.  Plus the implementation is in Java and really ideal for the actual course.

Source


http://jvmnotebook.googlecode.com/svn/trunk/blog/java/ConvertMachineLearningToJava/

Contact
berlin dot brown at gmail.com

"In the tumultuous business of cutting-in and attending to a whale, there is much running backwards and forwards among the crew. Now hands are wanted here, and then again hands are wanted there. There is no staying in any one place; for at one and the same time everything has to be done everywhere. It is much the same with him who endeavors the description of the scene. "

Wednesday, December 14, 2011

Quick LaTeX Equation Examples for use by programmers on windows, convert to PNG

LaTeX/TeX is a complex documenting system that is mostly used in a academic setting but can also be used by anyone to convey information.  It is a complete system but a massive system that has been in development for decades so it isn't something that you skim over and become fluent in.  But I did want to provide some full setup scripts so you can add write an equation and add an image of that equation or pseudo code to your blog or word documents.

Install Cygwin and tetex


You can install all of the tex software through cygwin.  Use the cygwin easy click through install wizard.  Select all of the Publishing/tetex*  applications.

1.1 Install of tetex through Cygwin setup
Install Cygwin, make and gcc and vim


gcc and make aren't required for tetext but I use a make script to run tex.  Install gcc and make through the cygwin installer.

Download my make script and example tex files


http://jvmnotebook.googlecode.com/svn/trunk/blog/LatexEquations/src/

There are several makefiles on the Internet for running tex files into tex and then converting them into some output.  Download the Makefile that I have in my link and you can simply type 'make' in a directory that has a collection of tex files.

1.2 At directory, see makefile, launch cygwin and run 'make' at a directory with tex files

Write a simple equation and convert to PNG


You will need to follow a three step process to in order to add an equation or pseudo image to your blog; write the equation in vim, execute the provided makefile, run the dvigif command.  Enter this equation using vim.

1.3 Equation in vim

1.4 Running 'make' and then dvigif command

dvigif --png -T'6.6in,7in' b.dvi

1.5 PNG image output after running make build on tex  files and the dvigif command
1.6.a Tex source with various equations and pseudo code

1.6.b Output PNG image from tex source defined in figure 1.6.a
1.7 Source with pseudo code
1.7.b Output from pseudo code
Additional Resources


[1]. Example Source - http://jvmnotebook.googlecode.com/svn/trunk/blog/LatexEquations/src/

[2]. http://en.wikibooks.org/wiki/LaTeX/Algorithms_and_Pseudocode

[3]. http://www.cs.uiuc.edu/~jeffe/teaching/algorithms/

Environment

Tested with:

WindowsXP


CYGWIN_NT-5.1 1.7.9(0.237/5/3) 2011-03-29 10:10 i686 Cygwin

TeX 3.141592 (Web2C 7.5.4)


----
"The extreme Cerebral differs from other types chiefly in the fact that while his head is unusually large compared to the body, his alimentive, thoracic, muscular and bony systems are smaller and less developed than the average. The latter fact is due to the same law which causes the Alimentive to have a large body and a small head. Nature is a wonderful efficiency engineer. She provides only as much space as is required for the functioning of any particular organ, giving extra space only to those departments that need it."


--- Berlin Brown

Monday, November 14, 2011

OpenJDK Java8 Lambda Syntax

This document provides some working examples of the future OpenJDK 8 lambda syntax.   There was a lot of discussion whether the language changes would get included in the Java7 or Java8 so it looks like we will see the changes in Java8 slated for release in 2013.

The lambda conversion uses a target SAM type or single abstract method.

You can see the conversion in this example:

    interface F {
        void f();
    }


        final F func = () -> System.out.println("Test");
        System.out.println("Function Object : " + func);
        func.f();
...
The variable type on the left is an interface of type 'F' with a single method 'f'.

It seems that the Java lambda implementation provides a slightly more expressive syntax for code blocks that you would normally see in an anonymous inner class.  These sections of  code are synonymous.

        for (int i = 0; i < 10; i++) {
            final int ii = i;
            final int res6 = ((Fx)( (final int y) -> y + ii )).f(10);          
            System.out.println("[6] Output from recent lambda call index="+i+" : " + res6);
        }
        ...

        for (int i = 0; i < 10; i++) {
            final int ii = i;
            // @line70, anon inner class call
            final Fx fxx = new Fx() {
              public int f(int y) { return y + ii; }
            };
            final int res6 = fxx.f(10);          
            System.out.println("[7] Output from anonymous inner call index="+i+" : " + res6);
        }


Resources:


The Lambda team provided a binary build of Javac and Java for Windows and Linux.

[1] http://jdk8.java.net/lambda/


$ ./java.bat
openjdk version "1.8.0-ea"
OpenJDK Runtime Environment (build 1.8.0-ea-b1314)
OpenJDK Client VM (build 23.0-b04, mixed mode)

https://github.com/berlinbrown/BuildingOpenJDKCookbook

BuildingJDK8/ExampleLambdaProject/LambdaJava8Test.java


http://hg.openjdk.java.net/lambda/lambda/

http://mail.openjdk.java.net/pipermail/lambda-dev/attachments/20100122/3764c21a/attachment.txt

----

The Thoracic system may be compared to a great freight system, with each of its tributaries[Pg 218]—from the main trunk arteries down to the tiniest blood vessels—starting from the heart and carrying its cargo of blood to every part of the body by means of the power furnished by the lungs.



Monday, November 7, 2011

Implementing a Parser and Simple Compiler for the Java Virtual Machine

1. Overview


  This document covers the implementation of a simple recursive-descent parser for an infix adder language with a lexer, parser, and compiler.  The language is implemented with Java and compiles to Java Virtual Machine (JVM) bytecode.  The first implementation of the compiler is different from other implementations because it is fully implemented in one class without third party parser generator libraries.  The implementation of the language only uses the Java standard libraries.  The code for the parser does not use a parser generator so it only contains pure Java standard libraries and no references to third-party libraries.

I wanted to discuss this particular example it helps for you to understand the nature of programming languages and their implementation.  Don't be scared about the parsing input token routines in them.  They help as a tool to the developer.  This a basic implementation but at least I provided a JVM compiler.  Actually code generator from the AST to JVM byte code.


Figure 1 : Mini adder language input (6 tokens are visible)
  The language program in the snippet above consists of a SYMBOL name token, an assignment token, NUMBER value the PLUS token and another NUMBER token.  The result of the add operation is stored in  global memory.  


2. Lexical Analysis


  The lexical analysis consists of reading the character tokens from the input stream and then converting those   ASCII characters into tokens that are used by our language.
Figure 2: Source code for lexer method, convert input ASCII characters into our language token types

  If you look at the code snippet above, the lexer method mostly consists of a large case statement that checks for a particular character and then creates a wrapper token object for that character. Once the token object is created, we add start to add the token node to the abstract syntax tree.

3. Lexer and Simple Parser with ANTLR


The parser example code uses only the Java standard libraries.   Most developers that write domain specific languages or other programming languages may use a parser generator.  ANTLR is a parser generator system written in Java that can output parser code in Java programming language or Python.  You provide a grammar and ANTLR generates the code that you can use for the lexer and parser.  In our case, are going to create a simple grammar and then two classes are created, the lexer and parser.

When then feed the input tokens to our ANTLR code generated code.





4. Parser Implementation and Abstract Syntax Tree (AST)


  The parser implementation converts and analyzes the tokens and coverts the tokens to an abstract syntax tree.  Once we build the AST, then we can traverse the tree and perform operations at each node.

Figure 3.1 : Lookahead parsing (LL(2)) and look for match errors

  We used look ahead two parsing.   Match method.

Figure 3.2 : Output from Abstract Syntax Tree
Figure 3:  Building the AST



4.1 Mini Language Functionality: Adding, Global Memory, Printing

Figure 4:  Visitor implementation, visit the AST expression nodes.  Perform 'add' operation

5. Java Bytecode


  The Java bytecode consists of  the magic number CAFEBABE.  After that comes the constant pool data.  After the constant pool data comes the data buffer which consists of the code block.


5.1 Java Tools : Javap

Figure 5 : Output from Javap Disassemble/Decompile on a Java Class

5.2 The Constant Pool


  The constant pool is a collection of constants that are referenced by ID in the data buffer or code section.


5.3 The Data Buffer and Code Section Attributes

The data buffer code section contains the code.

5.4 Analyzing the OpenJDK Java Source


Figure 6 : OpenJDK Java Source ClassWriter.java, writes Java bytecode to file/stream




6. Mini Compiler Implementation (writing to JVM bytecode)


  When thinking about the Java programming language, think of it as a wrapper for generating Java bytecode.  You don't necessarily need a mainstream programming language.  You do need to format the bytecode input into a class file and feed that into the Java virtual machine.


Figure 7 : Mini adder compiler, adding constants to constant pool. Matches Javap output (see comments)




7. Conclusion


This document covers the implementation of a compiler, a very basic compiler for the JVM.  We looked at the lexer, the parser, the AST, JVM bytecode and compiler.
A. Resources
B. Source Code
https://github.com/berlinbrown/ImperativeStaticCompiledLangOneFile - Github Source, see CompiledLangOneFile.java)

Also see:
http://math-services.appspot.com/lang2.jsp

C. Building the OpenJDK Java Compiler


D. Tools


http://www.antlr.org/


E. Disclaimer


For this document, I included snapshot images of the source instead of the actual source because I plan on converting this document to other formats.  I wanted to keep some of the syntax highlighting from my IDE.

-- Berlin Brown on 9/22/2011

Sunday, September 11, 2011

Exploring Common Lisp: Project Euler Number 8 in Common Lisp (Neophyte Version)

There isn't really much I can add about this example. The goal is to find the largest product of any consecutive digits given a 1000 digit number. I implemented the first approach that came to mind; I went with a large loop to iterate through the 1000 digits and then an inner loop to extract that digits we are going to use in our calculation. The key built-in lisp functions are "loop" and "reduce". If you are not used to a lisp programming language, a C version of this solution is provided.

;;
;; euler8.lisp (modify to find the "correct" solution)
;; Find the greatest product of five ;; consecutive digits in the 1000-digit number;;
;; [1] http://www.unixuser.org/~euske/doc/cl/loop.html
(defparameter *large-num* 
"73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843")

(defun find-great-product ()
  "Use reduce to find the product of a list of 5 digits out of the
 larger 1000 digit number"
  (let ((n (length *large-num*)) (m 0))
    (loop for i from 0 to (- n 5)
          for x = (let ((vals (loop for z from i to (+ i 4)
                                    for b = (digit-char-p (char *large-num* z))
                                    collect (if b b 1))))
                    (reduce #'* vals))
          do (when (> x m) (setf m x)))
    m))
(defun main ()
  (format t "Start~%")
  (print (find-great-product))
  (format t "Done~%"))
(main)

Saturday, September 10, 2011

Revisiting Self Replicating Molecules in an Artificial Chemistry Automaton

Introduction

  This blog entry describes an artificial chemistry simulation implemented through a cellular automaton. We show that basic rules can be used to produce complex behavior through simulated artificial chemical reactions. The chemical simulation exists on a fixed size two dimensional grid of cells.  Each active cell is represented by an artificial atom element, these atoms may collide with other atoms to produce a chemical reaction.  Strong chemical bonds will form if the chemical reaction is allowed by system.  Clusters of strong bonded atoms form molecule strings.   We show that self replicating molecule string patterns emerge from the artificial simulation.  This analysis is based on Timothy Hutton's artificial chemistry model from Squirm3.  It it is a basic model but a necessary step for analyzing and recreating similar natural systems.  Self-replication and self-organization is fundamental to all biological life.  Engineers use scientific knowledge to solve real-world problems.  Scientists study and experiment with nature and the Universe in order to add their research to the scientific knowledge base.  This small experiment attempts to simulate real chemical reactions using simple artificial physics.

  Chemical reactions occur when two atom cells collide.  In the simulated physical environment, this occurs when an atom cell sits next to another atom cell.  The chemical reaction rules are tested between the two atoms, if the rules allow the reaction then a bond forms.

Figure 1: Chemical Reactions over time



   The atom cell has a type of 'a', 'b', 'c', 'd', 'e', 'f'.  Each atom has a state of '0'-'8'.  Three chemical reactions typically occurred but eight were allowed.  During a chemical reaction, x3 for atom one and y6 for atom two with an output x2.  X and Y are variable substitutions for the atoms, 'a', 'b', 'c', 'd', 'e', 'f'.


Figure 2 : Squirm 3 Artificial Chemistry Java Application.  Clumps of bonded atoms represent molecules.

Figure 3 : Number of Bonds vs No Bond.  Over time, the bonded atoms will fill the screen.   Some atoms that don't have bonds still persist but with less frequency

Figure 4 : Total bonds over time



System Description

The simulation consists of a 2D grid, fifty cells in height and fifty cells in width.  A cell grid is inactive or active, the active grid cell may contain an atom element represented by a  'a', 'b', 'c', 'd', 'e', 'f' type and a 0-8 state,  e8 represents atom cell type 'e' with state 8.  Molecules consist of clumps of atoms.  We only use the atom type to chain molecule strings, cfab is a common molecule that self replicates in the simulation.

Establishing a chemical reaction, example reaction cell1=e8 + cell2=e0 creates cells e0 and e4 and a bond may form
After thousands of iterations, common patterns emerge on the grid.  Common bonded atoms (molecules) survive through out the simulation.



Figure 5 : Common Atoms and Atom State.  Common atom states fill the cell universe.
Figure 6 : Most Common Bonds

Figure 7 : Common Reactions
Source Code

https://github.com/berlinbrown/Squirm3ArtificialChemistry

References

[1] Evolvable Self-Replicating Molecules in an Artificial Chemistry Tim J. Hutton, Fall 2002, Vol. 8, No. 4, Pages 341-356 Posted Online March 11, 2006. (doi:10.1162/106454602321202417) at 2002 Massachusetts Institute of Technology

Date: 9/10/2011 -- Berlin Brown

Monday, July 4, 2011

Quick notes on Java profiling API



Java Profilers normally change the bytecode of methods in classes as they are loaded by the JVM.

See the instrument API. Also see the tijmp as an example memory profiler.

http://download.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html

http://khelekore.org/jmp/tijmp/

----

Because the Alimentive and Cerebral systems are farthest removed from each other, evolutionally, a large brain and a large stomach are a very unusual combination. Such an individual would be a combination of the Alimentive and Cerebral types and would have the Alimentive's fat body with a large highbrow head of the Cerebral. The[Pg 224] possession of these two highly developed but opposite kinds of systems places their owner constantly in the predicament of deciding between the big meal he wants and the small one he knows he should have for good brain work.


-- Ron Paul 2012

Wednesday, June 29, 2011

GTUG Atlanta, GWT and HTML5

I went to the GTUG Google Technology Atlanta group yesterday. It was a good crowd of about 30 people. The GWT demos focused on Local Storage, Canvas, Audio, Video and some other topics.

Wednesday, June 8, 2011

General Programming: Learning and using a programming language

This is an expert from a slashdot post on programming languages:

"We only make programming difficult because we suck at writing. The vast majority of programmers aren't fluent, and don't even have a desire to be fluent. They don't read other people's code. They don't recognise or use idioms. They don't think *in the programming language*. Most code sucks because we have the fluency equivalent of 3 year olds trying to write a novel."

"In language acquisition there is a hypothesis called the "Input Hypothesis". It states that *all* language acquisition comes from "comprehensible input". That is, if you hear or read language that you can understand based on what you already know and from context, you will acquire it. Explanation does not help you acquire language. I believe the same is true of programming. We should be immersing students in good code. We should be burying them in idiom after idiom after idiom, allowing them to acquire the ability to program without explanation."


-- http://ask.slashdot.org/comments.pl?sid=2198700&cid=36293622

Saturday, May 21, 2011

Thoughts on early computing history, addendum

1928 - The Entscheidungsproblem decision problem was proposed by David Hilbert
1936 - Church publishes "An Unsolvable Problem of Elementary Number Theory", Church's Thesis [1]. It is a paper on untyped lambda calculus. American Journal of Mathematics, Volume 58, No. 2. (Apr., 1936)
1936 - Alan Turning publishes a paper on an abstract machine , On Computable Numbers, with an Application to the Entscheidungsproblem' Proceedings of the London Mathematical Society, Series 2, 42 (1936-37). He proposed the concept of the stored-program.
1937+ - John von Neumann gains knowledge from Alan Turing's papers but Turing was not directly related to the development of ENIAC.
1943 - 1946 - Creation of ENIAC (Electronic Numerical Integrator And Computer)
1944 - John von Neumann became involved with ENIAC
1949-1960 - Early stored computers were created, some of the based on von Neumann architecture.
1952 - The IBM 701 was announced. The 701 was a stored-program computer.
1954 - IBM 704 introduced
1954 - FORTRAN and LISP developed for the IBM 704
1970 - Forth developed. Forth inspired the Java virtual machine.
1973 - C programming language appeared.

Thoughts on early computing history



When you look back at the major milestones in computing history, we moved quickly. We went from abstract models of computing to stored-program computers in a
decade or less. It was truly amazing.

1903 - Alonzo Church was born in Washington, D.C. (USA)
1928 - The Entscheidungsproblem decision problem was proposed by David Hilbert
1936 - Church publishes "An Unsolvable Problem of Elementary Number Theory", Church's Thesis [1]. It is a paper on untyped lambda calculus. American Journal of Mathematics, Volume 58, No. 2. (Apr., 1936)
1936 - Alan Turning publishes a paper on an abstract machine , On Computable Numbers, with an Application to the Entscheidungsproblem' Proceedings of the London Mathematical Society, Series 2, 42 (1936-37). He proposed the concept of the stored-program.
1936 - 1938 - Alan Turing studies under Alonzo Church
1937 - John von Neumann recommends Alan Turing for Fellowship at Princeton.
1938 - Alan Turing receives Ph.D from Princeton
1946 - Alan Turing presents a paper on the stored-program computer (Automatic Computing Engine).
1937+ - John von Neumann gains knowledge from Alan Turing's papers but Turing was not directly related to the development of ENIAC.
1943 - 1946 - Creation of ENIAC (Electronic Numerical Integrator And Computer). Note: ENIAC was not a stored-program computer.
1944 - John von Neumann became involved with ENIAC
1945 - John von Neumann publishes paper on Electronic Discreet Variable Computer (EDVAC)
1948 - Manchester Mark I developed at Manchester University, first stored-program computer
1949-1960 - Early stored computers were created, some of the based on von Neumann architecture.
1938 - Donald Knuth was born
1957 - Donald Knuth had access to a computer. "I saw my first computer in 1957, which is pretty late in the history game as far as computers are concerned. There were about 2000 programmers in the entire world"
1963 - Donald Knuth began work on the Art of Computer Programming.
1973 - C programming language appeared.

Note: I presented milestones but some of these events were not directly related.

Image of Alan Turing: "It is believed that the use of this image may qualify as fair use under United States copyright law. Other use of this image, on Wikipedia or elsewhere, may be copyright infringement"

[1] "INTRODUCTION Alonzo Church: Life and Work"

--- Berlin Brown

Saturday, May 7, 2011

Thoughts on Artificial Life, AI and AI reboot

"Unthinking Machines Artificial intelligence needs a reboot, say experts."

There are some issues with a top-down approach to automatic artificial complex behavior. The problem with modeling the brain or the brain's neural network is that you are just looking at the end result of millions of years of evolution. We should understand how the human brain became relevant and came to be and then we will find that other animals also have brains and exhibit complex behaviors. Simple animals have smaller brains but we can look how those systems evolved over time. You could go that route, completely model and understand the brain but you will still end up with issues. You will have a broken, less than accurate copy of the brain but then you still are missing other components of the human body. The heart, the nervous system, the lungs, millions of years of evolution. Scientists look at the brain and say, "Hey, that is pretty cool, let's model that". I say, "Hey the earth's biosphere is pretty cool. How did I and the rest of the other intelligent animals get there, let's model that". They are looking at intelligence. But what is intelligence? Why are humans more intelligent than monkeys? Or Crows? Or Dolphins? In reality, they aren't THAT much more intelligent. And even if humans are a lot more intelligent, a lot of other animals have the same hardware. So if we understand the system that created...animals and their hardware, I think that would be more interesting than look at just one animal "brain" and trying to copy that. What parts do you model/copy? No matter how accurate you model the brain, scientists will always play catch up trying to understand the interesting parts of the human brain. And then after 20 years of copying the brain's functionality, we still may have to copy other aspects of the human body that give the brain life.

We need a true bottom up approach that looks at biologically inspired entities if we truly want to understand emergent phenomena. Examine the the microbiology level and chemical reactions and move up. A truly bottom-up approach that looks at the biology of basic organisms and models basic organisms, starting from bacteria to cells is the way to go. And of top of the biology, I would look at inorganic matter and how that relates to organic matter. And then I would look at the evolution of these biologically inspired systems. You could play experiments, where did organic matter come from on earth? We should understand DNA, RNA, mRNA, cells, single celled organisms, water, on and on. Even those basic components are kind of interesting. Combine DNA, cells and other matter together and you have a complex entity. Understanding the reasons for those components and how they interact is the way to go. Evolve systems that generate those interactions. I would model simple creatures, evolve those creatures and then create an environment for those creatures to exist, have them interact and then evolve a system that has some form of brain..or multiple brains.

Even the term "artificial intelligence" leads people in the wrong direction and needs a reboot. I like "autonomous artificial adaptability". We want creatures that adapt to the world around them and do so at their own direction. The concept of intelligence implies "human brain intelligence". Humans are more intelligent than pigs. But pigs are WAY more intelligent than trees. That leap in adaptability is interesting and worth looking at. Think about it this way, the unintelligent parts of the human body are fascinating. And who is to say that there are creatures in the universe that are infinitely more intelligent than humans? We have one brain, is it possible that a creature could have a million brains that all operate independently of one another. We only use a small capacity of our brains. Is it possible a creature could use 100% of their brain capacity. Bacteria and plant life are not normally considered intelligent but they do adapt to the earth's changes conditions. Human beings are far more interesting than bacteria but that doesn't necessarily mean that replicating human brain intelligence doesn't have to be the ultimate goal for strong AI.

At the heart of strong AI will be computational biology, whether the artificially evolved creature has something similar to a brain or neuron cells is irrelevant to the problem, you can still create adaptable, seemingly intelligent creatures with artificial biology through a controlled artificial environment. That is why I think the AI field is missing, the focus has always been the brain. Even if you create an artificial brain that is similar to the human brain, you have the problem of replicating the signal processing mechanisms of the eyes and ears. You have an issue with creating pain receptors and other bits of information that are fed into the brain. Even if you can feed the right bits to the brain, you will hit the next philosophical question, what is this autonomous creature supposed to do? Everything that a person does is ultimately tied to their evolutionary inspired purpose. You eat because you are hungry, the human is hungry. You create societies to make it easier to survive for other humans. All of the adaptability of the human brain and the human are kind of tied to its evolutionary purpose. What will be the goal of this artificial brain? You still have the same problem with a biologically inspired, evolutionary inspired artificial systems but you can control the evolutionary constraints. Maybe the creature doesn't need a brain? But that is OK, it still may have interesting properties that encourage its survival. The computer science AI research community has tunnel vision as it relates to AI, "the human brain, the brain, the brain". If you stop and think, "what is the brain? what is a human?". We are really a collection of cells and bacteria, all wrapped in a nice protective package. Most of the individual cells in the human body are interesting on their own, the brain cells are not that much more interesting than the skin cells or blood cells or anything else.

With most software engineering and even most AI research, the developer is required to program the behavior into the system. The developer is careful to program a response to all known inputs. Even if you model the brain and create a close enough model of the brain, the puppet master will still have a problem of programming and training inputs that only this particular brain can respond to. You have reached the zenith of AI but now you have hit a wall trying to train and feed information to the brain. You are essentially programming the brain with known inputs. With a good biologically inspired model that evolves behavior and operates autonomously and completely independent of the "creator", you don't program any behavior (as much as you can). If you run the system 20, 100 years, we may not know what type of behavior emerges. These systems should have a start button but no kill switch. Killing the system means you start all over and completely new behavior emerges. In theory, The brain model and the bottom-up biological model are similar, you expect emergent behavior. Evolutionary design creates more emergent behavior than starting at the brain and watching what happens next.


\[
\begin{align}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}
{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{align}
\]

Resources

[1] http://en.wikipedia.org/wiki/Avida - Artificial life software platform

[2] http://en.wikipedia.org/wiki/Artificial_life

[3] http://en.wikipedia.org/wiki/Christopher_Langton

[4] googlecode/bottom-alife-demo.zip

-- Ron Paul 2012

Sunday, May 1, 2011

Confirmed Sources, Osama bin Laden is dead

It has just been reported, Osama bin Laden is dead. Now, I can stop looking for him.

"Justice has been done" -- Obama

Unit Testing / Extreme Programming

Unit Testing advocates use language that you hear from religious advocates.

"You can't write software without unit tests". "You must unit test your code".

That sounds a lot like:

"You will go to hell if you sin". "If you don't accept Jesus as your lord and savior, you will go to hell".

Where does that leave us?

You can write software without unit tests. A lot of software has and will be written without unit tests. No human will go to hell for not accepting Jesus as their lord savior.

Same question, where does that leave us?

I may have advocated the use of unit tests. I think the concept is beneficial. BUT there are a couple of issues. Developers not writing unit tests is a big one (I was thinking about creating a spreadsheet, software from github and sourceforge, projects that have unit tests and those that don't). Why don't developers write unit tests? Because they don't have to. That is the main reason. You need a compiler to compile code for languages that need to be compiled. You need some runtime. You need to your code. But you aren't required to write unit tests in order to execute your code.

So, maybe we need some form of system that checks for unit tests before allowing your code to run. In my mind, I kind of feel that unit tests are an extra compilation step or runtime step. Maybe if that sort of system was in place, we might see developers wanting to write more unit tests. I also want more information from the unit tests. It is great to know if the test passed or failed but I would like to see similar possible inputs fed into the unit testing systems and the output (possibly with a visual graph). QuickCheck and ScalaCheck are example tools that automate unit testing.

And like with most with religious practices, sometimes the underlying message is important but the message is delivered improperly.

If I say: "Write unit tests or else". If developers don't see a need or want to write unit tests, they won't. So telling developers to write unit tests doesn't really hold weight.

Now, I would like to hear, "Write unit tests in order to isolate this piece of code and test reasonable inputs and check the output of the tests. This is a core class in our library and we must validate the possible inputs and expected outputs. It will be interesting to look at this particular module, visualize the possible inputs from the calling client code and see what happens. Plus, isolating this particular component and testing it takes less time than running the entire system as a whole". That blurb won't make for a very good headline at an extreme programming conference but I think it is gets the point across, more so than, "Write unit tests or else". But my overly verbose blurb on unit testing still doesn't force developers to write unit tests. Even those that are well versed on testing will not write unit tests when under some critical deadline.

In Summary

I think the concept behind unit tests is beneficial but I still feel that implementation systems behind unit testing are still lacking. This is one possible reason that developers don't always write them (jUnit is one example of a system that lacks).

Response to critics of this post?

I have noticed if you step on any person's religion, critics tend to come at you from all directions. I don't mean to step on the unit testing religion. I am not advocating to stop writing unit tests. But I do want to point out that software is written without them. Maybe if we create a platform that forces the developer to write unit tests as part of some compilation or build step, then developers will start thinking about the practice.

How do you know that developers aren't writing unit tests? If it is possible not to write unit tests, then it is possible that developers won't write them. Also, I tend to want to include the edge cases of software development when talking about unit tests. Are people writing unit tests for embedded software development? Linux device driver development? Any Linux software development? Complex J2EE server environments?

Friday, April 22, 2011

Non-technical and more: Lindsay Lohan was sent to jail recently

Lindsay Lohan was sent to jail briefly and then posted bond. She was detained after the judge sentenced her to 120 days of jail. But she posted bond and is supposed to return in early May.

How many days will she actually spend in jail? 120? 2? No this blog was not hijacked. I find this interesting because I want to see how many ways Lohan and her attorneys can circumvent the real law so that she doesn't go to jail.

Some people actually go to jail and are detained for periods of time longer than their actual sentencing. Lohan may go to jail for a fraction of her actual 120 days.

Saturday, April 16, 2011

OpenJDK Hotspot, source code line count

Here are some notes, source code analysis of hotspot:
# perl cloc-1.53.pl  src
    1786 text files.
    1716 unique files.
     121 files ignored.
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C++                            673          64909          97522         340057
C/C++ Header                   796          25928          49603         101144
XML                             61            474            179          15360
Java                            78           1908           2397           8663
C                               11           1194           2327           7236
XSLT                             7            560            166           4406
Assembly                         6             89             36           2245
D                                4             83            127            869
SKILL                            3             71              0            495
make                             2             34             58            146
Javascript                       1              6             27             38
-------------------------------------------------------------------------------
SUM:                          1642          95256         152442         480659
-------------------------------------------------------------------------------
   5282 ./share/vm/gc_implementation/g1/g1CollectedHeap.cpp
   6041 ./os/solaris/vm/os_solaris.cpp
   6658 ./share/vm/c1/c1_LinearScan.cpp
   8982 ./cpu/x86/vm/assembler_x86.cpp
   9232 ./share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp


http://openjdk.java.net/groups/hotspot/docs/FOSDEM-2007-HotSpot.pdf
http://blogs.sun.com/jonthecollector/
http://blogs.sun.com/tony/

Friday, April 8, 2011

Declarative programming introduction

"Haskell is a very elegant language, and the functional nature of it makes it a beautiful glue language... because the nature of Haskell as a language can make things clearer than many other programming languages" -- Mark C. Chu-Carroll of the ScienceBlogs

"Haskell is a declarative language in that the program can be treated as a statement of facts, rather than as a set of commands that are sequenced in time" -- cdsmith


Declarative programming is a programming paradigm that encourages that the programming logic describes what the program will do as opposed to how it will do it. Also, you don't define your programming logic in a sequence of steps like you normally would using an imperative style programming. Functional programming is considered declarative programming.

With the imperative programming paradigm, one might do the following to reach a desired state.

In Java (imperative style):
 final SavingsAccount savings = new SavingsAccount(); // Step1 final CheckingAccount checking = new CheckingAccount(); // Step2 savings.setOwner("Bob Jones");
 checking.setOwner("Bob Jones");
 savings.deposit(100);
 checking.deposit(100);
 savings.withdraw(10);
 checking.withdraw(10);
 if ((savings.balance() > 0) || (checkings.balance() > 0)) {     
     sendEmailFromBankYouAreAGreatCustomer(savings, checkings); 
 } 

With the code snippet, it would be difficult to reach the send email function without first calling deposit and calling the set owner routines. The program must be initialized before the developer can really start to perform operations on the savings and checking accounts. Already one can see where problems might arise. The developer might be required to establish the owner name or the user needs to have a non zero account balance. Are the account classes instantiated? It really becomes complicated in programs with thousands of classes and hundreds of thousands of lines of code.

With many personal computers, the instructions are processed in a sequence of steps. Here is a program listing for the x86:
 mov    ah, 09h
 lea    dx, msg
 int    21h
 mov    ax, 4C00h
 int
Programmers are more familiar with computational logic that flows from top to bottom, in a sequence of steps because that is the way that many machines process instructions.

The Java Virtual Machine interprets compiled bytecode and executes those instructions. Here is the javap assembly translation of the Java bytecode of the bank account program:
 public static void main(java.lang.String[]);
  Code:
   Stack=2, Locals=3, Args_size=1
   0:   getstatic   #22; //Field java/lang/System.out:Ljava/io/PrintStream;
   3:   ldc #28; //String Running
   5:   invokevirtual   #30; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
   8:   new #36; //class thepack/ImperativeJavaExample$SavingsAccount
   11:  dup
   12:  invokespecial   #38; //Method thepack/ImperativeJavaExample$SavingsAccount."":()V
   15:  astore_1
   16:  new #39; //class thepack/ImperativeJavaExample$CheckingAccount
   19:  dup
   20:  invokespecial   #41; //Method thepack/ImperativeJavaExample$CheckingAccount."":()V
   23:  astore_2
   24:  aload_1
   25:  ldc #42; //String Bob Jones
   27:  invokevirtual   #44; //Method thepack/ImperativeJavaExample$SavingsAccount.setOwner:(Ljava/lang/String;)V
   30:  aload_2
   31:  ldc #42; //String Bob Jones
   33:  invokevirtual   #47; //Method thepack/ImperativeJavaExample$CheckingAccount.setOwner:(Ljava/lang/String;)V
   36:  aload_1
   37:  bipush  100
   39:  invokevirtual   #48; //Method thepack/ImperativeJavaExample$SavingsAccount.deposit:(I)V
   42:  aload_2
   43:  bipush  100
   45:  invokevirtual   #52; //Method thepack/ImperativeJavaExample$CheckingAccount.deposit:(I)V
   48:  aload_1
   49:  bipush  10
   51:  invokevirtual   #53; //Method thepack/ImperativeJavaExample$SavingsAccount.withdraw:(I)V
   54:  aload_2
   55:  bipush  10
   57:  invokevirtual   #56; //Method thepack/ImperativeJavaExample$CheckingAccount.withdraw:(I)V
   60:  aload_1
   61:  invokevirtual   #57; //Method thepack/ImperativeJavaExample$SavingsAccount.balance:()I
   64:  ifgt    74
   67:  aload_2
   68:  invokevirtual   #61; //Method thepack/ImperativeJavaExample$CheckingAccount.balance:()I
   71:  ifle    79
   74:  aload_1
   75:  aload_2
   76:  invokestatic    #62; //Method sendEmailFromBankYouAreAGreatCustomer:(Lthepack/ImperativeJavaExample$SavingsAccount;Lthepack/ImperativeJavaExample$CheckingAccount;)V
   79:  getstatic   #22; //Field java/lang/System.out:Ljava/io/PrintStream;
   82:  ldc #64; //String Done
   84:  invokevirtual   #30; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
   87:  return

The problem with the imperative paradigm becomes obvious. What happens if the developer doesn't invoke the routines in the right order? Will the program run correctly? Declarative programming, on the other hand, establishes what the program should do. What is required for this program to run correctly? Some parts of HTML are declarative. The HTML syntax describes how parts of the content should appear.
 <html>
   <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
   </head>   
   <body>
       <form action="/processBankAccount">
          <input name="amount" />
          <input type="submit" value="withdraw" />
          <input type="submit" value="deposit" />
       </form>
   </body>
 </html>
 

HTML is a not a Turing complete, general purpose programming language, but it does show an example of a declarative syntax. The HEAD tag declares to the browser to process any meta data, JavaScript or CSS include scripts. The BODY tag declares to the browser to process the BODY of HTML content to display to the user. In the example snippet, the FORM tag contains one input box and two submit button tags. When the user clicks on one of the buttons, the browser will send a request to the server, the URL processBankAccount. The server will respond to the request.

This HTML program does everything that it is expected to in order to give the desired state. All of the tags that we want present are present. Most modern browsers will interpret the head, body, form tags and render the form, input box and two buttons. It doesn't even matter if a server is available or not. As I mentioned with imperative programming, programs are processed from top to bottom. With HTML and with the simple example, if the developer declares one body tag, the browser could process the BODY tag before the HEAD and process from bottom to top.

The SQL SELECT statement is also a declarative syntax for returning data from a database. The query includes the list of columns to be included in the result set returned from the database.
 SELECT (FIELD1, FIELD2) from TABLE2 where FIELD1 = 3
 
 SELECT [column_parameter_listing] FROM [table_listing] WHERE [clause]
 

This Java programming example is written using a declarative approach. HTML was used as the basis for the example.
package org.berlin.basic;

import java.util.HashMap;
import java.util.Map;

/**
 * Declarative Java example based on HTML syntax. This example is intentionally
 * verbose.
 */
public class DeclarativeJavaHTMLExample {

  /**
   * A HTML TAG declaration type.
   */
  public static interface DeclarativeHtmlTag {
    public String contentGeneratedByCodeGenerator();
  }

  /**
   * Syntax validator, ensure that all HTML tags are provided before rendering
   * content.
   */
  public static interface HtmlSyntaxValidator {
    public void defineTag(final String tagName,
        final DeclarativeHtmlTag tag);

    public boolean validate();

    public Map<String, DeclarativeHtmlTag> queryMetaDataTags();
  }

  /**
   * HTML Browser system, this is the end point for our computations. Process
   * program and render output to user.
   */
  public static interface BrowerSystemRendererProgram {
    public String renderAndProcessProgram();
  }

  /**
   * A program loader type, allow developer to define program HTML tags.
   */
  public static interface ComputationLogicLoader {
    public DeclarativeMetaDataDescription loadProgramTags(
        final DeclarativeMetaDataDescription metaDataTargetOfLoad);
  }

  /**
   * A program loader type, allow developer to define program HTML tags. This
   * class is typically where the developer would add most of his logic. The
   * order is not important.
   */
  public static class ProgramLogicLoader implements
      ComputationLogicLoader {

    public DeclarativeMetaDataDescription loadProgramTags(
        final DeclarativeMetaDataDescription metaDataTargetOfLoad) {
      metaDataTargetOfLoad.defineTag("body",
          new DeclarativeHtmlTag() {
            public String contentGeneratedByCodeGenerator() {
              return "&lt;body&gt;DATA&lt;/body&gt;";
            }
          });
      metaDataTargetOfLoad.defineTag("input",
          new DeclarativeHtmlTag() {
            public String contentGeneratedByCodeGenerator() {
              return "&lt;input&gt;&lt;name&gt;account&lt;/name&gt;&lt;/input&gt;";
            }
          });
      metaDataTargetOfLoad.defineTag("form",
          new DeclarativeHtmlTag() {
            public String contentGeneratedByCodeGenerator() {
              return "&lt;form&gt;&lt;action&gt;/processor&lt;/action&gt;&lt;/form&gt;";
            }
          });
      metaDataTargetOfLoad.defineTag("input_submit_withdraw",
          new DeclarativeHtmlTag() {
            public String contentGeneratedByCodeGenerator() {
              return "&lt;input_submit_withdraw&gt;DATA&lt;/input_submit_withdraw&gt;";
            }
          });
      metaDataTargetOfLoad.defineTag("input_submit_deposit",
          new DeclarativeHtmlTag() {
            public String contentGeneratedByCodeGenerator() {
              return "&lt;input_submit_deposit&gt;DATA&lt;/input_submit_deposit&gt;";
            }
          });
      metaDataTargetOfLoad.defineTag("head",
          new DeclarativeHtmlTag() {
            public String contentGeneratedByCodeGenerator() {
              return "&lt;head&gt;RENDER_AS_UTF8&lt;/head&gt;";
            }
          });
      // Oops I want to correct my head tag, added another one      metaDataTargetOfLoad.defineTag("head",
          new DeclarativeHtmlTag() {
            public String contentGeneratedByCodeGenerator() {
              return "&lt;head&gt;RENDER_AS_UTF16&lt;/head&gt;";
            }
          });
      return metaDataTargetOfLoad;
    }
  }

  /**
   * Syntax validator, ensure that all HTML tags are provided before rendering
   * content.
   */
  public static class DeclarativeMetaDataDescription implements
      HtmlSyntaxValidator {
    private Map<String, DeclarativeHtmlTag> metaDataTags = new HashMap<String, DeclarativeHtmlTag>();

    public Map<String, DeclarativeHtmlTag> queryMetaDataTags() {
      return metaDataTags;
    }

    /**
     * Return true if the data contained in meta-data is valid.
     */
    public boolean validate() {
      // Verify that there are six tags      // head, body, form, input, input_submit_withdraw, input_submit_deposit      if (metaDataTags == null) {
        throw new IllegalStateException(
            "Invalid Declarative Requirements - no metadata found");
      }
      // Notice, I am not worried about order here:      if (metaDataTags.get("input") == null) {
        throw new IllegalStateException(
            "Invalid Declarative Requirements - no metadata found, input");
      }
      if (metaDataTags.get("input_submit_withdraw") == null) {
        throw new IllegalStateException(
            "Invalid Declarative Requirements - no metadata found, submit withdraw");
      }
      if (metaDataTags.get("input_submit_deposit") == null) {
        throw new IllegalStateException(
            "Invalid Declarative Requirements - no metadata found, submit deposit");
      }
      if (metaDataTags.get("body") == null) {
        throw new IllegalStateException(
            "Invalid Declarative Requirements - no metadata found, body");
      }
      if (metaDataTags.get("head") == null) {
        throw new IllegalStateException(
            "Invalid Declarative Requirements - no metadata found, head");
      }
      if (metaDataTags.get("form") == null) {
        throw new IllegalStateException(
            "Invalid Declarative Requirements - no metadata found, form");
      }
      return true;
    }

    @Override
    public void defineTag(final String tagName,
        final DeclarativeHtmlTag tag) {
      metaDataTags.put(tagName, tag);
    }
  } // End of class
  /**
   * HTML Browser system, this is the end point for our computations. Process
   * program and render output to user.
   */
  public static class BrowserSystemProcessMetaData implements
      BrowerSystemRendererProgram {
    private DeclarativeMetaDataDescription declarativeMetaData;

    public BrowserSystemProcessMetaData(
        final DeclarativeMetaDataDescription declarativeMetaData) {
      this.declarativeMetaData = declarativeMetaData;
    }

    public String renderAndProcessProgram() {
      declarativeMetaData.validate();
      final StringBuilder buf = new StringBuilder();
      // Render in a specific order, this is somewhat imperative      // because the user expects the rendered output in a particular order but      // that      // is a requirement of the browser not the input program code generator.      buf.append(this.declarativeMetaData.queryMetaDataTags()
          .get("head").contentGeneratedByCodeGenerator());
      buf.append('\n');
      buf.append(this.declarativeMetaData.queryMetaDataTags()
          .get("body").contentGeneratedByCodeGenerator());
      buf.append('\n');
      buf.append(this.declarativeMetaData.queryMetaDataTags()
          .get("form").contentGeneratedByCodeGenerator());
      buf.append('\n');
      buf.append(this.declarativeMetaData.queryMetaDataTags()
          .get("input").contentGeneratedByCodeGenerator());
      buf.append('\n');
      buf.append(this.declarativeMetaData.queryMetaDataTags()
          .get("input_submit_withdraw")
          .contentGeneratedByCodeGenerator());
      buf.append('\n');
      buf.append(this.declarativeMetaData.queryMetaDataTags()
          .get("input_submit_deposit")
          .contentGeneratedByCodeGenerator());
      buf.append('\n');
      return buf.toString();
    }

  } // End of Class //
  /**
   * Imperative Java main entry point, run the program.
   * 
   * @param args
   */
  public static void main(final String[] args) {

    final DeclarativeMetaDataDescription myCoreProgramDefinition = new DeclarativeMetaDataDescription();
    final BrowserSystemProcessMetaData browser = new BrowserSystemProcessMetaData(
        new ProgramLogicLoader()
            .loadProgramTags(myCoreProgramDefinition));
    System.out.println(browser.renderAndProcessProgram());

  }

} // End of the Class //
Output from the Java Renderer Program:

<head>RENDER_AS_UTF16</head>
<body>DATA</body>
<form><action>/processor</action></form>
<input><name>account</name></input>
<input_submit_withdraw>DATA</input_submit_withdraw>
<input_submit_deposit>DATA</input_submit_deposit>

Prolog is a programming considered to be declarative and Erlang is a popular general purpose programming influenced by Prolog.
 
 Factorial in prolog:
 
factorial(0,1). 
factorial(N,F) :-  
   N > 0, 
   N1 is N-1, 
   factorial(N1,F1), 
   F is N * F1.   
   
?-  factorial(3,W).    
 
Factorial in Erlang:

-module(mathFactorial).
-export([factorial/1, area/1]).
    
factorial(0) -> 1;
factorial(N) -> N * factorial(N-1).

factorial(3)
 

How would the system process the Erlang factorial definition? Declarative programming doesn't necessarily acknowledge a sequence of steps but the declared patterns are relevant. In the Erlang example, the function name is defined as well as an input and input pattern, factorial(0) -> 1;

Here is a verbose Java equivalent of the Erlang example. The 'Erlang copy' is at the top, the bottom portion contains the Java parser.
package org.berlin.basic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

/**
 * Declarative Java example based on Erlang syntax. This example is
 * intentionally verbose.
 */
public class DeclarativeJavaToErlangExample {
  /**
   * A program loader type, allow developer to define program lines of Erlang
   * code.
   */
  public static class DefaultErlangComputationLogicLoader implements
      ErlangComputationLogicLoader {
    @Override
    public ErlangProgramMetaData loadProgramTags(
        final ErlangProgramMetaData metaDataTargetOfLoad) {
      metaDataTargetOfLoad
          .defineErlangFunctionDefition("% Program in Erlang")
          .defineErlangFunctionDefition("% ------")
          .defineErlangFunctionDefition("FACT 0 -> 1 xxxxxxxxxxxx")
          .defineErlangFunctionDefition("FACT 1 -> 1 xxxxxxxxxxxx")
          .defineErlangFunctionDefition("FACT 2 -> 2 xxxxxxxxxxxx")
          .defineErlangFunctionDefition("FACT 3 -> 6 xxxxxxxxxxxx")
          .defineErlangFunctionDefition("FACT 4 -> 24 xxxxxxxxxxx")
          .defineErlangFunctionDefition("FACT 5 -> 120 xxxxxxxxxx")
          .defineErlangFunctionDefition("% Run the program")
          .defineErlangFunctionDefition("FACT 5");
      return metaDataTargetOfLoad;
    }
  }

  /**
   * A Line declaration type.
   */
  public static interface DeclarativeErlangLine {
    public String queryErlangLineFunctionName();

    public String queryErlangLineInputPattern();

    public String queryErlangLineOutputPattern();

    public int queryErlangLineNumber();
  }

  /**
   * Program container
   */
  public static interface ErlangProgramMetaData {
    public ErlangProgramMetaData defineErlangFunctionDefition(
        final String declarativeErlangLineOfCode);

    public List<DeclarativeErlangLine> queryLinesOfCode();
  }

  /**
   * A program loader type, allow developer to define program lines of Erlang
   * code.
   */
  public static interface ErlangComputationLogicLoader {
    public ErlangProgramMetaData loadProgramTags(
        final ErlangProgramMetaData metaDataTargetOfLoad);
  }

  /**
   * Erlang parser system, this is the end point for our computations. Process
   * program and render output to user.
   */
  public static interface ErlangSystemParserProgram {
    public String parseAndProcessProgram();
  }

  public static class ErlangProgram implements ErlangProgramMetaData {
    private final List<String> rawInputErlangProgram = new ArrayList<String>();
    private final List<DeclarativeErlangLine> validLinesOfCode = new ArrayList<DeclarativeErlangLine>();
    private int lineNumber = 0;

    public ErlangProgramMetaData defineErlangFunctionDefition(
        final String declarativeErlangLineOfCodeRawIn) {
      final String declarativeErlangLineOfCodeRaw = declarativeErlangLineOfCodeRawIn;
      // Perform parsing of the input, if valid      // add to query lines.      lineNumber++;
      if (declarativeErlangLineOfCodeRaw == null
          || (declarativeErlangLineOfCodeRaw.trim().length() == 0)) {
        // ignore whitespace        return this;
      }
      if (declarativeErlangLineOfCodeRaw.startsWith("%")) {
        return this;
      }
      rawInputErlangProgram.add(declarativeErlangLineOfCodeRaw);
      // FACT 0 -> 1 xxxxxxxxxxxx      // FACT _ -> N * FACT N - 1      // FACT 3      if (declarativeErlangLineOfCodeRaw.length() != 24
          && declarativeErlangLineOfCodeRaw.length() != 6) {
        throw new IllegalStateException("Parser Exception on Line:"
            + lineNumber
            + ", invalid line length(expecting 24), invalidLen="
            + declarativeErlangLineOfCodeRaw.length());
      }
      if (declarativeErlangLineOfCodeRaw.length() == 6) {
        // Run program        final int resLineNumber = lineNumber;
        validLinesOfCode.add(new DeclarativeErlangLine() {
          public String queryErlangLineFunctionName() {
            return declarativeErlangLineOfCodeRaw.toUpperCase()
                .substring(0, 4);
          }

          public String queryErlangLineInputPattern() {
            return declarativeErlangLineOfCodeRaw.toUpperCase()
                .substring(5, 6);
          }

          public String queryErlangLineOutputPattern() {
            return null;
          }

          public int queryErlangLineNumber() {
            return resLineNumber;
          }
        });
        return this;
      }
      // For the output, we don't care, just extract the last part      validLinesOfCode.add(new DeclarativeErlangLine() {
        final int resLineNumber = lineNumber;

        public String queryErlangLineFunctionName() {
          return declarativeErlangLineOfCodeRaw.toUpperCase()
              .substring(0, 4);
        }

        public String queryErlangLineInputPattern() {
          return declarativeErlangLineOfCodeRaw.toUpperCase()
              .substring(5, 6);
        }

        public String queryErlangLineOutputPattern() {
          return declarativeErlangLineOfCodeRaw.toUpperCase()
              .substring(8);
        }

        public int queryErlangLineNumber() {
          return resLineNumber;
        }
      });
      return this;
    }

    @Override
    public List<DeclarativeErlangLine> queryLinesOfCode() {
      return validLinesOfCode;
    }
  }

  public static class DefaultErlangSystemParserProgram implements
      ErlangSystemParserProgram {
    private ErlangProgramMetaData declarativeProgramMetaData;

    public DefaultErlangSystemParserProgram(
        final ErlangProgramMetaData declarativeMetaData) {
      this.declarativeProgramMetaData = declarativeMetaData;
    }

    /**
     * Parse the developer created data program.
     */
    public String parseAndProcessProgram() {
      // parser designed for factorial      final Map<String, DeclarativeErlangLine> program = new HashMap<String, DeclarativeErlangLine>();
      final Stack<DeclarativeErlangLine> runLineCache = new Stack<DeclarativeErlangLine>();
      final class AllowForRecursiveFunc {
        public int lookupAndParse(final String function,
            final String input) {
          // try to find function and input          final int inval = Integer.parseInt(input);
          final String lookupKeyCheck = "[" + function.toUpperCase()
              + " " + input + "]";
          final String lookupKeyCheckForOne = "["
              + function.toUpperCase() + " 1]";
          if (inval <= 0) {
            final DeclarativeErlangLine processLineRunLookup = program
                .get(lookupKeyCheckForOne);
            System.out
                .println("*SYS-OUT* {reached min input} pattern-match output = "
                    + processLineRunLookup
                        .queryErlangLineOutputPattern()
                    + " matches N = "
                    + inval
                    + " at line "
                    + processLineRunLookup.queryErlangLineNumber());
            return 1;
          } else {
            final DeclarativeErlangLine processLineRunLookup = program
                .get(lookupKeyCheck);
            if (processLineRunLookup != null) {
              System.out.println("*SYS-OUT* pattern-match output = "
                  + processLineRunLookup
                      .queryErlangLineOutputPattern()
                  + " matches N = " + inval + " at line "
                  + processLineRunLookup.queryErlangLineNumber());
              final int lastInput = lookupAndParse(function,
                  String.valueOf(inval - 1));
              return lastInput;
            }
          }
          return inval;
        }
      } // End of class      for (final DeclarativeErlangLine erlang : declarativeProgramMetaData
          .queryLinesOfCode()) {
        final String key = "[" + erlang.queryErlangLineFunctionName()
            + " " + erlang.queryErlangLineInputPattern() + "]";
        if (erlang.queryErlangLineOutputPattern() == null) {
          // Execute line          runLineCache.push(erlang);
        } else {
          program.put(key, erlang);
        }
      }
      // Run the run line caches      while (!runLineCache.isEmpty()) {
        final DeclarativeErlangLine processLineRunLookup = runLineCache
            .pop();
        System.out.println("*SYS-OUT* Parsing runLine : function="
            + processLineRunLookup.queryErlangLineFunctionName()
            + " inputParm="
            + processLineRunLookup.queryErlangLineInputPattern());
        new AllowForRecursiveFunc().lookupAndParse(
            processLineRunLookup.queryErlangLineFunctionName(),
            processLineRunLookup.queryErlangLineInputPattern());
      }
      return "";
    }
  }

  /**
   * Imperative Java main entry point, run the program.
   * 
   * @param args
   */
  public static void main(final String[] args) {
    final ErlangProgramMetaData myCoreProgramDefinition = new ErlangProgram();
    System.out.println(new DefaultErlangSystemParserProgram(
        new DefaultErlangComputationLogicLoader()
            .loadProgramTags(myCoreProgramDefinition))
        .parseAndProcessProgram());
  }

} // End of class //
Output from the Factorial Erlang Java Application:
*SYS-OUT* Parsing runLine : function=FACT inputParm=5
*SYS-OUT* pattern-match output = > 120 XXXXXXXXXX matches N = 5 at line 8
*SYS-OUT* pattern-match output = > 24 XXXXXXXXXXX matches N = 4 at line 7
*SYS-OUT* pattern-match output = > 6 XXXXXXXXXXXX matches N = 3 at line 6
*SYS-OUT* pattern-match output = > 2 XXXXXXXXXXXX matches N = 2 at line 5
*SYS-OUT* pattern-match output = > 1 XXXXXXXXXXXX matches N = 1 at line 4
*SYS-OUT* {reached min input} pattern-match output = > 1 XXXXXXXXXXXX matches N = 0 at line 4

Summary
For the most part, most popular programming languages are not entirely declarative or imperative. A developer may use an approach that is declarative or imperative in nature using most of the mainstream languages. But there is still no absolute guarantee that declarative programming is free of unexpected behavior. Take a harmless HTML page, let's say you copy-paste an action URL that contains UTF32 encoding in a HTML document that expects UTF8. Will the HTML FORM operate correctly? Or, what if you provide an action URL in your HTML FORM that is too long for the particular browser that the user is working with. The input HTML declaration might be correct but the browser could not parse the document correctly. This brings up one issue with declarative syntax, if the program is correct based on the language specification, it is possible that the magic behind the implementing system is incorrect or not consistent with the specification.

Resources:

http://en.wikipedia.org/wiki/Lambda_calculus

Why Haskell?