Pasted image 20261110163109.png

Regular Operations:

  • Union: L1 ∪ L1 = L1+L2 = {x|x∈L1 or x∈L2} basically all items in both sets combined
  • Concatenation: L1 * L2 = L1L2 = {xy|x∈L1 and y∈L2} so basically two of the strings combined together into one
  • Star: L1* = {x1,x2...xm | m ≥ 0, each x ∈ L1} so this is a unit operator that denotes all of the possible strings of only a SINGLE language, it includes the empty strings
  • Unary Plus: L1+ = {x1,x2,...xm | m > 0, each x ∈ L1}, so this is very similar to that of the start, the only thing is that this one does not include the empty string denoted by ε
Examples:

PRECEDENCE IS: *, ∘, ∪

Concatenation:

  • If a and b are two strings, then a.b = ab, basically you combine the two strings, so something like 1110.010 = 1110010 or something like that
  • If you have a concatenation with an epsilon, then a.ε = ε.a = a, since you add nothing
  • If you want to do something like concatenate a single string a with an entire language L then doing something like a.L is then equal to the concatenation of the string over every item in the language: {a.x | x∈L}
  • If you want to do something like combine multiple languages together, so L1.L2 you basically combine each string over each string, so you end up with a new language/set that is basically |L1| + |L2|, you also preserve the order:Pasted image 20261110164004.png
  • Concatenation is also associative, meaning the order of parenthesis does not matter when taking the concatenation between multiple languages
  • Whenever you concatenate a given language with an empty string, it changes nothing of course because nothing gets added
  • NOTICE: A * ∅ = ∅, so whenever you concatenate a language with an empty set, you get an empty set because there is nothing to concatenate over, but this has nuance because concatenation is not commutative, so it should be fine the other way around

Star

  • Basically denotes all possible strings that can be made with that language, so if you have something like L={a} then L* = {ε, a, aa, aaa, aaaa, ....}, notice that the empty string is included

Unary Plus

  • Basically the exact same thing as the start operator, but the only difference is that the empty string is not included in the operation, so you have something like L={a} then L+ = {a, aa, aaa, aaaa, ....}, notice the lack of ε
  • Notice that logically this means that the concatenation between L and L* is then actually equal to L+, so L+ = L.L*

Union:

  • Pasted image 20261110164344.png
  • A union is also commutative, so A ∪ B = B ∪ A between all given languages
  • It is also associative, so the parenthesis do not matter when doing union across multiple languages
  • Whenever you take a union of a language with a null set, you end up with the original language since nothing is added
  • Basically because languages are really just sets, anything that applies to a union between sets applies to a union to languages

Distributive properties:
Pasted image 20261110164831.png

Properties of regular operations:

  • ∅* = ∅, for obvious reasons
  • ε* = ε, once again, because you are obviously empty
  • (A*)* = A*, this is because all values are listed, you cannot list more in the thing listing them all
  • A*A* = A*, once again the concatenation of all possible strings just is the all of the possible strings because inherently A* is kind of infinite by nature since you can always add in another letter to the string

Atomic Regular Expressions:

  • The empty language ∅, is a regular expression which is the empty regular language
  • Any given letter a in Σ is a regular expression, and it’s language is {a}
  • An empty string, ε, is also a regular expression representing the regular language {ε}

Pasted image 20261110165256.png

Regular Expression Examples:

Example 1:

  • Σ = {a, b}, so what is the language of Σ*
  • We know that Σ* is basically the idea of all strings over {a,b} right
  • So, how ab is generated by this regular expression (RE)?
    • (a+b).(a+b) -> a.b = ab, so the concatenation with the union of a and b with the union of a and b, which is shrunk with binary plus, so the combination of sigma two times?
  • Is there any string that does not belong to this RE over the same alphabet? No! as sigma star generates all the strings over the alphabet sigma

Example 2:

  • Which string can/cannot be generated by (b*a+)*? So basically the star of the language b, which is {ε, b, bb, bbb, ...}, concatenated then with the unary plus of a which is {a, a, aaa, ...}, and then you take the star of all of that, which doesn’t matter it kind of gets cancelled out by the inner expressions

  • They also then ask, does bbaa belong in this RE?

  • So since you basically have a string of all values of A and of all values of B, then you concatenate them, bbaa will (maybe?) belong to this RE, depending on if the order preservation of concatenation gets in the way of things, but you concatenate B first so IDK

  • AND IT DOES BABY OH YEAH

  • Pasted image 20261110170214.png

  • Basically you need to understand that the string must in fact end with a because of the fact that you cannot have a value of ε in the language of a*, so you need to have a value of a inside of there

Example 3:

  • Which string can/cannot be generated by (ab* + ba+)*, so first off this is basically the star of the concatenations between language {a} and {b}, and this can in fact be empty because it is a star. This is also then the UNION, so all commonly shared values with the language ba+, which cannot be empty for one, and seemingly must end in a
  • Does abba belong to this RE? Yes as by this process:
  • Pasted image 20261110170607.png
  • Pasted image 20261110170728.png
  • Pasted image 20261110170822.png

Design Regular Expressions

So, try to design a regular expression for all binary words containing: bb, so like:

  • {bb, abb, bba, bbb, aabb, abba, abbb, babb, bbaa, bbab, bbba, bbbb}
  • I assume you can do something like (a∪b)*(bb)+(a∪b)*, so you have a possible number of a or b at the start and at the end, and then a possible empty string as well, you have the bb+ just to make sure that there is always a bb in there, my take on it as the very least
  • This is actually also then known as Σ*bbΣ*, and this is because you can have anything before or after, but there must be at least a single b in there

Now, try to design an expression for all binary words ending with ab or ba

  • {ab, ba, aab, bab, bab, aba, bba}
  • So you need to have either an ab OR a ba at the end, and then you can have anything in between, I guess something like Σ*(ba ∪ ba)+, I was kind of close, basically the real answer is: Σ*ab ∪ Σ*ba

Now try to make strings with at most one a

  • so you can have any and all b, but only a single A, so I assume you can do something like b*ab* ∪ b*, where you can have as many b values as you want, but you can only have one a, or no a values
  • Pasted image 20261110174357.png
  • Pasted image 20261110174438.png
  • Pasted image 20261110174511.png

Regular Expressions and Finite Automata

Kleene’s Theorem: a language is regular, if and only if, it can be described by a regular expression.

The, if and only if, means that we need a two-way theorem right, so ↔

  1. If a language is described by a regular expression, then it is regular
  2. If a language is regular, it can be described by a regular expression

So, where do finite automata come into this?

Pasted image 20261110192824.png

Basically, finite automata are connected over from the regular expression with the regular languages of course, we understand the connection between finite automata and regular expressions because they are both used to basically order the structure of a regular language

Two Main Theorems - part 1:

  1. If L = L(A) for some finite automaton A, then there is a regular expression R, such that L(R) = L, so basically you can equate a finite automaton to a regular expression

So, with this try to convert this given automaton to a regular expression:

Pasted image 20261110193100.png

Now this automaton expresses all strings that end with 0 right, so it can basically be any real value, as long as there is at least one zero and this zero is at the end of the given string. So we can describe this as Σ*0, at least I think so

Pasted image 20261110193336.png
Pasted image 20261110193345.png
Pasted image 20261110193431.pngPasted image 20261110193439.png
So basically you end up with 1 ∪ 0* 1)*0+

Two Main Theorems - Part 2

  1. If L = L(R) for some regular expression R, then there is a finite automaton A such that L(a) = L, this is proved by induction but is too hard for this topic, basically the inverse of the first part though, if you have an expression, you can make an automaton

Regular Expressions and Finite Automata Examples:

Example 1:

Pasted image 20261110193950.png

So, I assume the pattern is you basically create a new starting state and then a new ending state right, using the ε transition, same with the final state:

Pasted image 20261110194035.png

Now slowly you want to start with getting rid of the states as they come along, converting them into expressions that showcase the same thing, so something like C might become idk, 1(1* U 0*), you get rid of the things it is connected to, and then you simplify it:

Pasted image 20261110194232.png

Now after doing this, you go on and do B, so you know you have the transitions of zero to deal with and the expression that came from C, so the union of those two I think, basically: 00*1(1* U 0*)

Pasted image 20261110194402.png

Lastly, you need to remove A, and then because it just has the infinite loop with the one and what not, then you can just add in a 1*, so you would end up with 1*00*1(1* U 0*), and that would be the entire expression for the automaton, and it describes the language where there is at least one 01

Example 2:

Pasted image 20261110194637.png
Pasted image 20261110194709.png
Pasted image 20261110194732.pngPasted image 20261110194821.png

Exercises:

Now it’s time to put into practice the concepts that you have learnt so far in Week 9. Attempt the following exercises. If you get stuck, you can refer to the hints and tips on the next page.

Please note that these exercises are optional, further practice – but we strongly recommend that you engage with them in order to test your knowledge and see where you might need to do additional study.

  1. Given R=b∗(ba+∪a+)+b∗R=b∗(ba+∪a+)+b∗R, equals, b, start superscript, times, end superscript, left parenthesis, b, a, start superscript, plus, end superscript, \cup, a, start superscript, plus, end superscript, right parenthesis, start superscript, plus, end superscript, b, start superscript, times, end superscript and S=(a∗ba+b)∗S=(a∗ba+b)∗S, equals, left parenthesis, a, start superscript, times, end superscript, b, a, start superscript, plus, end superscript, b, right parenthesis, start superscript, times, end superscript

    1. give an example of a string that is neither in the language of RRR nor in SSS
    2. give an example of a string that is in the language of SSS but not RRR
    3. give an example of a string that is in the language of RRR but not SSS
    4. give an example of a string that is in the language of RRR and SSS.
  2. Design a regular expression that accepts the language of all binary strings with no occurrences of 001.

  3. Design a regular expression that accepts the language of all binary strings in which their length is odd, with no occurrences of 11.

  4. Over {0,1,2, 3} design a regular expression to generate all natural numbers greater than 210.

Weekly Practice:

“Regular languages part 1.pdf” could not be found.

Reading:

“Sipser pp63 77 Accessible.pdf” could not be found.# Regular Expressions:

Reading Notes:

So, in a regular math scenario, we can do things like use the operations + or * in order to build up expressions such as (5 + 3) * 4 right.

We can then in turn use regular operations to built up expressions describing a given language, and these are called regular expressions, so something like: (0 ∪ 1)0* this language describes all strings that contain at most a single 1 or none at all, and this 1 must also be in the front, so things like {1000, 1, 100, 00, 0} are all valid strings for this regular expression.

To break this down a bit, the symbols of 0 and 1 are sort hand for the sets: {0} and {1}, and then you apply different operations onto each of these sets. So you have the union of (0) ∪ (1) = {0, 1} right, and then 0* which is the possibly empty set of all possible strings that can be made with this value 0, so basically however many zeros you want or no zeros at all.

Now the two are naturally combined with “multiplication” which is basically the ∘ symbol although it is forgotten here for the fact that it is implied with the parenthesis. This basically means that the two strings are combined with one another into a single new string.

This is really useful because it allows us to describe strings in a given way right, so you as a programmer can use it to search through strings or see if they approach a certain pattern that you want them to. Things like awk or grep in the UNIX environment use it as a matter of fact, they provide mechanisms for description of patterns using regular expressions.


(0 ∪ 1)* is another expression that can describe any and every string that can be made up with Σ = {0, 1}, so this means we can actually sort hand it as Σ* and it means the exact same thing. We can also then do something like 0Σ* which is any binary string starting with a zero, or even add onto it and do something like 0Σ* ∪ Σ*1 which is any binary string that starts out with a zero and then ends with a 1, here is the order of precedence:

Pasted image 20261111201611.png


Formal Definition of a Regular Expression

Pasted image 20261111201635.png

This is basically to say hey, if you are made up of an element of a language, right, so basically like any character or symbol defined in an alphabet as denoted by sigma, and then the edge cases like an empty language, or an empty string then you are one of those fundamental building blocks of the regular expression.

Equally then, if you are made up of these blocks as they are described in a way that combines them and what not, so through a union a concatenation, a kleene star or unary plus, then you are also a regular expression.

Pasted image 20261111202031.png

This is a bunch of examples of different notations and how they describe certain languages. Through this you are given the following identities, which mind you do need to be in the order that they are in, concatenation of strings is NOT commutative for obvious reasons:

Pasted image 20261111202300.png

This is obviously pretty cool though because we can use it to do things like design compilers for programming languages. Using this sort of an idea we can do things like establish things like tokens right, so you can have something like a double which would be all possible integer values, a possible dot, and then all possible integer values, as the memory allows of course. See:

Pasted image 20261111202437.png

This is the lexical analysis for a programming language, and is basically how you would do things like build a scanner, this is also in part how I assume prompts and what not are scanned for LLMs in machine learning as well.


I think it is pretty obvious to see, what you can use these regular expressions in tandem with things like the finite state machines:

Pasted image 20261111202641.png

The above is the proof for this, I mean it is rather logical if you think about it though, they each just describe sets that define a given characteristic for a string, meaning that they apply to a given language of strings. You can basically convert any NFA (or DFA since each DFA is basically also an NFA) into a regular expression and vise versa. Here is how you can do it:

Pasted image 20261111202821.png

So this process describes building an NFA from a regular expression (ab ∪ a)* which is basically the language of ALL strings that do not contain two consecutive b and do not start with a b

The way we build is by taking each smaller and smaller portion and then combining them as we go. First we have all strings of a and then all strings of b, those are the “concatenated” using the ε symbol right. This is because the two connect but do not need a symbol to connect, they just do.

You then add in the ∪ a which adds another transition from our starting node, since we can now start and go into only A, or we can go into a and then a b, as the regular expression describes. To then make it follow for all of the possible strings over the language, you just have it go back to the starter node, but with a new accepting state for empty strings because of the kleene star on the whole thing.

Here is an example I am not going to type all of this explanation out for though, basically do one part and then keep on adding to it twin:

Pasted image 20261111203410.png


Now going back the other way, you can take a DFA and then turn it into a regular expression. This is done by first making the DFA into something called the generalized nondeterministic finite automaton. These are called GNFA(s) where some of the transitions may have regular expressions as the labels instead of just a single character string basically.

In essence though, the idea is to slowly take away states from the DFA and turn it into a more descriptive GNFA, so you basically go backwards, add a new epsilonic state to the beginning and end, and slowly take away states and combine them. So if you have a single loop for example then that would be like 1* or if the transition is 1, 0 then that becomes 1 ∪ 0 or Σ in the expression:

Pasted image 20261111203922.png

Pasted image 20261111204004.png

Real fuck you kind of an example at the end there isn’t there buddy