I have this matrix division issue. I have something like this
(AxB)/(C*C).
I think I can write it as
(A/C) * (B/C). Correct me if I am wrong.
Now is there any way to eliminate this from taking this form. B and C are both very huge matrices and calculating B/C takes almost 1 minute in matlab. So is there any other way I can manipulate this?
If all of your matrices are square, then for your first expression you have the equivalence
A * B / (C * C) <==> A * B * inv(C * C) <==> A * B * inv(C) * inv(C)
On the other hand, your second expression is equivalent to
(A / C) * (B / C) <==> A * inv(C) * B * inv(C)
Since matrices don't commute in general, these don't have to be the same. If we equate the right-hand sides, we find that (as long as A and C are invertible) we can make some cancellations, and end up with the equation
B * inv(C) == inv(C) * B
i.e. the two expressions are the same if B commutes with inv(C). In fact we can multiply on the left and right by C, and get
C * B = B * C
so this is the same as requiring that B commutes with C.
Related
I am working on solving a system of boolean equations. Specifically, I am trying to find the values of bit vectors S1...S3 and/or C1...C3 such that their XOR results are given in the table below (in hexadecimal values). Any ideas?
So we have six 32-digit sequences we want to determine, for a total of 192 unknown hexadecimal digits. We can focus on just the first digits of each to illustrate how we could try to solve for the others.
Let's call the first digits of S1, S2 and S3 a, b and c, respectively. Let's also call the first digits of C1, C2 and C3 x, y and z, respectively. Then we have the following equations, where * stands for XOR:
a * x = E b * x = A c * x = 7
a * y = 2 b * y = 6 c * y = B
a * z = 1 b * z = 5 c * z = 8
Let us note some properties of XOR. First, it is associative. That is, A XOR (B XOR C) is always equal to (A XOR B) XOR C. Second, it is commutative. That is, A XOR B is always equal to B XOR A. Also, A XOR A is always the "false" vector (0) for any A. A XOR FALSE is always A where FALSE stands for the "false" vector (0). These facts let us do algebra to solve for variables and substitute to solve. We can solve for c first, substitute in and simplify to get:
a * x = E b * x = A z * x = F
a * y = 2 b * y = 6 z * y = 3
a * z = 1 b * z = 5 c = 8 * z
We can do z next:
a * x = E b * x = A y * x = C
a * y = 2 b * y = 6 z = 3 * y
a * y = 2 b * y = 6 c = 8 * z
We found a couple of our equations are redundant. We expected that if the system were not inconsistent since we had nine equations in six unknowns. Let's continue with y:
a * x = E b * x = A y = C * x
a * x = E b * x = A z = 3 * y
a * x = E b * x = A c = 8 * z
We find now that we have even more unhelpful equations. Now we are in trouble, though: we only have five distinct equalities and six unknowns. This means that our system is underspecified and we will have multiple solutions. We can pick one or list them all. Let us continue with x:
a * b = 4 x = b * A y = C * x
a * b = 4 x = b * A z = 3 * y
a * b = 4 x = b * A c = 8 * z
What this means we have one solution for every solution to the equation a * b = 4. How many solutions are there? Well, there must be 16, one for every value of a. Here is a table:
a: 0 1 2 3 4 5 6 7 8 9 A B C D E F
b: 4 5 6 7 0 1 2 3 C D E F 8 9 A B
We can fill in the rest of the table using the other equations we determined. Each row will then be a solution.
You can continue this process for each of the 32 places in the hexadecimal sequences. For each position, you will find:
there are multiple solutions, as we found for the first position
there is a unique solution, if you end up with six useful equations
there are no solutions, if you find one of the equations becomes a contradiction upon substitution (e.g., A = 3).
If you find a position that has no solutions, then the whole system has no solutions. Otherwise, you'll have a number of solutions that is the product of the nonzero numbers of solutions for each of the 32 positions.
I have two equations with two unknowns but they seem to be quite non-linear. They are of the form,
C1 = (A1) * ((10)^(B1 * x)) * ((D1 * y)^(E1))
C2 = (A2) * ((10)^(B2 * x)) * ((D2 * y)^(E2))
I would like to solve for x and y and the rest are all constants. I have tried using 'SymPy' and 'solve' but the code seems to be running forever.
I need to prove: 256 * (x / 256) <= 256 * x / 256, or more generally forall a b c : N, c > 0 -> a * (b / c) <= a * b / c. This is true since either b is divisible by c and they are equal or it's not and multiplying first can inflate the number and result in greater precision. However, I could not find any theorem in the standard library that proves this, and no automatic tactic I know (auto, intuition, easy, zify and omega) worked. If it helps, I also know that x < 256 * 256, but checking all 65536 cases is not a good proof...
In my specific case I was able to solve it like this:
rewrite (N.mul_comm 256 x).
This switches around the right side to 256 * (x / 256) <= x * 256 / 256.
rewrite (N.div_mul x 256).
This reduced the right side to 256 * (x / 256) <= x.
rewrite (N.mul_div_le x 256).
After this automated tactics are sufficient.
in scala, given the integers d & x, I would have a boolean expression which should be true if and only if y = (x^2 - 1) / d^2 is a square.
I tried this:
(Math.sqrt((x * x - 1) / (d * d)).toInt * Math.sqrt((x * x - 1) / (d * d)).toInt == ((x * x - 1) / (d * d)))
but the 3-tuple (x = 2, d = <all values tested>, y = 0.0) seems to be always an answer of my problem, which is obviously wrong.
I think my error comes from the rounding made: if x=2, d=4 (for example) then x * x - 1 == 3 and d * d == 16 so the division leads to 0.
do you know what is the good expression?
if n is a round square, then Math.sqrt(n).toInt == Math.sqrt(n). In your case:
(Math.sqrt((x * x - 1) / (d * d)).toInt == Math.sqrt((x * x - 1) / (d * d)))
But before doing that, you need to make sure that x and d are doubles.
Try in REPL:
scala> val x = 1
scala> val d = 3
scala> x/d
A Int divided by an Int will result the rounded Int, so you are applying sqrt to zero.
Also due to float point arithmetic, you may want to compare like this instead:
(Math.sqrt((x * x - 1) / (d * d)).toInt - Math.sqrt((x * x - 1) / (d * d))) <= ZERO
where ZERO is replaced by a really small number like 0.00001
Because this is integer division, you are checking whether ((x*x-1)/(d*d)).toInt is a perfect square. You can convert everything to doubles first, but if you want to stay in the realm of integers, check that the division should result in an integer:
( x*x-1 % d*d == 0 ) && Math.sqrt(y).toInt == Math.sqrt(y)
As you see in the screen shot above, I have the following expression in my Matlab m-file code:
K = P * D * D' * P;
Where, P is an nxn matrix, and D is a nx1 column vector (n=4, if it matters).
Why am I getting this warning message?
What changes if I use or don't use parenthesis there?
Floating-point arithmetic is not associative. So in general, a * (b * c) won't necessarily give the same result as (a * b) * c.
Your statement as written is equivalent to ((P * D) * D') * P, so the compiler is warning you that if you're relying on the Hermitian symmetry of D * D', you should force it to calculate exactly that.
As a side note: you can always do
K = (K + K') / 2;
To enforce the Hermetian-ity of K, but it's better to compute it as Hermitian in the first place as is suggested by the P * (D * D') * P hint.
Edit: Actually, one thing to note is that K is only going to be necessarily Hermitian if P is diagonal in general. Even with P as a permutation matrix (as the letter implies), there's not guarantee of K being Hermitian. The only guaranteed Hermitian part D * D'.