#11036: improve solve_mod performance
---------------------------+------------------------------------------------
   Reporter:  dsm          |       Owner:  burcin
       Type:  enhancement  |      Status:  new   
   Priority:  minor        |   Milestone:        
  Component:  symbolics    |    Keywords:        
     Author:               |    Upstream:  N/A   
   Reviewer:               |      Merged:        
Work_issues:               |  
---------------------------+------------------------------------------------

Comment(by dsm):

 This patch doesn't attempt to do anything sophisticated, it simply reaches
 for the low-hanging fruit:

 (1) It modifies solve_mod_enumerate so that if the modulus is `5^100`,
 instead of iterating over `5^100` possibilities, it finds solutions mod 5,
 then uses those to find solutions mod `5^2`, etc.

 (2) It modifies solve_mod to short-circuit in some cases.

 (3) It also makes an unrelated change: currently solve_mod(x==1, 1)
 returns [()], but should probably return [(0,)].

 The change has little effect for small moduli but wins easily on anything
 nontrivial:

 {{{
 #OLD
 sage: time solve_mod(x^2==41, 10^7)
 CPU times: user 4.21 s, sys: 0.05 s, total: 4.27 s
 Wall time: 4.33 s
 [(3703821,), (1452429,), (3547571,), (1296179,), (8703821,), (6452429,),
 (8547571,), (6296179,)]
 }}}
 {{{
 # NEW
 sage: time solve_mod(x^2==41, 10^7)
 CPU times: user 0.04 s, sys: 0.00 s, total: 0.04 s
 Wall time: 0.04 s
 [(3703821,), (1452429,), (3547571,), (1296179,), (8703821,), (6452429,),
 (8547571,), (6296179,)]
 }}}

 It still behaves very badly for large primes, but a lot better than the
 current approach on powers of small primes.  This
 includes my use case of powers of 10-- there was an OEIS sequence I was
 extending which I had to do manually because solve_mod was too slow, and
 it irritated me that Mma could do it quickly..

 Beyond the doctests I've tested it for small-coefficient univariate
 polynomials of order <= 5 with modulus <= 12, and for lots of random
 multivariate polynomials.  Tests were against a four-line brute force
 solver.  Probably I've missed something, though, so more tests would be
 appreciated!

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11036#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to