#8283: A better Carmichael lambda function
----------------------------+-----------------------------------------------
   Reporter:  wdj           |       Owner:  mvngu
       Type:  defect        |      Status:  new  
   Priority:  minor         |   Milestone:       
  Component:  cryptography  |    Keywords:       
     Author:                |    Upstream:  N/A  
   Reviewer:                |      Merged:       
Work_issues:                |  
----------------------------+-----------------------------------------------
 Reported by ylchapuy:

 Here is another implementation:

  {{{

  def carmichael_lambda(n):
     n = Integer(n)

     if n < 1:
         raise ValueError("Input n must be a positive integer.")

     F = n.factor()
     L = []

     # first get rid of the even part
     if n & 1 == 0:
         e = F[0][1]
         F = F[1:]
         if e < 3:
             e = e-1
         else:
             e = e-2
         L.append(1<<e)

     # then other prime factors
     L += [ p**(k-1)*(p-1) for p,k in F]

     # finish the job
     return lcm(L)

  }}}

 This is a bit faster than the current implementation and, if you replace
 lcm with sage.rings.integer.LCM_list, it is even faster.

 A bug with the current function is that the output is not always an
 integer: e.g., carmichael_lambda(16) is of type
 sage.rings.rational.Rational .

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8283>
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