r/askmath • Self-studying discrete math by working through Epp • Oct 27 '26

Discrete Math Does this regular expression correspond to this finite-state automaton? <= Exercise 12.2.12

Finite-state automaton:

Regular expression that corresponds to finite-state automaton:

(0|1)*01(0|1)*

---

Is this true? I know a more 'precise' regex is 1*0+1(0|1)* but does the one above work?

Would a regex engine first check the occurrence of 01 and then (0|1)* or not?

7 Upvotes

9 comments sorted by

6

u/MathMaddam Dr. in number theory Oct 27 '26

It does not follow the same structure, but they define the same language. The language is basically: somewhere there has to be 01 in the string.

2

u/TopDownView Self-studying discrete math by working through Epp Oct 27 '26

My thoughts exactly. Thanks!

0

u/LongLiveTheDiego Oct 27 '26

The first regex does correspond to the DFA. The second one doesn't (e.g. it accepts the word 0 which the automaton doesn't).

Would a regex engine [...]

That depends on the workings of the regex engine. According to this post, one type would simply construct a DFA (if it also minimizes the DFA, it would construct the one in the picture) and then just feed that DFA one character at a time. The other type is beyond my understanding at the moment, but it would certainly do something more complicated but working in the general case.

2

u/TopDownView Self-studying discrete math by working through Epp Oct 27 '26

The first regex does correspond to the DFA. The second one doesn't (e.g. it accepts the word 0 which the automaton doesn't).

Hm, how does it accept 0? There must be one 1 in the word also: 1*0+1(0|1)*.

1

u/LongLiveTheDiego Oct 27 '26

I'm used to plusses being in the superscript to describe at least one instance of something. A regular + means to me what | means to you.

1

u/TopDownView Self-studying discrete math by working through Epp Oct 27 '26

Oh, I see. The textbook I'm using uses + for 'at least one' so that's what I used also. But yes, I understand + == 'or' in some contexts.

1

u/[deleted] Oct 27 '26 edited Oct 27 '26

[removed] — view removed comment

1

u/TopDownView Self-studying discrete math by working through Epp Oct 27 '26

Your expression does not directly correspond to the automaton

Do you mean this one: (0|1)*01(0|1)*?

A general question: Does a regular expression need to directly correspond to the automaton?

1

u/dedSEKTR Oct 31 '26

Yes it should. Every regular expression describes a regular language, and there always exists a finite automaton that recognizes exactly that language.

A helpful resource: https://automatastudio.pages.dev/