Skip to content

HexMerlin/Automata

Repository files navigation

🔂 Automata: A Lightweight Library for Finite-State Automata

NuGet Version Automata.Core - Core library (zero-dependency library, optimal if you do not need visualization).

NuGet Version Automata.Visualization - Full library that also includes visualization and rendering of automata.

Documentation Documentation


The Automata library provides functionality for working with finite-state automata. The library is highly optimized and ideal for very large automata.

⭐ Example Features:

  • Create automata from regular expressions, sequences, or other data.
  • Convert NFAs to DFAs.
  • Minimize Automata to their optimal minimal representation.
  • Provides Alang (Automata Language) as an option for defining and creating automata.
  • Perform many operations on automata (union, intersection, difference, complement, etc.).
  • Visualize automata as graphs (Automata.Visualization).

Example image

🔨 Automata.Core - Core Library

The core library all provides essential tools for finite-state automata operations. It offers a fast, lightweight and clean solution without visualization features.

💡 C# Example: Create and Operate on Automata

The following example utilizes regular expressions written in Alang. Alang (Automata Language) is a language for defining automata using regular operations. Read more about Alang in the Automata documentation.

// Compile a regex to a FSA (all sequences of {a, b, c} where any 'a' must be followed by 'b' or 'c')
var fsa = AlangRegex.Compile("(a? (b | c) )+");

// Compile two other automata
var test1 = AlangRegex.Compile("a b b c b");
var test2 = AlangRegex.Compile("a b a a b");

// Test the language overlap of the FSA with the two test regexes
Console.WriteLine(fsa.Overlaps(test1)); //output: true
Console.WriteLine(fsa.Overlaps(test2)); //output: false

🖼️ Automata.Visualization: Automata.Core + Visualization

The Automata.Visualization library extends the core Automata functionality with visualization capabilities, utilizing MSAGL (Microsoft Automatic Graph Library) for layout.

🔑 Key Features:

  • All Automata.Core functionality.
  • Visualize automata as graphs.

💡 C# Full Example Program: Create an Automaton and Display it from a Console Application

var fsa = AlangRegex.Compile("(a? (b | c) )+");  // Create an FSA from a regex

Console.WriteLine("Creating a minimal FSA and displaying it."); // Write some info to the console

Graph graph = fsa.CreateGraph(displayStateIDs: true); // Create a graph object (FSA with layout) 

GraphView graphView = GraphView.OpenNew(graph); // Open a new non-modal window that displays the graph

Console.WriteLine("FSA is displayed."); // Write some info to the console


📦 NuGet Package Installation

Install the packages via the .NET CLI or Package Manager in Visual Studio.

Automata.Core

dotnet add package Automata.Core

Automata.Visualization (Includes Automata.Core)

dotnet add package Automata.Visualization

💻 Target Framework Compatibility

  • Automata.Core: .NET 9.0 and later
  • Automata.Visualization: .NET 9.0 and later
    • Requires Windows compile target <TargetFramework>net9.0-windows</TargetFramework>

🔗 Dependencies

  • Automata.Core:

    • None
  • Automata.Visualization:

📜 License

This project is licensed under the MIT License.

👌 Credits

This repository uses the following libraries and tools: