Proving boolean expression - bit-manipulation

>>> import z3
>>> X = z3.BitVec('X', 32)
>>> z3.prove( X^18 == ((X|(~44)) & (X^62)) + (X&44) )
proved
x^18 is equivalent to ((x|(~44))&(x^62))+(x&44) ??
How could this be possible?
I want to know detailed information about proving this formula...

You could display the (intermediate) bit vectors as symbolic sets of 8 bits each:
| X | x7 | x6 | x5 | x4 | x3 | x2 | x1 | x0 |
| 44 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 |
| ~44 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 |
| X|(~44) | 1 | 1 | x5 | 1 | x3 | x2 | 1 | 1 |
| 62 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
| X^62 | x7 | x6 | !x5 | !x4 | !x3 | !x2 | !x1 | x0 |
| (X|(~44))&(X^62) | x7 | x6 | 0 | !x4 | 0 | 0 | !x1 | x0 |
| X&44 | 0 | 0 | x5 | 0 | x3 | x2 | 0 | 0 |
| (X|(~44))&(X^62)+(X&44) | x7 | x6 | x5 | !x4 | x3 | x2 | !x1 | x0 |
| X^18 | x7 | x6 | x5 | !x4 | x3 | x2 | !x1 | x0 |
Six bits would suffice, as 62 can be expressed with six bits.
The addition step cannot produce carry bits, as all corresponding bit pairs have one zero bit each. The other operations only have a bitwise effect. Therefore, one could analyze the equivalence bit position by bit position.
The final two table rows show that the expressions are in fact equivalent.

Related

How to Sum all working days for each month but restart from 0 for every month in power Bi Dax

I would like to know how could I get the Sum of all working days for specific month but in the table starting each month's Sum over again.
This is my DateTable Now with this query for Work Days Sum:
Work Days Sum =
CALCULATE (
SUM ( 'DateTable'[Is working Day] ),
ALL ( 'DateTable' ),
'DateTable'[Date] <= EARLIER ( 'DateTable'[Date] )
)
Date | Month Order | Is working day | Work Days Sum |
January - 21 331
2022/01/01 | 1 | 0 | |
2022/01/02 | 1 | 0 | |
2022/01/03 | 1 | 1 | 1 |
2022/01/04 | 1 | 1 | 2 |
2022/01/05 | 1 | 1 | 3 |
2022/01/06 | 1 | 1 | 4 |
.....
2022/01/27 | 1 | 1 | 19 |
2022/01/28 | 1 | 1 | 20 |
2022/01/29 | 1 | 0 | 20 |
2022/01/30 | 1 | 0 | 20 |
2022/01/31 | 1 | 1 | 21 |
February 20 890
2022/02/01 | 2 | 1 | 22 |
2022/02/02 | 2 | 1 | 23 |
2022/02/03 | 2 | 1 | 24 |
2022/02/04 | 2 | 1 | 25 |
|
|
V
Date | Month Order | Is working day | Work Days Sum |
January - 21 21
2022/01/01 | 1 | 0 | |
2022/01/02 | 1 | 0 | |
2022/01/03 | 1 | 1 | 1 |
2022/01/04 | 1 | 1 | 2 |
2022/01/05 | 1 | 1 | 3 |
2022/01/06 | 1 | 1 | 4 |
.....
2022/01/27 | 1 | 1 | 19 |
2022/01/28 | 1 | 1 | 20 |
2022/01/29 | 1 | 0 | 20 |
2022/01/30 | 1 | 0 | 20 |
2022/01/31 | 1 | 1 | 21 |
February 20 41
2022/02/01 | 2 | 1 | 1 |
2022/02/02 | 2 | 1 | 2 |
2022/02/03 | 2 | 1 | 3 |
2022/02/04 | 2 | 1 | 4 |
2022/02/05 | 2 | 0 | 4 |
.....
Any idea on how I can change my dax query to achieve output of second table below the down arrow would be much appreciated.

Yearly conditional sum in SAS

I have a below table
+------+------+------+------+------+-----+
| Yr | col1 | col2 | col3 | col4 | PQR |
+------+------+------+------+------+-----+
| 2012 | 1 | 0 | 1 | 1 | 2 |
| 2012 | 0 | 1 | 0 | 0 | 4 |
| 2013 | 1 | 1 | 1 | 1 | 6 |
| 2014 | 0 | 0 | 0 | 0 | 8 |
| 2012 | 1 | 0 | 1 | 1 | 7 |
| 2013 | 0 | 1 | 0 | 0 | 3 |
| 2014 | 1 | 0 | 1 | 1 | 2 |
| 2012 | 0 | 1 | 0 | 0 | 10 |
| 2014 | 0 | 0 | 1 | 0 | 12 |
| 2014 | 0 | 0 | 0 | 0 | 5 |
+------+------+------+------+------+-----+
The output I want is as below
+------+-------+------+------+------+
| | Total | 2012 | 2013 | 2014 |
+------+-------+------+------+------+
| col1 | 17 | 9 | 6 | 2 |
| col2 | 23 | 14 | 9 | 0 |
| col3 | 29 | 9 | 6 | 14 |
| col4 | 17 | 9 | 6 | 2 |
+------+-------+------+------+------+
For row col1 in my output table
The column `Total` is `SUM(PQR)` when `col1` is 1 my input table
The value `17` is `SUM(PQR)` when `col1` is 1 in my input table
The value in col `2012` is `SUM(PQR)` when `col1` is 1 and `Yr=2012` in my input table
The value `9` is `SUM(PQR)` when `col1` is 1 and `Yr=2012` in my input table
Similarly 6 in column 2013 is SUM(PQR) when col1 is 1 and Yr is 2013
Hope the process to get output table is understood
I want to achieve the above result with SAS.
Any help will be really appreciated
Transpose the data into a categorical form and use PQR as a weight in your aggregating sum. Proc TABULATE is very adept at creating such tabulations.
data have;
infile datalines dlm='|'; input
Yr col1 col2 col3 col4 PQR ; datalines;
| 2012 | 1 | 0 | 1 | 1 | 2 |
| 2012 | 0 | 1 | 0 | 0 | 4 |
| 2013 | 1 | 1 | 1 | 1 | 6 |
| 2014 | 0 | 0 | 0 | 0 | 8 |
| 2012 | 1 | 0 | 1 | 1 | 7 |
| 2013 | 0 | 1 | 0 | 0 | 3 |
| 2014 | 1 | 0 | 1 | 1 | 2 |
| 2012 | 0 | 1 | 0 | 0 | 10 |
| 2014 | 0 | 0 | 1 | 0 | 12 |
| 2014 | 0 | 0 | 0 | 0 | 5 |
run;
data have_row_id / view=have_row_id;
set have;
rowid+1;
run;
proc transpose data=have_row_id out=have_categorical;
by rowid yr pqr;
run;
proc tabulate data=have_categorical;
class yr _name_;
var col1;
weight pqr;
table _name_='', col1='' * sum=''*f=8. * (all='Total' yr='') / nocellmerge;
run;
The ='' removes labelling cells and compactifies the output.

Which datasets-merging operation would do this in Pandas?

Lets say I have two pandas DataFrames, X and Y:
X =
+---+----------+---------+
| | Value1 | Value2 |
+---+----------+---------+
| A | 1 | NaN |
| B | 0 | 0 |
+---+----------+---------+
Y =
+---+----------+---------+
| | Value1 | Value2 |
+---+----------+---------+
| A | 2 | NaN |
| C | 30 | NaN |
+---+----------+---------+
I want to merge / join them based on the index (row name) resulting in this:
+---+----------+---------+
| | Value1 | Value2 |
+---+----------+---------+
| A | 1 | 2 |
| B | 0 | 0 |
| C | 30 | NaN |
+---+----------+---------+
Using merge and 'outer', the resulting table has columns per table, instead of just concatenating. I need something that appends new rows to the end, but also appends new columns for a matching index.
This is the result of an 'outer' merge:
+---+----------+---------+----------+---------+
| | Value1_X | Value2_X| Value1_Y | Value2_Y|
+---+----------+---------+----------+---------+
| A | 1 | NaN | 2 | NaN |
| B | 0 | 0 | NaN | NaN |
| C | NaN | NaN | 30 | NaN |
+---+----------+---------+----------+---------+
Which is almost what I want, but ignoring the original column labels...
On the result of the 'outer' merge:
X =
+---+----------+---------+----------+---------+
| | Value1_X | Value2_X| Value1_Y | Value2_Y|
+---+----------+---------+----------+---------+
| A | 1 | NaN | 2 | NaN |
| B | 0 | 0 | NaN | NaN |
| C | NaN | NaN | 30 | NaN |
+---+----------+---------+----------+---------+
do, X = X.apply(lambda x: pd.Series(x.dropna().values), axis = 1)
which will give
0 1
A 1.0 2.0
B 0.0 0.0
C 30.0 NaN

Python - increment function from a dataframe

I would like to create an increment function from a dataframe.
Me dataframe look like this:
___________ ___________
| Action_ID | Unique_ID |
| 4 | |
| 3 | |
| 2 | |
| 1 | |
| 4 | |
___________ ___________
Would like to set Unique_ID egals i+1 when Action_ID egals 4. So:
___________ ___________
| Action_Id | Unique_Id |
| 4 | 1 |
| 3 | |
| 2 | |
| 1 | |
| 4 | 2 |
___________ ___________
I've try this code:
def order_code(grp):
i=0
if(grp.loc[grp.first_valid_index(),'Action_Id']==4):
i = i+1
grp['Unique_Id']=i
return(grp)
c=(c.groupby('Action_Id')).apply(order_code)
But it displays me:
___________ ___________
| Action_Id | Unique_Id |
| 4 | 1 |
| 3 | |
| 2 | |
| 1 | |
| 4 | 1 |
___________ ___________
Someone can help me please?
Your problem is that i is in the scope of the function which you're working in. If you were to do for example:
inc = 0
def order_code(grp):
global inc
if(grp.loc[grp.first_valid_index(),'Action_Id']==4):
inc += 1
grp['Unique_Id']=inc
return(grp)
c=(c.groupby('Action_Id')).apply(order_code)
it would work.

Get data from SmartCard UEC

I already asked a question here (https://stackoverflow.com/questions/28658283/c-getslotlisttokenpresent-pslotlist-pulcount-return-pulcount-0) about my SmartCard (https://en.wikipedia.org/wiki/Universal_electronic_card), but I would like to know: is it possible to get a specific record from a smart card, knowing the pin code and where the record is located?
Map developed by ISO-7816, so the APDU-command must be based on the following scheme:
[CLA] [INS] [P1] [P2] [Lc field] [Data field] [Le field]
How APDU-command should look like and what the library is better to use on C++/C#, if I need the data from the field 5F20?
P.s.: here is data from file sectors.ini:
[Sector1_11]
Icon = "IDENTIFICATION SECTOR"
BlockDescr1 = "0 | 0 | The data block for sharing"
BlockDescr2 = "0 | 0 | block public access to the PIN"
DataDescr21 = "DF27 | 1 | 6 | 0,0,0 | 1 | SNILS"
DataDescr22 = "DF2B | 4 | 8 | 0,0,0 | 1 | Number of MHI"
DataDescr23 = "5F20 | 0 | 26 | 0,0,0 | 1 | Name"
DataDescr24 = "DF23 | 0 | 100 | 0,0,0 | 1 | Address of the issuer"
DataDescr25 = "5F2B | 4 | 4 | 0,0,0 | 1 | Born"
DataDescr26 = "DF24 | 0 | 100 | 0,0,0 | 1 | Birthplace"
DataDescr27 = "5F35 | 3 | 1 | 0,0,0 | 1 | Paul"
DataDescr28 = "DF2D | 0 | 40 | 0,0,0 | 1 | Last"
DataDescr29 = "DF2E | 0 | 40 | 0,0,0 | 1 | Name"
DataDescr210 = "DF2F | 0 | 40 | 0,0,0 | 1 | Middle"
I only know that the third number indicates the amount of data in bytes.