I want to resolve the following equation for exponent $n$ for given value $v$:
$$ v\equiv(r\cdot(b+r)^n-r \cdot(b-r)^n) \cdot (r \cdot (b+r)^{n-1}-r\cdot(b-r)^{n-1})^{-1} \mod P$$
with
$$r^2 = 4\cdot a+b^2 \mod P$$
and a prime $P$
Looking for a function $f(v) = n$.
The values $a,b$ are chosen in that way that for $n=[0,..,(P-1)]$ the results $v$ will be all values in ${{0,..,P-1 }\brace{ }}=\mathbb{F}_P $. That works iff there is no such root $r$ in $\mathbb{F}_P$ exists for $a, b$. If both parts in formula above are expanded only $r^2$ is left over.
Example:
$P=11; a=5; b=3 -> r^2=7$
R.<a,b,r,v,n>=PolynomialRing(GF(11))
[ r*((b+r)^n-(b-r)^n)/ ( r*((b+r)^(n-1)-(b-r)^(n-1)) ) for n in R.base() if n>1]
[2*b,
(-5*b^2 + 2*r^2)/(4*b),
(-3*b^3 - 3*b*r^2)/(-5*b^2 + 2*r^2),
(-b^4 - 2*b^2*r^2 + 2*r^4)/(-3*b^3 - 3*b*r^2),
(b^5 - 4*b^3*r^2 + b*r^4)/(-b^4 - 2*b^2*r^2 + 2*r^4),
(3*b^6 + 4*b^4*r^2 - 2*b^2*r^4 + 2*r^6)/(b^5 - 4*b^3*r^2 + b*r^4),
(5*b^7 + 2*b^5*r^2 + 2*b^3*r^4 + 5*b*r^6)/(3*b^6 + 4*b^4*r^2 - 2*b^2*r^4 + 2*r^6),
(-4*b^8 + 3*b^6*r^2 - b^4*r^4 - 5*b^2*r^6 + 2*r^8)/(5*b^7 + 2*b^5*r^2 + 2*b^3*r^4 + 5*b*r^6),
(-2*b^9 - 2*b^7*r^2 - 2*b^5*r^4 - 2*b^3*r^6 - 2*b*r^8)/(-4*b^8 + 3*b^6*r^2 - b^4*r^4 - 5*b^2*r^6 + 2*r^8)]
There is some special case for $n=1$. With this the part which need to be inverted is $0$. In that case $v$ is assigned to 0.
As a alternative form without any root $r$: $$v\equiv \frac{\sum_{k=0}^{\lfloor n/2\rfloor} {n\choose 2k+1} b^{n-2k-1}(r^2)^{k+1} }{\sum_{k=0}^{\lfloor (n-1)/2 \rfloor} {n-1 \choose 2k+1} b^{n-2k-2} (r^2)^{k+1} } \mod P$$
in sagemath (not working):
a,b,r,v,k=var('a b r v k')
(sum( binomial(n, 2*k+1) * b^(n-2*k-1)*(4*a+b^2)^(k+1) , k,1,floor( n/2) ))*(sum( binomial(n-1, 2*k+1) * b^(n-2*k-2)*(4*a+b^2)^(k+1) , k,1, floor( (n-1)/2) ))^(-1)-v
There are some issues with the upper border of the sum.
How can I solve such equation in sagemath?
R.<n>=PolynomialRing(GF(11))
(2*k-8).roots(); #multiplication works
(2^k-8).roots(); #power not working
($a,b,r^2$ can be exchanged with current values)