FSM for long bit sequence - fsm

Currently, I'm working on a mealy fsm that detects a 17 bit sequence 10100001010000001. Due to the length of the sequence, I'm having difficulty figuring out which state to return to when the input doesn't allow me to move on to the next state. Any suggestions ??

Think about what previous pattern is satisfied when the expected pattern is not met. The FSM for a 10100001010000001 Mealy machine is shown below, in ASCII art (not sure how it will render here...)
s0-1->s1-0->s2-1->s3-0->s4-0->s5-0->s6-0->s7-1->s8-0->s9-1->s10-0->s11-0->s12-0->s13-0->s14-0->s15-0->s16-1->s17-0->s2
| | | | | | | | | | | | | | | | | |
0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 0 1
| | | | | | | | | | | | | | | | | |
s0 s1 s0 s1 s3 s1 s1 s0 s1 s0 s1 s3 s1 s1 s8 s1 s0 s1

Related

Overlap two equally dimension matrices in R

I have two matrices A and B, both have the same dimensions and are binary in nature. I want to overlap matrix A on matrix B.
Matrix A:
| Gene A | Gene B |
| -------- | ----------- |
| 0 | 1 |
| 0 | 1 |
Matrix B:
| Gene A | Gene B |
| -------- | ----------- |
| 1 | 0 |
| 0 | 0 |
Result:
Matrix C:
| Gene A | Gene B |
| -------- | ----------- |
| 1 | 1 |
| 0 | 1 |
The resultant matrix will also have the same dimension as the input.
How can this be done?
Please let me know.

(AVB)&(AV~B) is logically equivalent to ~~A, it that true or false?

(AVB)&(AV~B) is logically equivalent to ~~A?
It kind of confused me since they are in different dimension.
Starting from:
(A∨B)∧(A∨¬B)
One can first apply one of De Morgan's laws to the AND:
¬(¬(A∨B)∨¬(A∨¬B))
Next, one of De Morgan's laws can be applied to each side:
¬((¬A∧¬B)∨(¬A∧B))
By applying distributivity of AND over OR in reverse, ¬A can be extracted:
¬(¬A∧(¬B∨B))
By complementation, ¬B∨B is 1:
¬(¬A∧1)
By identity for AND:
¬¬A
Applying double negation:
A
This goes through your target ¬¬A without going through simple A. It's much simpler not to do that.
Starting again from:
(A∨B)∧(A∨¬B)
By applying distributivity of OR over AND in reverse, A can be extracted:
A∨(B∧¬B)
By complementation, B∨¬B is 1:
A∧1
By identity for AND:
A
Applying double negation in reverse:
¬¬A
Since you mention doing it by truth table, here's my go at showing that they're equivalent that way:
+---+---+----+----+-------+--------+--------------+-----+
| A | B | ¬A | ¬B | (A∨B) | (A∨¬B) | (A∨B)∧(A∨¬B) | ¬¬A |
+---+---+----+----+-------+--------+--------------+-----+
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 |
+---+---+----+----+-------+--------+--------------+-----+

How can I execute multiple queries in one query?

I am building a chat application where I am using Firebase to send and receive messages. Once I send or receive a message, I am storing it to SQLite as follows. Now it the recent chats screen, I need the last message from all the unique chats, number of unread messages in those unique chats in one single query as I am observing the SQLite database.
Mid(STRING) | SentBy | SentTo | message | readTime | sentTime| Type
----------------+--------+--------+---------+----------+---------+------
A | AA | JD | M1 | 1 | 0 | S
B | JD | AA | M2 | 2 | 1 | s
C | AA | JD | M3 | 3 | 2 | s
D | AB | JD | m5 | null | 3 | s
E | AA | JC | M1 | 5 | 4 | s
F | JD | AB | M2 | 6 | 5 | s
G | AA | JD | M3 | 7 | 6 | s
H | AA | JC | m5 | 8 | 7 | s
I | AA | JD | M1 | null | 8 | s
J | JD | AA | M2 | 10 | 9 | s
K | AA | JD | M3 | 11 | 10 | s
L | AB | JC | m5 | 12 | 11 | s
M | AA | JD | M1 | 13 | 12 | s
N | JC | AA | M2 | 14 | 13 | s
O | AB | JD | M3 | 15 | 14 | s
P | JC | JD | m5 | 16 | 15 | s
I tried
SELECT *,COUNT() FROM messagesTable GROUP BY min ( sentBy, sentTo ), max( sentBy , sentTo ) ORDER BY sentTime desc
This query gives me the last messages from every combination of sentTo and sentBy. But I also need to know how many messages are unread for that combination. I want to run a query for every row like
SELECT COUNT() FROM messagesTable WHERE sentBy = message.sentBy, sentTo = message.sentTo, readTime = null
How can I run both queries in a single query?
You must group by the combination of (sentby, sentto) and with a straight count(*) get the total number of messages and with conditional aggregation you can get the number of unread mesages.
Then join to the result to the table to get also the last message:
select
g.user1, g.user2, g.lasttime, m.message lastmessage,
g.totalcounter, g.unreadcounter
from messagestable m inner join (
select
min(sentby, sentto) user1, max(sentby, sentto) user2,
max(senttime) lasttime, count(*) totalcounter,
sum(case when readtime is null then 1 else 0 end) unreadcounter
from messagestable
group by user1, user2
) g
on g.user1 = min(m.sentby, m.sentto) and g.user2 = max(m.sentby, m.sentto)
and g.lasttime = m.senttime
order by g.lasttime desc
See the demo.
Results:
| user1 | user2 | lasttime | lastmessage | totalcounter | unreadcounter |
| ----- | ----- | -------- | ----------- | ------------ | ------------- |
| JC | JD | 15 | m5 | 1 | 0 |
| AB | JD | 14 | M3 | 3 | 1 |
| AA | JC | 13 | M2 | 3 | 0 |
| AA | JD | 12 | M1 | 8 | 1 |
| AB | JC | 11 | m5 | 1 | 0 |

Can modal operator be defined as a boolean function?

Let us consider for simplicity only Kripke structures with a single agent whose knowledge is described by the modal operator K. We know that in all the corresponding Kripke structures where K is interpreted by equivalence there holds for any formula A
a) the formula KA -> A (Knowledge Axiom) is valid ,
b) but the formulas A -> KA and ¬KA are not valid.
Utilize these facts to show that such a behaviour of the modal operator K cannot be encoded by any boolean function (ie. Truth values defined by a table).
Hint: Suppose the truth value of KA can be calculated from the truth value of A using a truth table for K (in the same way as ¬A is calculated form A). Consider all possible truth tables for K and show that none of them grants the properties a) and b) mentioned above.
I dont understand that hint... making truth table of K is like constructing truth table of negation symbol ¬ , which in my mind doesnt make sense I think it makes sense only to make negation of something and not just negation
Consider all possible truth tables for K:
| A | K₁A | K₂A | K₃A | K₄A |
—————————————————————————————
| 1 | 1 | 1 | 0 | 0 |
—————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
Show that none of them grants the properties a) and b) mentioned above.
Case 1
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 2
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 1 | 1 | 1 | 0 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, A->KA is a tautology.
Case 3
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 1 | 0 | 1 | 0 |
In this case, KA->A is not a tautology.
Case 4
| A | KA | KA->A | A->KA | ¬KA |
—————————————————————————————————
| 1 | 0 | 1 | 0 | 1 |
—————————————————————————————————
| 0 | 0 | 1 | 1 | 1 |
In this case, ¬KA is a tautology.
Can desired behaviour of K be encoded by many-valued matrix?
For alethic modal systems, the answer is the following:
3 values are insufficient,
4 values are sufficient for the so-called basic modal logic,
any finite number of values is insufficient for syntactically “full” and deductively “natural” modal system.
See, e. g., introductory parts in the article by Jean-Yves Beseau.
I hope these results are relevant for epistemic modal systems.

Is there an sqlite function that can check if a field matches a certain value and return 0 or 1?

Consider the following sqlite3 table:
+------+------+
| col1 | col2 |
+------+------+
| 1 | 200 |
| 1 | 200 |
| 1 | 100 |
| 1 | 200 |
| 2 | 400 |
| 2 | 200 |
| 2 | 100 |
| 3 | 200 |
| 3 | 200 |
| 3 | 100 |
+------+------+
I'm trying to write a query that will select the entire table and return 1 if the value in col2 is 200, and 0 otherwise. For example:
+------+--------------------+
| col1 | SOMEFUNCTION(col2) |
+------+--------------------+
| 1 | 1 |
| 1 | 1 |
| 1 | 0 |
| 1 | 1 |
| 2 | 0 |
| 2 | 1 |
| 2 | 0 |
| 3 | 1 |
| 3 | 1 |
| 3 | 0 |
+------+--------------------+
What is SOMEFUNCTION()?
Thanks in advance...
In SQLite, boolean values are just integer values 0 and 1, so you can use the comparison directly:
SELECT col1, col2 = 200 AS SomeFunction FROM MyTable
Like described in Does sqlite support any kind of IF(condition) statement in a select you can use the case keyword.
SELECT col1,CASE WHEN col2=200 THEN 1 ELSE 0 END AS col2 FROM table1

Resources