Changeset 7488:ee41e552f7c7
- Timestamp:
- 12/01/07 21:59:22 (6 years ago)
- 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. - Files:
-
- 2 edited
-
sage/matrix/matrix2.pyx (modified) (3 diffs)
-
sage/matrix/matrix2.pyx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sage/matrix/matrix2.pyx
r7483 r7488 381 381 return R(0) 382 382 383 k = int(k)384 383 pm = 0 385 384 for cols in _choose(n,k): … … 3062 3061 return -1 3063 3062 3063 3064 3064 def _choose(Py_ssize_t n, Py_ssize_t t): 3065 3065 """ 3066 3066 Returns all possible sublists of length t from range(n) 3067 3067 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]] 3069 3079 3070 3080 AUTHOR: 3071 -- Jaap Spies (2007-1 0-22)3081 -- Jaap Spies (2007-11-14) 3072 3082 """ 3073 cdef Py_ssize_t j 3074 3075 x = [] 3083 cdef Py_ssize_t j, temp 3084 3085 x = [] # initialize T1 3076 3086 c = range(t) 3087 if t == n: 3088 x.append(c) 3089 return x 3077 3090 c.append(n) 3078 3091 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 3088 3121 3089 3122 return x 3123 3090 3124 3091 3125 def _binomial(Py_ssize_t n, Py_ssize_t k): 3092 3126 """ 3093 3127 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 3094 3136 3095 3137 AUTHOR: … … 3112 3154 return result 3113 3155 3114 -
sage/matrix/matrix2.pyx
r7487 r7488 2967 2967 return self.__invert__() 2968 2968 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 2969 3010 2970 3011 def _dim_cmp(x,y):
Note: See TracChangeset
for help on using the changeset viewer.
