Ticket #6407: 6407_part2.patch

File 6407_part2.patch, 1.1 KB (added by boothby, 8 months ago)
  • sage/schemes/elliptic_curves/formal_group.py

    # HG changeset patch
    # User Tom Boothby <boothby@u.washington.edu>
    # Date 1247872854 25200
    # Node ID 814f029deef260021f42f0d1188996a04c8a08a0
    # Parent  16a632e998fe41f38736037a5ed4e599ac035edc
    #6407 -- slight improvement to double-and-add algorithm
    
    diff --git a/sage/schemes/elliptic_curves/formal_group.py b/sage/schemes/elliptic_curves/formal_group.py
    a b  
    568568 
    569569        - Hamish Ivey-Law (2009-06): double-and-add algorithm for 
    570570          non char 0 field case. 
     571 
     572        - Tom Boothby (2009-06): slight improvement to double-and-add 
    571573         
    572574        EXAMPLES:: 
    573575         
     
    654656                g = F(g)         
    655657            return R(g.add_bigoh(orig_prec)) 
    656658 
    657         result = F.parent().base_ring()(0) 
     659        if n&1: 
     660            result = g 
     661        else: 
     662            result = F.parent().base_ring()(0) 
     663        n = n >> 1 
     664 
    658665        while n > 0: 
     666            g = F(g, g) 
    659667            if n & 1: 
    660668                result = F(result, g) 
    661             g = F(g, g) 
    662669            n = n >> 1 
    663670 
    664671        return R(result.add_bigoh(orig_prec))