How can w’xz + w’yz + x’yz’ + wxy’z be implemented with 4 NOR gates (+ inverters), given d = wyz - digital-logic

How can you implement the following function with only four NOR gates and inverters:
F = w’xz + w’yz + x’yz’ + wxy’z
d = wyz

First get the Karnaugh map:
w’x z + w’ yz + x’yz’ + wxy’z
a b c e
wx\yz 00 01 11 10
---- c
00 0 0 | 1| |1 |
| b| ----
----|----
01 0 |a1 | 1|| 0
----|--|-
---
11 0 1e 0 0
---
10 0 0 0 |1 |
Then get the Product Of Sums:
wx\yz 00 01 11 10
| |
| |
00 | 0 0| 1 1
--------
------ -------
01 0| 1 1 | 0
| | A
| ---|
11 0| 1 |0|| 0
------ |C|--------
-------- | |
10 | 0 0| |0| 1
| | ---
| |
| B |
(x'+z)(x+y)(w'+y'+z')
A B C
Then reduce to utilize the available d =wyz pin, and to get the requested 4 nors:
=( (x'+z)(x+y) (w'+y'+z'))''
=(((x'+z)(x+y))(w'+y'+z'))''
=(((x'+z)(x+y))'+(w'+y'+z')')'
=(((x'+z)(x+y))'+(wyz))'
=(((x'+z)(x+y))'+d)'
=(((x'+z)'+(x+y)')+d)'
=(((x'+z)'+(x+y)')''+d)'
^ ^ ^ ^ 4 nors
^ ^ 2 inverters

Related

Programmable Logic Array (PLA) Design

I need to design Programmable Logic Array (PLA) circuit with given functions. How can I design circuit with POS form functions. Can someone explain that? enter image description here
Below is the design process completed for F, the other two outputs, G and H, can done in a similar fashon.
F Truth Table
A B C D # F G H
0 0 0 0 0 1
0 0 0 1 1 0
0 0 1 0 2 0
0 0 1 1 3 1
0 1 0 0 4 1
0 1 0 1 5 1
0 1 1 0 6 0
0 1 1 1 7 0
1 0 0 0 8 0
1 0 0 1 9 0
1 0 1 0 10 1
1 0 1 1 11 1
1 1 0 0 12 0
1 1 0 1 13 0
1 1 1 0 14 1
1 1 1 1 15 1
F Karnaugh Map:
AB\CD 00 01 11 10
\
----------
00 0 | 1 x 1 | 0
----------
--------
01 | 1 y 1 | 0 0
--------
----------
11 0 0 | 1 1 |
| z |
| |
10 0 0 | 1 1 |
----------
F Sum Of Product Boolean:
(A'B'D)+(A'BC')+(AC)
x y z ==>(for ref):
x=(A'B'D)
y=(A'BC')
z=(AC)
F Logic Circuit:
------- ------
A---NOT---| | ------- | |
| AND |---| | | |
B---NOT---| | | AND | x | |
------- | |--------------| |
D---------------------------| | | |
------- | |
| | F
------- | OR |---
A---NOT---| | ------- ------ | |
| AND |---| | y | | | |
C---NOT---| | | AND |---| | | |
------- | | | | y+z | |
B---------------------------| | | |-----| |
------- | OR | | |
------- | | | |
A---NOT---| | z | | | |
| AND |---------------------| | ------
C---NOT---| | | |
------- | |
------

Oracle unpivot many to one

I would like to unpivot from 1 column to 3 rows and my data looks like this.
to transform to this.
With this code I get 1 to 2, but not 1 to 3:
SELECT *
FROM (SELECT ID,
CAT1_Y1_FACT,
CAT1_Y2_FACT,
CAT1_Y3_FACT,
CAT2_Y1_FACT,
CAT2_Y2_FACT,
CAT2_Y3_FACT
FROM TABLE T) UNPIVOT(CAT1_Y1_FACT FOR NBR_YEARS IN(CAT1_Y1_FACT AS 1,
CAT1_Y1_FACT AS 2,
CAT1_Y1_FACT AS 3))
Use UNPIVOT with multiple arguments in the FOR ( ... ) IN clause:
Oracle Setup:
CREATE TABLE table_name (
id, cat1_y1_fact, cat1_y2_fact, cat1_y3_fact, cat2_y1_fact, cat2_y2_fact, cat2_y3_fact
) AS
SELECT LEVEL,
100 * LEVEL + 11,
100 * LEVEL + 12,
100 * LEVEL + 13,
100 * LEVEL + 21,
100 * LEVEL + 22,
100 * LEVEL + 23
FROM DUAL
CONNECT BY LEVEL <= 3;
Query:
SELECT *
FROM table_name
UNPIVOT ( fact FOR (cat, year) IN (
cat1_y1_fact AS (1, 1),
cat1_y2_fact AS (1, 2),
cat1_y3_fact AS (1, 3),
cat2_y1_fact AS (2, 1),
cat2_y2_fact AS (2, 2),
cat2_y3_fact AS (2, 3)
) )
Output:
ID | CAT | YEAR | FACT
-: | --: | ---: | ---:
1 | 1 | 1 | 111
1 | 1 | 2 | 112
1 | 1 | 3 | 113
1 | 2 | 1 | 121
1 | 2 | 2 | 122
1 | 2 | 3 | 123
2 | 1 | 1 | 211
2 | 1 | 2 | 212
2 | 1 | 3 | 213
2 | 2 | 1 | 221
2 | 2 | 2 | 222
2 | 2 | 3 | 223
3 | 1 | 1 | 311
3 | 1 | 2 | 312
3 | 1 | 3 | 313
3 | 2 | 1 | 321
3 | 2 | 2 | 322
3 | 2 | 3 | 323
db<>fiddle here
For multiple pivot columns the syntax is given in the Oracle SELECT documentation:
Oracle Setup:
CREATE TABLE table_name (
id, cat1_y1_fact, cat1_y2_fact, cat1_y3_fact, cat2_y1_fact, cat2_y2_fact, cat2_y3_fact,
cat1_y1_value, cat1_y2_value, cat1_y3_value, cat2_y1_value, cat2_y2_value, cat2_y3_value
) AS
SELECT LEVEL,
100 * LEVEL + 11,
100 * LEVEL + 12,
100 * LEVEL + 13,
100 * LEVEL + 21,
100 * LEVEL + 22,
100 * LEVEL + 23,
1000 * LEVEL + 110,
1000 * LEVEL + 120,
1000 * LEVEL + 130,
1000 * LEVEL + 210,
1000 * LEVEL + 220,
1000 * LEVEL + 230
FROM DUAL
CONNECT BY LEVEL <= 3;
Query:
SELECT *
FROM table_name
UNPIVOT ( (fact, value) FOR (cat, year) IN (
(cat1_y1_fact, cat1_y1_value) AS (1, 1),
(cat1_y2_fact, cat1_y2_value) AS (1, 2),
(cat1_y3_fact, cat1_y3_value) AS (1, 3),
(cat2_y1_fact, cat2_y1_value) AS (2, 1),
(cat2_y2_fact, cat2_y2_value) AS (2, 2),
(cat2_y3_fact, cat2_y3_value) AS (2, 3)
) )
Output:
ID | CAT | YEAR | FACT | VALUE
-: | --: | ---: | ---: | ----:
1 | 1 | 1 | 111 | 1110
1 | 1 | 2 | 112 | 1120
1 | 1 | 3 | 113 | 1130
1 | 2 | 1 | 121 | 1210
1 | 2 | 2 | 122 | 1220
1 | 2 | 3 | 123 | 1230
2 | 1 | 1 | 211 | 2110
2 | 1 | 2 | 212 | 2120
2 | 1 | 3 | 213 | 2130
2 | 2 | 1 | 221 | 2210
2 | 2 | 2 | 222 | 2220
2 | 2 | 3 | 223 | 2230
3 | 1 | 1 | 311 | 3110
3 | 1 | 2 | 312 | 3120
3 | 1 | 3 | 313 | 3130
3 | 2 | 1 | 321 | 3210
3 | 2 | 2 | 322 | 3220
3 | 2 | 3 | 323 | 3230
db<>fiddle here

Replace missing values by a reference value for each id in panel data

I have panel data:
Id | Wave| Localisation| Baseline
1 | 1 | AA | 1
1 | 2 | . | 0
1 | 3 | . | 0
2 | 2 | AB | 1
2 | 3 | . | 0
3 | 1 | AB | 1
3 | 3 | . | 0
4 | 2 | AC | 1
4 | 3 | . | 0
Some variable values of one panel (hhsize, localisation, whatever) serves as a reference (these values are included in the baseline interview only).
By consequence, for each id we do not have all the information. For the id==1 for instance, we have missing values in the column Localisation for not-baseline-interview (baseline==0).
I would like to spread the baseline values to each panel. That is, I want to replace missing values . in column Localisation by Localisation given in the baseline interview for each id.
In fact, the information Localisation remain the same across different waves. So it is useful to know the localization for each wave for one person.
If the data pattern you present is the same for the entire dataset, then the following should work:
clear
input Id Wave str2 Localisation Baseline
1 1 AA 1
1 2 . 0
1 3 . 0
2 2 AB 1
2 3 . 0
3 1 AB 1
3 3 . 0
4 2 AC 1
4 3 . 0
end
bysort Id (Wave): replace Localisation = Localisation[1] if Localisation == "."
list, sepby(Id) abbreviate(15)
+-------------------------------------+
| Id Wave Localisation Baseline |
|-------------------------------------|
1. | 1 1 AA 1 |
2. | 1 2 AA 0 |
3. | 1 3 AA 0 |
|-------------------------------------|
4. | 2 2 AB 1 |
5. | 2 3 AB 0 |
|-------------------------------------|
6. | 3 1 AB 1 |
7. | 3 3 AB 0 |
|-------------------------------------|
8. | 4 2 AC 1 |
9. | 4 3 AC 0 |
+-------------------------------------+

Multiply Matrices in DAX

Suppose I have two matrices MatrixA and MatrixB given as follows (where i is the row number and j is the column number:
MatrixA | MatrixB
i | j | val | i | j | val
---|---|---- | ---|---|----
1 | 1 | 3 | 1 | 1 | 2
1 | 2 | 5 | 1 | 2 | 3
1 | 3 | 9 | 2 | 1 | 7
2 | 1 | 2 | 2 | 2 | -1
2 | 2 | 1 | 3 | 1 | 0
2 | 3 | 3 | 3 | 2 | -4
3 | 1 | 3 |
3 | 2 | -1 |
3 | 3 | 2 |
4 | 1 | 0 |
4 | 2 | 7 |
4 | 3 | 6 |
In a more familiar form, they look like this:
MatrixA = 3 5 9 MatrixB = 2 3
2 1 3 7 -1
-1 2 0 0 -4
7 0 6
I'd like to calculate their product (which is demonstrated in this YouTube video):
Product = 41 -32
11 -7
12 -5
14 -3
In the unpivoted column form I used earlier, this is
i | j | val
---|---|----
1 | 1 | 41
1 | 2 | -32
2 | 1 | 11
2 | 2 | -7
3 | 1 | 12
3 | 2 | -5
4 | 1 | 12
4 | 2 | -3
I'm looking for a general calculation that multiplies any compatible k x n and n x m matrices together as a calculated table.
I think I've got it figured out. If MatrixA is k x n and MatrixB is n x m dimensional:
Product =
ADDCOLUMNS(
CROSSJOIN(VALUES(MatrixA[i]), VALUES(MatrixB[j])),
"val",
SUMX(
ADDCOLUMNS(
SELECTCOLUMNS(GENERATESERIES(1, DISTINCTCOUNT(MatrixA[j])), "Index", [Value]),
"A", LOOKUPVALUE(MatrixA[val], MatrixA[i], [i], MatrixA[j], [Index]),
"B", LOOKUPVALUE(MatrixB[val], MatrixB[i], [Index], MatrixB[j], [j])),
[A] * [B]))
The CROSSJOIN creates a new table with columns [i] and [j] which has k x m rows. For each i and j row pair in this cross join table, the value for that cell is computed as the sum product of i row of MatrixA with j column of MatrixB. The GENERATESERIES bit just creates an Index list that has a length of the matching dimension n.
For example, when i = 3 and j = 2, the middle section for the given example is
ADDCOLUMNS(
SELECTCOLUMNS(GENERATESERIES(1, DISTINCTCOUNT(MatrixA[j])), "Index", [Value]),
"A", LOOKUPVALUE(MatrixA[val], MatrixA[i], 3, MatrixA[j], [Index]),
"B", LOOKUPVALUE(MatrixB[val], MatrixB[i], [Index], MatrixB[j], 2))
which generates the table
Index | A | B
------|-----|----
1 | -1 | 3
2 | 2 | -1
3 | 0 | -4
where the [A] column is the 3rd row of MatrixA and the [B] column is the 2nd row of MatrixB.

How to understand this style of K-map

I have seen a different style of Karnaugh Map for logic design. This is the style they used:
Anyone knows how this K-Map done? How to comprehend with this kind of map? Or how they derived from that equation from that map. The map is quite different from the common map like this:
The maps relate to each other this way, the only difference is the cells' (terms') indexes corresponding to the variables or the order of the variables.
The exclamation mark is only an alternative to the negation of a variable. !A is the same as ¬A, also sometimes noted A'.
!A A A !A ↓CD\AB → 00 01 11 10
+----+----+----+----+ +----+----+----+----+
!B | 1 | 0 | 1 | 0 | !D 00 | 1 | 1 | 1 | 0 |
+----+----+----+----+ +----+----+----+----+
B | 1 | 1 | 1 | 1 | !D ~ 01 | 1 | x | x | 1 |
+----+----+----+----+ +----+----+----+----+
B | x | x | x | x | D 11 | x | x | x | x |
+----+----+----+----+ +----+----+----+----+
!B | 1 | 1 | x | x | D 10 | 0 | 1 | 1 | 1 |
+----+----+----+----+ +----+----+----+----+
!C !C C C
If you are unsure, of the indexes in the given K-map, you can always check that by writing the corresponding truth-table.
For example the output value of the first cell in the "strange" K-map is equal to 1 if !A·!B·!C·!D (all variables in its negation), that corresponds with the first line of the truth-table, so the index is 0. And so on.
index | A B C D | y
=======+=========+===
0 | 0 0 0 0 | 1
1 | 0 0 0 1 | 1
2 | 0 0 1 0 | 0
3 | 0 0 1 1 | x ~ 'do not care' state/output
-------+---------+---
4 | 0 1 0 0 | 1
5 | 0 1 0 1 | x
6 | 0 1 1 0 | 1
7 | 0 1 1 1 | x
-------+---------+---
8 | 1 0 0 0 | 0
9 | 1 0 0 1 | 1
10 | 1 0 1 0 | 1
11 | 1 0 1 1 | x
-------+---------+---
12 | 1 1 0 0 | 1
13 | 1 1 0 1 | x
14 | 1 1 1 0 | 1
15 | 1 1 1 1 | x
You can use the map the same way you would use the "normal" K-map to find the implicants (groups), because all K-maps indexing needs to conform to the Gray's code.
You can see the simplified boolean expression is the same in both styles of these K-maps:
f(A,B,C,D) = !A·!C + A·C + B + D = ¬A·¬C + A·C + B + D
!A·!C is marked red,
A·C blue,
B orange
and D green.
The K-maps were generated using latex's \karnaughmap command and tikz library.
it's the same in principle just the rows and columns (or the variables) are in a different order
The red labels are for when the variable is true, the blue for when it's false
It's actually the same map, but instead of A they have C and instead of B they have A and instead of C they have D and instead of D they have B

Resources