Class Mfa
Minimal Finite-state Automaton (MFA).
Implements
Inherited Members
Namespace: Automata.Core
Assembly: Automata.Core.dll
Syntax
public class Mfa : FsaDet, IEquatable<Mfa>
Remarks
Mfa is the most optimized automaton representation, characterized by:
DeterministicandMinimal: The least possible states and transitions.- Minimal memory footprint: Uses a contiguous memory block for data, with minimal overhead.
- Performance-optimized for efficient readonly operations.
- Immutable: Guarantees structural and behavioral invariance.
- Contiguous states: States are in range [0..MaxState].
- Initial state is always
0for a non-empty Mfa. - Canonical topology: States and transitions are canonically ordered.
- Two Mfas recognizing the same language are guaranteed to be identical.
Constructors
| Edit this page View SourceMfa(Dfa)
Declaration
public Mfa(Dfa dfa)
Parameters
| Type | Name | Description |
|---|---|---|
| Dfa | dfa | A DFA to create from. |
Mfa(string, Alphabet)
Creates a singleton Mfa that accepts only the single symbol once.
Declaration
public Mfa(string singleSymbol, Alphabet alphabet)
Parameters
| Type | Name | Description |
|---|---|---|
| string | singleSymbol | Symbol to be accepted by the MFA. |
| Alphabet | alphabet | Alphabet used by the MFA. |
Properties
| Edit this page View SourceFinalStates
Final states of the MFA.
Declaration
public override IReadOnlyCollection<int> FinalStates { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyCollection<int> |
Overrides
| Edit this page View SourceInitialState
Initial state. Always 0 for a non-empty Mfa.
For an empty Mfa, the initial state is InvalidState.
Declaration
public override int InitialState { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Remarks
An MFA without an initial state is completely empty (= IsEmptyLanguage).
IsEmptyLanguage
Indicates whether the language of the MFA is the empty language (∅). This means the MFA does not accept anything, including the empty string (ϵ).
Declaration
public bool IsEmptyLanguage { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Returns true only if either; the MFA has no states.
MaxState
The state number with the highest value.
Declaration
public override int MaxState { get; }
Property Value
| Type | Description |
|---|---|
| int | The maximum state number, or InvalidState (= |
Overrides
| Edit this page View SourceStateCount
Number of states in the MFA.
Declaration
public int StateCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
StateRange
Range covering all states in the automaton.
Declaration
public override Range StateRange { get; }
Property Value
| Type | Description |
|---|---|
| Range |
Overrides
Remarks
States are contiguous without gaps; all states lie within this range. The exclusive End equals both StateCount and the next unused state ID.
For non-empty automata: StateRange = [0, StateCount).
For empty automata: StateRange = [−1, −1).
TransitionCount
Number of transitions in the automaton.
Declaration
public override int TransitionCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
| Edit this page View SourceCreateEmpty(Alphabet)
Creates a Mfa that represents the empty language (∅), with a specified alphabet. The MFA has zero states and zero transitions.
Declaration
public static Mfa CreateEmpty(Alphabet alphabet)
Parameters
| Type | Name | Description |
|---|---|---|
| Alphabet | alphabet | Alphabet used by the MFA. |
Returns
| Type | Description |
|---|---|
| Mfa |
CreateEpsilonAccepting(Alphabet)
Creates a Mfa that represents the language {ϵ}, with a specified alphabet.
The MFA has a single initial, final state and zero transitions.
Declaration
public static Mfa CreateEpsilonAccepting(Alphabet alphabet)
Parameters
| Type | Name | Description |
|---|---|---|
| Alphabet | alphabet | Alphabet used by the MFA. |
Returns
| Type | Description |
|---|---|
| Mfa |
CreateWildcard(Alphabet)
Returns an automaton that accepts one occurrence of any symbol in the specified alphabet. It corresponds directly to the "." in Alang expressions.
Declaration
public static Mfa CreateWildcard(Alphabet alphabet)
Parameters
| Type | Name | Description |
|---|---|---|
| Alphabet | alphabet | Alphabet containing the set of symbols |
Returns
| Type | Description |
|---|---|
| Mfa | An automaton representing any symbol accepted exactly once. |
Equals(Mfa?)
Indicates whether this MFA is equal to the specified MFA.
Declaration
public bool Equals(Mfa? other)
Parameters
| Type | Name | Description |
|---|---|---|
| Mfa | other | MFA to compare with. |
Returns
| Type | Description |
|---|---|
| bool | true
|
Remarks
This method is similar to LanguageEquals(Mfa) but is stricter:
It also requires the alphabets of both MFAs to be equal (not just the referenced symbols).
See Also
| Edit this page View SourceEquals(object?)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current object. |
Returns
| Type | Description |
|---|---|
| bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
| Edit this page View SourceGetHashCode()
Hash code for the current MFA.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code for the MFA. |
Overrides
| Edit this page View SourceIsFinal(int)
Indicates whether the specified state is a final state.
Declaration
public override bool IsFinal(int state)
Parameters
| Type | Name | Description |
|---|---|---|
| int | state | State to check. |
Returns
| Type | Description |
|---|---|
| bool | true
|
Overrides
| Edit this page View SourceLanguageEquals(Mfa)
Indicates whether this MFA represent the exact same language as the specified MFA: Language Equality.
Declaration
public bool LanguageEquals(Mfa other)
Parameters
| Type | Name | Description |
|---|---|---|
| Mfa | other | MFA to check language equality against. |
Returns
| Type | Description |
|---|---|
| bool | true
|
Remarks
Language Equality means both MFAs represent the same language. Due to the canonical property, Language Equality also means the MFAs are completely identical (identical states, and identical transition arrays).
The alphabets need however not need to be equal, but every referenced symbol must have the same index in both alphabets.
State(int)
Returns a view of the specified state.
Declaration
public override StateView State(int fromState)
Parameters
| Type | Name | Description |
|---|---|---|
| int | fromState | The state origin. |
Returns
| Type | Description |
|---|---|
| StateView | A StateView for the given state. |
Overrides
| Edit this page View SourceToCanonicalString()
Returns a canonical string representation of the MFA's data. Used by unit tests and for debugging.
Declaration
public override string ToCanonicalString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Examples
Canonical string for a 2-state MFA, with 2 states, 2 transitions and 1 final state, that accepts the language {a | b}:
S#=2, F#=1: [1]: T#=2: [0->1 a, 0->1 b]
|
Edit this page
View Source
Transition(int, int)
Returns the state reachable from the given state on the given symbol.
Declaration
public override int Transition(int fromState, int symbol)
Parameters
| Type | Name | Description |
|---|---|---|
| int | fromState | The state origin of the transition. |
| int | symbol | Symbol for the transition. |
Returns
| Type | Description |
|---|---|
| int | The state reachable from the given state on the given symbol. If no such transition exists, InvalidState is returned. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
See Also
Transitions()
Gets the transitions of the MFA.
Declaration
public override IReadOnlyCollection<Transition> Transitions()
Returns
| Type | Description |
|---|---|
| IReadOnlyCollection<Transition> | An collection of transitions. |
Overrides
Operators
| Edit this page View Sourceoperator ==(Mfa, Mfa)
Indicates whether two specified instances of Mfa are equal.
Declaration
public static bool operator ==(Mfa left, Mfa right)
Parameters
| Type | Name | Description |
|---|---|---|
| Mfa | left | First Mfa to compare. |
| Mfa | right | Second Mfa to compare. |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(Mfa, Mfa)
Indicates whether two specified instances of Mfa are not equal.
Declaration
public static bool operator !=(Mfa left, Mfa right)
Parameters
| Type | Name | Description |
|---|---|---|
| Mfa | left | First Mfa to compare. |
| Mfa | right | Second Mfa to compare. |
Returns
| Type | Description |
|---|---|
| bool |