I have a grammar S -> (S)S | empty
I converted it to a Chomsky Normal Form like this
S -> AS | empty
A -> LB
B -> SR
L -> (
R -> )
I'm not sure if I converted it correctly, but how do I parse this input ()() using the CNF
Do the following derivation in reverse:
S S → AS
→ AS A → LB
→ LBS L → (
→ (BS B → SR
→ (SRS S → ε
→ (RS R → )
→ ()S S → AS
→ ()AS A → LB
→ ()LBS L → (
→ ()(BS B → SR
→ ()(SRS S → ε
→ ()(RS R → )
→ ()()S S → ε
→ ()()
Related
Let's say I have a render function:
rasterize : ℕ → ℕ → Tile → List (List Color
I need to prove this statement:
if rasterize w h t1 = rasterize w h t2 then t1 ≡ t2
in other words if t1 and t2 render to the same value given the same width and height, then they are equal.
I dont know how to say this in agda, I came up with the following:
obs-eq : ∀ (t₁ t₂ : Tile) (w h : ℕ) →
rasterize w h t₁ ≡ rasterize w h t₂ → t₁ ≡ t₂
but I suspect this is not what I mean and from googling around I think I need to define an operator that compares the rendered values? Also some kind of sigma type is involved?
Your parenthesization is wrong: when you write
obs-eq :
∀ (t₁ t₂ : Tile) (w h : ℕ) →
rasterize w h t₁ ≡ rasterize w h t₂ →
t₁ ≡ t₂
it means that if I give you any two tiles and any two dimensions, such that the tiles rasterize to the same picture at those dimensions, then you can prove that they are equal.
Consider what happens if I choose w = 0 and h = 0 for you...
But what you want to say is that if I give you any two tiles, and a proof that for any two dimensions they rasterize to the same picture, then you can prove that the tiles are equal:
obs-eq :
∀ (t₁ t₂ : Tile) →
(∀ w h → rasterize w h t₁ ≡ rasterize w h t₂) →
t₁ ≡ t₂
The following proves the equality of two functions:
η-→ : ∀ {A B : Set} (f : A → B) → (λ (x : A) → f x) ≡ f
η-→ f = refl
Why doesn't it need extensionality? How does Agda know that the function to the left of the ≡ simplifies to f?
(λ x → f x) ≡ f is a basic rule of definitional equality for functions, called the eta rule. It's built into the type checker. Implementations of type theory commonly support it.
how can it be that the rule "Aa -> aA" is context-sensitive? According to the definition, context-sensitive rules have to be like this form:
αAβ → αγβ
where
A ∈ N, α,β ∈ (N∪Σ)* and γ ∈ (N∪Σ)+
Thanks.
It depends on what you mean. If you scroll down the Wikipedia entry, you can see that, formally,
cB → Bc
does not fit the scheme, but it can be simulated by 4 rules that do fit it:
c B → W B
W B → W X
W X → B X
B X → B c
So Aa → aA is not a CSG rule in itself, but the langue it generates is. Perhaps whoever told you it is, was using it as a shorthand (you could expand the definition of CSG rules to include these types of things as "macros").
Suppose a grammar is given like this:
AB → CD
CD → CE
C → aC
C → b
bE → bc
what is a trick to find either it is type 0,1,2, or 3 grammar?
This is an extension of the question posted here:
Agda and Binary Search Trees
I have
trans₁ : ∀ {a b c} → suc a ≤ suc b → suc b ≤ c → suc a ≤ c
for the definition of trans₁, but this would require me to change the definition of widen below to:
widen : ∀{min max newMin newMax}
→ BST min max
→ suc newMin ≤ suc min
→ max ≤ newMax
→ BST newMin newMax
How would i change a <= b to suc a <= suc b? This would then allow me to change the definition of trans₁ to:
trans₁ : ∀ {a b c} → a ≤ b → suc b ≤ c → suc a ≤ c
Any help is greatly appreciated.
Look at the s<=s constructor for the less than or equal to relation. Please ask on the course forums, not on stack overflow.