Code Monkey home page Code Monkey logo

Comments (3)

Aunsiels avatar Aunsiels commented on June 9, 2024

The transformation to normal form does not work when the language generates epsilon. I will write a warning about it. In this case, it normalise the language without epsilon.

I checked several sources about it, and it seems that the article on Wikipedia about the normal form is not correct. Then, the error propagated. It refers to Hopcroft's textbook introduction to automata theory languages and computation, but the definition is not the same. The original is what is called Chomsky reduced form on Wikipedia. I suggest you read Hopcroft's chapter about it and make your own opinion. I also checked Chomsky original paper, but the notation are too different from what we use now. So it is hard to conclude what really is Chomsky normal form. Generally, Hopcroft is the reference.

If you have another source, I take it. However, as most algorithms are from Hopcroft's book, changing the normal form might have impacts at other places.

from pyformlang.

gsvgit avatar gsvgit commented on June 9, 2024

Hello. @Aunsiels I guess you may be confused the way used for this transformation description. For example, look at the Parsing Techniques by Dick Grune (https://www.google.com/url?sa=t&source=web&rct=j&url=https://dickgrune.com/Books/PTAPG_1st_Edition/BookBody.pdf&ved=2ahUKEwjA05SloIbsAhXSl4sKHc9xBu0QFjAEegQIAhAB&usg=AOvVaw1rCCDoN8wpDI9548A_y3M6) In the section section 4.2.3 which describes transformation to CNF, you can see a step for epsilon rules elimination. But look into section 4.2.3.1 carefully (this section describes details of epsilon rules elimination). Here you can see, that in order to preserve the language the rule s->eps may be required. So, I think that @viabzalov is right. Moreover, main property of any grammar normalization (including CNF and gnf) is language preservation.

from pyformlang.

Aunsiels avatar Aunsiels commented on June 9, 2024

Hi! Thank you for this additional source. I read it and it confirms my saying. For the book:

Two of the restrictions that we want to impose on the grammar are obvious by now: no
unit rules and no ε-rules.[...] A grammar is in Chomsky Normal Form (CNF), when all rules either have the form A→a, or A→BC, where a is a terminal and A, B, and C are non-terminals. [...] There are no ε-rules in a CNF grammar

For this definition and all formal proofs, they cite Hopcroft and Ullman. Under these conditions, the language cannot generate epsilon anyway. Hopcroft clearly states that:

Theorem 7.16 If G is a CFG whose language contains at least one string other than ε then there is a grammar G1 in Chomsky Normal such that L(G1) = L(G) - {ε}.

I am a bit afraid to change this definition of the normal form and it might impact other algorithms.

To me, the main goal of the normal form is to make other algorithms effective. If the grammar generates epsilon, it is handled by the algorithms using the normal form, as it is done in Hopcroft.

I hope it answers your question.

from pyformlang.

Related Issues (10)

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.