|Discrete Log Calculator|
|Complex Discrete Logarithms|
|Residue Roots and CDLs|
|Unitary Prime Test|
|Complex Linear Congruence|
|Indexed Complex Discrete Logarithms|
The python script, invlog, was a step forward for me. It correctly calculated n for any member of the sequence x=2^n mod p given x and p where p is a number with factors small enough to store a discrete log table. That was good, but it was disappointing that it did not work for numbers less than p that were not in this sequence.
It turns out that in addition to the sequence 1*2^n mod p, there are also sequences of the for r*2^n mod p, and every number less than p must be a member of one and only one of these sequences. These r*2^n mod p sequences are the complex discrete logarithms.
Below is the result of that analysis on the number 12331, which is 11*18*59. There are 13 sequences with a total of 12330 entries.
|Length of sequences||Sequence count||Count times length||Sequence start||Sequence start factored||Sequence ratios|
In the bottom line of the chart, the Sequence start is one, and the sequence ratios are 1, 3, 7, and 21. That tells us there are four sequences 2610 entries long starting with 1, 3, 7, and 21.
In the second line from the bottom, the sequence start is 11 and the sequences ratios are 1 and three. That means there are two sequences 522 entries long starting with 11 and 33.
I got this data from my setana program which gives interesting results, but is very slow. To get results shortly after you enter them, the number p needs to be less than about 100,000.
I also have a very slow brute force complex log program, blog. Below are a couple of results from that program.
If x=r*(2^n) mod p:
I wanted to make a program that worked like the brute force blog, but was much faster. I called it clog, for complex logarithm. I was partially successful. Clog is much faster. It does a 300 decimal digit number in Python on my computer in about 40 milliseconds, and it does produce an answer that can be plugged into the complex log formula and produce the desired results. But setana gives us a total of 13 sequences for the number 12331, and a similar analysis using clog gives us well over a hundred sequences for the number 12331.
To put it another way, blog gives results that are completely unambiguous with no overlap of sequences. Clog gives ambiguous results with lots of sequence overlap. I'm guessing that I could disambiguate the clog algorithm in some small number of weeks, but I'm not sure that is my best next move.
Here is the top level Python function for the clog algorithm.
print 'err', xp, locx
return (xp, loc)
The variable, strt, would be n in the discrete log formula. The variable, xmxm is p. The function dudif uses ilg which is a function I have explained in previous posts. If we calculate ilg(strt) and ilg((strt*2)%xmxm), and subtract the two results, we get the difference that dudif is looking for. If gcd(strt,xmxm) is 1, then this difference will be one, and the sequence will with be the max for this xmxm, which in the case of 12331 is 2610. If not the sequence will be one of the shorter ones. The exact length of the short sequence is determined by the dudif difference and the max sequence length. The function dudif returns the output of ilg(strt) and the difference as discussed above.
The fnd function uses a linear congruence in the log domain to find the smallest result of the ilg algorithm that is in the sequence of which strt is a member. This is the part of the algorithm that can possibly be improved to reduce the level of ambiguity in clog.
The function, duof, uses the product of squares algorithm to compute xp, or r in the complex log formula, r*2^n mod p. The variable, locx, corresponds to the n in the formula.
The rest of the function just checks the results. So far it has not found any errors since I got the code working, but that has only been a few days.
I wrote a separate program, ducons, to compute the constants needed for this algorithm. To use ducons to get the constants:
That will produce constants that give clog a range of about 350 decimal digits. You can change that in the ducons code, of course.
The algorithm could use other sets of radices, of course, or it could be designed for variable radices. This particular radix set is designed for maximum computational efficiency.
Below is a sample run of clog. We are asking clog to get a complex discrete log for 1000 using 10 radices.
/t:clog 10 1000|
The clog script tells us:
35723762789612788353*(2^ 168549820180347435) mod 286606661257088753537=1000
I have added the txt extension to the python source code to avoid downloading difficulties: