Preprint
Article

This version is not peer-reviewed.

Computation of Approximate Symmetric Chordal Metric for Complex Numbers

A peer-reviewed article of this preprint also exists.

Submitted:

22 May 2025

Posted:

23 May 2025

You are already at the latest version

Abstract
The basic theoretical properties of the approximate symmetric chordal metric (ASCM) for two real or complex numbers is studied, and reliable, accurate and efficient algorithms are proposed for its computation. ASCM is defined as the minimum between the moduli of the differences of the two numbers and of their reciprocals. It differs from chordal metric by including the modulus of the difference of the numbers. Is is shown that ASCM is not a true mathematical distance, but a useful replacement for a distance in some applications, such as block diagonalization of matrix pencils. A factored representation of the modulus of complex numbers is introduced, which allows to obtain very accurate results for the entire range of the floating point number system of a computer. Two different ways to evaluate the distance between the reciprocals of the given numbers are described. The algorithms can be easily implemented on various architectures and compilers. Extensive numerical tests have been performed to assess the performance of the associated implementation. The results have been compared to those obtained in MATLAB, but with appropriate modifications for numbers very close to the bounds of the range of representable values, where usual formulas give wrong results.
Keywords: 
;  ;  ;  

1. Introduction

The approximate symmetric chordal metric for two real or complex numbers is defined by
d ( a 1 , a 2 ) : = min ( | a 1 a 2 | , | 1 / a 1 1 / a 2 | ) = : min ( d 1 , d 2 ) .
It differs from the Euclidean distance by also considering the absolute difference of the reciprocals of the given numbers. As shown in Remark 1, Section 2, d in (1) is not a true mathematical distance, but a useful replacement for a distance in some applications. In particular, it can be used even if one number, say a 2 , is infinite; as shown in Theorem 1 (vi), the result is finite if a 1 0 .
There are quite many references on chordal metric, but no references to the approximate symmetric chordal metric could be found. In one of the early papers on chordal metric, Klamkin and Meir [1] have shown that a normed linear space is Ptolemaic if and only if it is symmetric, and that the chordal metric, defined using that space norm, d ( x , y ) = x y / x / y , for x, y 0 , satisfies the triangle inequality. A main approach to define the chordal metric is via the stereographic projection, e.g., [2,3,4]. Let S 2 R 3 be the Riemann sphere with diameter 1 and center in ( 0 , 0 , 1 / 2 ) R 3 , defined by u 2 + v 2 + ( w 1 / 2 ) 2 = ( 1 / 2 ) 2 . The u v -plane tangent to S 2 in the origin can be seen as the complex z-plane C . Let ı be the purely imaginary unit. Stereographic projection is the map C S 2 defined by the intersection of the chord z N ¯ with S 2 , where z : = ( u , v , 0 ) is identified with z = u + v ı = : ( z ) + ( z ) ı in the u v -plane, and N : = ( 0 , 0 , 1 ) is the north pole of S 2 . Let L ( t ) : = ( t u , t v , 1 t ) be a parametrization of the line from N to z, with t R ; clearly, L ( 0 ) = N and L ( 1 ) = ( u , v , 0 ) = z ; hence, the intersection S 2 L ( t ) is for t z [ 0 , 1 ) , and t z satisfies the equation ( u 2 + v 2 + 1 ) t z 2 t z = 0 . The solutions are t z = 0 , corresponding to N, and t z = 1 / ( u 2 + v 2 + 1 ) , giving L ( t z ) = ( u , v , u 2 + v 2 ) / ( u 2 + v 2 + 1 ) . The stereographic projection of C to S 2 is defined by
χ : C S 2 N : z ( ( z ) , ( z ) , | z | 2 ) 1 + | z | 2 .
If d ( z , w ) = | z w | is the Euclidean metric in C and d ( χ ( z ) , χ ( w ) ) that on S 2 inherited from R 3 , then it can be shown that,
d ( χ ( z ) , χ ( w ) ) = | z w | 1 + | z | 2 1 + | w | 2 ,
which is the chordal metric of S 2 . Clearly, d ( χ ( z ) , χ ( w ) ) = 0 d ( z , w ) = 0 . If z , then χ ( z ) ( 0 , 0 , 1 ) = N . This way, χ becomes a map from the extended complex plane C ¯ = C { } to S 2 . Note that χ ( z , w ) = χ ( 1 / z , 1 / w ) if z, w C . The triangle inequality is satified by d ( χ ( z ) , χ ( w ) ) , being implied by that inequality for Euclidean distance in R 3 ; therefore, chordal metric is indeed a distance. If w , then the formula becomes d ( z , ) = 1 / 1 + | z | 2 . If a Riemann sphere with unit radius and center in the origin is used, then the formulas for the chordal metric should be multiplied by 2 [3,5]. It is also mentioned in [3] that χ ( z , w ) = 0 if z and w .
Several authors present theretical results and various applications of the chordal metric. Rainio and Vuorinen [4] use (2) to identify some cases where the distortion caused by symmetrization of a quadruple of points or objects, mapped by a Möbius transformation, can be measured in terms of the Lipschitz constant of this transformation in the Euclidean or the chordal metric. Álvarez-Tuñón et al [6] investigate various pose representations and metric functions in visual odometry networks, and show that the chordal distance ensures better generalization and faster convergence of the network parameters than distances measured by Euler angles or quaternions; this is useful to estimate the change of position, e.g., of robots, relative to a starting location, based on data from motion sensors. However, this paper uses the chordal distance between two rotations, R A and R B , defined as R A R B F = R A R B T I F , where I is the identity matrix of order 3 and F denotes the Frobenius norm. Xu et al [7] provide explicit expression and sharper bounds of the chordal metric between generalized singular values of Grassmann matrix pairs. A constrained optimization problem of the form max U U n f ( U ) , where U n is the set of n × n unitary matrices, is studied and its optimal solution is given. The results are applied to comparative analysis of gene mRNA expression data for mice macrophage under different conditions. Sun [8] considers the generalized singular values (GSVD) when rank ( [ A ; B ] ) < n , where A and B are complex m × n and p × n , respectively. Then, any pair ( a , b ) satisfying a , b 0 and ( a , b ) ( 0 , 0 ) is a singular value, a / b . For such a case, it is difficult to investigate the perturbation of singular values. It is shown that when [ A ; B ] is strongly perturbed, the singular values are insensitive to perturbations in the elements of A and B, if the chordal metric is used to describe such perturbations. Sasane [2] defines an abstract chordal metric on linear control systems described by their transfer functions and shows that strong stabilizability is a robust property in this metric. In [9], a refinement of this metric for standard classes of stable transfer functions is introduced.
A common application of the approximate symmetric chordal metric is related to ordering the eigenvalues of a matrix or matrix pencil, according to their pairwise distances measured using (1). For generalized eigenvalue problems, i.e., for matrix pencils, some eigenvalues may be infinite. Ordering (generalized) eigenvalues is very important in many applications of numerical linear algebra, control theory and other domains. For instance, it is essential for computing invariant or deflation subspaces of matrices or matrix pencils, respectively. A more general application of the approximate symmetric chordal metric is for computing the block-diagonal form for matrices or matrix pencils [10], especially for large order problems. This form is useful for finding reciprocal condition numbers for eigenvalues and related eigenspaces, as well as for fast computation of matrix functions or of the responses of linear time invariant standard or descriptor systems. Assuming that the matrix (pencil) is already reduced to a (generalized) Schur form [11], an essential part of the computations is the solution of a (generalized) Sylvester equation. This part involves non-unitary transformations. To ensure an acceptable numerical precision, the solution elements should be bounded. Specifically, if any element of the solution exceeds a given threshold τ > 1 , then the process is stopped, and an enlarged Sylvester equation is tried to be solved. If many failed attempts are necessary, then the computational effort might be unacceptably high, especially for large order problems. A clever strategy for ordering the eigenvalues of the matrix (pencil) might reduce the number of failed trials, since the magnitude of the solution is influenced by the sensitivity of the spectrum associated to the current block that should be separated. The sensitivity of eigenvalue problems and related topics are investigated in [11,12,13,14,15,16]. Efficient and reliable implementations of the theoretical results are available in the LAPACK package [17] and in interactive environments like MATLAB [18] or Mathematica [19]. The eigenvalues can be ordered based on their pairwise “distances” measured by (1). These eigenvalue applications do not need the triangle inequality be satisfied. But it is important that close eigenvalues be included in the same cluster. The use of the min function in (1) will choose an eigenvalue a 2 to be added to a cluster containing a value a 1 if either | a 1 a 2 | or | 1 / a 1 1 / a 2 | is smaller than a given threshold. An approach based on the chordal metric cannot do that. Clearly, d 2 = | 1 / a 1 1 / a 2 | = | a 1 a 2 | / | a 1 | / | a 2 | , if a 1 0 and a 2 0 . Therefore, in such a case, d 2 coincides to the chordal metric in [1], and d 2 is often quite close to the usual definition of the chordal metric (2). The distance d 1 = | a 1 a 2 | is not directly taken into account, although it could be smaller than d 2 .
This section is ended by some issues, needed in the sequel, concerning the floating point system of computers. For technical convenience, R ¯ will denote the real numbers field R extended by the and symbols, and similarly for C ¯ . This is useful, since practical calculations with computer software like MATLAB encounter such situations.
A complex "number" a = α + β ı , with α , β R ¯ , is infinite if α = ± and/or β = ± . Otherwise, a is finite. Consider two finite complex numbers, a 1 = α 1 + β 1 ı , a 2 = α 2 + β 2 ı . It is assumed that α i and β i , i = 1 , 2 , are in the range of the floating point system of a computer, hence a 1 and a 2 are (approximately) representable by their real and imaginary parts. Therefore, | α i | , | β i | K , i = 1 , 2 , where K is the maximum representable number, defined by
K = b e M ( 1 ϵ ) ,
where b is the base of the numeral system, e M is the maximum exponent, and ϵ is the smallest distance between two representable numbers (also called the relative machine precision). In a commonly used binary double precision floating point system, b = 2 , e M = 1024 , ϵ = 2 1 t (or ϵ = 2 t for machines with proper rounding in the addition operation), and t = 53 , where t is the number of base digits in the mantissa, i.e., the fractional part of the representation in base b. Note that the result of evaluating K as in (3) might not be representable on such a computing machine, since it could exceed K; but evaluating K = b e M 1 ( 1 ϵ ) × 2 will not overflow. The number ε = b ϵ is called precision. On the machine considered above, with proper rounding, ( 1 + ϵ ) 1 = 0 , but ( 1 + ε ) 1 = ε .
Clearly, not all real or complex numbers can be represented on a digital computer, since the floating point system deals with rational approximations of the numbers in the range K , K . If an arithmetic operation would produce a result outside this range, that fact is called overflow. Compilers and interactive environments may represent such a result as ±Infinity or ±Inf, and if this happens in a sequence of computations, the final result might be completely wrong. Therefore, overflows should be avoided. On the other hand, very small (in magnitude) numbers may also be not representable, and if this is the case for the result of a mathematical operation, it may be set to zero. This is the counterpart of an overflow, and it is called underflow, but it is not as severe as overflows. The underflow threshold is defined by k = b e m 1 , where e m is the minimum exponent before underflow. For the machine considered above, e m = 1021 . Many computer systems allow for gradual underflow, i.e., they may also use numbers less than k, in the range ε k , k . For this reason, the availability of gradual underflow will be assumed in this paper.
Algorithms for discovering the properties of the floating point arithmetic, like in [20,21], are implemented, e.g., in the SLAMCH and DLAMCH routines of the LAPACK package [17], for single and double precision computations, respectively. A special function is used to ensure that all relevant values are stored, and not held in registers, or not affected by compiler optimizations.
In the sequel, there will be no distinction between a number and its floating point representation. Note that the assumption that | α i | , | β i |     K , i = 1 , 2 , does not imply that | a 1 |     K and | a 2 |     K . If | α 1 |   = K and | β 1 |   = K , then | a 1 |   = K 2 , which is not representable. The specific case of our application allows to work with a factored form of | a 1 | and | a 2 | .
The rest of the paper is organized as follows. Section 2 investigates the properties of the approximate symmetric chordal metric, while Section 3 presents reliable, accurate, and efficient algorithms for its computation. Section 4 discusses the numerical results obtained using a careful implementation of these algorithms. Section 5 summarizes the conclusions.

2. Basic Properties of the Approximate Symmetric Chordal Metric

In some applications using (approximate symmetric) chordal metric, a 1 and/or a 2 or the terms in (1) may not be numbers, but 0/0 or . For instance, some eigenvalues of singular matrix pencils are 0/0. Moreover, even for nonsingular matrix pencils, some eigenvalues are infinite, but in some routines, e.g., as those in LAPACK [17], the eigenvalues are in fact ratios of pairs of numbers, μ 0 and ν , with ν possibly 0; if a 1 = a 2 = in (1), for a 1 , a 2 R ¯ , then the first term of the min function in (1) is . In such cases, it is necessary to use special computer rules for mathematical operations, as shown below.
A Not-a-Number entity is represented by NaN in compilers and interactive environments like MATLAB.
Definition 1.  (Basic operations withNaNs and numbers)
  • NaNa = NaN, NaNa = NaN, aNaN = NaN, where { + , , × , / } , × and / are the multiplication and division binary operations, and a R ¯ .
  • NaNa = NaNβı, NaNa = NaN + NaNı, aNaN = NaN + NaNı, for a = : α + β ı C ¯ .
  • |NaN| = NaN, min(NaN, a) = a, max(NaN, a) = a, for a C ¯ .
For convenience, conventions like 1 / 0 = and 1 / 0 = are adopted here; these conventions make sense thinking in terms of limits, for intance, lim x 0 1 / x = ± , for x taking positive of negative values only, respectively.
The next theorem shows the basic properties of the approximate symmetric chordal metric. The results are true even if α i and/or β i , i = 1 , 2 , are infinite.
Theorem 1
(Basic properties of d in (1)). Let a, a 1 and a 2 be finite or infinite complex numbers. Then, with (1)
(i) 
d ( a 1 , a 2 ) = d ( a 2 , a 1 ) ;
(ii) 
d ( a , 0 ) = | a | , a C ¯ ;
(iii) 
d ( a , a ) = 0 , a C ¯ ;
(iv) 
d ( a 1 , a 2 ) = 0 if a 1 and a 2 are infinite;
(v) 
d ( a 1 , a 2 ) = 0 a 1 = a 2 , a 1 , a 2 C ¯ ;
(vi) 
d ( a 1 , a 2 ) = 1 / | a 1 | , if a 2 is infinite, a 1 C ¯ ;
(vii) 
d ( a 1 , a 2 ) > 0 if a 1 a 2 and a 1 or a 2 , or both, are finite.
Proof. 
The symmetry property (i) follows immediately from (1). Property (ii) holds since the second argument of the min function in (1) is infinite, hence, d 2 = , and d 1 = | a | ; clearly, (ii) is also true for a = ± , a = ± + β ı , a = α ± ı , or a = ± ± ı , with α and β finite, since then d 1 = too. (For convenience, when a = ± ± ı appears, the other two cases, with either α or β finite, will not be mentioned, but the related property is also true for these cases.) From (1), property (iii) holds for finite a; if a = ± or a = ± ± ı , then d 1 = NaN, d 2 = 0 , and d = 0 , according to the third item in Definition 1. If a 1 = ± or a 1 = ± ± ı and a 2 = a 1 , (iv) has been proved in (iii), while if a 2 = a 1 , or a 2 = ± a ¯ 1 , where a ¯ is the complex conjugate of a, then (iv) follows, since d 1 = and d 2 = 0 . Clearly, from (iii) and (iv) it follows that a 1 = a 2 implies d ( a 1 , a 2 ) = 0 . Conversely, if d ( a 1 , a 2 ) = 0 , then either | a 1 a 2 | = 0 , if a 1 and a 2 are finite, or | 1 / a 1 1 / a 2 | = 0 , if a 1 and a 2 are infinite, so a 1 = a 2 . These two facts prove the identity property (v). If a 1 0 is finite, (vi) follows since d 1 = and d 2 = 1 / | a 1 | ; (vi) is also true if a 1 = ± or a 1 = ± ± ı since, from (iv), d ( a 1 , a 2 ) = 0 = 1 / | a 1 | . If a 1 = 0 , then (vi) holds since d 1 = and d 2 = , so d = = 1 / | a 1 | . If a 1 and a 2 are finite and distinct, both terms of min are strictly positive, which prove (vii); if a 1 is finite, but a 2 is infinite, then d 1 is infinite, hence, by (vi), d = d 2 = 1 / | a 1 | > 0 . The symmetry property makes the result true also for a 1 infinite and a 2 finite.    □
Remark 1.
Theorem 1 proves that three properties of a distance or metric, namely, symmetry, identity and non-negativity, are satisfied by d ( a 1 , a 2 ) . But it is easy to verify that the fourth needed property, the triangle inequality, does not hold for (1), therefore the inequality d ( a , c ) d ( a , b ) + d ( b , c ) , is not true in general, for a , b , c C . Consequently, d ( a 1 , a 2 ) is not a distance or metric function. Moreover, the approximate symmetric chordal metric does not satisfy a scaling property, that is, d ( s a 1 , s a 2 ) differs, in general, from | s | d ( a 1 , a 2 ) , with a 1 , a 2 , s C . For instance, for a 1 = 1 , a 2 = 2 , and s = 2 , d ( a 1 , a 2 ) = 0.5 and d ( s a 1 , s a 2 ) = 0.25 , but for s = 4 , d ( s a 1 , s a 2 ) = 0.125 . The ratios d ( s a 1 , s a 2 ) / d ( a 1 , a 2 ) in the two cases are 0.5 and 0.25, respectively, not 2 and 4. Such scaling property holds for | a 1 a 2 | and for | 1 / a 1 1 / a 2 | , but not necessarily for their minimum.
In order to be able to accurately work on the entire range of representable complex numbers, a special representation of the absolute value is used, as defined below.
Definition 2.  (Factored representation of the absolute value of a complex number a)
Let a = α + β ı C with | α | K and | β | K . Let M : = max ( | α | , | β | ) , m = min ( | α | , | β | ) , and δ = 1 + ( m / M ) 2 . Then | a | = M δ is called the factored representation of | a | .
From Definition 2 it follows that δ 1 , 2 , since δ = 1 if m = 0 , δ = 2 if m = M , and values m / M 0 , 1 will imply δ 1 , 2 . Factored representation is useful when M is vey close to or coincides to K. In such a case, the product M δ could exceed K, and then | α | cannot be computed. Still, its factors can be used in all computations needed for obtaining the approximate symmetric chordal metric.

3. Algorithms for Computing the Approximate Symmetric Chordal Metric

A conceptual algorithm is first presented, and then it will be detailed. The symbols ∧, ∨ and ¬, used in the algoriths and their description below, are the binary logical operators AND, OR and NOT, respectively. Moreover, C ¯ r and R ¯ r denote the sets of complex and real representable numbers, respectively. However, the algorithms below will also correctly work for a 1 and/or a 2 set to ±Infinity or ±Infinity ±Infinityı, if the IEEE arithmetic is available on the computer. Although the computational problem for approximate symmetric chordal metric looks mathematically very simple, a reliable, accurate, and efficient implementation needs a thorough analysis. These desirable properties are supported by careful consideration of all possible special cases and lower level algorithms. Efficiency can be measured by an estimate of the number of floating point operations, or flops, which have been used especially for numerical linear algebra algorithms [11,22]. One definition says that a flop consists in an addition, a multiplication and few memory addresses. Another definition considers each addition, subtraction, multiplication and division of two floating point numbers as a flop. This is suitable in the paper context.

3.1. Conceptual Algorithm

In the first part of the Algorithm chordal, the value of d = d ( a 1 , a 2 ) is computed for special cases. If the maximum absolute value, M, of the real and imaginary parts of a 1 and a 2 , is zero, or if a 1 = a 2 , then d = 0 , according to (iii) in Theorem 1. Otherwise, if M 1 = 0 , which implies that a 1 = 0 , then d =   | a 2 | , using (i) and (ii). Similarly, if M 2 = 0 , then d =   | a 1 | . The absolute values | a i | , for i = 1 and i = 2 , are computed by a lower level algorithm, called absa, introduced in the next subsection. Algorithm absa needs on input the auxiliary parameters M and u = u 1 or u = u 2 , set in Algorithm chordal, using κ : = K / 2 .
Another special case is when one of the numbers | a 1 | or | a 2 | is negligible compared to the other. Then, as shown below, | a 1 a 2 | can be found using | a 1 | , | a 2 | , or both. Detecting this situation involves the logical variable f : = m / M ε / 4 , with m : = min ( M 1 , M 2 ) . See Remark 2 below. If f is true, then it is easier to obtain the terms d 1 and d 2 of d in (1). Specifically, if M = M i and j i , i , j { 1 , 2 } , it follows that: if m < 0.1 / M , then d = | a i | ; else if m > 1.1 / M , then d = 1 / | a j | ; else d = min | a i | , 1 / | a j | . The tests involving m and M are motivated by the following reason: M = M i implies that d 1 = | a i | is of the order of M, and d 2 = 1 / | a j | is of the order of 1 / m ; if m 1 / M , d 1 and d 2 have comparable values, and d should be found as min d 1 , d 2 ; if m is smaller enough than 1 / M , then d 1 < d 2 and so d = d 1 . Similarly, if m is larger enough than 1 / M , then d 1 > d 2 , and so d = d 2 . The bounds 0.1 and 1.1 have been found after few trials, so that all tests returned the correct results. Note that, in the discussion above and in Algorithm chordal, the product m M is not used, since it may overflow if | a 1 | and | a 2 | are close to K.
Remark 2.
Using Definition 2, the absolute value of a i , i = 1 , 2 , can be expressed as | a i | = M i δ i , where δ i : = 1 + m i / M i 2 1 , 2 . Indeed, δ i = 1 , if m i = 0 and δ i = 2 , if m i = M i . Clearly, if m i 0 , M i , then δ i 1 , 2 . This factored form of | a i | is valid even if M i = m i = K , when the factors cannot be multiplied without producing an overflow. If M 1 / M 2 ε / 4 , it follows that
| a 1 | / | a 2 | ( M 1 / M 2 ) ( δ 1 / δ 2 ) ( ε / 4 ) 2 < ϵ ,
since δ 1 2 and δ 2 1 . Therefore, if M 1 is negligible compared to M 2 , the same is true for | a 1 | and | a 2 | . The last inequality in (4) assumes that the base of the floating point system is b = 2 . For the previous paragraph, M 1 = m and M 2 = M .
If no special case appears in Algorithm chordal, it follows that a 1 and a 2 are nonzero, distinct and relatively “close” to each other, in the sense that m / M > ε / 4 . This is the general case, for which it is necessary to compute d 1 = | a 1 a 2 | and d 2 = | 1 / a 1 1 / a 2 | . Finally, d = min ( d 1 , d 2 ) . These more involved computational steps of the conceptual algorithm are detailed in the next subsections.
An account of the needed computations can be given here for the part involving special cases, but additional details, including those for general case, will be available in the remaining subsections of this section. At the beginning of Algorithm chordal, the computation of the absolute values for four real scalars, as well as three standard max operations (i.e., with two arguments) are needed, for getting M i , i = 1 , 2 , and M. If M = 0 or a 1 = a 2 , which requires three comparisons of real scalars, the result is d = 0 . Otherwise, if M i = 0 , then d = | a j | , with j i and i = 1 or i = 2 ; each of these cases needs an evaluation of one norm (either of a 1 or of a 2 ); in addition, a division and two tests are needed to set u i = M i κ , κ : = K / 2 . If M i 0 for i { 1 , 2 } , the special case when | a 1 | | a 2 | or | a 1 | | a 2 | is tried. The initialization of this pseudocode segment involves a standard min operation, two divisions and a comparison, setting the value of the logical variable f. If f = true and M = M i , then there are three cases: if m < 0.1 / M , then d = | a i | ; else, if m > 1.1 / M , then d = 1 / | a j | , for j i ; else, d = min | a 2 | , 1 / | a 1 | . Hence, in addition to the inialization part, the computations involve three or four tests, one or three divisions, one or two evaluations of the absolute value, and—for the third case—one standard min operation.
Algorithm 1 chordal computes ASCM for two complex numbers
Preprints 160607 i001

3.2. Computation of | a | , a C ¯ r

If the magnitude of the real and imaginary parts of a = α + β ı C ¯ r are close to the maximum representable number, K, then | a | may overflow. For the computation of the approximate symmetric chordal metric d, it is possible to use the factored form of | a | , using M and δ given in Definition 2, namely, M = max ( | α | , | β | ) , and δ = 1 + ( m / M ) 2 0 , 2 , with m = min ( | α | , | β | ) .
For example, for a = K + K ı , the direct computation of abs(a) in MATLAB gives Inf, the machine infinity, while | a | can very accurately be represented by the product factors M = K and δ = 2 . Actually, abs(a), i.e., α 2 + β 2 , is also evaluated internally in a factored form in MATLAB or in other available routines, like DLAPY2 from LAPACK [17], but the result is returned as a product, M δ . However, in most cases, | a | is far from K, and always using the factored form would involve some unnecessary computations. For efficiency, a bound is used to detect a case when the factored form might be needed. Specifically, if M κ , with κ : = K / 2 defined in Algorithm chordal, then one can safely use abs(a) in MATLAB, or DLAPY2 from LAPACK to obtain | a | . Otherwise, it is safer to employ the factored form. Since κ is a conservative bound, it is possible that | a | = M δ be representable. The needed test is included in the Algorithm absa, listed below, and explained in Remark 3; the logical variable u, externally initialized to true if M κ , is updated internally as u = M K / δ .
Algorithm 2 absa computes the modulus (or its factored representation) of a complex number
  • Require:  a = α + β ı C ¯ r , M, K, u
  • Ensure:  | a | , if u is true on exit, or M and δ , otherwise
  • if  u  then
  •      | a | = α 2 + β 2
  • else
  •      m = min ( | α | , | β | ) , δ = 1 + ( m / M ) 2 , u = M K / δ
  •     if u then
  •         | a | = M δ
  •     end if
  • end if
If u = true on entry, Algorithm absa needs in principle to square two real numbers and make an addition and a square root. This computation can be performed using abs ( a ) in MATLAB, or by a call to the LAPACK routine DLAPY2. This is preferable since there are professional implementations of this routine on many computing platforms, that could return a more accurate result than a direct evaluation of the the formula α 2 + β 2 . If u = false on entry to Algorithm absa, then the computations involve a standard min operation, the absolute values of two real numbers, two divisions, an addition, a square of a number, a square root and a test u = M K / δ . If u = true after this test, then a multiplication is done, in order to simplify the subsequent calculations. Actually, DLAPY2 uses the factors M and δ as in the else part of the algorithm, but then always multiplies them; therefore, the actual operations are the same as above, but, in extreme cases, the product M δ may overflow.
The algorithm absa can be used to compute | a 1 | , | a 2 | , d 1 = | a 1 a 2 | , and d 2 = | 1 / a 1 1 / a 2 | in Algorithm chordal. For d 2 it is necessary to first evaluate 1 / a 1 and 1 / a 2 . This topic will be dealt with in Section 3.5.
Remark 3.
The logical variable u i is initialized to  true   in Algorithm  chordal   for a i , if M i κ , i = 1 , 2 . If u i is  false   on entry to Algorithm absa, but if, after computing the corresponding δ i , it follows that M i K / δ i , then u i is reset to  true, using u i = M i K / δ i , and hence | a i | = M i δ i . Otherwise, | a i | is represented and used in the factored form. For instance, for finding | a 1 | or its factored representation, the following MATLAB-like command can be used,
u 1 , μ 1 , δ 1 = absa a 1 , M 1 , K , u 1
where μ 1 = | a 1 | , if u 1 = true on exit from  absa, and M 1 and δ 1 define the factored representation of | a 1 | , if u 1 = false on exit. Note that the closeness to the underflow threshold, k, is not taken into account in Algorithm  absa, since underflow is less harmful than overflow. If M δ underflows, then the product might become 0 instead of a very small positive value. Having a machine with gradual underflow is helpful in such a case, because some nonzero values smaller than k are representable.

3.3. Computation of d 1 = | a 1 a 2 | , a 1 , a 2 C ¯ r

The computation of d 1 needs the real and imaginary parts of a 1 a 2 , and these parts are computed separately. Using triangle inequality for the Euclidean distance between the points a 1 and a 2 in the complex plane, it follows that | a 1 a 2 | | a 1 | + | a 2 | . Denoting M 12 = max ( | α 1 α 2 | , | β 1 β 2 | ) , the same inequality expressed in the infinity norm, | a i | = M i , i = 1 , 2 , implies that M 12 M 1 + M 2 . Clearly, even simple operations like α 1 α 2 or β 1 β 2 may produce overflow or underflow, if any of these scalars is close to K or k, respectively, and the other has appropriate sign and magnitude. These exceptions can be avoided in a professional implementation, but it is worth to estimate their possible occurrence. This is done in an algorith that computes the difference σ : = α γ between two real numbers, α and γ . If IEEE arithmetic is available, and either α 1 α 2 or β 1 β 2 are/is ±Infinity, then the corresponding d 1 could not be computed, but d 2 will certainly be. Without IEEE arithmetic, the computation is more involved, as shown in Algorithm subtract below.
Algorithm 3 subtract computes the difference of two complex numbers
  • Require:  α , γ R ¯ r , K, ε .
  • Ensure:  σ = α γ , ϕ
  • M = max ( | α | , | γ | ) , ϕ = true
  • if  M = 0   then
  •      σ = 0
  • else
  •      m = min ( | α | , | γ | )
  •     if  m / M ε / 4  then
  •       if  m = | α |  then
  •           σ = γ
  •       else
  •           σ = α
  •       end if
  •     else
  •        s α = sign ( α )
  •       if  s α = sign ( γ )  then
  •           σ = α γ
  •       else
  •          if ( γ = sign ( γ ) K | α | > K ε / 4 ) | α | > K + s α γ  then
  •             σ = s α K , ϕ = false
  •          else
  •             σ = α γ
  •          end if
  •       end if
  •     end if
  • end if
The Algorithm subtract uses the sign function, defined as sign ( α ) = 1 , if α > 0 , sign ( α ) = 0 , if α = 0 , and sign ( α ) = 1 , if α < 0 . Note that the value 0 cannot appear in Algorithm subtract, since sign is used there only when its argument is nonzero.
Three special cases are dealt with by Algorithm subtract. If M : = max ( | α | , | γ | ) = 0 , then σ = 0 . This case needs the absolute values of two real numbers, a max operation, a test, and setting ϕ = true . The second special case is when one of the values | α | and | γ | is negligible compared to the other, i.e., when m / M ε / 4 , with m = min ( | α | , | γ | ) . In such a case, σ = γ if m = | α | , or σ = α , otherwise. In addition to the operations performed for the first special case, a min operation, two divisions and two tests are needed. The third special case is when α and γ have the same sign, which implies that the result is σ = α γ . This case needs two sign operations, a subtraction and a test. The general case may involve few additional operations: a multiplication, an addition, one or two logical operations and a test. If the test is satisfied, then σ = sign ( α ) K and ϕ is set to false. Otherwise, σ = α γ .
To obtain d 1 = | a 1 a 2 | , Algorithm subtract has to be called for both the real and imaginary parts of σ = a 1 a 2 = : σ r + σ i ı . If it succeeded to obtain representable values for σ r and σ i , then d 1 = | σ | can be obtained using Algorithm absa. Let M d = max ( | σ r | , | σ i | ) be the value of M on input (and output) of Algorithm absa applied to σ , and let d 1 or u d and δ d be its outputs. If u d is true, then | a 1 a 2 | = d 1 ; otherwise, M d and δ d are the factored representation of d 1 . If the parameter ϕ is false on exit of the first or the second call of the algorithm, it means that σ r or σ i , respectively, would exceed K in magnitude and therefore d 1 could not be computed. In such a case, σ r and/or σ i are set to ± K , or to ± Infinity , if the IEEE arithmetic is available.

3.4. Computation of d 2 = | 1 / a 1 1 / a 2 | , Using | a 1 a 2 |

Algorithm chordal has to compute d 2 only when a 1 0 and a 2 0 , since the special cases a 1 = 0 or a 2 = 0 have already been solved, resulting in d = | a 2 | or d = | a 1 | , respectively. If ϕ = true on exit of both calls of Algorithm subtract made in Algorithm chordal to compute d 1 = | a 1 a 2 | , i.e., if d 1 is a representable result (possibly in a factored form), then d 2 : = | 1 / a 1 1 / a 2 | can be obtained more efficiently than using the direct formula, based on evaluating 1 / a 1 1 / a 2 , as done in Section 3.5. Indeed, since 1 / a 1 1 / a 2 = ( a 2 a 1 ) / ( a 1 a 2 ) , it follows that
d 2 = 1 a 1 1 a 2 = | a 2 a 1 | | a 1 | | a 2 | = d 1 | a 1 | | a 2 | .
The absolute values of a 1 and a 2 are easily computed using Algorithm absa. Then, d 2 can be obtained using (5), taking into account that all factors, d 1 , | a 1 | , and | a 2 | can be in factored form or not. From (5), it follows that d 2 > d 1 if | a 1 | | a 2 | < 1 , hence d 2 should not be evaluated in this case, since then d = d 1 . The computations are summarized in Algorithm d2byd1 shown below.
The order of the arithmetic operations in Algorithm d2byd1 is important; changing it could produce overflows or underflows. Parentheses are used to enforce that order, and avoid possible optimizations made by compilers. Note that if ¬ u 1 ¬ u 2 , i.e., in the two else cases of the test branches for u d , then M and m are already available from Algorithm chordal. Another observation is that if u 1 = u 2 = u d = true and M = max ( | a 1 | , | a 2 | ) < 1 , it follows that d 2 > d 1 , since d 2 = ( d 1 / M ) / min ( | a 1 | , | a 2 | ) , where also min ( | a 1 | , | a 2 | ) M < 1 ; therefore d = d 1 . Note that | a 1 | | a 2 | > 1 in the other three combinations of u 1 and u 2 for u d = true , since either | a 1 | or | a 2 | (or both) are larger than K, and the other value must be at least K ε / 4 , because otherwise the special case f = true , already detected by Algorithm chordal, appears.
If ϕ = false in Algorithm subtract, d 2 cannot be computed by Algorithm d2byd1 since d 1 is not available, and therefore d 2 has to be found using the direct formula, which involves more computations.
Algorithm 4 d2byd1 computes d 2 in (1) using d 1
Preprints 160607 i004
Besides the evaluations of | a 1 | and | a 2 | or of their factored representations, in the usual case, with u d = true , Algorithm d2byd1 needs three, four or four tests, and three, three or four divisions, for the cases when only u 1 = true or u 2 = true , or when u 1 = u 2 = false , respectively; the case u 1 = u 2 = true needs three tests, one ∧, one max and one min operations, and two divisions. If u d = false , an additional multiplication with M d is also required in all these four cases.

3.5. Direct Computation of d 2 : = | 1 / a 1 1 / a 2 |

The direct computation of d 2 using its definition in (1),
d 2 = | 1 / a 1 1 / a 2 | ,
needs to evaluate the reciprocals of a 1 and a 2 , then the difference 1 / a 1 1 / a 2 , and finally the absolute value of this difference. The following algorithm shows how the reciprocal of a complex number a has to be safely computed. Note that if a = α + β ı , 1 / a = ( α β ı ) / | a | 2 , where | a | can be given in a factored form, M δ , but this product might not be representable. However, squaring up | a | is prone to overflow, and therefore it must be avoided. Algorithm inva listed below shows how 1 / a should be evaluated.
Algorithm 5 inva computes the reciprocal of a complex number given its modulus or factored representation
  • Require:  a = α + β ı C ¯ r , | a | if u = true , or M, δ , if u = false , K
  • Ensure:  1 / a = μ + ν ı
  • if  u  then
  •      μ = ( α / | a | ) / | a | , ν = ( β / | a | ) / | a |
  • else
  •      μ = ( α / δ ) / δ / M / M , ν = ( β / δ ) / δ / M / M
  • end if
Remark 4.
The minus sign in front of ν is not necessary in this context, since the real and imaginary parts will be used to evaluate | 1 / a 1 1 / a 2 | using Algorithm absa. Indeed, the signs of the imaginary parts of 1 / a 1 and 1 / a 2 do not matter.
Algorithm inva needs one test and four divisions if u = true , or six divisions if u = false , but it should be applied to both 1 / a 1 and 1 / a 2 . Therefore, two tests and eight, ten or twelve divisions are necessary if u 1 = u 2 = true , u i = true and u j = false , for i , j { 1 , 2 } , i j , or u 1 = u 2 = false , respectively. The remaining computations are the same as those for computing d 1 , but applied to | 1 / a 1 1 / a 2 | . Therefore, the computational effort for computing d 2 = | 1 / a 1 1 / a 2 | using Algorithm inva shoud be compared to that of Algorithm d2byd1, which needs at most four tests and four divisions, or at most three tests, two divisions, one ∧, one max and one min operations, if u 1 = u 2 = u d = true ; if u d = true , another multiplication is needed.
Clearly, the direct approach needs more computations than the first approach, based on d 1 . Note that the first approach can easily and efficiently detect the case when | 1 / a 1 1 / a 2 | is not needed, since its value will exceed | a 1 a 2 | . However, the direct approach has to be used when the first approach could not be used, namely, when d 1 overflows.
Remark 5.
The implementation inlines the low level algorithms, except for Algorithm  subtract, that is more involved; it is called two times, if d 2 can be found using d 1 , or four times, otherwise. Similarly, Algorithm inva   is either not called, or called twice. The very simple Algorithm absa   is called at most four times, and Algorithm d2byd1   is inlined once.

4. Numerical Results

This section starts by presenting four examples that show the significance of the proposed approach. Then, the numerical results obtained in a large experiment with randomly generated examples, which cover the entire range of representable numbers, are discussed. Finally, the performance of two solution approaches for a block diagonalization problem of order 999 is analyzed, illustrating the advantages of using a good eigenvalue reordering strategy and fast algorithms for computing the approximate symmetric chordal metric.

4.1. Detailed Examples

The numerical results for four examples are presented and compared with those got by the direct use of MATLAB computations.
Example 1.
Let a 1 = K + K / 10 ı , a 2 = K / 10 + K ı . Implementing formula (1) in MATLAB, the result is d = 0 , while Algorithm  chordal, together to the lower level algorithms, returns d ̲ = 7.010041250456554e−309. Both d 1 and d 2 computed using (1) in MATLAB are wrong. Specifically, a 1 a 2 = σ σ ı , with σ = 1.617923821376084e+308, and the MATLAB command abs ( a 1 a 2 ) gives d 1 = Inf . Moreover, evaluating 1 / a i , it follows that 1 / a 1 = 1 / a 2 = 0 , and therefore d = d 2 = 0 . On the other hand, the factored form of | a 1 a 2 | has M d = σ and δ d = 2 . Moreover, M = K and m = K / 10 , so that δ 1 = δ 2 = : δ = 1 + ( m / M ) 2 = 1.004987562112089; therefore, | a 1 a 2 | / | a 1 | / | a 2 | = ( δ d / δ / δ ) / M M d / M = d ̲ > 0 .
Example 2.
Let a = 1.16e308 + 1.66e308 ı. MATLAB command  1/a  gives the result 0. While this is close to the true value, it is qualitatively wrong, since it does not satisfy the mathematical condition that a × ( 1 / a ) = 1 . But using the factored form of | a | , | a | = M δ , with M = 1.66e308 and δ = 1 + ( m / M ) 2 = 1.219965042368649, as m = 1.16e308, it follows that
Preprints 160607 i002
and then a × 1 / a = 9.999999999999996e−01 − 1.665334536937735e−16ı, which is very close to 1; the error is of the order of ε. Note that the denominator in (7) should be evaluated as shown there (or with permuted factors), but not as | a | 2 ; multiplying M δ would give  Inf. Clearly, the result obtained is very close to 0, but it can be accurately obtained and it numerically verifies the condition on reciprocal of a complex number, while 0 does not. Note also that | 1 / a | can be obtained directly as 1 / M / δ .
For computing d 2 in (1), it is necessary to evaluate both 1 / a 1 and 1 / a 2 , and then the absolute value of their difference. If a 1 and/or a 2 have real and imaginary parts with very big magnitude, as in Example 2, then using (1) will give an inaccurate result for d, as shown in the next example.
Example 3.
Let a 1 = a from Example 2, and a 2 = K + K ı . Implementing (1) in MATLAB, the result is d = 3.933412034978399e-309, while the implementation of Algorithm   chordal   gives d ̲ = 1.267129104195721e-309. The absolute difference between these values is very small, about  2.66628e-309. However, their relative difference, | d d ̲ | / d is about 0.67785, and taking d ̲ as reference, | d d ̲ | / d ̲ 2.10419 . These big relative differences are due to the fact that using (1) to evaluate d = d 2 in MATLAB gives 1 / a 1 = 0 , and d 2 = | 1 / a 2 | = 1 / K / 2 = d . Both MATLAB and Algorithm  chordal   compute d 1 = 6.523894033771084e+307, but Algorithm  chordal   uses Algorihm  d2byd1  to obtain d ̲ = d 2 = d 1 / | a 1 | / | a 2 | , where the factored representations are used for | a 1 | and | a 2 | .
Example 4.
Let a = K / ( 4 / 3 ) + K / 2 ı . Using MATLAB, it follows that  1/a   = 0, which is wrong, since it implies that a × ( 1 / a ) = 0 , while the true result is 1. On the contrary, Algorithm  inva   gives 1 / a = 5.134785827324312e-309 - 3.423190551549538e-309 ı. With this value, it follows that a × ( 1 / a ) = ( 1 / a ) × a = 1.000000000000000e+00 + 3.885780586188048e-16 ı, that has absolute and relative errors less than 2 ε .

4.2. Large Experiment with Randomly Generated Examples

In a run with 4188166 random examples, the first three examples had a 2 = 0 , a 1 = 0 , and a 1 = a 2 = 0 . Specifically, all examples have been generated using the following MATLAB commands, where a1 and a2 are used for a 1 and a 2 , respectively.
a1 = randn + 1i*randn; a2 = 0;
a2 = a1; a1 = 0;
a2 = 0;
for ii = -1022 : 1023
    s1 = 2^ii;  re = s1*randn;  im = s1*randn;
    if abs( re ) > realmax,  re = sign( re )*realmax;  end
    if abs( im ) > realmax,  im = sign( im )*realmax;  end
    a1 = re + 1i*im;
    for jj = -1022 : 1023
        s2 = 2^jj;  re = s2*randn;  im = s2*randn;
        if abs( re ) > realmax,  re = sign( re )*realmax;  end
        if abs( im ) > realmax,  im = sign( im )*realmax;  end
        a2 = re + 1i*im;
    end
end
s1 = realmax;  re = s1*randn;  im = s1*randn;
if abs( re ) > realmax,  re = sign( re )*realmax;  end
if abs( im ) > realmax,  im = sign( im )*realmax;  end
a1 = re + 1i*im;
for jj = -1022 : 1023
    s2 = 2^jj;  re = s2*randn;  im = s2*randn;
    if abs( re ) > realmax,  re = sign( re )*realmax;  end
    if abs( im ) > realmax,  im = sign( im )*realmax;  end
    a2 = re + 1i*im;
end
s2 = realmax;  re = s2*randn;  im = s2*randn;
if abs( re ) > realmax,  re = sign( re )*realmax;  end
if abs( im ) > realmax,  im = sign( im )*realmax;  end
a2 = re + 1i*im;
  • The for loop with counter ii generates numbers s1 between k = 2 . 225073858507201 e 308 (realmin) and 8.988465674311580e+307, which is very close to, but smaller than K / 2 , K = 1 . 797693134862316 e + 308 (realmax), the relative error being smaller than 5.552e-17. The number s1 multiplies pseudorandom double precision values drawn from the standard normal distribution (with mean 0 and standard deviation 1), to obtain the real and imaginary parts of a 1 . If any of the computed parts of a 1 exceeds K in magnitude, i.e., if ± Inf is obtained, that value is reset to ± K . The number a 2 is obtained in the same way in the internal loop with counter jj. The second part of the code segment has s 1 = K and use it to obtain a 1 ; a 2 is generated as above. The last part also sets s 2 = K , and use it to obtain a 2 . Clearly, complex numbers with | a 1 | > K and/or | a 2 | > K are generated.
For reproductibility of the results, the command sequence above has been run after the MATLAB statement
rng( ’default’ )
  • which ensures that the (initial) seed of the random number generator is the same, and therefore the same sequence of random numbers is generated after using this command. However, for some further tests, the generating sequence has been run repeateadly several times, but the rng( ’default’ ) command has been placed just before the first run. This way, a larger number of tests have been performed.
Inside the (internal) loops, an implementation of Algorithm chordal is called, and its results are compared with those obtained using a MATLAB command for (1), but also a more sophisticated MATLAB code based on algorithms described in Section 3. This is needed since using (1) directly might return inaccurate results, as shown in Section 4.1.
The maximum relative error in this run has been 6.3088e-16; the relative error is defined as | d d ̲ | / max ( 1 , d ) , where d and d ̲ denote the results obtained by evaluating (1) in MATLAB and by using an implementation of Algorithm chordal, respectively. If the absolute error is computed as | d d ̲ | / d , if d 0 , and | d d ̲ | , otherwise, its maximum has been 0.2649. The value became zero after a correction using a MATLAB code based on algorithms described in the previous section. After ten consecutive runs (without reinitialization of the random number generator), the maximum relative error and its mean value have been 7.6144e-16 and 6.3663e-16, respectively, while using the second definition, the values have been 0.73077 and 0.35080, and they became zero after correction.
In this test sequence, there were 3970109 examples with a 1 or a 2 negligible compared to the other, hence the logical variable f in Algorithm chordal was true. This represents 94.794% from the total number of examples. Specifically, 1985994 and 1984115 examples have M = M 1 and M = M 2 , respectively. From those with M = M 1 , 987937 have d = | a 1 | , 994601 have d = 1 / | a 2 | , and 3456 have d = min | a 1 | , 1 / | a 2 | . From examples with M = M 2 , 987834 have d = | a 2 | , 992853 have d = 1 / | a 1 | , and 3428 have d = min | a 2 | , 1 / | a 1 | . These categories correspond to the three cases, with m < 0.1 / M , m > 1.1 / M , and 0.1 / M m 1.1 / M , respectively. For M = M i , the logical variables u i and u j , j i , have been true for all examples satisfying m < 0.1 / M and m > 1.1 / M , respectively. Moreover, for examples satisfying 0.1 / M m 1.1 / M , when | a 1 | as well as | a 2 | needed to be computed, both u 1 and u 2 have been true. Using a factored representation has never been necessary for any of these 3970109 examples.
For the remaining 218055 examples, representing 5.206% of all examples, a 1 and a 2 are nonzero, distinct and relatively “close” to each other, since m / M > ε / 4 . Algorithm subtract has been used to compute the real and imaginary parts, σ r and σ i , of σ : = a 1 a 2 . For three and two examples, σ r or σ i , respectively, would exceed K in magnitude. For these five examples with ϕ = false , d 1 cannot be computed, hence d = d 2 , and consequently, | 1 / a 1 1 / a 2 | needed to be directly computed calling twice Algorithm inva (for 1 / a 1 and 1 / a 2 ) and Algorithm subtract (for the real and imaginary parts of 1 / a 1 1 / a 2 ). For the other 218050 examples, d 1 has been computed as | σ | , using Algorithm absa, and d 1 could be used to obtain d 2 via Algorithm d2byd1. Specifically, u d was true on input to absa, called for evaluating d 1 for 217980 examples, and it was false for the remaining 70 examples with expected overflow; but u d could be reset to true for 12 examples, for which d 1 could be evaluated as d 1 = M d δ d ; therefore, d 1 needed a factored representation, defined by M d and δ d , for only 58 examples.
All these 218055 examples needed both | a 1 | and | a 2 | values. A factored representation for | a 1 | has been required for 56 examples. Although 21 examples were expected to require a factored representation for | a 2 | , the factors could be multiplied without overflows for nine of these examples.
Since d 1 could not be computed for five examples, due to expected overflows in σ r or σ i , it follows that d 2 can be found using Algorithm d2byd1 for 218050 examples. But for 107475 of them, with u 1 u 2 = true , d 2 was not computed, since max | a 1 | , | a 2 | < 1 , which implies that d 2 > d 1 , hence d = d 1 . For 110517 examples, d 2 has been evaluated using d 1 , | a 1 | (or M 1 and δ 1 ) and | a 2 | (or M 2 and δ 2 ); therefore, for these examples, d = min d 1 , d 2 . Specifically, the case u 1 u 2 = true , when d 2 = d 1 / | a 1 | / | a 2 | , happened for 110514 examples; the case u 1 = false and u 2 = true , when d 2 = ( d 1 / δ 1 ) / M 1 / | a 2 | , and the case u 1 u 2 = false , when d 2 = d 1 / δ 1 / δ 2 / M / m , appeared for just one and two examples, respectively. There was no case with u 1 = true and u 2 = false . For the remaining 58 examples for which d 1 needed a factored representation, defined by M d and δ d , there were six cases with u 1 = true , 51 cases with u 2 = true and one case with u 1 u 2 = false . The corresponding formulas are d 2 = δ d / δ j / M i M δ / M j , for j i , i = 1 , 2 , and d 2 = δ d / δ 1 / δ 2 / m M δ / M , respectively. The case with u 1 u 2 = true never appeared; for it, the formula would be d 2 = δ d / min | a 1 | , | a 2 | M δ / M max | a 1 | , | a 2 | , for u 1 u 2 = false .
Finally, for the five examples for which d 1 could not be computed, since σ r or σ i exceeded K, d = d 2 has been evaluated by calling Algorithm inva twice, for a 1 and a 2 . The logical variables u 1 and u 2 were true for four and one examples, respectively, and false for one and four examples. Therefore all formulas for μ and ν in Algorithm inva have been applied. Then, τ = 1 / a 1 1 / a 2 has been obtained using Algorithm subtract separately for the real and imaginary parts of τ ; the variable ϕ remained true for each of these examples. The result d 2 = | τ | has been found by Algorithm absa.
These results show that all examples have been solved using the simplest possible formulas, which prove the efficiency of the implementation. Moreover, it was checked out that the results have been practically the same with those obtained when d 2 has been always computed using (6). This demonstrates that the accuracy of the results was preserved using the simplified formulas.

4.3. Block Diagonalization of a Matrix Pencil

This subsection summarizes the results obtained for block diagonalization of a matrix pencil of order n = 999 , with 107 real and 446 complex conjugate eigenvalues, revealing dense clusters. The numerical approach has been briefly discussed in Section 1. Without using clustering information, a solution with 135 diagonal block pairs has been computed in 62.68 s (seconds). The largest block pair, of order 734, appeared in the 89-th block position on the diagonals; in addition, there are three 1 × 1 and 131 2 × 2 diagonal block pairs. The remaining 104 real eigenvalues are included in the largest block pair.
Using an eigenvalue reordering strategy based on pairwise “distances” between eigenvalues, measured by the approximate symmetric chordal metric, another solution has been computed in 4.6905 s, hence the execution time has been 13.36 times shorter. More block pairs, specifically 141, have been found and the largest block pair, of order 719, appeared in the last position. This is the preferred situation, since well separated eigenvalues could be quickly placed in small block pairs in the leading part, while big clusters remain to be placed in the trailing part of the matrix pencil. There were 140 2 × 2 block pairs, and so, all real eigenvalues were available in the largest block pair. The efficiency gain is mainly due to a better eigenvalue reordering, which reduced the number of failed attempts to solve generalized Lyapunov equations. However, it is worth to mention that the number of “distances” between eigenvalues is n ( n + 1 ) / 2 , hence it increases quadratically with the problem size. Therefore, it is important that the algorithms for computing the approximate symmetric chordal metric be as fast as possible.

5. Conclusions

The basic theoretical properties of the approximate symmetric chordal metric for two real or complex numbers are investigated, and reliable, accurate and efficient algorithms for its computation are proposed. A factored representation of the modulus of a complex number is introduced, which allows to obtain very accurate results for the entire range of the floating point number system of a computer. Two different ways to evaluate the distance between the reciprocals of the given numbers are described. The algorithms can be easily implemented on various architectures and compilers. Extensive numerical tests have been performed to assess the performance of the associated implementation. The results have been compared to those obtained in MATLAB, but with appropriate modifications for numbers very close to the bounds of the range of representable values, where usual formulas give wrong results, as shown in several detailed numerical examples. A block diagonalization example is also discussed to illustrate the efficiency improvement possible using a proper eigenvalue reordering strategy and fast algorithms for computing the approximate symmetric chordal metric.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Klamkin, M.S.; Meir, A. Ptolemy’s inequality, chordal metric, multiplicative metric. Pac. J. Math. 1982, 101, 389–392. [Google Scholar] [CrossRef]
  2. Sasane, A. A generalized chordal metric in control theory making strong stabilizability a robust property. Complex Anal. Oper. Theory 2013, 7, 1345–1356. [Google Scholar] [CrossRef]
  3. Papadimitrakis, M. Notes on Complex Analysis. 2019. Available online: http://fourier.math.uoc.gr/~papadim/complex_analysis_2019/gca_vvn_r.pdf (accessed on 3 May 2025).
  4. Rainio, O.; Vuorinen, M. Lipschitz constants and quadruple symmetrization by Möbius transformations. Complex Anal. Synerg. 2024, 20, 8. [Google Scholar] [CrossRef]
  5. Bishop, C. Complex Analysis I, MAT 536, Spring 2024. Stony Brook University, Dep Mathematics, 100 Nicolls Road, Stony Brook, NY 11794, 2024. [Google Scholar]
  6. Álvarez Tuñón, O.; Brodskiy, Y.; Kayacan, E. Loss it right: Euclidean and Riemannian metrics in learning-based visual odometry. arXiv 2023, arXiv:2401.05396v1 [cs.CV]. [Google Scholar] [CrossRef]
  7. Xu, W.; Pang, H.K.; Li, W.; Huang, X.; Guo, W. On the explicit expression of chordal metric between generalized singular values of Grassmann matrix pairs with applications. SIAM J. Matrix Anal. Appl. 2018, 39, 1547–1563. [Google Scholar] [CrossRef]
  8. Sun, J.-g. Perturbation theorems for generalized singular values. J. Comput. Math. 2025, 1, 233–242. [Google Scholar]
  9. Sasane, A. A refinement of the generalized chordal distance. SIAM J. Control & Optimiz. 2014, 52, 3538–3555. [Google Scholar] [CrossRef]
  10. Bavely, C.; Stewart, G.W. An algorithm for computing reducing subspaces by block diagonalization. SIAM J. Numer. Anal. 1979, 16, 359–367. [Google Scholar] [CrossRef]
  11. Golub, G.H.; Van Loan, C.F. Matrix Computations, fourth ed.; The Johns Hopkins University Press: Baltimore, Maryland, 2013. [Google Scholar]
  12. Wilkinson, J.H. The Algebraic Eigenvalue Problem; Oxford University Press (Clarendon): Oxford, UK, 1965. [Google Scholar]
  13. Wilkinson, J.H. Kronecker’s canonical form and the QZ algorithm. Lin. Alg. Appl. 1979, 28, 285–303. [Google Scholar] [CrossRef]
  14. Stewart, G.W. On the sensitivity of the eigenvalue problem Ax=λBx. SIAM J. Numer. Anal. 1972, 9, 669–686. [Google Scholar] [CrossRef]
  15. Demmel, J.W. The condition number of equivalence transformations that block diagonalize matrix pencils. SIAM J. Numer. Anal. 1983, 20, 599–610. [Google Scholar] [CrossRef]
  16. Kågström, B.; Westin, L. Generalized Schur methods with condition estimators for solving the generalized Sylvester equation. IEEE Trans. Automat. Contr. 1989, 34, 745–751. [Google Scholar] [CrossRef]
  17. Anderson, E.; Bai, Z.; Bischof, C.; Blackford, S.; Demmel, J.; Dongarra, J.; Du Croz, J.; Greenbaum, A.; Hammarling, S.; McKenney, A.; et al. LAPACK Users’ Guide: Third Edition; Software · Environments · Tools, SIAM: Philadelphia, 1999. [Google Scholar]
  18. MathWorks®. MATLAB™, Release R2024b.; The MathWorks, Inc.: 3 Apple Hill Drive, Natick, MA, 01760, 2024.
  19. Wolfram, S. The Story Continues: Announcing Version 14 of Wolfram Language and Mathematica, 2024. Available online: http://writings.stephenwolfram.com/2024/01/the-story-continues-announcing-version-14-of-wolfram-language-and-mathematica (accessed on 3 May 2025).
  20. Malcolm, M.A. Algorithms to reveal properties of floating-point arithmetic. Commun. ACM 1972, 15, 949–951. [Google Scholar] [CrossRef]
  21. Gentleman, W.M.; Marovich, S.B. More on algorithms that reveal properties of floating point arithmetic units. Commun. ACM 1974, 17, 276–277. [Google Scholar] [CrossRef]
  22. Boyd, S.; Vandenberghe, L. Convex Optimization; Cambridge University Press: Cambridge, United Kingdom, 2004. [Google Scholar]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.
Prerpints.org logo

Preprints.org is a free preprint server supported by MDPI in Basel, Switzerland.

Subscribe

Disclaimer

Terms of Use

Privacy Policy

Privacy Settings

© 2025 MDPI (Basel, Switzerland) unless otherwise stated