Re: [Caml-list] From a recursive circuit to a functional/recursive OCaml-code...

On Sun, Feb 05, 2006 at 04:42:47PM +1100, skaller wrote:
> On Sun, 2006-02-05 at 05:16 +0100, Oliver Bandel wrote:
>
> > But I'm not clear about how to write this function "f",
> > because it needs mutual recursion...
>
> No it doesn't, not even with feedback, because your
> system is CLOCKED.
OK, a clocked circuit.
But in the non-trivial machine example,
not all operators are clocked.
The hint with the clock is good, HvF has not
expplicitly mentioned, which thing is cloecked
in the block diagram.
But I think it is funcion_C (the "C" in the picture),
because it is round and the other operators are in square.
And this is the only part, which can be critical, because of the
feedback.
Maybe this (a cirlce) is american (and maybe old) notation of a clocked thingy?
When looking at circuits I would have seen different symbols than
squares and cirlces.
I programmed a version with a record-type and got different
results than I found in a paper about the non-trivial machine (NTM).
So there may be a problem of wrong timing, so that my program
does not the same as it was meant by the block diagram of the
circuit.
[...]
> Basically .. you're asking hard questions about how
> to design synchronous circuits. Don't expect a clocked
> circuit to just be a simple composition of functions.
Well... IMHO the problem here is, when which function get's
which value. If it is time n -1, n or n+1 ?!
> The functions get very complicated -- otherwise circuit
> designers wouldn't have a job :)
Well, I doubt that for the simple NTM the functions
will get too complicated.
Here follows my implementation of the NTM, but it creates
different results than I saw in examples in papers,
so it seems the initial state is not there at the correct time.
So I have to rewrite the code.
Or I should use explicit timing, using specialized functions
or so...?!
(* ============================================================= *)
type state_t = { st_e: int option; st_u: int option }
let function_A x1 x2 = x1 + x2
let rec function_B x e = x + e
let function_C u = u + 3
let initialize() = 0 (* initial value, could also be a ransom value... :) *)
let initial_state () = { st_e = None; st_u = None }
let get_e state = match state.st_e with Some x -> x | _ -> initialize()
let get_u state = match state.st_u with Some x -> x | _ -> initialize()
let _ =
let rec calc state =
let inval = int_of_string (read_line())
in
let u = function_B inval (get_e state)
and e = function_C (get_u state)
and outval = function_A inval (get_e state)
in
Printf.printf "%d => %d \t e: %d u: %d \n" inval outval e u;
calc { st_u = Some u; st_e = Some e }
in
calc (initial_state2()) (* yes, I like this recursive style: I can set starting state here. :) *)
(* ============================================================= *)
Ciao,
Oliver