This constitutes a proof if the first tuple is (1,0), the last tuple is (z,y), and each tuple is related to the next tuple by a multiplication of the first part by x and incrementing the second part by 1.
Unfortunately, QCPL doesn't support sequences or tuples. Therefore, we will need to represent a tuple of naturals as a natural and a series of naturals as a natural.
Representing a tuple of naturals as a natural can be done as follows: the tuple (a,b) can be represented as a*m+b. This works if we can guarantee that m is greater than any b we may wish to encode. Because we won't need to put anything larger than y on the right hand side of our tuples, any m larger than y will do.
A useful QCPL function for packing and unpacking tuples is DIVMOD.
The function LT is true if and only if b<m. It, and the other useful comparators, can be defined as follows:
Representing a sequence, a0 through ay, can be done by selecting a base, n, and taking the sum of niai for all i between 0 and y. This works for any n larger than the maximum expected ai value, which, in our case, can be anything at least as large as (z+1)*(y+1). (NB - This packing method is a bit simplistic, as it doesn't work well if we have trailing zero values in the sequence. It's always possible to just add one to every element to solve this problem, but for our current purposes this was deemed unnecessary.)
To unpack a single element of a sequence, we can use the following function.
Using this function with ni as the value of v will give the element ai of the sequence packed into the natural a.
This, however, seems to return us back to where we started: now we need to be able to verify that a number is a power of n. In fact, this is a much simpler problem than the original one, and that for two reasons:
This definition uses the definition for PRIME given in the question. In words, it says (with a few simplifications) that if x is a prime power of p then p is its only prime divisor.
So, armed with all this, we can verify the three conditions required of a natural (representing a sequence of tuples) to be our proof. First, it must begin with (1,0). Letting a be the "proof" sequence, p be the prime used for decoding it and m be the modulo for decoding tuples inside it, this condition can be stated as
Second, the sequence must end with (z,y).
(We don't use the function ELEMENT here, because this allows us to easily verify, as part of the extraction, that this is, indeed, the last element in the sequence. For all elements other than the last, the z value that satisfies the condition is greater than p.)
Third, each element in the sequence (except the last) must be related to the next element by multiplication of the left part of the tuple by x and incrementing the right part by one.
With these three conditions, we can now formulate our main function.
Here are some asides you may find interesting regarding this month's riddle:
Back to riddle
Back to main page