Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.alpha.net!uwm.edu!cs.utexas.edu!news.sprintlink.net!EU.net!sun4nl!freya.let.rug.nl!vannoord
From: vannoord@let.rug.nl (Gertjan van Noord)
Subject: finite-state automata operations in Prolog (ANNOUNCE)
Sender: news@let.rug.nl (News system at let.rug.nl)
Message-ID: <1995Mar16.130944.22507@let.rug.nl>
Date: Thu, 16 Mar 1995 13:09:44 GMT
Nntp-Posting-Host: saga.let.rug.nl
Organization: Faculteit der Letteren, Rijksuniversiteit Groningen, NL
Lines: 130

ANNOUNCE: FSA utilities (version 0.1)

A few weeks ago there was some discussion whether or not finite
state automaton operations (intersection, determinization, minimalization,
intersection..) could be efficiently implemented in Prolog.
Fernando Pereira doubted this; although some others were less pessimistic.

I don't have an opinion, but merely tried to implement a few of these
things to see what can be done (and mostly as an exercise for myself).
If you're interested, you can get the package from ftp.let.rug.nl in
directory pub/prolog-app/FSA.

The package is implemented in SICStus Prolog, but it should not be
too difficult to adapt it to other Prologs. Upon installation of the
package a Prolog saved state is built that can be used either as an
interactive shell (as usual) or as a Unix filter. 

Generally, a fsa is represented by a Prolog program defining the
relations 
	start(StateName). 
	final(StateName).
	trans(StateName,Symbol,StateName).
	jump(StateName,StateName).

The man page is included below:

 FSA(Utilities)                                               FSA(Utilities)




 NAME
      fsa - various utilities to manipulate finite state automata

 SYNOPSIS
      fsa [-a Words] [-c] [-d] [-da] [-dr] [-g] [-i file file] [-m] [-n] [-r
      [RegExpr]] [-t] [-v]

 DESCRIPTION
      The fsa program can be used to manipulate fsa automata. The options
      indicate which manipulation (determinization, intersection, etc.) is
      chosen. If no options are given, the program acts as an interpreter,
      using the SICStus Prolog top-level.

 OPTIONS
      fsa accepts the following options:

      -a Words
              A finite state automaton is read from standard input (either
              in compiled or interpreted mode, cf. below). The program
              determines whether Words is accepted by this automaton or not.
              If it is, the program returns succesfully, otherwise it exits
              with 1.

      -c      Compile a fsa automaton into a set of Prolog clauses. Standard
              input consists of the fsa automaton to be compiled. The
              compiled clauses are written to standard output.

      -d      Determinize a finite state automaton. Standard input consists
              of the fsa automaton to be compiled. The determinized FSA is
              written to standard output.

      -da     To the deterministic finite state automaton (read from
              standard input) transitions are added such that there will be
              a transition for each symbol and each state.

      -dr     From the finite state automaton (read from standard input) all
              transitions are removed that cannot possibly be continued to a
              final state.

      -g      An arbitrary finite state automaton is written to standard
              output.

      -i File File
              The two files are assumed to contain finite state automata.
              The intersection is written to standard output.

      -m      The finite state automaton (read from standard input) is
              minimalized.  The result is written to standard output.

      -n      A finite state automaton is read from standard input. An
              equivalent one is written to standard output, but all state
              names are of the form qi, where i is an integer. This is
              useful to simplify complicated state names that result from
              various other manipulations.

      -r [RegExp]
              A regular expression (either RegExp, or read from standard
              input) is translated into an equivalent FSA. This FSA is
              written to standard output.

      -t      A binary relation is read in from standard input. The
              transitive closure of that relation is written to standard
              output.

      -v      Indicate verbosity. All of the above options can be combined
              with this option. More informative output is written to
              standard error.

 EXAMPLES
      If the file t1.nd consists of a definition of a non-deterministic
      finite state automaton, then the following computes the deterministic
      equivalent, and writes it to t1.d:

      fsa -d < t1.nd > t2.nd

      More complex examples:

      fsa -m < t1.nd | fsa -n | fsa -c > t1.pl

      fsa -a a a a < t1.pl

      fsa -a a a a < t1.nd

      fsa -i d2.nd d3.nd | fsa -c | fsa -a a a a a a a

      fsa -t < p.pl

      fsa -g | fsa -m | fsa -n


 COPYRIGHT
      Copyright c 1995 by Gertjan van Noord.

 AUTHOR
      Gertjan van Noord, vannoord@let.rug.nl, Comments welcome.

 BUGS
      Probably a lot. This has not been extensively tested yet..

