On Thu, Jan 25, 2024 at 06:36:12PM +0800, Qian Yun wrote:
> Hi Waldek,
>
> Since the method used by "possibleOrder" is random in nature,
> so it doesn't harm to try a few times right?
>
> With following patch it gives another try when encountering "division
> by zero". And now the failure rate drops to lower than 10%. Of course
> we can try more times.
Well, there is a harm: 'possibleOrder' is potentially quite
expensive and it may be particularly expensive in failing
cases.
A little theory: 'possibleOrder' reduces divisor, first
plugging in integers for parameters and then reducing
coefficients modulo a prime. With current code this part
may cause division by zero even on "good" divisors.
The result of this part is a divisor over finite field.
Over finite field we try to compute order of divisor
essentially by brute force: we compute all powers of
divisor until we get a divisor of a function.
Theory says that it is enough to compute order over finite
field once: we either get actual order (if divisor is of
finite order) or divisor is of infinite order. So
after result of 'possibleOrder' we need to check to
exclude cases of infinite order (this is done by the
line with 'generator'). This check again may be quite
expensive. To reduce chance of failure in the final
check in many cases we run main part of 'possibleOrder'
twice. If second run produces division by zero, then
the results of first run is effectively lost.
So, IMO 'torsionIfCan' is not the right place to catch
errors. Rather we should catch them at lower level, that
is check if reduction to finite field worked. That way
we could reuse computations.
Also, there is another aspect: in our code randomness comes
from integers which are substituted for paramemeters. If
there are no parameters, then there is no randomness.
Theoretically prime could be rendomized, but cost of
computation grows (potentially quite fast) with size of
the prime, so currently we try smallest suitable prime.
But if changing parameters does not help we could try
bigger prime.
BTW: I wrote "with current code", because at least theoretically
there is a way to avoid division by zero when reducing
divisors to obtain divisor over finite field. But
this requires checking at various stages and more important,
a different representaion of divisors: our current code can only
represet divisors which are zero "at infinity", but
division by zero means that we will get part at infinity.
BTW2: Keeping reduction to finite field fixed at least in
principle allows various efficiency improvements. And different
representation of divisors should give us better efficiency.
Also, different representation is needed to complete Risch
algorithm.
--
Waldek Hebisch