Changeset 7488:ee41e552f7c7


Ignore:
Timestamp:
12/01/07 21:59:22 (6 years ago)
Author:
mabshoff@…
Branch:
default
Parents:
7486:b75f20360b8d (diff), 7487:733fe81ceb61 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sage/matrix/matrix2.pyx

    r7483 r7488  
    381381            return R(0) 
    382382 
    383         k = int(k) 
    384383        pm = 0 
    385384        for cols in _choose(n,k): 
     
    30623061        return -1 
    30633062 
     3063 
    30643064def _choose(Py_ssize_t n, Py_ssize_t t): 
    30653065    """ 
    30663066    Returns all possible sublists of length t from range(n) 
    30673067 
    3068     Based on algoritm L from Knuth's taocp part 4: 7.2.1.3 p.4 
     3068    Based on algoritm T from Knuth's taocp part 4: 7.2.1.3 p.5 
     3069    This fuction replaces the one base on algorithm L because it is faster. 
     3070 
     3071    EXAMPLES: 
     3072        sage: from sage.matrix.matrix2 import _choose 
     3073        sage: _choose(1,1) 
     3074        [[0]] 
     3075        sage: _choose(4,1) 
     3076        [[0], [1], [2], [3]] 
     3077        sage: _choose(4,4) 
     3078        [[0, 1, 2, 3]] 
    30693079 
    30703080    AUTHOR: 
    3071         -- Jaap Spies (2007-10-22) 
     3081        -- Jaap Spies (2007-11-14) 
    30723082    """ 
    3073     cdef Py_ssize_t j 
    3074  
    3075     x = [] 
     3083    cdef Py_ssize_t j, temp 
     3084 
     3085    x = []               # initialize T1 
    30763086    c = range(t) 
     3087    if t == n: 
     3088        x.append(c) 
     3089        return x 
    30773090    c.append(n) 
    30783091    c.append(0) 
    3079     j = 0 
    3080  
    3081     while j < t: 
    3082         x.append(c[:t]) 
    3083         j = 0 
    3084         while c[j]+1 == c[j+1]: 
    3085            c[j] = j 
    3086            j = j+1 
    3087         c[j] = c[j]+1 
     3092    j = t-1 
     3093 
     3094    while True: 
     3095        x.append(c[:t])    # visit T2 
     3096        if j >= 0: 
     3097            c[j] = j+1 
     3098            j = j-1 
     3099            continue       # goto T2 
     3100 
     3101        if c[0]+1 < c[1]:  # T3 easy case! 
     3102            c[0] = c[0]+1 
     3103            continue 
     3104        else: 
     3105            j = 1 
     3106 
     3107        while True: 
     3108            c[j-1] = j-1      # T4 find j 
     3109            temp = c[j]+1 
     3110            if temp == c[j+1]: 
     3111                j = j+1 
     3112            else: 
     3113                break 
     3114 
     3115 
     3116        if j >= t:     # T5 stop? 
     3117            break 
     3118 
     3119        c[j] = temp    # T6 
     3120        j = j-1 
    30883121 
    30893122    return x 
     3123 
    30903124 
    30913125def _binomial(Py_ssize_t n, Py_ssize_t k): 
    30923126    """ 
    30933127    Fast and unchecked implementation of binomial(n,k) 
     3128    This is only for internal use. 
     3129 
     3130    EXAMPLES: 
     3131        sage: from sage.matrix.matrix2 import _binomial 
     3132        sage: _binomial(10,2) 
     3133        45 
     3134        sage: _binomial(10,5) 
     3135        252 
    30943136 
    30953137    AUTHOR: 
     
    31123154    return result 
    31133155 
    3114  
  • sage/matrix/matrix2.pyx

    r7487 r7488  
    29672967        return self.__invert__() 
    29682968 
     2969    def gramm_schmidt(self): 
     2970        r""" 
     2971        Return the matrix G whose rows are obtained from the rows of self (=A) by 
     2972        applying the Gramm-Schmidt orthogonalization process.  Also return 
     2973        the coefficients mu ij, i.e., a matrix mu such that \code{(mu + 1)*G == A}. 
     2974 
     2975        OUTPUT: 
     2976            G -- a matrix whose rows are orthogonal 
     2977            mu -- a matrix that gives the transformation, via the relation 
     2978                  (mu + 1)*G == self 
     2979         
     2980        EXAMPLES: 
     2981            sage: A = matrix(ZZ, 3, [-1, 2, 5, -11, 1, 1, 1, -1, -3]); A 
     2982            [ -1   2   5] 
     2983            [-11   1   1] 
     2984            [  1  -1  -3] 
     2985            sage: G, mu = A.gramm_schmidt() 
     2986            sage: G 
     2987            [     -1       2       5] 
     2988            [  -52/5    -1/5      -2] 
     2989            [  2/187  36/187 -14/187] 
     2990            sage: mu 
     2991            [     0      0      0] 
     2992            [   3/5      0      0] 
     2993            [  -3/5 -7/187      0] 
     2994            sage: G[0] * G[1] 
     2995            0 
     2996            sage: G[0] * G[2] 
     2997            0 
     2998            sage: G[1] * G[2] 
     2999            0 
     3000 
     3001        The relation between mu and A is as follows: 
     3002            sage: (mu + 1)*G == A 
     3003            True 
     3004        """         
     3005        from sage.modules.misc import gramm_schmidt 
     3006        from constructor import matrix 
     3007        Bstar, mu = gramm_schmidt(self.rows()) 
     3008        return matrix(Bstar), mu 
     3009 
    29693010     
    29703011def _dim_cmp(x,y): 
Note: See TracChangeset for help on using the changeset viewer.