Proofs: Baby-step giant-step
These are the human proofs of Baby-step giant-step, at full length.
Correctness of baby-step giant-step full
This proof shows: correctness, termination, minimality.
Let be a group, , and . Let , so and .
Lemma 1 (baby steps). After the loop of lines L4 to L6, the table contains exactly the elements , and for each such element , is the least with .
Proof. By induction on , at the start of round we have (line L3 gives , and line L6 multiplies by ). Line L5 inserts with the value only if is not yet in , and never changes an entry already present. So each element enters with the first, least index at which it occurs, and every with is present after round .
Lemma 2 (giant steps). At the test of line L10 in round of the loop of lines L9 to L11, .
Proof. Line L8 gives for , and line L11 multiplies by from line L7.
Soundness. If line L10 returns with , then by the lemmas , so , and .
Completeness. Suppose and let be the least with . Then , because would otherwise give a smaller solution. Write with . Since , also , so round is executed unless the algorithm returned earlier. In round , , which is in by Lemma 1. So the algorithm returns in some round .
Minimality. Let the algorithm return in round with . If , the returned is a solution by soundness, smaller than the least solution, which is impossible. So . In this round with the least exponent below for (Lemma 1), so , and is a solution; by the choice of , .
Non-membership. If , no round can return, since a return gives by soundness. The loops are bounded, so the algorithm stops at line L12 with NONE. Conversely, by completeness, NONE is returned only when .
Termination and cost. Both loops run at most rounds, and line L7 uses multiplications by square and multiply, so the algorithm stops after at most group operations, insertions and lookups.