Loop invariant(discrete math's)

  • Thread starter Thread starter vvvidenov
  • Start date Start date
  • Tags Tags
    Loop
Click For Summary

Homework Help Overview

The discussion revolves around demonstrating that the inequality {m^5 ≤ n^4} serves as a loop invariant for a specific while loop structure where m and n are repeatedly multiplied by constants during each iteration. The context is rooted in discrete mathematics and computer science concepts related to loop invariants.

Discussion Character

  • Exploratory, Conceptual clarification, Mathematical reasoning, Problem interpretation, Assumption checking

Approaches and Questions Raised

  • Participants explore the concept of loop invariants and attempt to relate the values of m and n through their iterative transformations. Some participants question the initial values of m and n and how they affect the loop invariant. Others analyze the ratio m^5/n^4 and consider logarithmic approaches to demonstrate the required inequality.

Discussion Status

There is ongoing exploration of the problem with various participants offering insights and alternative methods of analysis. Some guidance has been provided regarding the use of logarithms to analyze the ratio of m and n, but there is no explicit consensus on the best approach or resolution of the problem.

Contextual Notes

Participants express confusion regarding the constants used in their calculations (such as 81 and 64) and the derivation of these values from the transformations of m and n. There is also mention of similar solved examples that may influence their understanding of the current problem.

vvvidenov
Messages
23
Reaction score
0

Homework Statement


show that {m^5 \leqn^4} is a loop invariant for the loop
while 1 \leq m do

m:= 3m
n: = 4n


Homework Equations



similar solved example:
while 1\leq m do
m:=2m
n: =3n

a) n^2\geq m^3 is given [so 8n^2\geq 8m^3 by multiplying both sides by 8; and 9 n^2 > 8 n^2 because n^2>0]
Hence ("new-n")^2=(3n)^2=9n^2>8n^2\geq8m^3=(2m)^3=("new-m").
So ("new-n")^2\geq ("new-m")

b)2m^6 is given [so 81(2m^6)< 81(n^4) by multiplying by 81, and 64(2m^6) < 81(2m^6)]
Hence 2("new-m")^6=2(2m)^6=2^6*2*m^6<81(2m^6)<81(n^4)=(3n)^4=(new-n")

The Attempt at a Solution



m^5\leqn^4

81(m^5) < 81(n^4), and 64(m^5)< 81(m^5)

("new-m")^5=(3m)^5 < 81 (n^4)= (4n)^4

("new-m") \leq ("new-n")

please help if I did something wrong in this attempt to solve the problem. It is confusing for me even I have the solved one above.
 
Last edited by a moderator:
Physics news on Phys.org
No one else has replied, so I'll give it a shot. I understand the loop invariance concept as it pertains to computer science, and I understand loops such as the while loop in your example. However, I can't make much sense out of your work.

Each iteration of the loop, m gets reset to 3 times its previous value, and n gets reset to 4 times its previous value. What I don't see are the initial values of m and n. Assuming for the moment that m and n are intialized to 1, here are the values of m and n:
m 1 3 9 27 81 243 ...
n 1 4 16 64 256 1024...

In general, at any step k, m's value is 3^k, and n's value is 4^k.

Looking at your loop invariant, you need to show that m^5 <= n^4.

Let's look at the ratio m^5 / n^ 4. If you can show that this ratio is <= 1, you'll be done. I'll be working with logs, so I will show that the log of the ratio is <= 0.

m^5/n^4 = (3^k)^5 / (4^k)^4 = (3^(5k))/(4^(4k))

So ln [m^5/n^4] = ln [(3^(5k))/(4^(4k))]
= ln(3^(5k)) - ln(4^(4k))
= 5k ln(3) - 4k ln(4)
= k [ln(3^5) - ln(4^4)]
The quantity in brackets is ln(243) - ln(256), which is negative.
If k = 0, k [ln(3^5) - ln(4^4)] = 0

Therefore
ln [m^5 / n^ 4] <= 0
or m^5 / n^ 4 <= 1
or m^5 <= n^4, as required.
 
Mark, thank you very much for showing me this way. I will work on this problem again and I will be glad if you review it for me again. It is complicated problem. I really want to find how to solve it. I am not surprise that no one else try it. :smile:

81 and 64 I have from solving (3m)^5 and (4n)^4 That is how I have to use one of the numbers and multiply both sides, but why I really don't understand.

Here is more clear solution which still confus me how it 's been done.

Look part a) n^2>= m^3
n^2>= 1
multiplay by 8
8n^2>=8m^3=(2m)^3
8n^2>=(2m)^3

9n^2>8n^2
so 9n^2> (2m)^3

(3n)^2>(2n)^2
(3n)^2>=(2m)^3
which means n^2>= m^3 (follow the top in bold.
 
Last edited:
for part b) from above: 2m^6< n^4

2m^6 < n^4

multiply both sides by 81
81(2m^6) < 81n^4
162m^6 < (3n)^4

128m^6 < 162m^6

2*64=128m^6<81n^4

2(2m)^6 < (3n)^4

2^6=64 and 3^4=81 this is how they find 64 and 81 and start with them but nothing is clear.

My problem is combined from these two solved problems somehow.
Actually, it is close to the problem a) I think plus the (=) sign.
 
Last edited:
vvvidenov said:
Mark, thank you very much for showing me this way. I will work on this problem again and I will be glad if you review it for me again. It is complicated problem. I really want to find how to solve it. I am not surprise that no one else try it. :smile:

81 and 64 I have from solving (3m)^5 and (4n)^4 That is how I have to use one of the numbers and multiply both sides, but why I really don't understand.
I don't understand where you get 81 and 64. I thought it might be from 3^5 and 4^4, but those values are 243 and 256, respectively. And when you say you are "solving" (3m)^5 and (4n)^4, you have to have an equation or inequality to solve.
vvvidenov said:
Here is more clear solution which still confus me how it 's been done.

Look part a) n^2>= m^3
n^2>= 1
multiplay by 8
8n^2>=8m^3=(2m)^3
8n^2>=(2m)^3

9n^2>8n^2
so 9n^2> (2m)^3

(3n)^2>(2n)^2
(3n)^2>=(2m)^3
which means n^2>= m^3 (follow the top in bold.

OK, let's look at this problem, using the same kind of analysis as I did before.
You have m >= 1, so let's start with m = 1, and assume that n = 1 to start with.
You want to show that n^2 >= m^3 is invariant.

At each iteration of the loop m is reset to 2m, and n is reset to 3n, which gives us these numbers at each loop iteration k, where the integer k >= 0:

m: 1 2 4 8 16 32 ... (after k iterations, m becomes 2^k)
n: 1 3 9 27 81 243 ... (after k iterations, n becomes 3^k)

To show that n^2 >= m^3 is equivalent to showing that the ratio (n^2)/(m^3) >= 1, or equivalently, that the log of this ratio is >= 0.

ln [(n^2)/(m^3)] = ln((3^k)^2) - ln((2^k)^3)
= ln(3^(2k)) - ln(2^(3k))
= 2k ln(3) - 3k ln(2)
= k ln(3^2) - k ln(2^3)
= k[ln 9 - ln 8]

When k = 0, the expression above is 0.
For any other value of k, the expression above is positive, so ln(3^(2k)) - ln(2^(3k)) >= 0.
Working backward, ln [(3^(2k)) / (2^(3k)) ] >= 0,
so [(3^(2k)) / (2^(3k)) ] >= 1,
so (3^k)^2 >= (2^k)^3,
and finally, n^2 >= m^3, which was to be shown.

If you'll notice, I did this problem almost exactly the same way I did the other one. I didn't grab some number and multiply both sides of something to get this result.
Mark
 
Mark, I agree with you. I read in the book a lot.
 

Similar threads

Replies
7
Views
4K
Replies
14
Views
2K
  • · Replies 20 ·
Replies
20
Views
3K
Replies
15
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K