Help me with this please.
I have this input column in a datatable
First Case: Second Case: Third Case:
Operation Operation Operation
C C V
C C V
V C V
V C V
C C V
C C V
V C V
C C V
V C V
And I want to know if the dt has C and V or just C or just V.
First you need 2 boolean variables to store the information if C and V exist or not. After that you need to loop through your dt using for each row activity. Inside foreach activity you can use an if activity with assign activty to compare row value with "C" or "V" and set the values of variables accordingly. Finally you can use the values of these variables to decide if your datatable has C and V or just C or just V.
Click here for the answer. Turing Machine
The question is to construct a Turing Machine which accepts the regular expression,
L = {a^n b^n | n>= 1}.
I am not sure if my answer is correct or wrong. Thank you in advance for your reply.
You cannot "accept the regular expression", only the language it describes. And what you provide is not a regular expression, but a set description. In fact, the language is not regular and therefore cannot be described by standard regular expressions.
The machine from your answer accepts the language described by the regular expression a^+ b^+.
A TM could mark the first a (e.g. by converting it to A) then delete the first b. And for each n one loop. If you and up with a string only of A, then accept.
As stated before, language L = {a^nb^n; n >= 1} cannot be described by regular expressions, it doesn't belong into the category of regular grammars. This language in particular is an example of context-free grammar, and thus it can be described by context-free grammar and recognized by pushdown automaton (an automaton with LIFO memory, a stack).
Grammar for this language would look something like this:
G = (V, S, R, P)
Where:
V is finite set of non-terminal characters, V = { S }
S is finite set of terminal characters, S = { a, b }
R is relation that describes "rewrites" from non-terminal characters to non-terminals and terminals, in this case R = { S -> aSb, S -> ab }
P is starting non-terminal character, P = S
A pushdown automata recognizing this language would be more complex, as it is a 7-tuple M = (Q, S, G, D, q0, Z, F)
Q is set of states
S is input alphabet
G is stack alphabet
D is the transition relation
q0 is start state
Z is initial stack symbol
F is set of accepting states
For our case, it would be:
Q = { q0, q1, qF }
S = { a, b }
G = { z0, X }
D will take a form of relation (current state, input character, top of stack) -> (output state, top of stack) (meaning you can move to a different state and rewrite top of stack (erase it, rewrite it or let it be)
(q0, a, z0) -> (q0, Xz0) - reading the first a
(q0, a, X) -> (q0, XX) - reading consecutive a's
(q0, b, X) -> (q1, e) - reading first b
(q1, b, X) -> (q1, e) - reading consecutive b's
(q1, e, z0) -> (qF, e) - reading last b
where e is empty word (sometimes called epsilon)
q0 = q0
Z = z0
F = { qF }
The language L = {a^n b^n | n≥1} represents a kind of language where we use only 2 character, i.e., a, b. In the beginning language has some number of a’s followed by equal number of b’s . Any such string which falls in this category will be accepted by this language. The beginning and end of string is marked by $ sign.
Step-1:
Replace a by X and move right, Go to state Q1.
Step-2:
Replace a by a and move right, Remain on same state
Replace Y by Y and move right, Remain on same state
Replace b by Y and move right, go to state Q2.
Step-3:
Replace b by b and move left, Remain on same state
Replace a by a and move left, Remain on same state
Replace Y by Y and move left, Remain on same state
Replace X by X and move right, go to state Q0.
Step-5:
If symbol is Y replace it by Y and move right and Go to state Q4
Else go to step 1
Step-6:
Replace Y by Y and move right, Remain on same state
If symbol is $ replace it by $ and move left, STRING IS ACCEPTED, GO TO FINAL STATE Q4
I'm wondering if the CTL formulas below are equivalent and if so, can you help me persuade myself that they are?
A(p U ( A(q U r) )) = A(A(p U q) U r)
I can't come up with any models that contradicts it and my guts tells me the formulas are equivalent but I can't find any equivalences that supports that statement. I've tried to rewrite the equivalence
A(p U q) == not(E ((not q) U not(p or q)) or EG (not q))
into something helpful but failed several times.
I've looked through my course material as well as google but I can't find anything. I did however find another question here that has the same equivalence question but with no answer, so I'm trying to make a second try.
Note: this answer might be late.
However, since the question was raised multiple times, I think it's still useful.
Question: Is A[p U A[q U r]] equivalent to A[A[p U q] U r]?
Answer: no.
To prove that the inequality stands, it is sufficient to provide a single Kripke Structure s.t. A[p U A[q U r]] is verified but A[A[p U q] U r] is not (or the converse).
Now, for simplicity, we assume to deal with a Kripke Structure in which every state has only one possible future state. Therefore, we can forget about the A modifier and consider the LTL version of the given problem: is [p U [q U r]] equivalent to [[p U q] U r]?.
Let's break down [p U [q U r]]:
[q U r] is true on paths which match the expression {q}*{r}
[p U [q U r]] is true on paths that mach {p}*{[q U r]} = {p}*{q}*{r}
What about [[p U q] U r]?
[p U q] is true on paths which match the expression {p}*{q}
[[p U q] U r] is true on paths that mach {[p U q]}*{r} = {{p}*{q}}*{r}
Now, {p}*{q}*{r} != {{p}*{q}}*{r}.
In fact, {p}*{q}*{r} matches any path in which a sequence of p is followed by r and there is no q along the way.
However, {{p}*{q}}*{r} does not. If a path contains a sequence of p, then the occurrence of q before r is mandatory.
Thus, the two formulas are not equivalent.
Hands-On Answer:
Let's encode a Kripke structure that provides the same counter-example using NuSMV
MODULE main ()
VAR
p: boolean;
q: boolean;
r: boolean;
INVAR !q;
INIT
!q & p & !r
TRANS
r -> next(r);
TRANS
p & !r -> next(r);
CTLSPEC A[p U A[q U r]];
CTLSPEC A[A[p U q] U r];
and check it:
~$ NuSMV -int
NuSMV > reset; read_model -i test.smv; go; check_property
-- specification A [ p U A [ q U r ] ] is true
-- specification A [ A [ p U q ] U r ] is false
-- as demonstrated by the following execution sequence
Trace Description: CTL Counterexample
Trace Type: Counterexample
-> State: 1.1 <-
p = TRUE
q = FALSE
r = FALSE
Indeed, one property is verified but the other is not.
I want to proof this lemma in Coq:
a : Type
b : Type
f : a -> b
g : a -> b
h : a -> b
______________________________________(1/1)
(forall x : a, f x = g x) ->
(forall x : a, g x = h x) -> forall x : a, f x = h x
I know that Coq.Relations.Relation_Definitions defines transitivity for relations:
Definition transitive : Prop := forall x y z:A, R x y -> R y z -> R x z.
Simply using the proof tactic apply transitivity obviously fails. How can I apply the transitivity lemma to the goal above?
The transitivity tactic requires an argument, which is the intermediate term that you want to introduce into the equality. First call intros (that's almost always the first thing to do in a proof) to have the hypotheses nicely in the environment. Then you can say transitivity (g x) and you're left with two immediate applications of an assumption.
intros.
transitivity (g x); auto.
You can also make Coq guess which intermediate term to use. This doesn't always work, because sometimes Coq finds a candidate that doesn't work out in the end, but this case is simple enough and works immediately. The lemma that transitivity applies is eq_trans; use eapply eq_trans to leave a subterm open (?). The first eauto chooses a subterm that works for the first branch of the proof, and here it also works in the second branch of the proof.
intros.
eapply eq_trans.
eauto.
eauto.
This can be abbreviated as intros; eapply eq_trans; eauto. It can even be abbreviated further to
eauto using eq_trans.
eq_trans isn't in the default hint database because it often leads down an unsuccessful branch.
Ok, I was on the wrong track. Here is the proof of the lemma:
Lemma fun_trans : forall (a b:Type) (f g h:a->b),
(forall (x:a), f x = g x) ->
(forall (x:a), g x = h x) ->
(forall (x:a), f x = h x).
Proof.
intros a b f g h f_g g_h x.
rewrite f_g.
rewrite g_h.
trivial.
Qed.
Can anyone explain why these two statements aren't equal?
if not(a and not b):
// do some stuff
if (not a and b):
// do some stuff
I tried to make my program more understandable by changing the first statement to the second but it doesn't work. I don't totally understand why.
You should look into De Morgan's Thereom, half of which is (a):
not(p and q) -> not(p) or not(q)
In terms of how that applies to your situation, just replace p with a and q with not(b):
not(a and not b) -> not(a) or not(not(b))
-> not(a) or b
(a) The other half is:
not(p or q) -> not(p) and not(q)
if not(a and not b) is the same as if (not a) or b, not what you wrote.
You also need to flip the 'and' to 'or' due to De Morgan's law
if not(a and not b)
becomes
if (not a or b)