(* 

   Non-Trivial Machine (NTM) following Heinz von Foersters paper 
   
   "Prinzipien der Selbstorganisation im sozialen und
    betriebswirtschaftlichen Bereich"
      (Hvf: Wissen und Gewissen, Ffm 1993)
   
   (title of the english vesrion: "Principles of Self-Organization in Socio-Managerial Context")

   -----------------------------------------------------------
   geschrieben von Oliver Bandel, am 05.02.2006 und 06.02.2006
   -----------------------------------------------------------
*)


type state_t = First | Second

(* two TM's here, which are calculating simply   *)
(* the output out of the input by mapping values *)
let f_1 input = match input with
     "A" -> "0"
   | "U" -> "1"
   | "S" -> "1"
   | "T" -> "0"
   | _ -> raise Not_found

let f_2 input = match input with
     "A" -> "1"
   | "U" -> "0"
   | "S" -> "0"
   | "T" -> "1"
   | _ -> raise Not_found



(* this is for calculating the next internal state *)
(* out of the input data and the internal state    *)
(* that is now active.                             *)
let z_calc input z = match (input,z) with
     ("A", First)  -> First
   | ("U", First)  -> First
   | ("S", First)  -> Second
   | ("T", First)  -> Second

   | ("A", Second) -> First
   | ("U", Second) -> Second
   | ("S", Second) -> First
   | ("T", Second) -> Second
   | _ -> raise Not_found



(* calculating the result by calling the correct TM *)
let calculating inval state =
      match  (inval, state) with
        (x,First)  -> f_1 x
      | (x,Second) -> f_2 x




(* here the calculations of the output will be done *)
(* maybe calling other functions that do the work,  *)
(* this here is for the timing/toggling-structure of*)
(* the program *)
let rec calc inval state =
   let result = calculating inval state
   in
     Printf.printf "%s => %s\n" inval result;
     update inval state

(* here the update of the internal state as well as reading new input will be done *)
(* maybe calling other functions that do the work,  *)
(* this here is for the timing/toggling-structure of*)
(* the program *)
and update inval state =
  (* calc    newdata       newstate          *)
     calc (read_line()) (z_calc inval state)



(* Main-Part of the program *)
let _ = calc (read_line()) First


This document was generated using caml2html