Can anyone give a formal Mathematical proof to this one.

uart

Member
May 26, 2000
174
0
0

Someone posted his CS homework (which was subsequently locked) HERE.


Unfortunately I was just about to post a question regarding the formal proof of the "self evident" conclusion, but the thread got locked first.

Ok, I know that it was fully legit to lock that thread because the guy couldn't even paraphrase the problem and just made it so obvious that it was a regurgitated homework question. But knowing that there are a few mathematical folk frequenting this forum, then just for fun does anyone want to have a crack at a formal proof to the result stated in the linked post.

Hey we've gota do the odd maths problem here otherwise it's too dam quite. :)

 

sao123

Lifer
May 27, 2002
12,653
205
106
I started to do the math and got stuck. In theory...here is my foundation

P1 P2 P3...Px = times of each task
C1 C2 C3...Cx cumulative time of each task. Cn = Sum of P1 to Pn.
Average completion time is C1 + C2 + ... Cx / X

The sum C1 + C2 + ... + Cx can be rewritten as
(P1) + (P1 + P2) + .... + (P1 + P2 + ... + Px)
By factoring...
(X)(P1) + (X-1)(P2) + (X-2)(P3) + ... + 1(Px)

Sum from 1 to X of (Pn)*(X-n) =

This series looks familiar, I know there should be a way to minimize it based on ordering the terms of P1,P2,...Pn
Especially since the sum of (X-n) from n = 1 to X converges.

But I cant remember any such theorems to do it.

HELP!!!
 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
Let's see if I can remember how the CS version of it goes (the books are all packed away in boxes right now).

Basically, the idea is that you can show that any ordering except doing the jobs from shortest to longest gives a longer running time than ordering them shortest to longest.

If you start with the jobs in order from shortest to longest, there is no way to reshuffle or swap them around such that the metric you're interested in (average completion time) goes down (it has to go up). I don't recall the exact details of how they proved it, but that was the direction they went in. Mathematically, it's probably equivalent to what the previous poster was trying to do. I'll have to see if I can find my operating systems book; I know this was in there in the section on process scheduling.
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
167
111
www.slatebrookfarm.com
Ahhh, I understand the problem now... taking a crack at it...
Proof by contradiction seems like it might work, but that's just not as elegant. working...
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
167
111
www.slatebrookfarm.com
Originally posted by: sao123
I started to do the math and got stuck. In theory...here is my foundation

P1 P2 P3...Px = times of each task
C1 C2 C3...Cx cumulative time of each task. Cn = Sum of P1 to Pn.
Average completion time is C1 + C2 + ... Cx / X

The sum C1 + C2 + ... + Cx can be rewritten as
(P1) + (P1 + P2) + .... + (P1 + P2 + ... + Px)
By factoring...
(X)(P1) + (X-1)(P2) + (X-2)(P3) + ... + 1(Px)

Sum from 1 to X of (Pn)*(X-n) =

This series looks familiar, I know there should be a way to minimize it based on ordering the terms of P1,P2,...Pn
Especially since the sum of (X-n) from n = 1 to X converges.

But I cant remember any such theorems to do it.

HELP!!!


perfect start. Rather than minimize the average, it's sufficient to minimize the sum

sum = p1*x + p2(x-1) + p3(x-2) + .... + px(1)

egads... I have it almost down on the paper, almost there, but not quite there... like on the tip of my tongue...
I'm trying to prove it first for 2 terms then generalize it for more than 2 terms

 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
167
111
www.slatebrookfarm.com
Got it... (for the first two terms... I'll generalize more later, or else someone else can generalize more later)
I tried to spread the logic out instead of making it look too formal... This is an extension from where Sao left off.

Assume p1 <= p2 and
Then, -p2 <= -p1

Add p1*x to both sides and
p1*x - p2 <= p1*x -p1

Add p2*x to both sides and
p1*x + p2*x - p2 <= p2*x + p1*x - p1

Factor
p1*x + p2*(x -1) <= p2*x + p1*(x-1)

Therefore, if p1 <= p2, then

p1*x + p2*(x-1) <= p2*x + p1*(x-1)

I don't think it's too hard to generalize from there to the xth term.
"I'll leave the generalization to you for homework," said the typical professor.


I take that back. It looks to me, at least at first, to be a PITA to generalize it formally. (and be able to type it)
Here's an attempt though...

Assume p(sub a) <= p(sub b)
then negative p(sub b) <= negative p(sub a)
etc. (don't forget to tack on the well ordered principle)
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
167
111
www.slatebrookfarm.com
Aaaaaaaaaaaaccccckkkkkkk!!

I wrote the sum as p1x + p2(x-1) + ... + pa(x - m + 1) + ... + pb(x - n + 1) + ... + px*1
where m is the mth term and n is the nth term. I started trying to show that if m < n, and pa < pb then pa*(x-m+1) + pb*(x-n+1) <= pb*(x - m + 1) + pa*(x - n + 1)

(ughhhhh)

Then, I realized that all I did was move from the first two terms to any two terms, and hadn't quite taken care of the entire thing, but so tantalizingly close. Then my stomach growled, I looked at the time... my computer's clock is somehow off by close to an hour, and I'm hungry. But, I think this part (were I ambitious enough to type it) proves that if pa < pb then pa will have to occur before pb in the series... then somehow tying in the well ordered principle, and neglecting if pa = pb (that's another homework problem, kids)... close enough
 

KalTorak

Member
Jun 5, 2001
55
0
0
Okay - I'm not quite there yet, but I do think this is awfully similar to a Putnam Exam problem I remembered...
Turns out it's problem B3 from 1996:

B?3 Given that {x1, x2, ... , xn} = {1, 2, ..., n}: Find, with proof, the largest possible value of x1x2 + x2x3 + ... + x(n-1)xn + xnx1 (as a function of n)

From the NIU Putnam archive:

B3. There are n terms to be added, each at most n(n-1), so we cannot
exceed a cubic function of n. In fact, the maximum value (if my
calculations are correct) is P(n) = (2n^3-3n^2-11n+72)/6 for n>=3.
(P(2)=2.)

Observe that the "circular sum" in question is determined by the
ordered set {x_1=1, ..., x_n=n} and the permutation f used to write
the sum as
x_f(1) * x_f(2) + x_f(2) * x_f(3) + ... + x_f(n) * x_f(1).
In particular, with fixed x_i, there are only as many sums to
consider as there are permutations, and so there is a maximum. It
does not occur for a unique f (indeed, the circular sum is really
a function of the coset of <(1 2 ... n)> to which f belongs),
but it's essentially unique, as we will see by construction.
In particular, we will see that the optimal circular sum involves
the product x_1*x_2 .

For n=2,3, there is really only one circular sum
x_1 x_2 and
x_1 x_2 + x_2 x_3 + x_3 x_1
respectively. With the given values of x_i these equal P(2)=2 and
P(3)=11 respectively.

So now by induction suppose that for any permutation of {1, 2, ..., n-1}
we know the circular sum to be no larger than P(n-1). I claim that
the maximum value of a circular sum for {x_1=2, x_2=3, ..., x_(n-1)=n}
is then P(n-1) + n(n-1) + (n-1). Indeed, for any permutation f of these
terms, we relate the circular sum for the x_i to the corresponding sum
for the y_i=x_i-1 (={1, 2, ..., n-1}): by expanding the former we get
y_f(1) * y_f(2) + y_f(2) * y_f(3) + ... + y_f(n) * y_f(1)
+ 2 * (y_1+...+y_(n-1))*1 + (n-1)*1^2
which is the latter's circular sum plus 2*Sum( i, i=1..n-1 ) + (n-1).
[The factor "2" here is absent when n-1 = 2].
By induction, that circular sum is at most P(n-1). Note that by induction
we have the additional information that the optimal circular sum of
the x_i includes x_1*x_2 = 2*3 as a summand.

Now suppose an (optimal) permutation for {1, 2, ..., n} is selected.
Writing x and y for the terms multiplying 1, we see the circular
sum C is
C = 1*x+ 1*y - x*y + S
where S is a circular sum of {2, 3, ..., n} formed by adding x*y
to the sum of all terms in C not having 1 as a factor. (That is, we
"remove the 1 and close the loop".) Since this may be written
C = 1 - (x-1)*(y-1) + S,
it is clear that C <= 1 - (2-1)*(3-1) + max(S), the last term being
the maximum (over all permutations of {2,3,..., n}) of the circular
product involving those n-1 numbers.

By an earlier paragraph, we know that this maximum is
P(n-1) + (n+1)*(n-1). This gives an upper bound of P(n-1) + (n^2-2)
to C.

Now, we would not know whether this upper bound were ever attained except that
we know the optimal circular sum for {2, 3, ..., n} does involve 2*3
as a summand. Thus, replacing this summand by 1*2+1*3 gives a circular
summand of {1, 2, ..., n} equal to the established upper bound.

It remains only to check that the recurrence relation
P(n)=P(n-1)+(n^2-2)
P(3)=11
has the solution
P(n) = (n^3-n)/3 - (n^2-n)/2 - 2n + 12 = (2n^3-3n^2-11n+72)/6,
which is elementary.
[djr - well, it would be if I kept my signs straight! Actually it comes out
to (2n^3+3n^2-11n+18)/6.]

NOTE: The optimal product may be found from this proof: it's
1*3 + 3*5 + 5*7 + ... (top odd)*(top even)+ ... + 8*6 + 6*4 + 4*2 + 2*1
 

uart

Member
May 26, 2000
174
0
0
OK, I did this proof a few days ago and was just about to post it when the other thread got locked. I didn't post the proof at the start of the thread because I didn't want to spoil everyones fun. I was also kind of interested in how many different ways people might try to tackle the same problem.

Ahhh, I understand the problem now... taking a crack at it...
Proof by contradiction seems like it might work, but that's just not as elegant. Working...
Very good, proof by contradiction was exactly how I tackled it. Though admittedly I tried a bunch of other things involving partial differentiation before I finally hit upon good ol' contradiction.

Ok here is my original proof, it's fairly straightforward.

Statement :
The sum, Y = Sum (k=1 to n) of { (n+1-k) * p(n)}, is minimized when p(1)...p(n) are arranged in ascending order. That is, p(k) >= p(j) whenever k > j


Proof : (by contradiction)
Assume that the above statement is wrong and that Y is minimized for an indexing such that there exists some p(k) < p(j) for a given k > j.

Then we can write the sum Y for this case as,
Y = C + (n+1-j) * p(j) + (n+1-k) * p(k) : where constant C is the sum of all the other terms apart from the jth and the kth.

But the above Y can easily be rearranged as,
Y = { C + (n+1-j) * p(k) + (n+1-k) * p(j) } + { ( k - j ) * ( p(j) ? p(k) ) }

Now the first ?{}? bracketed term in the above expression is precisely the value that the sum Y would have attained if the p()'s were re-ordered by interchanging the positions of the p(j) and p(k) terms. And the second ?{}? bracketed term is strictly positive under the given assumptions. So the original sum Y can not be the minimum (as the above clearly shows that the sum Y can be made smaller by rearranging the j and k terms). So the assumption that the statement is wrong is proven to be false and hence the stament is true. Q.E.D #


 

sao123

Lifer
May 27, 2002
12,653
205
106
I started to do the math and got stuck. In theory...here is my foundation

P1 P2 P3...Px = times of each task
C1 C2 C3...Cx cumulative time of each task. Cn = Sum of P1 to Pn.
Average completion time is C1 + C2 + ... Cx / X

The sum C1 + C2 + ... + Cx can be rewritten as
(P1) + (P1 + P2) + .... + (P1 + P2 + ... + Px)
By factoring...
(X)(P1) + (X-1)(P2) + (X-2)(P3) + ... + 1(Px)

Sum from 1 to X of (Pn)*(X-n) =


I can now from here go into an inductive proof. (Which job should I pick next?)
As this was a compsci proof, I should have known this was the way to go...

Given the set S = [P1, P2, P3 ... Px] where any Py < Pz where y < z -> to minimize the sum here we go.
----------------------
base:
Choose P1
P1 < all x in S.
true
-------------------
case 1: choose p2 vs any other x in P (Which job should I pick next?)

P1 + (P1 + P2) <= P1 + (P1 + P(x>2))
2P1 + P2 <= 2P1 + P(x>2)
P2 <= P(x>2)
P2 - P(x>2) <= 0
true

now check. (What if i did p2 first?)
P1 + (P1 + P2) <= P2 + (P2 + P1)
2P1 + P2 <= 2P2 + P1
P1 - P2 <= 0
true
--------------------------
general case: (Which job should I pick next?)

P1 + (P1 + P2) +...+ (P1 + P2 + ... + P(x-1) + Px) <= P1 + (P1 + P2) +...+ (P1 + P2 + ... + P(x-1) + Py) where x < y.
(x) * P1 + (x-1) * P2 + ... (2) * P(x-1) + 1 * Px <= (x) * P1 + (x-1) * P2 + ... (2) * P(x-1) + 1 * Py
Px - Py <= 0
true