automata in ocaml -


i bit new ocaml. want implement product construction algorithm automata in ocaml. confused how represent automata in ocaml. can me?

a clean representation finite deterministic automaton be:

type ('state,'letter) automaton = {   initial    : 'state ;   final      : 'state -> bool ;   transition : 'letter -> 'state -> 'state ; } 

for instance, automaton determines whether word contains odd number of 'a' represented such:

let odd = {   initial    = `even ;    final      = (function `odd -> true | _ -> false) ;   transition = (function      | 'a' -> (function `even -> `odd | `odd -> `even)     |  _  -> (fun state -> state)) } 

another example automation accepts onlythe string "bbb" (yes, these taken this online handout) :

let bbb = {   initial = `b0 ;   final   = (function `b3 -> true | _ -> false) ;   transition = (function      | 'b' -> (function `b0 -> `b1 | `b1 -> `b2 | `b2 -> `b3 | _ -> `fail)     |  _  -> (fun _ -> `fail)) } 

automaton product described mathematically using cartesian product of state sets new sets, , natural extensions of final , transition functions on set:

let product b = {   initial = (a.initial, b.initial) ;   final   = (fun (x,y) -> a.final x && b.final y) ;   transition = (fun c (x,y) -> (a.transition c x, b.transition c y) } 

this product automaton computes intersection of 2 languages. can use || in lieu of && implement union of 2 languages.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -