Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A proof illustrating Kleene’s theorem: a language is regular if it can be represented by a finite automaton or a regular expression.

NotificationsYou must be signed in to change notification settings

shinbatsu/kleene-theorem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This module implements a Nondeterministic Finite Automaton (NFA) in Haskell, following the concepts of automata theory and based on Kleene’s Theorem, which asserts the equivalence of regular expressions and NFAs.

📚 Overview

An NFA is a computational model used to recognize regular languages. This implementation supports:

  • Creation of an NFA with states and transitions
  • Input simulation and state transitions
  • Final state verification
  • Transition table printing

🔧 Data Types

type State = Int

An alias for state identifiers.

type Symbol = String

An alias for input symbols.

type TransitionInput = (State, Symbol)

Defines the key for the transition function: a state and an input symbol.

type DestStates = Set State

The set of destination states for a given transition.

data NFA

dataNFA=NFA{initState::State,currentStates::SetState,totalStates::SetState,finalStates::SetState,transitions::MapTransitionInputDestStates,inputAlphabet::SetSymbol}

📦 NFA Structure

Represents the NFA structure with:

  • initState: The starting state
  • currentStates: The current active states
  • totalStates: All defined states
  • finalStates: The set of accepting states
  • transitions: A map of transitions
  • inputAlphabet: All used input symbols

🛠️ Functions

newNFA :: State -> Bool -> NFA

Creates a new NFA with an initial state. Optionally marks it as final.

addState :: State -> Bool -> NFA -> NFA

Adds a new state to the NFA and optionally marks it as final. Ignores the dead state-1.

addTransition :: State -> Symbol -> [State] -> NFA -> NFA

Adds a transition from a source state to a list of destination states on a given input symbol.

inputSymbol :: Symbol -> NFA -> NFA

Consumes an input symbol and updates the current active states based on the transition function.

verify :: NFA -> Bool

Checks whether any of the current states is a final state (i.e., the input string is accepted so far).

resetNFA :: NFA -> NFA

Resets the NFA to its initial state. All transitions and states remain unchanged.

verifyInputs :: [Symbol] -> NFA -> Bool

Simulates the NFA over a sequence of input symbols and returnsTrue if the final state is accepting.

printTransitionTable :: NFA -> IO ()

Prints the transition table to the console in a readable format.


🧠 Theoretical Context

According toKleene’s Theorem, regular expressions, DFAs, and NFAs are equivalent in expressive power. This implementation enables one to:

  • Construct an NFA from state/transition rules
  • Evaluate input sequences
  • Eventually transform the NFA into a regular expression (GNFA-based algorithms not included here)

About

A proof illustrating Kleene’s theorem: a language is regular if it can be represented by a finite automaton or a regular expression.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp