Ticket #8825: trac_8825-more-norm-doc.patch
File trac_8825-more-norm-doc.patch, 8.9 KB (added by , 12 years ago) |
---|
-
sage/matrix/matrix2.pyx
# HG changeset patch # User Minh Van Nguyen <nguyenminh2@gmail.com> # Date 1272656283 25200 # Node ID d18a4dd6434c5c08316149189094ca59d2b47983 # Parent d2f2f1bd8c082a20c3b35a4625ca3942b420d205 #8825: improve documentation for function norm and cross reference various norm functions diff --git a/sage/matrix/matrix2.pyx b/sage/matrix/matrix2.pyx
a b 6452 6452 6453 6453 6454 6454 OUTPUT: RDF number 6455 6456 .. SEEALSO:: 6457 6458 - :func:`sage.misc.functional.norm` 6455 6459 6456 6460 EXAMPLES:: 6457 6461 -
sage/misc/functional.py
diff --git a/sage/misc/functional.py b/sage/misc/functional.py
a b 1059 1059 return x.ngens() 1060 1060 1061 1061 def norm(x): 1062 """1063 Returns the norm of x.1062 r""" 1063 Returns the norm of ``x``. 1064 1064 1065 For matrices and vectors, this returns the L2-norm. 1066 For complex numbers, it returns the field norm. 1065 For matrices and vectors, this returns the L2-norm. The L2-norm of a 1066 vector `\textbf{v} = (v_1, v_2, \dots, v_n)`, also called the Euclidean 1067 norm, is defined as 1068 1069 .. MATH:: 1070 1071 |\textbf{v}| 1072 = 1073 \sqrt{\sum_{i=1}^n |v_i|^2} 1074 1075 where `|v_i|` is the complex modulus of `v_i`. The Euclidean norm is often 1076 used for determining the distance between two points in two- or 1077 three-dimensional space. 1078 1079 For complex numbers, the function returns the field norm. If 1080 `c = a + bi` is a complex number, then the norm of `c` is defined as the 1081 product of `c` and its complex conjugate 1082 1083 .. MATH:: 1084 1085 \text{norm}(c) 1086 = 1087 \text{norm}(a + bi) 1088 = 1089 c \cdot \overline{c} 1090 = 1091 a^2 + b^2. 1092 1093 The norm of a complex number is different from its absolute value. 1094 The absolute value of a complex number is defined to be the square 1095 root of its norm. A typical use of the complex norm is in the 1096 integral domain `\ZZ[i]` of Gaussian integers, where the norm of 1097 each Gaussian integer `c = a + bi` is defined as its complex norm. 1098 1099 .. SEEALSO:: 1100 1101 - :meth:`sage.matrix.matrix2.Matrix.norm` 1102 1103 - :meth:`sage.modules.free_module_element.FreeModuleElement.norm` 1104 1105 - :meth:`sage.rings.complex_double.ComplexDoubleElement.norm` 1106 1107 - :meth:`sage.rings.complex_number.ComplexNumber.norm` 1108 1109 - :meth:`sage.symbolic.expression.Expression.norm` 1067 1110 1068 EXAMPLES: :1069 1070 sage: z = 1+2*I1071 sage: norm(z) 1072 51111 EXAMPLES: 1112 1113 The norm of vectors:: 1114 1115 sage: z = 1 + 2*I 1073 1116 sage: norm(vector([z])) 1074 1117 sqrt(5) 1118 sage: v = vector([-1,2,3]) 1119 sage: norm(v) 1120 sqrt(14) 1121 sage: _ = var("a b c d") 1122 sage: v = vector([a, b, c, d]) 1123 sage: norm(v) 1124 sqrt(abs(a)^2 + abs(b)^2 + abs(c)^2 + abs(d)^2) 1125 1126 The norm of matrices:: 1127 1128 sage: z = 1 + 2*I 1075 1129 sage: norm(matrix([[z]])) 1076 1130 2.2360679775 1131 sage: M = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]]) 1132 sage: norm(M) 1133 10.6903311292 1077 1134 sage: norm(CDF(z)) 1078 1135 5.0 1079 1136 sage: norm(CC(z)) 1080 1137 5.00000000000000 1138 1139 The norm of complex numbers:: 1140 1141 sage: z = 2 - 3*I 1142 sage: norm(z) 1143 13 1144 sage: a = randint(-10^10, 100^10) 1145 sage: b = randint(-10^10, 100^10) 1146 sage: z = a + b*I 1147 sage: bool(norm(z) == a^2 + b^2) 1148 True 1149 1150 The complex norm of symbolic expressions:: 1151 1152 sage: a, b, c = var("a, b, c") 1153 sage: z = a + b*I 1154 sage: bool(norm(z).simplify() == a^2 + b^2) 1155 True 1156 sage: norm(a + b).simplify() 1157 a^2 + 2*a*b + b^2 1158 sage: v = vector([a, b, c]) 1159 sage: bool(norm(v).simplify_full() == sqrt(a^2 + b^2 + c^2)) 1160 True 1081 1161 """ 1082 1162 return x.norm() 1083 1163 -
sage/modules/free_module_element.pyx
diff --git a/sage/modules/free_module_element.pyx b/sage/modules/free_module_element.pyx
a b 748 748 `\geq 1`, Infinity, or a symbolic expression. If `p=2` (default), 749 749 this is the usual Euclidean norm; if p=Infinity, this is the 750 750 maximum norm; if `p=1`, this is the taxicab (Manhattan) norm. 751 752 .. SEEALSO:: 753 754 - :func:`sage.misc.functional.norm` 751 755 752 756 EXAMPLES:: 753 757 -
sage/rings/complex_double.pyx
diff --git a/sage/rings/complex_double.pyx b/sage/rings/complex_double.pyx
a b 1112 1112 1113 1113 def abs(self): 1114 1114 """ 1115 This function returns the magnitude of the complex number 1116 `z`, `|z|`. 1115 This function returns the magnitude `|z|` of the complex number 1116 `z`. 1117 1118 .. SEEALSO:: 1119 1120 - :meth:`norm` 1117 1121 1118 1122 EXAMPLES:: 1119 1123 … … 1142 1146 1143 1147 def abs2(self): 1144 1148 """ 1145 This function returns the squared magnitude of the complex number 1146 `z`, `|z|^2`. 1147 1149 This function returns the squared magnitude `|z|^2` of the complex 1150 number `z`, otherwise known as the complex norm. 1151 1152 .. SEEALSO:: 1153 1154 - :meth:`norm` 1155 1148 1156 EXAMPLES:: 1149 1157 1150 1158 sage: CDF(2,3).abs2() … … 1153 1161 return RealDoubleElement(gsl_complex_abs2(self._complex)) 1154 1162 1155 1163 def norm(self): 1156 """ 1157 This function returns the squared magnitude of the complex number 1158 `z`, `|z|^2`. 1164 r""" 1165 This function returns the squared magnitude `|z|^2` of the complex 1166 number `z`, otherwise known as the complex norm. If `c = a + bi` 1167 is a complex number, then the norm of `c` is defined as the product of 1168 `c` and its complex conjugate 1169 1170 .. MATH:: 1171 1172 \text{norm}(c) 1173 = 1174 \text{norm}(a + bi) 1175 = 1176 c \cdot \overline{c} 1177 = 1178 a^2 + b^2. 1179 1180 The norm of a complex number is different from its absolute value. 1181 The absolute value of a complex number is defined to be the square 1182 root of its norm. A typical use of the complex norm is in the 1183 integral domain `\ZZ[i]` of Gaussian integers, where the norm of 1184 each Gaussian integer `c = a + bi` is defined as its complex norm. 1185 1186 .. SEEALSO:: 1187 1188 - :meth:`abs` 1189 1190 - :meth:`abs2` 1191 1192 - :func:`sage.misc.functional.norm` 1193 1194 - :meth:`sage.rings.complex_number.ComplexNumber.norm` 1159 1195 1160 1196 EXAMPLES:: 1161 1197 -
sage/rings/complex_number.pyx
diff --git a/sage/rings/complex_number.pyx b/sage/rings/complex_number.pyx
a b 552 552 def norm(self): 553 553 r""" 554 554 Returns the norm of this complex number. If `c = a + bi` is a 555 complex number, then the norm of `c` is defined as 555 complex number, then the norm of `c` is defined as the product of 556 `c` and its complex conjugate 556 557 557 558 .. MATH:: 558 559 559 \text{norm}(c) = \text{norm}(a + bi) = a^2 + b^2 560 \text{norm}(c) 561 = 562 \text{norm}(a + bi) 563 = 564 c \cdot \overline{c} 565 = 566 a^2 + b^2. 560 567 561 568 The norm of a complex number is different from its absolute value. 562 569 The absolute value of a complex number is defined to be the square 563 570 root of its norm. A typical use of the complex norm is in the 564 571 integral domain `\ZZ[i]` of Gaussian integers, where the norm of 565 572 each Gaussian integer `c = a + bi` is defined as its complex norm. 573 574 .. SEEALSO:: 575 576 - :func:`sage.misc.functional.norm` 577 578 - :meth:`sage.rings.complex_double.ComplexDoubleElement.norm` 566 579 567 580 EXAMPLES: 568 581 -
sage/symbolic/expression.pyx
diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
a b 4564 4564 def norm(self): 4565 4565 r""" 4566 4566 The complex norm of this symbolic expression, i.e., 4567 the expression times its complex conjugate. 4567 the expression times its complex conjugate. If `c = a + bi` is a 4568 complex number, then the norm of `c` is defined as the product of 4569 `c` and its complex conjugate 4570 4571 .. MATH:: 4572 4573 \text{norm}(c) 4574 = 4575 \text{norm}(a + bi) 4576 = 4577 c \cdot \overline{c} 4578 = 4579 a^2 + b^2. 4580 4581 The norm of a complex number is different from its absolute value. 4582 The absolute value of a complex number is defined to be the square 4583 root of its norm. A typical use of the complex norm is in the 4584 integral domain `\ZZ[i]` of Gaussian integers, where the norm of 4585 each Gaussian integer `c = a + bi` is defined as its complex norm. 4586 4587 .. SEEALSO:: 4588 4589 - :func:`sage.misc.functional.norm` 4568 4590 4569 4591 EXAMPLES:: 4570 4592