~c[7] & (~c[6] & (c[5] & (c[4] & (~c[3] | (~c[2] & ~c[1])))))
Arranging the operators into a tree (colon (:) represents a wire since pipe (|) is logical or),
c[7] 6 5 4 3 2 1 0 ~ ~ : : ~ ~ ~ : & : : : & & : | & : &
My thought based on this is to insert “input lead” tokens into the tree which receive the values of the input bit assigned in a left-to-right manner. And I also need a ground or sink to explicitly ignore certain inputs (like c[0] above). This leads me to make NOT (~) a binary operator which negates the left input and simply absorbs right input. And in the course of trying this, I also realized the necessity for a ZERO token to build masks (and to provide dummy input for NOTs). So the new set is: &(and) |(or) ^(xor) ~(not x, sink y) 0(zero) I(input) So the tree becomes (flipping up for down)
^ & & & | I 0 & I ~ & & I I 0 ~ ~ ~ ~ I 0 I 0 I 0 I 0 = = = = = = = = 7 6 5 4 3 2 1 0
Which encodes into the array (skipping the “forest<=>tree” part, “_” represents a blank)
_ ^ & & & | I 0 & I ~ & _ _ _ _ & I _ _ I 0 ~ ~ _ _ _ _ _ _ _ _ ~ ~ _ _ _ _ _ _ _ _ _ _ I 0 I 0 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ I 0 I 0
The tree->array encoding always put the root in array(1) so with zero-indexed array, there’s a convenient blank at the beginning that could be used for linkage, I think. With only 6 operators, I suppose it could be encoded in octal. By packing a forest of trees, we could represent a chain of acceptors each applied on the next input depending on the result of the previous.
Asked By : luser droog
Answered By : Dave Clarke
- What kinds of computation are you trying to perform?
- How can these computations be composed?
- How can the results of these computations be stored? How can they be used in subsequent computations?
- How can I represent this syntactically?
- Does my chosen syntax have a clear denotational meaning? Or clear operational meaning?
- Do my syntactic constructs compose nicely? Are they sufficiently orthogonal and free from arbitrary constraints?
- Can I modularise computations in my language?
- What forms of abstraction does my language offer?
There are a number of places you could use as a starting point:
- The imperative language WHILE — a simple language with variables, assignment, sequencing, if statements, and while statements. Maybe later add procedures.
- The lambda calculus.
- Combinatorial logic. Programs consist of combinators which are plugged together. No variables.
- Something like Prolog or Datalog.
Or you could be completely wild and ignore these and see how far you get (which could result in something interesting).
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/4618