Monday, December 11, 2017

number theory - Almost extended Euclidean algorithm - $ax+by=gcd(a,b)+2$




So I have this equation: $$\eta+2=2g+1n,$$ where $g,n \in \mathbb{N}_{\geq 0}$ and $\eta \in \mathbb{N}_{>0}$. I want to find all possible integer-valued 2-tuples $(g,n)$ that satisfy this equation, e.g. $(g,n)_{|_{\eta=1}} = \{(0,3),(1,1)\}$.



I immediately thought of Diophantine equations/Chinese remainder thm./Bezout/extended Euclidean algorithm.. but



1.) I don't have $ax+by=\gcd(a,b)$ for extended Euclidean algorithm.



2.) I cannot use Pell's equation, $x^2-ny^2=1$, since my $n$ wouldn't be a nonsquare positive number.



3.) Re-writing the equation as $1=\frac{2}{\eta+2}g+\frac{1}{\eta+2}n$ is no good as a Diophantine equation since the fractions are no longer integers.




My last attempt was trying to use the extended Euclidean algorithm in a finite field, like $\mathcal{Z}/(\eta+1)\mathcal{Z} = \{\overline{0},\overline{1},\ldots,\overline{\eta}\}$ s.t. $\overline{\eta+2} \equiv \overline{1}$. But I'm not strong in number theory and am unsure of whether this is even the best approach (if it is one that is even valid).



Lastly I would like to implement this in Maxima and iterate over integer values of $\eta$ from $\eta=1$ to $\eta=10$ (or more).



Thanks!!



NOTE



I know I could do something like,




for(g=0;g<\eta+2;g++){

for(n=0;n<\eta+2;n++){

if (2g+n=eta+2)

then ans[s]: [g,n]

else


print("bad")


which is a bad mix of Maxima and C. If ther isn't a better way, this will be my "brute" force method.


Answer



$(g,n)$ is a solution to your problem if and only if $$\begin{cases} 0\le g\le\left\lfloor {\eta\over 2}\right\rfloor+1\\ n=\eta+2-2g\end{cases}$$



And I sincerely see no better way to describe them (because this allows you to generate each of them in constant time). For a single $\eta$, you just have to make $g$ range from $0$ to $\left\lfloor{\eta\over 2}\right\rfloor+1$ and calculate the corresponding $n$-s.




Of course, one could try be smart about it and notice that, for instance, if $\left\{(g_1,n_1),\cdots,(g_k,n_k)\right\}$ are the solutions for $\eta=2\mu$, then the solutions for $\eta+1=2\mu+1$ are $\left\{(g_1,n_1+1),\cdots,(g_k,n_k+1)\right\}$ and the solutions for $\eta+2=2\mu+2$ are $\left\{(0,\eta+2),(g_1+1,n_1+2),\cdots,(g_k+1,n_k+2)\right\}$. This might help, but as far as I know this does not drop significantly the complexity of the algorithm: if you aim to write down all the solutions for $1\le\eta\le M$, then you need to write down $\sim {M^2\over 4}$ couplets of integers. As long as you generate them in constant time, you neither lose nor gain anything.


No comments:

Post a Comment

analysis - Injection, making bijection

I have injection $f \colon A \rightarrow B$ and I want to get bijection. Can I just resting codomain to $f(A)$? I know that every function i...