Trying to draw a Non- Deterministic Finite Automata [closed] - automata

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm completely new to finite automata and kind of struggling to understand the topic.
I'm able to draw simple ones but I have a practice question that asks to:
Design a Non- Deterministic Finite Automata that accepts ∑={0,1}. The Non-Deterministic Finite Automata should be able to determine all strings that have at most two zeroes and at least two ones.
How do I do this?

Here is a minimal DFA for the language (minimal DFAs are DFAs are NFAs):
0 0 0
----->(0,0)----->(1,0)----->(2,0)-------+
| | | |
| 1 | 1 | 1 | __
| | | | / \
V 0 V 0 V 0 V V | 0, 1
(0,1)----->(1,1)----->(2,1)----->dead--/
| | | ^
| 1 | 1 | 1 |
| | | |
V 0 V 0 V 0 |
(0,2)----->(1,2)----->(2,2)-------+
/ ^ / ^ / ^
1 | | 1 | | 1 | |
\_/ \_/ \_/
The idea is that state (x,y) is visited after seeing x zeroes and y ones; if you've seen two zeroes and you see another, the string is rejected by transitioning to a dead state; if you've seen two ones, you can see as many more as you like. States of the form (x,2) are accepting.

Related

Google Sheets - Logical AND between ranges [duplicate]

This question already has answers here:
ArrayFormula and "AND" Formula in Google Sheets
(4 answers)
Closed 4 months ago.
How can I perform a logical AND between two ranges?
I've tried using the AND function, but it collapses the array into a single TRUE/FALSE value by performing an AND between all the cells, instead of operating pairwise between the ranges.
Example:
ARRAYFORMULA(AND(A1:B2, C1:D2))
where A1:B2 is
| | A | B |
|-|-----|-----|
|1|TRUE |FALSE|
|2|FALSE|TRUE |
and C1:D2 is
| | C | D |
|-|----|-----|
|1|TRUE|FALSE|
|2|TRUE|FALSE|
would result in
| | X | Y |
|-|-----|-----|
|1|TRUE |FALSE|
|2|FALSE|FALSE|
But instead what happens is
| | X | Y |
|-|-----|-----|
|1|FALSE| |
|2| | |
multiplication is the way:
=ARRAYFORMULA(A1:B2*C1:D2)
=INDEX(A1:B2*C1:D2=1)

Interleave two vectors

I'm trying my first steps with SIMD and I was wondering what the right approach is to the following problem. Consider two vectors:
+---+---+---+---+ +---+---+---+---+
| 0 | 1 | 2 | 3 | | 4 | 5 | 6 | 7 |
+---+---+---+---+ +---+---+---+---+
How to "interleave" the elements of those vectors so that they become:
+---+---+---+---+ +---+---+---+---+
| 0 | 4 | 1 | 5 | | 2 | 6 | 3 | 7 |
+---+---+---+---+ +---+---+---+---+
I was surprised I could not find an instruction for doing it, given the great many kinds of shuffles, broadcasts, permutes, ... Probably it could be done with some unpacklo and unpackhi and what not, but I was wondering if there is a canonical way of doing it as it seems to be quite common problem (SoA vs. AoS). For simplicity let's assume AVX(2) and vectors of four floats.
Edit:
Floats vs. doubles
The comment below (correctly) suggest I should use unpcklps and unpckhps for floats. Which instruction should I use to unpack vector of four doubles? I'm asking because _mm256_unpacklo_pd/_mm256_unpackhi_pd:
Unpack and interleave double-precision (64-bit) floating-point elements from the high half of each 128-bit lane in a and b, and store the results in dst.
DEFINE INTERLEAVE_HIGH_QWORDS(src1[127:0], src2[127:0]) {
dst[63:0] := src1[127:64]
dst[127:64] := src2[127:64]
RETURN dst[127:0]
}
dst[127:0] := INTERLEAVE_HIGH_QWORDS(a[127:0], b[127:0])
dst[255:128] := INTERLEAVE_HIGH_QWORDS(a[255:128], b[255:128])
dst[MAX:256] := 0
So what it apparently does is:
+---+---+---+---+ +---+---+---+---+
| 0 | 4 | 2 | 6 | | 1 | 5 | 3 | 7 |
+---+---+---+---+ +---+---+---+---+

Does endianness refer to ordering within a defined array or memory or also the actual memory used?

I'm having trouble expressing my question in words, but I think I can express it visually quite simply. Storing the string abcd, is the difference between Big and Little Endian this:
memory address | 0 | 1 | 2 | 3 | 4 | 5 | 6 | ...
little endian | d | c | b | a |
big endian | a | b | c | d |
Or this:
memory address | 0 | 1 | 2 | 3 | 4 | 5 | 6 | ...
little endian | d | c | b | a |
big endian | a | b | c | d |
My attempt in words: does "endianness" refer to the ordering of bytes within a specific memory "array", where in both cases the array begins at the same point in memory, or does it refer to both the ordering and the actual array used?
Endianness refers to the ordering of bytes used to store a single multi-byte numerical value. The "big endian" system in your second image is storing 4-byte integers unaligned, which no system would normally do.

Generate random Numbers with Specific need

I am developing Cocos 2D game.
Please Mention Below Arrangement.
---------------------------------|
| | | |
| | | |
---------------------------------|
| | | |
| | | |
---------------------------------|
| | | |
| | | |
---------------------------------|
---------------------------------|
| | | |
| | | |
---------------------------------|
Now, I need to generate numbers between 1-99 in Upper Block so, When user touch the numbers they dropped into below block. And I have to check for is that numbers make any combination of operation(i.e. +,-, *,/) Thus it divided by 10 or not?
For example if user choose numbers like 3,2,7,8 Then I have internally calculated (3 +2 +7 +8 = 20 so 20%10 == 0 so number is divisible by 10 so increase score), Same thing for -, *,/.
Math operator is will be same but I have to decide by some code that what user has think for dragging numbers.
So my question is how to generate that numbers in upper block that most probably support calculation(Any one of +,-,*,/) for combinations of them give dividability by 10?
Numbers are not such like any combinations(Either +, -, * ,/) of them thus they did not give answer which have modulo 0 to 10.
Any help will be appreciated.
You could try an inefficient algorithm. Repeatedly generating numbers then testing to see if they pass your condition
do
{
a = random();
b = random();
c = random();
d = random();
} while( !test(a,b,c,d) );
This simplifies the logic. You do need to ensure that at least some combination will work or you will get an infinite loop.

Entity Relation notation in text

Is there a standard (non-graphical) notation for Entity Relationships?
right now I'm using my own janky notation:
User >> Photo , (1-many)
User > Profile , (1-1 hasOne)
Profile < User , (1-1 belongsTo)
Photo << User , (many-1 belongsTo)
Photo <> Tag , (many-many)
Almost 10 years later and I've also had a hard time finding plaintext standards. Here's what I've found so far (fair warning though, it's mostly graphical standards that happen to work well in text).
First, the common term for describing the cardinality of a relationship between objects is "multiplicity".
This association relationship indicates that (at least) one of the two related classes make reference to the other. This relationship is usually described as "A has a B" (a mother cat has kittens, kittens have a mother cat).
Wikipedia
Though a considerable number of sources also use the term "cardinality".
There's a few good answers about the difference on this SO question about Multiplicity vs Cardinality. I found this one to be pretty succinct:
...a multiplicity is made up of a lower and an upper cardinality. A cardinality is how many elements are in a set. Thus, a multiplicity tells you the minimum and maximum allowed members of the set.
Jim L.
UML's Multiplicity Notation
UML's multiplicity notation works well in text.
+--------------+--------+-----------------------------------------+
| Multiplicity | Option | Cardinality |
+--------------+--------+-----------------------------------------+
| 0..0 | 0 | Collection must be empty |
| 0..1 | | No instances or one instance |
| 1..1 | 1 | Exactly one instance |
| 0..* | * | Zero or more instances |
| 1..* | | At least one instance |
| 5..5 | 5 | Exactly 5 instances |
| m..n | | At least m but no more than n instances |
+--------------+--------+-----------------------------------------+
There seem to be a few variations of this:
Microsoft's Relational Notation
+---------------------------------+---------------------+
| Multiplicity | Cardinality |
+---------------------------------+---------------------+
| * | One to zero or more |
| 1..* | One to one or more |
| 0..1 | One to zero or one |
| 1 | Exactly one |
| Two numbers separated by a dash | a range |
+---------------------------------+---------------------+
IBM's
+------+--------------------+-------------------------------+
| Rose | Software Architect | Description |
+------+--------------------+-------------------------------+
| n | * | Unlimited number of instances |
| 1 | 1 | Exactly 1 instance |
| 0..n | * | 0 or more instances |
| 1..n | 1,,* | 1 or more instances |
| 0..1 | 0..1 | 0 or 1 instances |
+------+--------------------+-------------------------------+
Smartdraw's Martin Style
Chen Style
From what I've read Chen style is the "original format". I commonly see this expressed in text as:
+----------+--------------+
| Notation | Description |
+----------+--------------+
| 1:1 | One to One |
| 1:N | One to Many |
| N:1 | Many to One |
| M:N | Many to Many |
+----------+--------------+
IDEF1X and Others
There's IDEF1x (a NIST standard):
IDEF1X is a method for designing relational databases with a syntax designed to support the semantic constructs necessary in developing a conceptual schema.
That seems to describe the Min-Max / ISO notation (the English link is currently broken but here's a German article) referenced by Wikipedia's Entity–relationship model article which also lists a few other styles of graphical notations, some of which are text-friendly.
The German language article on (min,max) notation also has a useful table comparing UML, Chen, (min,max) and MC (Modified Chen):
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
| (min,max) [Entity 1] | [UML, Entity 1] | Chen-Notation | MC-Notation | [UML, Entity 2] | (min,max) [Entity 2] |
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
| (0,1) | 0..1 | 1:1 | c:c | 0..1 | (0,1) |
| (0,N) | 0..1 | 1:N | c:mc | 0..* | (0,1) |
| (0,N) | 1..1 | 1:N + total participation | 1:mc | 0..* | (1,1) |
| (0,N) | 0..* | M:N | mc:mc | 0..* | (0,N) |
| (1,1) | 0..1 | total participation + 1:1 | c:1 | 1..1 | (0,1) |
| (1,N) | 0..1 | total participation + 1:N | c:m | 1..* | (0,1) |
| (1,1) | 1..1 | total part. + 1:1 + total part. | 1:1 | 1..1 | (1,1) |
| (1,N) | 1..1 | total part. + 1:N + total part. | 1:m | 1..* | (1,1) |
| (1,N) | 0..* | total participation + M:N | mc:m | 1..* | (0,N) |
| (1,N) | 1..* | total part. + M:N + total part. | m:m | 1..* | (1,N) |
+----------------------+-----------------+---------------------------------+-------------+-----------------+----------------------+
Why not use the same than in ER-Diagramms:
User 1-n Photos
User 1-1 Profile
Photo n-1 User
and so on. But I never heard of an official plaintext standart.
There is software available that transforms plain text descriptions into visual ER diagrams.
For instance erd uses the following notation:
Cardinality Syntax
0 or 1 ?
exactly 1 1
0 or more *
1 or more +
Examples:
Person *--1 `Birth Place`
Artist +--? PlatinumAlbums
Check also this list of similar tools.
However, none of these could be called a standard.

Resources