質問

I'm currently studying compilers and am having some issues with understanding regular sets. For example, lets say I had a set of binary strings, (0, 1). Would all integers that are even and positive be considered part of a regular set? Lets say I have that same set, but instead of being even, they are divisible by 5, would it still be a regular set?

I've been looking at this helpful guide I found online, but I'm still confused about what can be defined as a regular set.

役に立ちましたか?

解決

Would all integers that are even and positive be considered part of a regular set?

Yep! You can generate them with this regular expression:

2 | 4 | 6 | 8 | (0|1|2|3|4|5|6|7|8|9)+(0|2|4|6|8)

Lets say I have that same set, but instead of being even, they are divisible by 5, would it still be a regular set?

Yep! Here's the regex:

5 | (0|1|2|3|4|5|6|7|8|9)+(0|5)

More generally, to determine whether a set is a regular set, you should try to find a finite automaton that accepts precisely the strings in the language or a regular expression for that set. If you can do that, the language is regular. If not, it's not regular.

Hope this helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top