Proving termination and correctness of the algorithm

  • Context: Graduate 
  • Thread starter Thread starter Bipolarity
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary

Discussion Overview

The discussion revolves around proving the termination and correctness of a swapping algorithm involving two nonempty finite subsets, ##B## and ##C##, from an ordered field. Participants explore various methods to demonstrate that a finite number of operations can lead to a state where the maximum of ##B## is less than the minimum of ##C##. The conversation includes aspects of algorithm proof techniques, such as induction and loop invariants.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests using induction or loop invariants to prove the algorithm's correctness, expressing uncertainty about their experience with algorithm proofs.
  • Another participant proposes finding a way to measure the distance to the final state as part of the proof strategy.
  • A participant mentions that the problem is part of a larger project related to proving the correctness of Gauss-Jordan elimination.
  • There is a suggestion to consider the case where ##B## has only one element as a base case for induction.
  • One participant questions how to prevent infinite loops during the swapping process and suggests tracking swapped elements or writing a small program to explore the problem further.
  • A method is proposed to label elements of both sets and swap them based on their order, aiming to achieve the desired condition.
  • Another participant raises a concern about the initial condition, arguing that it is possible for ##\max(B) \geq \min(C)## without being able to achieve ##\max(B) < \min(C)## in certain cases.

Areas of Agreement / Disagreement

Participants express various viewpoints on the proof methods, with some suggesting induction and others questioning the feasibility of achieving the desired condition under certain circumstances. The discussion remains unresolved regarding the effectiveness of the proposed approaches and the implications of the initial conditions.

Contextual Notes

There are limitations regarding the assumptions made about the sets ##B## and ##C##, particularly concerning their elements and the implications of the initial condition. The discussion also highlights the need for clarity on the definitions and properties of the sets involved.

Bipolarity
Messages
773
Reaction score
2
I've been trying to prove the following, without much success.
Let ##B## and ##C## be nonempty finite subsets of an ordered field ##\mathbb{F}##. Define the swapping operation ##S## as follows:
It takes an element ##b## from ##B##, an element ##c## from ##C##, removes ##b## from ##B## and gives it to ##C##, removes ##c## from ##C## and gives it to ##B##. Now suppose that ##\max(B) \geq \min(C)##. Then prove that in a finite number of operations of S, the sets ##B## and ##C## can be transformed so that ##\max(B) < \min(C)##.

Where would I start? I'm thinking by we can use induction/loop invariants, but I don't have much experience in algorithm proofs, so I could use some help. Thanks!

BiP
 
Last edited by a moderator:
Physics news on Phys.org
I can think of 3 ways to prove this. The invariant idea is probably what your teacher/the author wants. Try to find a way to measure how far you are from the final state. That is, given B and C, can you estimate how many swap operations are required?
 
  • Like
Likes   Reactions: 1 person
verty said:
I can think of 3 ways to prove this. The invariant idea is probably what your teacher/the author wants. Try to find a way to measure how far you are from the final state. That is, given B and C, can you estimate how many swap operations are required?

I actually made the problem myself. It is part of a larger project in which I have been trying to rigorously prove correctness of Gauss-Jordan elimination. The algorithm I described above is needed to make sure a finite number of row interchange operations exist on a matrix so that all nonzero rows precede the zero rows.

I'm clueless as to how you would do this proof. Like I said, I don't have much experience in algorithms let alone proving their correctness. Perhaps you could recommend me a text, or help me work through this problem?

Which 3 ways are you referring to?

Thanks by the way.

BiP
 
Bipolarity said:
I actually made the problem myself. It is part of a larger project in which I have been trying to rigorously prove correctness of Gauss-Jordan elimination. The algorithm I described above is needed to make sure a finite number of row interchange operations exist on a matrix so that all nonzero rows precede the zero rows.

I'm clueless as to how you would do this proof. Like I said, I don't have much experience in algorithms let alone proving their correctness. Perhaps you could recommend me a text, or help me work through this problem?

Which 3 ways are you referring to?

Thanks by the way.

BiP

First of all, the field hypothesis is unnecessary. It works for any totally ordered set.

Try an induction proof:
Let ##B## have ##n## elements and ##C## have ##m## elements.

1) Can you prove this in the case that ##B## has ##1## element?
2) Assume that it works for any ##B## with ##n^\prime<n## elements. Prove that it works for ##n##. Hint: take the element ##\max(B)##. Look at the set ##B^\prime = \{\max(B)\}##. Apply (1) to get this element smaller than ##\min(C)##. Then take ##B^{\prime\prime}## the set of all elements bigger than ##\min(C)##. This has ##<n## elements.
 
Bipolarity said:
I've been trying to prove the following, without much success.
Let ##B## and ##C## be nonempty finite subsets of an ordered field ##\mathbb{F}##. Define the swapping operation ##S## as follows:
It takes an element ##b## from ##B##, an element ##c## from ##C##, removes ##b## from ##B## and gives it to ##C##, removes ##c## from ##C## and gives it to ##B##.


Now suppose that ##\max(B) \geq \min(C)##. Then prove that in a finite number of operations of S, the sets ##B## and ##C## can be transformed so that ##\max(B) < \min(C)##.

Where would I start? I'm thinking by we can use induction/loop invariants, but I don't have much experience in algorithm proofs, so I could use some help. Thanks!

BiP

Do you keep track of the elements that have been swapped? Owise, how do you prevent an infinite loop; say you have (assume restricition of standard ordering on naturals):

C={1,3,4,8}

B={2,5,6}

S: 4<->6

Then

C'={1,3,6,8}

B'={2,4,5}

What prevents you from swapping 4 and 6 again (strictly-speaking, 6<->4 )...and again...

Why don't you try to write a small program .

You may have to index the terms of C,B, so that you have finite sequences, instead of sets.
 
Label the elements of both sets ##e_1, e_2, \dots e_k## where ##e_1 \le e_2 \le \dots \le e_k## (independent of which set they are in).

For ##p = 1, 2, \dots## up to the number of elements in ##C##:

If ##e_p## is not in ##C##, swap ##e_p## from ##B## with any element ##e_q## of ##C## such that ##q > p##.

Done!
 
Bipolarity said:
Now suppose that ##\max(B) \geq \min(C)##. Then prove that in a finite number of operations of S, the sets ##B## and ##C## can be transformed so that ##\max(B) < \min(C)##.
I think you meant max(B)≤min(C), not max(B)<min(C). Consider the sets B={0}, C={0}. This satisfies the condition that max(B)≥min(C). Swap all you want and you will never be able to transform the sets such that max(B)<min(C).
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 27 ·
Replies
27
Views
4K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 66 ·
3
Replies
66
Views
8K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
Replies
1
Views
2K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K