Coder Social home page Coder Social logo

deterministic.finite.automata's Introduction

Deterministic Finite Automata (DFA) implementation

  • DFA refers to deterministic finite automata. Deterministic refers to the uniqueness of the computation. The finite automata are called deterministic finite automata if the machine is read an input string one symbol at a time.

  • In DFA, there is only one path for specific input from the current state to the next state.

  • DFA does not accept the null move, i.e., the DFA cannot change state without any input character.

  • DFA can contain multiple final states. It is used in Lexical Analysis in Compiler.

A DFA is a collection of 5-tuples same as we described in the definition of FA.

Q: finite set of states
∑: finite set of the input symbol
δ: Transition function
Q0: initial state
F: final state

Transition function can be defined as:

δ: Q x ∑→Q

Usage

Example L(M) = {x | x is in {0, 1}* which when interpreted as binary it is divisible by 3}

dfa-for-L-of-M

from rebuni import DFA


STATES = (0, 1, 2)
SYMBOLS = ("0", "1")
TRANSITIONS = {0: {"0": 0, "1": 1}, 1: {"0": 2, "1": 0}, 2: {"0": 1, "1": 2}}

dfa = DFA(
    STATES,
    SYMBOLS,
    transition_function=TRANSITIONS,
    intial_state=0,
    final_states=0,
)
fails = 0

for number in range(10000): # Test using the first 10000 natural number
    number_binary = bin(number).lstrip('0b')
    checker = (number % 3 == 0)
    if dfa.check_state(number_binary) != checker:
        fails += 1
print(f'{fails} Fails')

Thank You!

deterministic.finite.automata's People

Contributors

ashebir07 avatar wendirad avatar

Stargazers

Getabalew Temesgen avatar  avatar  avatar

Forkers

esraeldawit-a

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.