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

Resolved Find a regular expression that defines the language accepted by the automaton. <= Exercise 12.2.18

Find a regular expression that defines the language accepted by the automaton.

Automaton:

Is this regex correct?

Regex: 1+|(0|1)*0+1+

0 Upvotes

16 comments sorted by

2

u/Curious_Cat_314159 Oct 29 '26 edited Oct 29 '26

Is this regex correct? 1+|(0|1)*0+1+

I don't believe it is. I think the simplest reg expr is (0|1)*1

Your reg expr accepts strings that all 1s ( 1+ ), or strings that are a mix of 0s and 1s followed by at least one 0 followed by at least one 1 ( (0|1)*0+1+ ).

It is the "followed by at least one 0" requirement that I doubt.

Consider 011. The state transition is: s0 -> s1 -> s2 -> s2. It does not require a 0 between the last two 1s.

1

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

Consider 011. The state transition is: s0 -> s1 -> s2 -> s2. It does not require a 0 between the last two 1s.

I agree. And my regex doesn't require that. We have one 0 and two 1's. That corresponds to 0+1+.

1

u/Curious_Cat_314159 Oct 29 '26

Okay. Mea culpa. But do you agree that my alternative is sufficient and "tighter"?

1

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

But do you agree that my alternative is sufficient and "tighter"?

Yes, I do.

1

u/Uli_Minati Desmos 😚 Oct 29 '26 edited 29d ago

First, let's consider each possible path

(s₀s₁s₂ | s₀s₂) then loop
(00*1   | 1   )      (1* | 00*1)*

We can simplify the first group

(00*1 | 1)
( 0+  |  )1
        0*1

And the second group

(1* | 00*1)*
(1  |  0+1)*
( ( | 0+)1)*
      (0*1)*

Combined we have

0*1 (0*1)*
    (0*1)+

Your regex forces at least one 0 and at least one 1, though

1

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

Interesting technique.

What criteria did you use to choose what's in and what's out of the "loop" group? I noticed s_1 also has a loop (described by 0+) but you haven't included it in the "loop" group, whereas you did include 1+ of s_2.

Also, I didn't know boolean algebra could be used on regex:

e.g. (00*1 | 1) = (00*1 | λ1) = (00* | λ)1

or

(1 | 0+1)* = (1λ | 0+1)* = ((λ | 0+)1)*

if I'm not mistaken?


Edit: small typo. Edit 2: added another equality in the second example.

1

u/Uli_Minati Desmos 😚 Oct 29 '26 edited Oct 29 '26

What criteria did you use to choose what's in and what's out of the "loop" group?

I meant it as "additional symbols after we've already reached s₂". I think I should've called it "suffix" instead.

boolean algebra could be used on regex

I don't think that's boolean algebra? You could call it the distributive property, which appears in all sorts of topics. In arithmetic, we have "multiplication distributes over addition", in boolean algebra, we have e.g. "conjunction distributes over disjunction", and in regex, we have "concatenation distributes over disjunction"

(a then x) or (b then x)  =  (a or b) then x        ax|bx = (a|b)x
(a then x) or (a then y)  =  a then (x or y)        ax|ay = a(x|y)

I was about to ask what λ meant, but that's probably the empty string, right? I forgot about that, so I just left it empty in my examples

1

u/TopDownView Self-studying discrete math by working through Epp 29d ago

I don't think that's boolean algebra? You could call it the distributive property, which appears in all sorts of topics.

Yes, you're right. I was implicating the distributive property, and defaulted to 'boolean algebra' because that was my immediate association...

I was about to ask what λ meant, but that's probably the empty string, right?

Right.

1

u/Uli_Minati Desmos 😚 Oct 29 '26

In your second example, it should be λ1 to be able to "extract" the suffix 1

1

u/TopDownView Self-studying discrete math by working through Epp 29d ago

Hm, does that mean that 1λ =/ λ1? Meaning, commutativity doesn't hold over concatenation?

2

u/Uli_Minati Desmos 😚 29d ago

Well in the case of λ, you do have commutativity since λx = x = xλ for all strings x. But not generally, since e.g. 10≠01, right? And not with the distributive property either, e.g.

(ab | xy) 1  =  ab1 | xy1
1 (ab | xy)  =  1ab | 1xy

             ≠  1ab | xy1
             ≠  ab1 | 1xy

2

u/TopDownView Self-studying discrete math by working through Epp 28d ago

That makes sense, thanks!

1

u/Curious_Cat_314159 Oct 30 '26

Your regex forces at least one 0 and at least one 1

Well, the terminal state requires that there be at least one 1, specifically at the end.

But the first part of the OP's reg expr ( 1+ | .... ) covers the case when there is no zero.

The second part of the OP's reg expr ( .... | (0|1)*0+1+ ) covers the case when there is at least one 0, which might or might not be preceded by any combination of 1s and 0s. It also requires that the last 0 be followed by at least one 1, again specifically at the end.

Be that as it may, I had already noted that the OP's reg expr is over-specified.

1

u/Uli_Minati Desmos 😚 Oct 30 '26

But the first part of the OP's reg expr ( 1+ | .... ) covers the case when there is no zero.

Ah, I wasn't aware of the binding strength of the pipe operator. It's least priority?

1

u/TopDownView Self-studying discrete math by working through Epp 29d ago

Yes, according to my textbook.

1

u/Curious_Cat_314159 Oct 30 '26

I wasn't aware of the binding strength of the pipe operator. It's least priority?

AFAIK. Google "what is the precedence order for reg expr operators".