задачка (математическое)
Mar. 20th, 2009 11:50 pmВ рабочую рассылку прислали хорошую задачку.
У вас есть пять целых чисел N1, N2, N3, N4, N5. Вы повторяете следующую операцию: выбираете какое-нибудь отрицательное среди них, меняете его знак с минуса на плюс, и вычитаете его положительное значение из обоих его соседей. Например, если у вас есть [10, 5, -4, -8, 2] и выбрали -4, то получится [10, 1, 4, -12, 2]. У крайних чисел один из соседей берется с второго края (так, соседи N1 - N2 и N5). Обратите внимание, что сумма всех чисел после этой операции не меняется.
Дано, что вначале сумма всех чисел положительна. Доказать или опровергнуть: невзирая на то, как выбираются числа, после конечного числа операций отрицательных чисел не останется.
Комменты не скрываются.
У вас есть пять целых чисел N1, N2, N3, N4, N5. Вы повторяете следующую операцию: выбираете какое-нибудь отрицательное среди них, меняете его знак с минуса на плюс, и вычитаете его положительное значение из обоих его соседей. Например, если у вас есть [10, 5, -4, -8, 2] и выбрали -4, то получится [10, 1, 4, -12, 2]. У крайних чисел один из соседей берется с второго края (так, соседи N1 - N2 и N5). Обратите внимание, что сумма всех чисел после этой операции не меняется.
Дано, что вначале сумма всех чисел положительна. Доказать или опровергнуть: невзирая на то, как выбираются числа, после конечного числа операций отрицательных чисел не останется.
Комменты не скрываются.
no subject
Date: 2009-03-20 11:40 pm (UTC)Обычно ее дают на курсах по алгоритмах как демонстрацию доказательства терминированности
no subject
Date: 2009-03-21 12:06 am (UTC)no subject
Date: 2009-03-21 12:14 am (UTC)no subject
Date: 2009-03-21 01:43 am (UTC)no subject
Date: 2009-03-21 01:49 am (UTC)Типа
-1 -1 -1 -1 -1
no subject
Date: 2009-03-21 01:49 am (UTC)no subject
Date: 2009-03-21 02:02 am (UTC)x -a M -b y
(знак x и y неизвестен, но M-a-b+x+y > 0).
Тогда первым шагом получаем
х M-a -M M-b y
Дальше рассматриваем все комбинации знаков x и y, и выясняем, что не более чем через 4 шага у нас останутся рядом два положительных числа, в сумме больших M, отчего на следующем шаге максимум возрастет. ЧТД.
no subject
Date: 2009-03-21 02:26 am (UTC)no subject
Date: 2009-03-21 05:39 am (UTC)no subject
Date: 2009-03-21 05:40 am (UTC)no subject
Date: 2009-03-21 07:37 am (UTC)no subject
Date: 2009-03-21 09:33 am (UTC)no subject
Date: 2009-03-21 01:26 pm (UTC)Однако это одновременно не совсем верно ("на следующем шаге максимум возрастет" - но следующий шаг не обязан использовать одно из этих чисел), и недостаточно: это доказывает, что в исходной процедуре нет цикла, но не доказывает, что невозможно, чтобы числа по модулю продолжали расти неограниченно.
Кажется, для решения обеих проблем нужен небольшой шажок: показать по индукции, что если - пользуясь обратной процедурой, меняющей положительные на отрицательные - рядом стоят положительные a,b, то не позднее какого-то фиксированного числа шагов, зависящего только от суммы всех чисел (! но не от самих чисел, это важно), появится положительное число не меньше a+b.
Если это верно, и число шагов равно например K, то при использовании обычной процедуры максимальное положительное число должно быть достигнуто не более чем за K+4 шага от начала, иначе мы сможем обратить время и получить еще большее число, опровергая его максимальность. Значит, и максимальное отрицательное число должно появиться за это время, и поэтому все числа ограничены, а раз циклов нет, процедура останавливается.
Чтобы эту лемму доказать, достаточно смотреть на три оставшиеся числа и показать, что на них крутиться можно только конечное число шагов, зависящее от общей суммы. Т.к. использование только одного из них не задевает a,b, а остальные задевают и увеличивают a либо b, через конечное число шагов, зависящее от общей суммы, сумма трех оставшихся будет отрицательной; но задача с отрицательной суммой и обратным движением эквивалентна задаче с положительной суммой и обычным движением (с несущественным изменением "потери" части суммы в a,b при каждом шаге), и из случая для трех чисел ясно, что она окончится - опять таки за число шагов, зависящее от общей суммы.
no subject
Date: 2009-03-21 05:44 pm (UTC)no subject
Date: 2009-03-21 06:02 pm (UTC)no subject
Date: 2009-03-21 06:36 pm (UTC)Обозначим через Nij сумму чисел от N i до N j, с переходом по циклу, если j < i. Например
N42 = N 4 + N 5 + N 1 + N2.
Будем называть Nij интервальными суммами пятерки N. В качестве нормы |N| пятерки N возьмем сумму модеулей интевальных сумм меньших нуля, то есть
|N| = foldr (+) 0 [ -Nij | i <- [1..5], j<- [1..5], Nij < 0 ].
Чтобы показать, что норма уменьшается, без ограничения общности можно предполагать, что применяется операция с использованием N2, то есть, что N2< 0 и новая пятерка имеет вид
N1 + N 2 , -N2, N2+N3, N4,N5.
Будем обозначать элементы этой пятерки через Mi, i=1,2,3,4,5, а саму пятерку через M.
Как будут выглядеть набор интервальных сумм для M?
Очевидно, что Mij = Nij, если ни i, ни j не равно ни одному из чисел 1,2,3, так как в этом случае соответствующие суммы либо вовсе не содержат N1,N2, N3, либо содержат сумму
M1 + M2 + M3 = N 1 + N2 + N3.
Пусть j &isin {4,5}. Тогда
M1j = N1j
M2j = N3j
M3j = N2j
Mj1 = Nj2
Mj2 = Nj1
Mj3 = Nj3
Остаются случаи, когда оба индекса принадлежат множеству 1,2,3:
где n сумма всех элементов в пятерке. Из этих вычеслений можно заметить, что чтобы превратить набор интревальных сумм для N в набор интервальных сумм для M, из него надо выбросить N22 = N2 и N31 = n - N2, а потом добавить M22 = -N2 и M31 = n + N2. Так как n положительно, а N2 отрицательно, интервальная сумма N31 положительна, а соответственно не учавствует в вычислении нормы пятерки N. Далее M22 = -N2 > 0, а значит не учавствует в вычислении нормы M. Теперь возможны два варианта:
если n+N2 &ge 0, то |M| = |N| - abs(N2) < |N|;
если n+N2 < 0, то |M| = |N| - abs(N2) + abs(n+N2) = |N| + N2 -n - N2 = |N| -n < |N|.
no subject
Date: 2009-03-21 07:06 pm (UTC)no subject
Date: 2009-03-21 07:32 pm (UTC)no subject
Date: 2009-03-21 07:44 pm (UTC)no subject
Date: 2009-03-21 07:58 pm (UTC)no subject
Date: 2009-03-21 07:59 pm (UTC)Let's call the rules as stated a positive-sum positive-direction game (because we change -x -> +x in the positive direction). We can also consider variants with negative initial sum and/or negative direction, where +x -> -x and the neighbors get a positive boost. Finally we'll need to look at a variant with no wraparound - that is, when inverting an edge
number only one neighbor gets a boost, changing the total sum.
Given any variant of the rules and an initial tuple, there are three
conceivable outcomes: the game "diverges", producing unbounded
numbers; the game stops, because all the numbers are nonnegative (or
nonpositive for a neg-direction game); the game goes into a cycle
repeating the same bounded set of tuples. I'll prove that for a
pos-direction game with wraparound, regardless of the initial tuple
and choices of numbers to invert, the outcomes are as follows,
depending on the total sum:
positive sum -> the game stops (this solves the puzzle as requested)
negative sum -> the game diverges
zero sum -> the game goes into a cycle.
Note that it's easy to flip both the sign of the sum and the direction
of play by inverting the signs of all numbers, obtaining essentially
the same game; so the above claim also solves the neg-direction case
with the condition on the sum inverted.
I first need a lemma to show what happens in a no-wraparound game with
few numbers:
Lemma 1. A no-wraparound positive-direction game with 2 or 3 numbers
will stop at a nonnegative tuple in a number of steps that depends
only on the initial sum, not the numbers themselves.
Proof: With two numbers, after one step one of them will be positive,
e.g. [-A B], then after the next step we get [A B-A], and if B-A is
negative, this transforms into [B A-B] with both numbers nonnegative,
so we're done after at most 3 steps.
With three numbers A B C, every time we invert an edge number, we
increase the total sum at least by 1 (due to no-wraparound), and we do
that at least every second step, because we can't invert B twice in a
row. So after a number of steps depending only on the initial sum, the
total sum becomes nonnegative. After that, I'll show that all numbers
become nonnegative in at most 4 steps. If two numbers are negative,
e.g. -A -B C, then C >= A+B by sum being nonnegative, so inverting A
or B leaves just one negative number. So assume just one number is
negative, and there are two cases of it being on the edge or in the
middle:
[-A B C] -> [A (B-A) C]. Now if B-A is negative, this -> [B (A-B)
(C+B-A)], and C+B-A >=0 being the initial sum, so we're done.
[A -B C] -> [(A-B) B (C-B)]. Suppose e.g. A-B is negative and inverted
-> [(B-A) A (C-B)],if
C-B is also negative, then this -> [(B-A) (A-B+C) (B-C)], and this is
nonnegative, the middle
number being the initial sum. Q.E.D.
Now we go back to 5 numbers with wraparound. An easy consequence of
the above lemma is:
Lemma 2, the "hanging gun" lemma: If A,B are two neighbors, A+B < 0,
in a tuple in a positive-direction game, the game will produce a
number <= A+B in a number of steps dependent only on the total sum. A
and B are like a gun hanging on the wall in act 1 that must eventually
fire by the end of the play.
Proof: If either A or B are inverted, the other number becomes A+B. As
long as they're not inverted, they can only decrease due to their
other neighbors being inverted. Avoiding A and B and using only three
other numbers amounts to a game with 3 numbers and no wraparound,
which by Lemma 1 must end in K steps, where K depends on the sum of
the three numbers; this sum is bounded from below by the total sum
because A+B < 0. Q.E.D.
no subject
Date: 2009-03-21 08:00 pm (UTC)immediately from a stronger claim that I'll need for the positive-sum
later:
Lemma 3. In a negative-sum positive-direction game, given a tuple with
a minimal number -M, M > 0 (the minimal number is negative because
the game is negative-sum), the game will produce a tuple with a number
less than M in no more than K steps, where K depends only on the total
sum and not on the particular tuple or M.
Proof. The game cannot stop at all - the sum is negative so there'll
always be a negative number. The game cannot continue long without
inverting either -M or one of its neighbors, using just the two
remaining slots, because that is identical to a 2-number no-wraparound
game, and this finishes in 3 steps by Lemma 1. So after 3 steps we'll
have to invert -M or its neighbors; inverting an neighbor will
decrease -M immediately so this is a trivial case; therefore we can
assume -M is inverted to M. If one of its neighbors is negative at the
time, it gets decreased to a number less than -M, and we're done too;
so we can assume that the tuple looks like this when inverting -M:
[x A -M B y] -> [x (A-M) M (B-M) y], here A,B,M are nonnegative and
the signs of x,y are uncertain. We also know that the total sum is
negative: x + A -M + B + y < 0.
We want to show that after a constant number of steps, we'll get two
neighbors with total sum less than -M; and then by the hanging-gun
lemma (Lemma 2) we're done.
A-M and B-M might both be positive; or they could be negative but we
might choose to invert x or y instead of either of them. But we can
only focus on x,y for a few steps (by Lemma 1), and every time we
invert x or y, we decrease one of (A-M), (B-M), and we can still
denote them (A-M), (B-M) after such a decrease, shifting A or B
appropriately. We can assume that A-M and B-M won't get less than -M
as a result of this (because otherwise we're done), so A,B remain
nonnegative. After no more than a few steps, we'll invert either A-M
or B-M - either out of choice or due to turning x,y nonnegative by
Lemma 1; the tuple at that point can still be represented as
[x (A-M) M (B-M) y], with A,B,M nonnegative, x,y uncertain
Suppose we invert A-M at this point, getting to [(x+A-M) (M-A) A (B-M)
y]. If B-M is positive, then B >= M; but B is the sum of the three
middle numbers in the tuple now, and since the total sum is < 0, the
sum of the edge numbers will be < -M, and we're done. So we can assume
B-M is negative just as A-M is, and rewrite the tuple, before
inverting A-M, as
[x -C M -D y], C, D, M nonnegative, C,D <= M, we're about to invert -C.
The next tuple we get is
[(x-C) C (M-C) -D y]
We now repeatedly show that any way to proceed will quickly lead us to
a triple of consecutive numbers with total sum >=M, so that the other
two numbers must have sum < -M, which is enough by the hanging lemma.
To start with, if we invert -D now, we get
[(x-C) C (M-C) -D y] -> [(x-C) C (M-C-D) D (y-D)],
and the sum of three middle numbers is M. So we can't invert -D. M-C
is nonnegative, so it's out. If x-C is negative, and we invert it, we
get
[(x-C) C (M-C) -D y] -> [(C-x) x (M-C) -D (y+x-C)],
and the sum of the first three numbers is M. The only remaining option
is to invert y, assuming it's negative, to get
[(x-C) C (M-C) -D y] -> [(x-C-y) C (M-C) (-D-y) y].
Now we have only one or two remaining negative numbers to invert -
(x-C-y), possibly, and (-D-y), certainly; and using either leads to a
triple summing to M:
[(x-C-y) C (M-C) (-D-y) y] --inverting (x-C-y)--> [(y+C-x) (x-y) (M-C)
(-D-y) y], first three numbers
[(x-C-y) C (M-C) (-D-y) y] --inverting (-D-y)--> [(x-C-y) C (M-C-D-y)
(D+y) y], middle three numbers
To sum all of this up, in the worst case, after 10 steps from the
initial tuple - three before we have to invert -M, one to invert -M,
three more before we have to invert one of its neighbors, one to
invert a neighbor, and three more to exhaust all possibilities after
that - we reach a situation where we can invoke Lemma 2 and conclude
that a number less than -M will be generated. This proves Lemma 3 and
the claim that a negative-sum game will diverge.
no subject
Date: 2009-03-21 08:00 pm (UTC)as requested).
Proof: Let the sum of the initial tuple be S. We first prove that
there's an upper bound on the numbers appearing in the game, starting
from a given tuple. Suppose we played for N steps, and see a number M
in the tuple that's larger than all the numbers in previous tuples. If
we now start from the current tuple and reverse the arrow of time,
we'll be playing a positive-sum negative-direction game, with sum S.
But this game is equivalent, by inverting all numbers, to a
negative-sum positive-direction game with sum -S, with -M in the
starting tuple. By Lemma 3, after some K steps, where K depends only
on -S, we'll see a tuple with a number less than -M, or - inverting
back - larger than M. This is impossible if by going back K steps
we're still within the N steps we played in the original game, by the
maximality of M in it. So by choosing N larger than K, we can ensure
that we'll never see a new maximal champion after N steps.
Now we prove that the numbers must be bounded from below as well. If M
is a positive upper bound on all numbers in the game starting from a
given tuple, then any negative number -M', M' > M, that appears in the
game, must never be inverted again - it can only be further decreased.
That turns the remaining numbers into a 4-number no-wraparound game A,
B, C, D. In this game, inverting A or D increases the total sum, and
it's impossible to only keep inverting B and C (Lemma 1), so the total
sum keeps increasing. Yet it can't grow beyond 4M, because M is the
upper bound on everything in the enclosing 5-game; so the game must
stop, meaning A,B,C,D will be nonnegative and we'll have to invert
-M', contradicting the maximality of M. It follows that a negative
number -M' with M' > M cannot arise in the game, so that the game is
bounded by [-M, M].
Finally, the game cannot end in a cycle, because such a cycle becomes
a cycle in a negative-direction game (played from finish to start by
reversing the time), and this in turn becomes a cycle in a
negative-sum positive-direction game by inverting all numbers, and
this is impossible by Lemma 3.
The last claim, that given an initial sum of 0, the game goes into a
cycle, is a consequence of the above: because the sum is nonnegative,
the game is bounded, but it cannot stop at any nonnegative tuple
except [0,0,0,0,0].
no subject
Date: 2009-03-21 08:02 pm (UTC)Здорово, да. Я пытался найти инвариант, и даже складывать последовательные цепочки членов и смотреть только на отрицательные среди них пытался, но я искал среди них "самую отрицательную" вместо того, чтобы сложить все вместе ;)
no subject
Date: 2009-03-21 08:04 pm (UTC)no subject
Date: 2009-03-21 08:05 pm (UTC)no subject
Date: 2009-03-21 10:01 pm (UTC)no subject
Date: 2009-03-21 10:50 pm (UTC)no subject
Date: 2009-03-21 11:01 pm (UTC)no subject
Date: 2009-03-21 11:07 pm (UTC)Более элегантная и более общая формулировка задачи - для общего случая N и суммы 0. Случайно берутся позиции и перещелкиваются, две соседние сдвигаются в обратную сторону с сохраненим суммы. Доказать, что максимальная амплитуда стремится к нулю. Найти асимтотический закон.
no subject
Date: 2009-03-22 04:41 pm (UTC)(задача о жадинах и манной каше). А эта задача (с моей точки зрения) -- про группы порожденные отражениями, конкретно про аффинную группу Вейля типа А.
no subject
Date: 2009-03-22 04:43 pm (UTC)no subject
Date: 2009-03-22 04:44 pm (UTC)no subject
Date: 2009-03-22 07:47 pm (UTC)a finite group, namely the group S_5 of permutations on 5 letters -- this is easy to see by choosing auxiliary coordinates y_1, .., y_5, so
that x_i = x_{i+1}-x_i, x_5=y_1-y_5, then the change
of x's you described corresponds to switching a pair
of neighboring y's. Geometrically one can think of it as a group generated by reflections in the hyperplanes y_i=y_j. Replacing 5 by 3 we would get 3 lines intersecting at 60 or 120 degrees partitioning the plane in 6 regions. Those regions
for a general n (instead of 3,5) are called (Weyl) chambers.
A standard thing to do with a sequence of numbers is to change the order "locally" interchanging two neighbors (where at the moment "neighborhood" is understood non-cyclically, so y_1 and y_5 aren't neighbors)
appearing in a "wrong" order, after a few steps
the sequence necessarily becomes monotone.
Geometrically this corresponds to reflecting a point in a Weyl chamber at a hyperplane bounding the chamber and separating it from the standard chamber (the latter consists of points with x_i>0,
y_i monotone). This gets the point closer (in some sense) to the standard chamber and eventually into it.
Now, your problem is about an "affine" version of this. For non-zero sum the group is an infinite but still discrete group of affine-linear transformations of the 4-space, in fact it's isomorphic to the semi-direct product of S_n and a group of translations. The role of chambers is played by
alcoves, with 5 replaced by 3 these are members in the tesselation of the plane by equilateral triangles,
see e.g. the "A_2" picture at
http://www.math.ubc.ca/~cass/coxeter/r.html
Again, each transformation you describe takes
the point closer to the "fundamental alcove"
(where all x_i are positive) and eventually into it.
One can rewrite this argument algebraically -- say, using y_i such that x_i = y_{i+1}-y_i, though now we'll have to have y_i indexed by all integers, with y_{i+5}=y_i+s, where s is the sum of x_i's.
But then things get less intuitive.
no subject
Date: 2009-03-22 07:48 pm (UTC)no subject
Date: 2009-03-22 08:20 pm (UTC)a finite group, namely the group S_5 of permutations on 5 letters -- this is easy to see by choosing auxiliary coordinates y_1, .., y_5, so
that x_i = x_{i+1}-x_i, x_5=y_1-y_5, then the change
of x's you described corresponds to switching a pair
of neighboring y's.
I lost you here. E.g. if my x's are
[1 1 1 1 -4]
then the list of y's, the differences, is
[0 0 0 -5 5]
Now if I apply the transformation to -4 in the original list, I get:
[1 1 1 1 -4] -> [-3 1 1 -3 4]
with the list of differences
[4 0 -4 7 -7]
which isn't a permutation of [0 0 0 -5 5] at all. Am I missing something?
no subject
Date: 2009-03-22 08:41 pm (UTC)(0,1,2,3,4) for y's. Permuting I get
(4,1,2,3,0) with the list of differences
(-3,1,1,-3,4).
In fact, the algebraic argument is also short (even if less intuitive), here it is.
Choose y_i for all integer i, s.t. x_i=y_{i+1}-y_i
for i=1,..,5, and y_{i+5}=y_i+s, where s is the sum of x_i's. Since s is positive, the total number of disorders, i.e. of pairs i,j, s.t. iy_j, modulo
the change (i,j) \to (i+5k,j+5k), is finite.
The transformation you describe amounts
to swapping y_{i+5k} with y_{i+1+5k} for some
i s.t. y_i>y_{i+1}. It decreases the number of disorders by 1, so after a finite number of steps
the sequence of y's will be monotone, and the sequence of x's won't have negative terms.
Of course, integrality of x's is irrelevant.
no subject
Date: 2009-03-23 09:18 am (UTC)no subject
Date: 2009-03-23 04:30 pm (UTC)no subject
Date: 2009-03-23 06:57 pm (UTC)Dlja vashih x'ov nado brat' beskonechnuju v obe storony posledovatel'nost' y'ov: ..., 2,2,2,2,1,3,3,3,3,2, ...
takaja posl-t' budet perestavljat'sja.
no subject
Date: 2009-03-23 08:40 pm (UTC)no subject
Date: 2009-03-23 08:41 pm (UTC)no subject
Date: 2009-03-23 08:48 pm (UTC)Моя попытка разрешения. Возможно понадобится помощь-б
Date: 2009-03-26 07:21 pm (UTC)no subject
Date: 2009-03-26 09:58 pm (UTC)no subject
Date: 2012-05-14 01:46 pm (UTC)F(a,b+c,-c,d+c,e) = a^2+b^2+2bc+c^2+c^2+d^2+2cd+c^2+e^2+(a+b)^2+2(a+b)c+c^2+(b+c)^2-2(b+c)c+c^2+(c+d)^2-2(c+d)c+c^2+(d+e)^2+2(d+e)c+c^2+(e+a)^2 =
= F(a,b,c,d,e) + 2bc+c^2+2cd+c^2+2(a+b)c+c^2-2(b+c)c+c^2-2(c+d)c+c^2+2(d+e)c+c^2 =
= F(a,b,c,d,e) + c(2b+c+2d+c+2a+2b+c-2b-2c+c-2c-2d+c+2d+2e+c) =
= F(a,b,c,d,e) + 2c(a+b+c+d+e) < F(a,b,c,d,e)