How can the union of X and Y be equal to the intersection of Y and Z (X u Y = Y n Z)? - set

On which conditions can the equation X u Y = Y n Z be true?
I need to prove this equation step by step, but I do not know where to start.

X union Y = Y intersect Z if and only if X is a (possibly improper) subset of Y and Y is a (possibly improper) subset of Z.
To prove this, we need to show the implication in both directions.
If X is a (possibly improper) subset of Y and Y is a (possibly improper) subset of Z, is it true that X union Y = Y intersect Z? Because X is a subset of Y, X union Y = Y. Because Y is a subset of Z, Y intersect Z = Y. Thus, X union Y = Y = Y intersect Z, as required.
If X union Y = Y intersect Z, is it true that both X is a subset of Y and Y is a subset of Z? Suppose X were not a subset of Y. That means there is some x in X not in Y. So, X union Y must contain x. But Y intersect Z cannot contain anything not in Y, such as x; therefore, X union Y cannot equal Y intersect Z - a contradiction. Suppose instead Y were not a subset of Z. Then Y would contain some element y not in Z. But then Y intersect Z does not contain y, whereas X union Y must. So, X union Y cannot equal Y intersect Z, a contradiction.
This completes the proof that X union Y = Y intersect Z iff X is a (possibly improper) subset of Y and Y is a (possibly improper) subset of Z.
Note: X is a proper subset of Y if X is a subset of Y but X is not equal to Y. If X equals Y, it is an "improper" subset.

Related

Find a number for minimum sum of nth power of absolute difference in an array

My question is similar to this, but instead if the absolute difference is raised to a power 'c' (which will be given as input) is there an algorithm to find the answer?
For example, given A = {a1, a2,...., an} and c it should find an x such that it minimises |a1 − x|^c +|a2 − x|^c +··· +|an − x|^c.
If c = 1 it's the median of the sorted array and if c = 2 it's the average of the array, but I can't find connection between median and average which we can extend to any value of c.
I assume that c is a positive integer.
If it is not an integer, then the fractional powers are hard to calculate. If it is negative, then as x goes to infinity (either way) the result goes to 0, so there is no global minimum. If it is 0, then x does not matter. So a positive integer is the only thing that makes sense.
Now each term is a convex function. The sum of convex functions is itself convex. Convex functions have the following properties. Suppose that x < y < z. If f(x) = f(z) then the global minimum is between them. If f(x) = f(y) = f(z), that's a straight line segment. And finally, if f(y) < min(f(x), f(z)) then the global minimum is between x and z.
This is sufficient for a variation on binary search.
while z - x > some tolerance:
if z-y > y-x:
y1 = (y + z) / 2
if f(y1) < f(y):
(x, y, z) = (y, y1, z)
elif f(y1) = f(y):
(x, y, z) = (y1, (2*y1 + y)/3, y)
else:
(x, y, z) = (y1, y, z)
else:
y1 = (x + y) / 2
if f(y1) < f(y):
(x, y, z) = (x, y1, y)
elif f(y1) = f(y):
(x, y, z) = (y1, (2*y1 + y)/3, y)
else:
(x, y, z) = (y1, y, z)
As this runs, each iteration reduces the size of the interval to at most 3/4 of what it previously was. And therefore you will narrow in on the answer.
If you special case c = 1, you can do even better. The second derivative will be defined everywhere and be a non-decreasing function. This allows you to do a binary search, but guess where in the interval the minimum is expected to be. If you land close, you know which way you're wrong, and can put a much tighter bound on it.

How to prove the correctness of the algorithm for "Arrange given numbers to form the biggest number"?

Arrange given numbers to form the biggest number gives the algorithm.
It uses the following text to prove the correctness of the algorithm:
So how do we go about it? The idea is to use any comparison based sorting algorithm. In the used sorting algorithm, instead of using the default comparison, write a comparison function myCompare() and use it to sort numbers. Given two numbers X and Y, how should myCompare() decide which number to put first – we compare two numbers XY (Y appended at the end of X) and YX (X appended at the end of Y). If XY is larger, then X should come before Y in output, else Y should come before. For example, let X and Y be 542 and 60. To compare X and Y, we compare 54260 and 60542. Since 60542 is greater than 54260, we put Y first.
Consider three numers: X, Y and Z. Use X -> Y to indicate that X should come before Y. A comparison based algorithm can use the following two comparisons to sort X, Y and Z into XYZ: XY >= YX => X -> Y and YZ >= ZY => Y -> Z. But these two comparisons do not necessarily ensure that XYZ is the largest number. In other words, the fact that X should come before Y and Y should come before Z does not necessarily ensure that XYZ form the largest number. Take YZX as an example. To prove XYZ >= YZX, we need to prove that X(YZ) >= (YZ)X which meains that X should before YZ as a whole to form a bigger number.
Can anyone give a formal proof of the correctness of the algorithm?
First we will prove that if X "<" Y and Y "<" Z then X "<" Z. Assuming that they have p, q and r digits respectively, the first two relations reduce to
X * 10^q + Y ≥ Y * 10^p + X ⇒ X * (10^q - 1) ≥ Y * (10^p - 1)
Y * 10^r + Z ≥ Z * 10^q + Y ⇒ Y * (10^r - 1) ≥ Z * (10^q - 1)
We want to prove
X * 10^r + Z ≥ Z * 10^p + X which is equivalent to X * (10^r - 1) ≥ Z * (10^p - 1)
But this can be proved simply by multiplying the first two inequalities and cancelling off common terms.
Now that we have shown that the relation is transitive (and thus can be used to define a sort order), it is easy to show that it works to solve the problem.
Suppose the numbers given are A, B, C … such that A "<" B "<" C "<" D…. We will show that A has to come first in the final number. If not, we have a string like (some prefix)XA(some suffix) as the final number. Easily, (some prefix)AX(some suffix) is a larger number because A "<" X for all X due to transitivity. Continuing in this fashion A bubbles to the left till it becomes the first element.
Now that we have fixed the first element, the same argument can be applied to B and so on to show that the best solution is ABCD…

Combinations of three positive numbers x, y, z so that x + y, x - y, y + z, y - z, x + z and x - z are perfect squares

Good morning, I'm new here and I bring a small problem. I'm having trouble develop efficient an algorithm for the following problem:
I need to find combinations of three positive numbers x, y and z so that x + y, x - y, y + z, y - z, x + z and x - z are perfect squares.
The issue is to develop an algorithm that finds all combinations of x, y and z between 1
and 2,000,000.
Currently I use a for within a for that certainly will not end before I have my grandchildren.
The basic idea to begin with a substitution, like:
u = x + y
v = x - y
w = y + z
Then x + y, x - y, y + z, y - z, x + z and x - z becomes
u, v, w, u - v - w, v + w, u - w [all have to be squares]
Then with another substitution, u = a², v = b², w = c², you get:
a², b², c², a² - b² - c², b² + c², a² - c² [all have to be squares]
now you can enumerate all a, b, c-s which may already be fast enough.
Further ideas could be to first enumerate all b², c², b²+c² using Pythagorean triples (by substituting it to m and n, enumerating all coprime (m,n) and then using Euclid formula) and then find for given (b,c) the as in a similar way (e.g. change a² - c² = x² to a² = x² + c² and use the triples again).
Extending BeniBela's answer,
x + y = (x - z) + (y + z)
x + y = (x + z) + (y - z)
So, triplets are valid only if the hypotenuse can be represented in two different forms.
Further filtering can be done by observing that (x - z) and (x + z) also form the hypotenuse of a Pythagorean triplet.

cartesian product of a power set with a set

how to explicitly write the cartesian product of a power set with another set.
eg: P({a,b})x{a,b}
Now P({a,b}) = {{},{a},{b},{a,b}}
so i need to know {{},{a},{b},{a,b}}x{a,b}
Let X be a a set. The power set of X is defined to be
P(X) := { S | S ⊆ X }
Let X and Y be sets. The product X × Y is defined to be
X × Y := { (x,y) | x ∈ X, y ∈ Y }
Now let X and Y be sets. We will describe the Cartesian product of the power set of X with Y:
P(X) × Y = { (S,y) | S ∈ P(X), y ∈ Y }
But S ∈ P(X) if and only if S ⊆ X. This allows us to rewrite our product
P(X) × Y = { (S,y) | S ⊆ P(X), y ∈ Y }
In other words, P(X) × Y consists of ordered pairs such that the first coordinate is some subset of X and the second coordinate is an element of Y.
Your example is not consistent with your question:
You ask "how to explicitly write the cartesian product of a power set with another set?", and then you give the example of P({a,b})x{a,b}, which is the cartesian product of a power set with the same set, namely {a,b}.
For your example, as you said you have:
P({a,b}) = {{},{a},{b},{a,b}}
Then recall the definition of the cartesian product of two sets:
E x F = {(e,f), e in E, f in F}
Then by applying this definition:
P({a,b}) x {a,b} = {{},{a},{b},{a,b}} x {a,b}
= {({}, a), ({}, b), ({a}, a), ({a}, b), ({b}, a), ({b}, b), ({a,b}, a), ({a,b}, b)}
However, it is very unlikely that this kind of property would be useful in any concrete case or even theoretical theorem, because we almost never meet cases where {a} and a are treated "equally" (I mean, on the same "level" of sets), although it is absolutely correct from a mathematical point of view.

Lambda calculus help

So i'm totally stuck on this one part of a problem. It would be awesome if someone could help.........
Show that the term ZZ where Z is λz.λx. x(z z x) satisfies
the requirement for fixed point combinators that ZZM =β M(ZZM).
This is completely trivial.
You just apply the definition of β-reduction two times:
Z Z M = (λz.λx. x(z z x)) Z M > (λx. x(Z Z x)) M > M (Z Z M)
where > is the β-reduction.
Therefore Z Z M β-reduces to M (Z Z M) in two steps, hence Z Z M =β M (Z Z M).

Resources