DSCI 220, 2025 W1
November 4, 2025
Start with <T> and roll a die to choose which rule to apply.
<T> ::= <CORE> | <CORE> <FEAT>
<FEAT> ::= "feat." <ARTIST>
<ARTIST> ::= "Taylor Swift" | "Sabrina Carpenter" | "Olivia" <LN> | "Chappell Roan"
<LN> ::= "Rodrigo" | "Dean"
<CORE> ::= <NP> | <NP> <PREP> <NP>
<NP> ::= <DET> <ADJLIST> <NOUN>
<DET> ::= "the" | "my" | "your" | "our"
<ADJLIST> ::= <ADJ> <ADJ> | <ADJ> | ε
<ADJ> ::= "midnight" | "lonely" | "wild" | "broken" | "golden" | "electric"
<NOUN> ::= "heart" | "city" | "dreams" | "summer" | "memories" | "night"
<PREP> ::= "in" | "of" | "for" | "at"https://www.json.org/json-en.html
We ignore lexical details and focus on structure.
Example: Is {"a":[1,2,{"b":null}]} in the language?
Create a Grammar for \(L = \{a^nb^nc^n, n\geq 0\}\)
Regular languages
Context-free languages
Context-sensitive languages
Recursively enumerable languages
Question: How many different outfits do you have in your closet?
No rules, just count.
Write down how you’d start to count, not just an answer.
05:00
What categories did you use?
What rules did you impose?
Key Idea:
How we model outfits (what’s allowed, what’s ignored) changes the counting.
Define a wardrobe for the rest of this lesson:
We’ll choose a model:
Define sets of items:
A bottom is either pants or a skirt:
\[ B = P \cup K \]
Assuming no overlap between pants and skirts:
\[ |B| = |P \cup K| = |P| + |K| = j + m \]
Type 1 outfit: shirt + bottom + shoes
As a set of combinations:
\[ \text{Type1} = S \times B \times T \]
Each outfit is a triple:
\[ (\text{shoe}, \text{bottom}, \text{shirt}) \in S \times B \times T \]
So the number of Type 1 outfits is:
\[ |\text{Type1}| = |S||B||T| = k(j + m)n \]
Type 2 outfit: dress + shoes
As a set of combinations:
\[ \text{Type2} = S \times D \]
Each outfit is a pair:
\[ (\text{shoe}, \text{dress}) \in S \times D \]
So the number of Type 2 outfits is:
\[ |\text{Type2}| = |S||D| = kp \]
We’ve partitioned outfits into two disjoint types:
Total number of outfits in our model:
\[ \begin{aligned} \#\text{outfits} &= |\text{Type1}| + |\text{Type2}| \\ &= k(j + m)n + kp \\ &= k\big((j + m)n + p\big). \end{aligned} \]
This matches the informal idea:
Fundamental counting fact:
If \(A\) and \(B\) are finite sets, then
\[ |A \times B| = |A|\cdot|B|. \]
Generalizing:
For sets \(A_1, A_2, \dots, A_k\): \[ |A_1 \times A_2 \times \dots \times A_k| = |A_1| \cdot |A_2| \cdot \dots \cdot |A_k|. \]
Interpretation:
The combinatorics lesson:
Once you’ve decided what “counts,” express the valid items as a product of simpler choices.
This pattern will be used for: