Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am trying to find the possible values of this expression.
(a mod 2*x)-(a mod x)
I suspect they might be 0 or x, but I'm really not sure. I can't seem to be able to write down a proper argument.
You are correct that the possible values are 0 and x, assuming that both a and x are positive. The logic is as follows.
Let a have the form
a = p*x + b
Then it is easy to see that a mod x = b.
For a mod 2*x, if p = 2*r (p is even) then
a = 2*r*x + b = (2*x)*r + b
so that a mod 2*x = b and p = 2*r + 1 (p is odd) then
a = (2*r + 1)*x + b = 2*r*x + x + b = (2*x)*r + x + b
so that a mod 2*x = x + b. Combining these results, the difference is either b - b = 0 (when p is even) or (x + b) - b = x (when p is odd).
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Been trying to figure out this stuff. This has to do with boolean algebra and is suing the C language. It has some algebra in it. Not sure how this works. Been trying to figure this out for half hour
Simplify the following Boolean expressions.
a. F = A*B*C*D + A*B*C*D + A*B*C*D + A*B*C*D
b. F = A*B*C + A*B*C + A*C*D + A*B*C*D
As in boolean algebra + is OR you can simplify it with:
F = A*B*C*D + A*B*C*D + A*B*C*D + A*B*C*D (A v A) = A
= A*B*C*D + A*B*C*D + A*B*C*D (A v A) = A
= A*B*C*D + A*B*C*D (A v A) = A
= A*B*C*D (A v A) = A
F = A*B*C + A*B*C + A*C*D + A*B*C*D (A v A) = A
= A*B*C + A*C*D + A*B*C*D
= A*B*C + A*C*D
= A*C*(B + D)
Suppose H is some hash function (such as MD5 or SHA256 or whatever) and I have a collision for this hash: two different pieces of data x and y, that have the same hash.
In other words x≠y but H(x)=H(y).
Now if I concatenate some random data z, will H(x+z) be the same as H(y+z) ?
The idea is: x and y being a collision may imply that they happen to bring the H function in the same state (thus resulting in the same hash). From that point on, it doesn't matter what other data we append, their hashes will remain equal.
I tested the above for this MD5 collision and it seemed to work there. But I don't know if this is true in general?
This particular technique is called a length extension attack. Whether or not a hash function is vulnerable obviously depends on the particular hash function. Hash functions based on the Merkle–Damgård construction, such as MD5 and SHA-1, are vulnerable. SHA-3 is not vulnerable, and HMAC constructions are also not vulnerable.
Depends on the has function. Since hash functions are not homomorphic (that is, where: f(x) = f(y) implies x = y), it does not follow that f(x + z) and f(y + z) will map to the same item. Consider a counter example:
Given the hash function
f(x) = (x * 3) + 1 mod 6
then f(2) = 1 and f(6) = 1. Let z = 1. Then:
f(2 + z) = 4 and f(6 + z) = 1
thus f(2) = f(6) but f(2 + z) ≠ f(6 + z).
However, if the hash function were homomorphic, then by definition of homomorphism:
f(p + q) = f(p) + f(q)
and therefore:
f(x + z) = f(x) + f(z)
f(y + z) = f(y) + f(z)
which but since f(x) = f(y) as you initially stated:
f(x) + f(z) = f(y) + f(z)
and so their hashes would be the same.
(Please be indulgent, it's my first answer :D)
Not necessarily:
Consider the following data (as lists of numbers)
x = [8 0 4]
y = [8 1 0]
z = [5]
and the hashing function:
H([a b c]) = a + b*c
H([a b c d]) = H([b c d]) + H([a b c])
Then, a collision for x and y occurs:
H(x) = H([8 0 4]) = 8 + 0*4 = 8
H(y) = H([8 1 0]) = 8 + 1*0 = 8
But when appending data, the hashes aren't equal:
H(z + x) = H([5 8 0 4]) = H([5 0 8]) + H([8 0 4]) = 5 + 8 = 13
H(z + y) = H([5 8 1 0]) = H([5 8 1]) + H([8 1 0]) = 13 + 8 = 21
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I wanna solve this form of equation:
x' = -A.x + B.|sin(100*pi*t)|
and i use ode45 like this:
function find_x
t = 0:0.001:10;
x0 = 0;
R1 = 90000;
R2 = 1000;
C = 0.001;
[t,x]=ode45(#rhs, t , x0);
plot(t,x);
function dxdt = rhs(t,x)
dxdt = -(C/R1 + C/R2)*x + C/R1*abs(sin(100*pi*t)) ;
%It's form is dx/dt = -A.x + B.U(t)
end
end
but i think it give me the wrong answer.
actually, i get this equation from a problem "find output voltage form after a diode bridge and a capacitor" like this:
can anyone suggest to me a another way to solve it ? thanks.
Not really the place to solve this, and this takes me back to my signal & systems days, but basically your equations should have C as a divider...
Remember it's
I = C *dV/dt
Therefore if you have dV/dt on the RHS, you should expect to see 1/C on the LHS:
function khan
t = 0:0.001:10;
x0 = 0;
R1 = 90000;
R2 = 1000;
C = 0.001;
options = odeset('RelTol',1e-6,'AbsTol',1e-8);
[t,x]=ode45(#rhs, t , x0,options);
plot(t,x);
function dxdt = rhs(t,x)
dxdt = -(1/R1 + 1/R2)*x/C + 1/R1*abs(sin(100*pi*t))/C ;
%It's form is dx/dt = -A.x + B.U(t)
end
end
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm doing a past paper for my exam on Thursday, and I'm struggling with boolean algebra a bit.
One question asked me to simplify:
[(X + Y).(X + 'Y)]
I can simplify most of it. I got it down to
[X(1 + 'Y + Y)]
The mark scheme says this is equal to [X].
But I don't quite understand why - I guess it's because of the
['Y + Y]
but we're not using the '+' symbol to add them, so why is it like this?
Starting from X * (1 + 'Y + Y), note that 'Y + Y == 1 for any Y because either Y is 1 or else 'Y is, so Y + 'Y is 1 + 0 or 0 + 1, which in both cases equals 1.
That would make the function equivalent to X * (1 + 1), but we also know that 1 + 1 == 1 (true OR true is true) and also X * 1 == X (X AND true is X), so in the end you are left with just X.
Reference: Laws of Boolean algebra, also in a convenient 2-page PDF.
['Y + Y]
X + X' = 1 Now imagine picking one between a value and its opposite.
Since we are referring to Boolean logic, the only options are going to
be 0 or 1. Now see what is the output of the OR operation between 0
and its opposite, i.e. 1. Or see what 1 OR 0 yields. Both yield a 1,
which means that the output of an OR operation between a value and its
negative (opposite), is 1.
http://www.buzzle.com/articles/boolean-algebra-rules.html
In Boolean algebra, If A = 1, A' = 0 and A = true, A' = false. Also every AND operation is (.) and every or operation is (+).
Let me simplify the expression :
(X+Y)(X+'Y)
= XX + XY' + YX + YY'
= X + XY' + YX + 0 // since X.X = X & Y.Y'= 0
= X + XY' + XY // = X(1 + 'Y + Y)
= X + X(Y+Y')
= X + X(1) // Y+Y' = 1
= X + X
= X
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I try To find a solution to a question ....
we have a number , example : 20 ...
and we have 6 number :{ a ,b , c , d , e , f} < 20 ,
t try to find all values of these numbers , but only if we can combinate (whit + or -) whit 2 of this numbers and getting all the value below to 20 : for example
we choose 31 :
a = 22 b = 21 c = 14 d = 11 e = 9 f = 5
we have :
22 - 21 = 1 ;
11 - 9 = 2 ;
14 - 11 = 3 ;
9 - 5 = 4 ;
f = 5 ;
11 - 5 = 6 ;
21 - 14 = 7 ;
....
....
....
....
....
21 + 9 = 30 ;
9 + 22 = 31 ;
This appears like homework, so I'll try to just give you some hints.
You want to loop over all combinations of two numbers from the array. To do that, you can use an outer loop that loops over all the numbers and then inside that loop, an inner loop that also loops over all the numbers.
Depending on exactly what you want to do, you need to decide if you want to handle x, y separately from y, x
Given a natural number n, find all combinations of 6 positive integers a, b, c, d, e, and f such that {a, b, c, d, e, f} ∪ {a + b, a + c, ..., a + f, b + c, b + d, ..., b + f, ..., e + f} ∪ {a - b, a - c, ..., a - f, b - c, b - d, ..., b - f, ..., e - f, b - a, c - a, ..., f - a, c - b, d - b, ..., f - b, ..., f - e} contains 1, 2, 3, 4, ..., n - 1, and n.
I haven't thought about this problem very much, but it appears to me to be a hard problem, indeed. Maybe there is a trick, I am not sure, but if I had to solve this problem, I would first try to find the least n for which there are not infinitely-many solutions (if n is 1, for example, then any combination of 6 natural numbers containing two consecutive natural numbers will work).
I think that you will have better luck with finding a solution to this problem in a mathematics discussion forum.
void FindCombinations(int n, int [] values)
{
for(int i = 0; i < values.length; i++)
{
int left = values[i];
for(int j = 0; k < values.length; j++)
{
int right = values[j];
if (left == right)
continue;
if (left + right < n)
Console.Write(string.Format("{0} + {1} = {2} < {3}", left, right, left+right, n);
if (left - right < n)
Console.Write(string.Format("{0} - {1} = {2} < {3}", left, right, left-right, n);
}
}
}
While this question stinks of homework it's not really that hard (although arguably hard to interpret).
Note: This solution is O(n^2) and is not efficient, please keep this in mind.