If L1 and L2 are languages we have a new language
INTERLACE(L1, L2) = {w1v1w2v2 . . . wnvn | w1w2 . . . wn ∈ L1, v1v2 . . . vn ∈ L2}.
For example, if abc ∈ L1 and 123 ∈ L2, then a1b2c3 ∈ INTERLACE(L1, L2)
How can I prove that the INTERLACE is:
decidable ?
recognizable ?
I know how to show this language is regular.
For decidable I am not so sure..
Here's what I think:
To show that the class of decidable languages is closed under operation INTERLACE need to show that if A and B are two decidable languages, then there is method to find if INTERLACE language is decidable. Suppose A, B decidable languages and M1, M2 two TM who decide, respectively.
After I think I have to say how to construct the DFA that recognize the language?
L1 and L2 decidable ==> INTERLACE(L1, L2) decidable
Citation from Wikipedia:
There are two equivalent major definitions for the concept of a recursive (also decidable) language:
...
2. A recursive language is a formal language for which there exists a Turing machine that, when presented with any finite input string, halts and accepts if the string is in the language, and halts and rejects otherwise.
Using this definition:
If L1 and L2 are decidable, then algorithms (or Turing machines) M1 and M2 exist, so that:
M1 accepts all inputs w ∈ L1 and rejects all inputs w ∉ L1.
M2 accepts all inputs v ∈ L2 and rejects all inputs v ∉ L2.
Now let's construct algorithm M which accepts all inputs x ∈ INTERLACE(L1, L2) and rejects all inputs x ∉ INTERLACE(L1, L2), as follows:
Given an input x1 x2 .. xn.
If n is odd, reject the input, otherwise (n is even):
Run M1 for the input x1 x3 x5 .. xn-1. If M1 rejects this input, then M rejects its input and finishes, otherwise (M1 accepted its input):
Run M2 for the input x2 x4 x6 .. xn. If M2 rejects this input, then M rejects its input, otherwise M accepts its input.
One can easily prove that M is the decision algorithm for INTERLACE(L1, L2), thus, the language is decidable.
L1 and L2 recognizable ==> INTERLACE(L1, L2) recognizable
Citation from Wikipedia:
There are three equivalent definitions of a recursively enumerable (also recognizable) language:
...
3. A recursively enumerable language is a formal language for which there exists a Turing machine (or other computable function) that will halt and accept when presented with any string in the language as input but may either halt and reject or loop forever when presented with a string not in the language. Contrast this to recursive languages, which require that the Turing machine halts in all cases.
The proof is very similar to the proof of the 'decidable' property.
If L1 and L2 are recognizable, then algorithms R1 and R2 exist, so that:
R1 accepts all inputs w ∈ L1 and rejects or loops forever for all inputs w ∉ L1.
R2 accepts all inputs v ∈ L2 and rejects or loops forever for all inputs v ∉ L2.
Let's construct algorithm R which accepts all inputs x ∈ INTERLACE(L1, L2) and rejects or loops forever for all inputs x ∉ INTERLACE(L1, L2):
Given an input x1 x2 .. xn.
If n is odd, reject the input, otherwise (n is even):
Run R1 for the input x1 x3 x5 .. xn-1. If R1 loops forever, then R loops forever as well ("automatically"). If R1 rejects this input, then R rejects its input and finishes, otherwise (if R1 accepts its input):
Run R2 for the input x2 x4 x6 .. xn. If R2 loops forever, then R loops forever as well. If R2 rejects this input, then R rejects its input, otherwise R accepts its input.
P.S. you were almost there, actually ;)
Related
The two definitions are these:
Inductive perm : list nat -> list nat -> Prop :=
| perm_eq: forall l1, perm l1 l1
| perm_swap: forall x y l1, perm (x :: y :: l1) (y :: x :: l1)
| perm_hd: forall x l1 l2, perm l1 l2 -> perm (x :: l1) (x :: l2)
| perm_trans: forall l1 l2 l3, perm l1 l2 -> perm l2 l3 -> perm l1 l3.
Fixpoint num_oc (x: nat) (l: list nat): nat :=
match l with
| nil => 0
| h::tl =>
if (x =? h) then S (num_oc x tl) else num_oc x tl
end.
Definition equiv l l' := forall n:nat, num_oc n l = num_oc n l'.
The theorem that I'm trying to prove is this:
Theorem perm_equiv: forall l l', equiv l l' <-> perm l l'.
The perm -> equiv direction is ready, but the equiv -> perm direction isn't working. I tried this strategy:
- intro H. unfold equiv in H.
generalize dependent l'.
induction l.
+ intros l' H. admit.
+ intros l' H. simpl in H.
generalize dependent l'.
intro l'. induction l'.
* intro H. specialize (H a).
rewrite <- beq_nat_refl in H.
simpl in H. Search False.
inversion H.
destruct (a =? a0) eqn:Ha.
** simpl in H. inversion H.
** apply False_ind.
apply beq_nat_false in Ha.
apply Ha. reflexivity.
* destruct (x =? a). *).
I'm out of ideas for the first branch, so it's admitted for now, but the second one is crashing at the destruct tactic. How do I proceed with this proof?
You should attempt to write a proof on paper before attempting to encode it in Coq. Here is a possible strategy.
Nil case
When l = [], you know that every number in l' occurs zero times because of H. It should be possible to prove an auxiliary lemma that implies that l' = [] in this case. You can conclude with perm_eq.
Cons case
Suppose that l = x :: xs. Let n = num_oc x xs. We know that num_oc x l' = S n by H. You should be able to prove a lemma saying that l' is of the form ys1 ++ x :: ys2 where num_oc x ys1 = 0. This would allow you to show that equiv xs (ys1 ++ ys2). By the induction hypothesis, you find that perm xs (ys1 ++ ys2). Hence, by perm_hd, perm (x :: xs) (x :: ys1 ++ ys2).
You should be able to prove that perm is a transitive relation and that perm (x :: ys1 ++ ys2) (ys1 ++ x :: ys2) holds. Combined with the last assertion, this will yield perm l l'.
The main takeaway in this case is that attempting to write every proof with single, direct induction is only going to work for the simplest results. You should start thinking about how to break down your results into simpler intermediate lemmas that you can combine to prove your final result.
so here a grammar R and a Langauge L, I want to prove that from R comes out L.
R={S→abS|ε} , L={(ab)n|n≥0}
so I thought I would prove that L(G) ⊆ L and L(G) ⊇ L are right.
for L (G) ⊆ L: I show by induction on the number i of derivative steps that after every derivative step u → w through which w results from u according to the rules of R, w = v1v2 or w = v1v2w with | v2 | = | v1 | and v1 ∈ {a} ∗ and v2 ∈ {b} ∗.
and in the induction start: at i = 0 it produces that w is ε and at i = 1 w is {ε, abS}.
is that right so far ?
so here a grammar R and a Langauge L, I want to prove that from R comes out L.
Probably what you want to do is show that the language L(R) of some grammar R is the same as some other language L specified another way (in your case, set-builder notation with a regular expression).
so I thought I would prove that L(G) ⊆ L and L(G) ⊇ L are right.
Given the above assumption, you are correct in thinking this is the right way to proceed with the proof.
for L (G) ⊆ L: I show by induction on the number i of derivative steps that after every derivative step u → w through which w results from u according to the rules of R, w = v1v2 or w = v1v2w with | v2 | = | v1 | and v1 ∈ {a} ∗ and v2 ∈ {b} ∗. and in the induction start: at i = 0 it produces that w is ε and at i = 1 w is {ε, abS}.
This is hard for me to follow. That's not to say it's wrong. Let me write it down in my own words and perhaps you or others can judge whether we are saying the same thing.
We want to show that L(R) is a subset of L. That is, any string generated by the grammar R is contained in the language L. We can prove this by mathematical induction on the number of steps in the derivation of strings generated by the grammar. We start with the base case of one derivation step: S -> e produces the empty word, which is a string in the language L by choosing n = 0. Now that we have established the base case, we can state the induction hypothesis: assume that for all strings derived from the grammar in a number of steps up to and including k, those strings are also in L. Now we must prove the induction step: that any string derived in k+1 steps from the grammar is also in L. Let w be any string derived from the grammar in k+1 steps. From the grammar it is clear that the derivation of w must be S -> abS -> ababS -> ... -> abab...abS -> abab...abe = abab...ab. But this derivation is the same as the derivation of a string from the grammar in k steps, except that there was one extra application of S -> abS before the application of S -> e. By the induction hypothesis we know that the string w' derived in k steps is of the form (ab)^m for some m at least zero, and adding an extra application of S -> abS to the derivation adds ab. Because (ab)^m(ab) = (ab)^(m+1) we can choose n = m+1. So, all strings derived from the grammar in k+1 steps are also in the language, as required.
To prove that all strings in the language can be derived in the grammar, consider the following construction: to derive the string (ab)^n in the grammar, apply the production S -> abS a number of times equal to n, and the production S -> e exactly once. The first step gives an intermediate form (ab)^nS and the second step gives a closed form string (ab)^n.
When reading formal descriptions of the lambda calculus, the set of variables seems to always be defined as countably infinite. Why this set cannot be finite seems clear; defining the set of variables as finite would restrict term constructions in unacceptable ways. However, why not allow the set to be uncountably infinite?
Currently, the most sensible answer to this question I have received is that choosing a countably infinite set of variables implies we may enumerate variables making the description of how to choose fresh variables, say for an alpha rewrite, natural.
I am looking for a definitive answer to this question.
Most definitions and constructs in maths and logic include only the minimal apparatus that is required to achieve the desired end. As you note, more than a finite number of variables may be required. But since no more than a countable infinity is required, why allow more?
The reason that this set is required to be countable is quite simple. Imagine that you had a bag full of the variables. There would be no way to count the number of variables in this bag unless the set was denumerable.
Note that bags are isomorphic to sacks.
Uncountable collections of things seem to usually have uncomputable elements. I'm not sure that all uncountable collections have this property, but I strongly suspect they do.
As a result, you could never even write out the name of those elements in any reasonable way. For example, unlike a number like pi, you cannot have a program that writes out the digits Chaitin's constant past a certain finite number of digits. The set of computable real numbers is countably infinite, so the "additional" reals you get are uncomputable.
I also don't believe you gain anything from the set being uncountably infinite. So you would introduce uncomputable names without benefit (as far as I can see).
Having a countable number of variables, and a computable bijection between them and ℕ, lets us create a bijection between Λ and ℕ:
#v = ⟨0, f(v)⟩, where f is the computable bijection between 𝕍 and ℕ (exists because 𝕍 is countable) and ⟨m, n⟩ is a computable bijection between ℕ2 and ℕ.
#(L M) = ⟨1, ⟨#L, #M⟩⟩
#(λv. L) = ⟨2, ⟨#v, #L⟩⟩
The notation ⌜L⌝ represents c_{#L}, the church numeral representing the encoding of L. For all sets S, #S represents the set {#L | L ∈ S}.
This allows us to prove that lambda calculus is not decidable:
Let A be a non-trivial (not ∅ or Λ) set closed under α and β equality (if L ∈ A and L β= M, M ∈ A). Let B be the set {L | L⌜L⌝ ∈ A}. Assume that set #A is recursive. Then f, for which f(x) = 1 if x ∈ A and 0 if x ∉ A, must be a μ-recursive function. All μ-recursive functions are λ-definable*, so there must be an F for which:
F⌜L⌝ = c_1 ⇔ ⌜L⌝ ∈ A
F⌜L⌝ = c_0 ⇔ ⌜L⌝ ∉ A
By letting G ≡ λn. iszero (F ⟨1, ⟨n, #n⟩⟩) M_0 M_1, where M_0 is any λ-term in B and M_1 is any λ-term not in B. Note that #n is computable and therefore λ-definable.
Now just ask the question "Is G⌜G⌝ in B?". If yes, then G⌜G⌝ = M_1 ∉ B, so G⌜G⌝ could not have been in B (remember that B is closed under β=). If no, then G⌜G⌝ = M_0 ∈ B, so it must have been in B.
This is a contradiction, so A could not have been recursive, therefore no closed-under-β= non-trivial set is recursive.
Note that {L | L β= true} is closed under β= and non-trivial, so it is therefore not recursive. This means lambda calculus is not decidable.
* The proof that all computable functions are λ-definable (we can have a λ-term F such that F c_{n1} c_{n2} ... = c_{f(n1, n2, ...)}), as well as the proof in this answer, can be found in "Lambda Calculi With Types" by Henk Barendregt (section 2.2).
How can I prove using a reduction method that a language's length is divided by 2?
L={ | is a Turing machine where |L(M)|= 0 mod 2}
I have 2 ideas but I am afraid to follow the wrong one
1) I use the reduction method with Amt and I say that the turing machine takes an x=w0.....wi as input and accept if and only if wi = 0 mod 2 .
2) I use the reduction method with NOT HALT, and I say that the turing machine will refuse any input, so the length of the turing machine will be 0 which is satisfies the condition above!
Any Suggestion ?
Here's one option. Given a TM M and a string w, build this new TM N:
N = "On input x:
If x isn't the empty string, reject.
Otherwise, run M on w.
If M accepts, accept; if M rejects, reject.
(Implicitly, if M loops on w, N loops on x.)"
This TM has the property that if M accepts w, then L(N) = {ε}, so |L(N)| = 1. Otherwise, if M doesn't accept w, then L(N) = ∅, so |L(N)| = 0.
See if you can use that in a reduction.
Here are two other approaches you could take:
Apply Rice's theorem to immediately conclude that this language is undecidable because asking whether |L(M)| is even is a nontrivial property of the RE languages.
Use the Recursion Theorem: build a TM that asks whether its language has an even number of strings in it, then chooses to accept nothing if the answer is "yes" and just the empty string if the answer is "no." This TM's language has even size if and only if it doesn't - a contradiction!
Given a set of n elements U, and a set of m properties P where each element of P defines a function from U to boolean.
Given two composite logical expressions of the form (recursively defined):
p1 : true iff p1(x) is true
e1 and e2 : means e1 and e2 are both true
e1 or e2 : means e1 and e2 are not both false
not e1 : true iff e1 is false
(e1) : true iff e1
These logical expressions are parsed into expression statements (parse trees).
Assume that for any p1, p2: All four sets (p1 and p2), (p1 and not p2), (not p1 and p2), (not p1 and not p2), are non-empty.
I want to determine if a logical expression L1 is a subset of L2. That is for every element x in U, if L1(x) is true then L2(x) is true.
So for example:
is_subset(not not p1, p1) is true
is_subset(p1, p2) is false
is_subset(p1 and p2 and p3, (p1 and p2) or p3) is true
I think I need to "normalize" the parse trees somehow and then compare them. Can anyone outline an approach or sketch an architecture?
Since you don't do anything with the objects (x) it seems you want propositional logic, where all combinations of the truth values for p1 to pn are possible.
So essentially you want to do theorem proving in propositional logic.
Your is_subset(e1,e2) translates to a logical operator e1 implies e2, which is the same as not e1 or e2. To know if these hold universally you can check if the negation is unsatisfiable with an algorithm for satisfiability checking such as DPLL.
This is just a starting point, there are many other options to prove theorems in propositional logic.
You can convert each formula to the disjunctive normal form and find if one contains a subset of the conjunctive clauses in the other. The complexity of this approach grows as the exponent of the number of pn mentioned.
I think your instructor essentially wants you to implement the Quine-McCluskey Algorithm Note that as the other answer implies, the execution time grows exceptionally fast because the problem is-NP Hard.