you know that the truth table for material implication is:
A | C | Y = A --> C
0 | 0 | 1
0 | 1 | 1
1 | 0 | 0
1 | 1 | 1
From this table we can deduce
A --> C = Y = ~A~C + ~AC + AC (where ~X stands for NOT X)
But it is also well known that
A --> C = ~(A~C)
I can't reduce the 1st expression (~A~C + ~AC + AC) to the 2nd ( ~(A~C) ), can you show me through which steps can you obtain the 2nd from the 1st?
Thank you.
(~A~C + ~AC + AC)
(~A~C + ~AC) + AC
~A(~C + C) + AC
~A(T) + AC
~A + AC
~~(~A + AC)
~((~~A)~(AC))
~(A~(AC))
~(A(~A + ~C))
~(A~A + A~C)
~(F + A~C)
~(A~C)
Related
Let's define a 2-adic in Haskell as its infinite binary expansion:
data Adic = O Adic | I Adic deriving Show
We can represent finite numbers as follows:
zero = O zero
one = I zero
neg1 = I neg1
And we can easily define Inc and Add for Adic:
inc :: Adic -> Adic
inc (O a) = I a
inc (I a) = O (Inc a)
add :: Adic -> Adic -> Adic
add (O a) (O b) = O (add a b)
add (O a) (I b) = I (add a b)
add (I a) (O b) = I (add a b)
add (I a) (I b) = I (inc (add a b))
We can convert adics to ints follows:
a2i :: Int -> Adic -> Int
a2i 1 (O x) = 0
a2i 0 (I x) = -1
a2i s (O x) = 2 * i2a (s - 1) x
a2i s (I x) = 2 * i2a (s - 1) x + 1
This allows us to do basic arithmetic. For example:
print $ a2i 64 (add one neg1)
Would print 0, after computing 1 + -1 on 2-adics.
Now, I'm interested in the hyper-operation sequence function, i.e.:
hyp :: Int -> Adic -> Adic -> Adic
hyp 0 a b = add a b
hyp 1 a b = mul a b
hyp 2 a b = exp a b
hyp 3 a b = tet a b
...
An efficient way to implement it is by generalizing the exponentiation by squaring algorithm, as follows:
hyp :: Int -> Adic -> Adic -> Adic
hyp 0 a b = add a b
hyp s a 1 = a
hyp s a (O b) = let r = hyp s a b in hyp (s - 1) r r
hyp s a (I b) = let r = hyp s a (Inc b) in hyp (s - 1) r r
To visualize the function above, below is the evaluation of hyp 2 4 4, i.e., 4^4:
4^4 =
4^2 * 4^2 =
4^1 * 4^1 * 4^1 * 4^1 =
4 * 4 * 4 * 4 =
4*4 * 4*4 =
(4*2 + 4*2) * (4*2 * 4*2) =
(4*1 + 4*1 + 4*1 + 4*1) * (4*1 + 4*1 + 4*1 + 4*1) =
(4 + 4 + 4 + 4) * (4 + 4 + 4 + 4) =
16*16 =
16*8 + 16*8 =
16*4 + 16*4 + 16*4 + 16*4 =
16*2 + 16*2 + 16*2 + 16*2 + 16*2 + 16*2 + 16*2 + 16*2 =
16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 + 16*1 =
16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 =
256
Sadly, the function above doesn't actually work, because the hyp s a 1 = a line attempts to match an Adic against the Int 1, which makes no sense. What it should do, instead, is match against the 2-adic number 1. The problem is: 2-adics are infinite, so we can't match them. We can't even create an is one function. As such, while the function above seems elegant and efficient, it, as far as I can tell, can't be constructed. My question is: am I right in concluding hyp can't be implemented that way, or am I missing something? Is there an alternative approach that would let this work?
Help me please to solve this problem:
I have a vector A and I get vector B this way:
B = M1 * A * 0.5 + M2 * A * 0.5;
M1 - rotation matrix 0 deg.
M2 - rotation Matrix 45 deg.
I need to get a way to compute A if B is known. For instance if B == (0.8535, 0.3535), then A should be (1.0, 0.0). How can I get the inverted formula?
UPD: for 0.4/0.6 the result formula is:
A=(M1*0.4+M2*0.6)^-1 * B
Bring this equation into a single matrix-vector product
B = M1 * A * 0.5 + M2 * A * 0.5
B = (M1 * 0.5 + M2 * 0.5)*A
B = M*A
and invert M
A = inv(M)*B = M\B
For example
M1 = | 1 0 | M2 = | 1/√2 -1/√2 |
| 0 1 | | 1/√2 1/√2 |
makes
M = | √2/4+1/2 -√2/4 |
| √2/4 √2/4+1/2 |
and the inverse
inv(M) = | 1 √2-1 |
| 1-√2 1 |
you will find that
inv(M)*| 0.8535 | = | 0.999999 |
| 0.3535 | | -3e-5 |
The above process is part of linear algebra, exactly because you can use the associative & distributive properties with non-scalar quantities.
A = (M1 * 0.5 + M2 * 0.5)^-1 * B
I am dealing with a huge dataframe containing 3 columns and 5 Bil. rows. The size of the data is 360 GB. For the analysis of the Data I am using the following set-up:
-Jupyternotebooks running on a AWS r4.16xlarge
-PySpark Kernel
The table called customer_sales looks similar to the following example:
+--------------------+----------+-------+
| business_unit_id | customer | sales |
+--------------------+----------+-------+
| 1 + a + 5000 +
| 1 + b + 2000 +
| 1 + c + 3000 +
| 1 + d + 5000 +
| 2 + f + 600 +
| 2 + c + 7000 +
| 3 + j + 200 +
| 3 + k + 800 +
| 3 + c + 4500 +
Now I want to get for each business_unit_id the customer with the highest sales. If there is a draw in sales between several customer I want to get them all. The information should be stored in a table called best_customers_for_each_unit. So for the above illustrated example the table best_customers_for_each_unit looks as follows:
+--------------------+----------+-------+
| business_unit_id | customer | sales |
+--------------------+----------+-------+
| 1 + a + 5000 +
| 1 + d + 5000 +
| 2 + c + 7000 +
| 3 + c + 4500 +
In a second step I want to count how often it happens that a customer is the one with the highest sales in a specific business_unit_id. The output of this query will be:
+----------+-------+
| customer | count |
+----------+-------+
| a + 1 +
| b + 1 +
| c + 2 +
For the first query I used spark.sql with window functions. The used query looks as follows:
best_customers_for_each_unit = spark.sql("""
SELECT
business_unit_id,
customer,
sales
FROM (
SELECT
business_unit_id,
customer,
sales,
dense_rank() OVER (PARTITION BY business_unit_id ORDER BY sales DESC)as rank
FROM customer_sales) tmp
WHERE
rank =1
""")
For the second query I used the following PySpark snipped:
best_customers_for_each_unit.groupBy("customer").count()
My queries do actually work, but it takes ages to only process a minor part of the data. So do you know any efficient way to do such queries with PySpark?
Regards
I am trying to prove an equation given in the CLRS exercise book. The equation is:
Sigma k=0 to k=infinity (k-1)/2^k = 0
I solved the LHS but my answer is 1 whereas the RHS should be 0
Following is my solution:
Let's say S = k/2^k = 1/2 + 2/2^2 + 3/2^3 + 4/2^4 ....
2S = 1 + 2/2 + 3/2^2 + 4/2^3 ...
2S - S = 1 + ( 2/2 - 1/2) + (3/2^2 - 2/2^2) + (4/2^3 - 3/2^3)..
S = 1+ 1/2 + 1/2^2 + 1/2^3 + 1/2^4..
S = 2 -- eq 1
Now let's say S1 = (k-1)/2^k = 0/2 + 1/2^2 + 2/2^3 + 3/2^4...
S - S1 = 1/2 + (2/2^2 - 1/2^2) + (3/2^3 - 2/2^3) + (4/2^4 - 3/2^4)....
S - S1 = 1/2 + 1/2^2 + 1/2^3 + 1/2^4...
= 1
From eq 1
2 - S1 = 1
S1 = 1
Whereas the required RHS is 0. Is there anything wrong with my solution? Thanks..
Yes, you have issues in your solution to the problem.
While everything is correct in formulating the value of S, you have calculated the value of S1 incorrectly. You missed substituting the value for k=0 in S1. Whereas, for S, even after putting the value of k, the first term will be 0, so no effect.
Therefore,
S1 = (k-1)/2^k = -1 + 0/2 + 1/2^2 + 2/2^3 + 3/2^4...
// you missed -1 here because you started substituting values from k=1
S - S1 = -(-1) + 1/2 + (2/2^2 - 1/2^2) + (3/2^3 - 2/2^3) + (4/2^4 - 3/2^4)....
S - S1 = 1 + (1/2 + 1/2^2 + 1/2^3 + 1/2^4...)
= 1 + 1
= 2.
From eq 1
2 - S1 = 2
S1 = 0.
I have a formula that looks like
a = (b + 1 + c)%d
I want to express c in terms of rest, i.e. have "C" on the LHS.
Any suggestions ?
a = (b + 1 + c)%d
a + n*d = b + 1 + c
a -1 - b + n*d = c
For any integer n.