Next Article in Journal
A Machine Proof of the Filter-Method Construction for Real Numbers
Previous Article in Journal
Return Level Prediction with a New Mixture Extreme Value Model
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Computation of the Approximate Symmetric Chordal Metric for Complex Numbers

Technical Sciences Academy of Romania, 030167 Bucharest, Romania
Mathematics 2025, 13(17), 2706; https://doi.org/10.3390/math13172706
Submission received: 21 May 2025 / Revised: 6 August 2025 / Accepted: 15 August 2025 / Published: 22 August 2025
(This article belongs to the Section E: Applied Mathematics)

Abstract

The basic theoretical properties of the approximate symmetric chordal metric (ASCM) for two real or complex numbers are 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 the chordal metric by including the modulus of the difference of the numbers. ASCM is not a true mathematical distance, but is a useful replacement for a distance in some applications. For instance, sensitivity analysis or block diagonalization of matrix pencils benefit from a measure of closeness of eigenvalues and also of their reciprocals; ASCM is ideal for this purpose. The proposed algorithms can be easily implemented on various architectures and compilers. Extensive numerical tests were performed to assess the performance of the associated implementation. The results were compared to those obtained in MATLAB, but with appropriate modifications for numbers very close to the bounds of the range of representable values, where the usual formulas give wrong results.
MSC:
15A20; 15A22; 65Y04; 68-04; 68Q25; 93B11

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. It is not a true mathematical distance, but can be used instead of a distance in some applications.
The approximate symmetric chordal metric in (1) measures the closeness of two numbers. In mathematics, a measure is a function that assigns a non-negative number to certain subsets of a set. Using pairwise distances (1) of a set of numbers, it is possible to build subsets (clusters) and a measure of their closeness. Measures are used in various fields, including analysis, probability theory, and geometry, as well as in sophisticated investigations and computational techniques.
There are quite a number of references on the chordal metric, but no references to the approximate symmetric chordal metric could be found. Klamkin and Meir [1] have shown that the chordal metric on a normed linear space, defined as d ( x , y ) = x y / x / y , x, y 0 , satisfies the triangle inequality. Let S 2 R 3 be the Riemann sphere with diameter 1 and center ( 0 , 0 , 1 / 2 ) . With z, w C , d ( z , w ) = | z w | Euclidean metric in C , the chordal metric of S 2 is [2,3,4]
d ̲ ( z , w ) : = d ( χ ( z ) , χ ( w ) ) = | z w | 1 + | z | 2 1 + | w | 2 ,
where χ : C S 2 N : z ( ( z ) , ( z ) , | z | 2 ) / ( 1 + | z | 2 ) is the stereographic projection, C is the complex plane, and N is the north pole of S 2 . Clearly, d ( χ ( z ) , χ ( w ) ) = 0 d ( z , w ) = 0 and d ̲ ( z , w ) = d ̲ ( 1 / z , 1 / w ) . If z , then χ ( z ) N . This way, χ maps the extended complex plane C ¯ = C { } to S 2 . The chordal metric is indeed a distance, since d ( χ ( z ) , χ ( w ) ) satisfies triangle inequality. If w , then d ̲ ( z , w ) 1 / 1 + | z | 2 , and if z too, then d ̲ ( z , w ) 0 . If a sphere with unit radius and center in the origin is used, the right hand side in (2) is multiplied by 2 [3,5].
Several authors present theoretical results and various applications of the chordal metric. Rainio and Vuorinen [4] use (2) to identify cases where the distortion caused by symmetrization of a quadruple of objects, mapped by a Möbius transformation, can be measured in terms of its Lipschitz constant in the Euclidean or the chordal metric. Álvarez-Tuñón et al. [6] investigate various pose representations in visual odometry networks, and show that the chordal distance between two rotations ensures faster convergence of the parameters than distances measured by Euler angles or quaternions. Xu et al. [7] provide sharper bounds of the chordal metric between generalized singular values of Grassmann matrix pairs. Sun [8] shows that the generalized singular values of [ A ; B ] , with  rank ( [ A ; B ] ) < n , and A and B complex m × n and p × n , are insensitive to strong 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 transfer functions and shows that strong stabilizability is a robust property in this metric. A refinement of this metric for stable transfer functions is introduced in [9].
A possible application of the approximate symmetric chordal metric is ordering the (generalized) eigenvalues of a matrix (pencil), according to their pairwise distances measured using (1). This is important in numerical linear algebra, control theory, and other domains. For instance, it is essential for computing invariant or deflating subspaces of matrices or matrix pencils, respectively, or of their block-diagonal form [10]. The available algorithms for finding this form use non-unitary transformation matrices with a controlled numerical condition, but they can be inefficient for a matrix (pencil) with dense clusters of eigenvalues. Since the numerical condition is related to the sensitivity of the spectrum associated to the current block (pair) that should be split, a clever strategy for ordering the eigenvalues may increase the efficiency. The sensitivity of eigenvalue problems is 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 recent releases of interactive environments like MATLAB [18] or Mathematica [19]. The applications mentioned in this paragraph do not need the triangle inequality, but it is important that close eigenvalues be included in the same cluster. With (1), an eigenvalue a 2 will be added to a cluster containing a value a 1 if either d 1 or d 2 is smaller than a given threshold. If a 1 0 , a 2 0 , d 2 = | a 1 a 2 | / | a 1 | / | a 2 | coincides to the chordal metric in [1], and it is an approximation of the value given by (2). So, an approach based on the chordal metric will choose d 2 or its approximation, even if d 1 < d 2 . If a 1 and a 2 are eigenvalues for a matrix pencil defined by A λ B , then 1 / a 1 and 1 / a 2 are eigenvalues of the matrix pencil B μ A . Since A and B have a symmetric role, it is reasonable to consider the closeness of eigenvalues for both A λ B and B μ A .
The idea of decoupling a dynamical system to simpler subsystems, preserving the essential dynamics, has been recently extended to certain nonlinear systems, mainly described by ordinary differential equations (ODE) or difference equations. A so-called normal form is obtained using a near-identity transformation of coordinates, preserving the essential system behavior near an equilibrium point. Higher-order Taylor expansion of the system model can capture the major nonlinear effects. An application of the normal form theory to power systems described by differential algebraic equations (DAE) is studied in [20]. The new, structure-preserving method allows direct application of the theory to the DAE system.
A main contribution of the paper is the systematic presentation of the properties of the approximate symmetric chordal metric and of reliable, accurate and efficient algorithms for its computation. A factored representation of the modulus of complex numbers is introduced, which allows obtaining very accurate results for the entire range of the floating point system. Two different approaches to evaluate d 2 are described. The most efficient approach needs only the moduli of the two numbers and of their difference, but it cannot be used if that difference is not in the range of representable numbers. The proposed algorithms were implemented in Fortran and exhaustively tested in MATLAB.
The rest of the paper is organized as follows. Section 2 summarizes the notation and the main issues concerning the floating point system of computers, needed in the sequel. Section 3 investigates the properties of the approximate symmetric chordal metric, while Section 4 presents reliable, accurate, and efficient algorithms for its computation. Section 5 discusses the numerical results obtained using a careful implementation of these algorithms. Section 6 summarizes the conclusions.

2. Preliminaries

For technical convenience, R ¯ will denote the real numbers field R extended by the and symbols, and similarly for C ¯ . A complex number a = α + β 𝚤 , with  α , β R ¯ , is infinite if α = ± and/or β = ± ; otherwise, a is finite. Let a 1 = α 1 + β 1 𝚤 , a 2 = α 2 + β 2 𝚤 be two finite complex numbers. For performing computations with/on a 1 and a 2 , it should be assumed that α i and β i , i = 1 , 2 , are in the range of the computer floating point system, that is, a 1 and a 2 are (approximately) representable by their real and imaginary parts. Hence, | α i | , | β i | K , i = 1 , 2 , where K is the maximum representable number,
K : = b e M ( 1 ϵ ) ,
with b the base of the numeral system, e M the maximum exponent, and  ϵ the relative machine precision. In a common binary double precision floating point system, b = 2 , e M = 1024 , ϵ = 2 1 t (or ϵ = 2 t for machines with proper rounding), and t = 53 is the number of base digits in the mantissa. The number ε = b ϵ is called precision. Representable real numbers in a digital computer are rational approximations of values in the range K , K . An overflow is generated if an arithmetic operation would produce a result outside this range. 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. Hence, overflows should be avoided. Very small (in magnitude) numbers may also be not representable, and if this so-called underflow happens after an arithmetic operation, the result is set to zero. 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 . Algorithms for discovering the properties of the floating point arithmetic, as in [21,22], are implemented, e.g., in the SLAMCH and DLAMCH routines of the LAPACK package [17], for single and double precision computations, respectively.
The assumption that | α i | , | β i | K , does not imply that | a i | K . If | α 1 | = K and | β 1 | = K , then | a 1 | = K 2 , which is not representable. The specific case of our problem allows working with a factored form of | a 1 | and | a 2 | .

3. Basic Properties of the Approximate Symmetric Chordal Metric

In some applications using the (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 can be infinite even for regular matrix pencils. If a 1 = a 2 = in (1), for  a 1 , a 2 R ¯ , then d 1 is . A Not-a-Number entity is represented by NaN in compilers and interactive environments, and  special computer rules are used for mathematical operations. Specifically, in the paper context, the basic rules are | NaN | = NaN , min ( NaN , a ) = a , max ( NaN , a ) = a , a C ¯ . The properties below follow directly from (1) and these rules.
  • Basic properties of d in (1). Let a, a 1 , a 2 C ¯ . Then, with (1)
  (i)
d ( a 1 , a 2 ) = d ( a 2 , a 1 ) ;
 (ii)
d ( a , 0 ) = | a | ;
(iii)
d ( a , a ) = 0 ;
(iv)
d ( a 1 , a 2 ) = 0 a 1 = a 2 ;
 (v)
d ( a 1 , a 2 ) = 1 / | a 1 | , if a 2 is infinite;
(vi)
d ( a 1 , a 2 ) > 0 if a 1 a 2 and a 1 or a 2 , or both, are finite.
Remark 1.
The three properties of a distance or metric, namely, symmetry (i), identity (iv), and non-negativity (iii) and (vi), 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), in general. Consequently, d ( a 1 , a 2 ) is not a distance or metric function. Moreover, d ( s a 1 , s a 2 ) may differ from | s | d ( a 1 , a 2 ) , with  a 1 , a 2 , s C . Such property holds for | a 1 a 2 | and for | 1 / a 1 1 / a 2 | , but not necessarily for their minimum.
Definition 1.
(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 representationof | a | .
From Definition 1, it follows that δ 1 , 2 , since δ = 1 if m = 0 , δ = 2 if m = M , and  δ 1 , 2 for m / M 0 , 1 . Factored representation is useful when M is very close or coincides to K. Then, M δ could exceed K, and  | α | cannot be computed. Still, its factors can be used for finding the approximate symmetric chordal metric.

4. Algorithms for Computing the Approximate Symmetric Chordal Metric

A mathematical-style pseudocode is used for each algorithm. A MATLAB-style function construct, with possibly optional arguments, is adopted for calling lower level algorithms. See Remark 3 in Section 4.2. The symbols ∧, ∨, and ¬, appearing in the algorithms and their description, 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 work correctly 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 is 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,23]. There are several definitions for a flop, but counting each arithmetic operation is suitable in the paper context.

4.1. Main Algorithm

This subsection presents the main algorithm, chordal (Algorithm 1). The lower level algorithms are introduced in the next subsections.
Algorithm 1  chordal computes ASCM for two complex numbers
  • Require:  a 1 , a 2 C ¯ r , a i = α i + β i 𝚤 , K in (3), ε .
  • Ensure:  d : = d ( a 1 , a 2 ) = min ( | a 1 a 2 | , | 1 / a 1 1 / a 2 | )
  •      M i = max ( | α i | , | β i | ) , i = 1 , 2 , M = max ( M 1 , M 2 )
  •     if  M = 0 or a 1 = a 2  then
  •         d = 0
  •     else
  •         κ = K / 2 , u i = M i κ , i = 1 , 2
  •        if  M 1 = 0  then
  •           [ d , u 2 ] = absa ( a 2 , u 2 , M 2 , K )
  •          if  ¬ u 2 , d = , end if
  •        else if  M 2 = 0  then
  •           [ d , u 1 ] = absa ( a 1 , u 1 , M 1 , K )
  •          if  ¬ u 1 , d = , end if
  •        else
  •           m = min ( M 1 , M 2 ) , f = m / M ε / 4
  •          if f then
  •             for  i = 1 , 2  do
  •                j = i + 1 , if  j > 2 , j = 1 , end if
  •               if  M = M i  then
  •                  if  m < 0.1 / M  then
  •                     d = absa ( a i , u i )
  •                  else if  m > 1.1 / M  then
  •                     d = 1 / absa ( a j , u j )
  •                  else
  •                     d = min absa ( a i , u i ) , 1 / absa ( a j , u j )
  •                  end if
  •               end if
  •             end for
  •          else
  •              [ δ 1 , u 1 ] = absa ( a 1 , u 1 , M 1 , K ) , [ δ 2 , u 2 ] = absa ( a 2 , u 2 , M 2 , K )
  •              [ σ r , ϕ r ] = subtract ( α 1 , α 2 , K , ε ) , [ σ i , ϕ i ] = subtract ( β 1 , β 2 , K , ε )
  •             if  ϕ r ϕ i  then
  •                M d = max ( | σ r | , | σ i | ) , u d = M d κ , [ δ d , u d ] = absa ( σ r + σ i 𝚤 , u d , M d , K )
  •                [ d 2 , M δ ] = d 2 byd 1 ( δ 1 , u 1 , M 1 , δ 2 , u 2 , M 2 , δ d , u d , M d , M , m )
  •               if  M δ < 1  then
  •                   d = d 2
  •               else
  •                   d = min ( δ d , d 2 )
  •               end if
  •             else
  •                [ ξ r , ξ i ] = inva ( a 1 , δ 1 , u 1 , M 1 ) , [ ζ r , ζ i ] = inva ( a 2 , δ 2 , u 2 , M 2 )
  •                τ r = subtract ( ξ r , ζ r , K , ε ) , τ i = subtract ( ξ i , ζ i , K , ε )
  •                d = absa ( τ r + τ i 𝚤 , true )
  •             end if
  •          end if
  •        end if
  •     end if
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 the basic property (iii). Otherwise, if  M 1 = 0 , that is, if  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 (Algorithm 2), 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 . If u = true on input to absa, but also on its output, then the absolute value has been obtained. If u = false on output from absa, then the absolute value would exceed K in (3); hence, a factored representation has to be used. The chosen κ is the largest number for which the absolute value is at most K. The algorithm will work correctly for smaller values of κ , but the computations would be somewhat more expensive.
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 sufficiently larger than 1 / M , then d 1 > d 2 , and so d = d 2 . The bounds 0.1 and 1.1 were found after several 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 1, 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 . 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 .
The definition of the logical variable f uses the value of ε / 4 . This value guarantees that one of the given numbers is indeed negligible compared to the other. Larger values, such as ε / 3 might not do that. Smaller values can always be used, but the computations would be somewhat more expensive, since simplified formulas will not be used in all possible cases.
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 often 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 main 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 i | , 1 / | a j | . Hence, in addition to the initialization 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.

4.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 1, namely, M = max ( | α | , | β | ) , and  δ = 1 + ( m / M ) 2 1 , 2 , with m = min ( | α | , | β | ) .
For example, for  a = K + K 𝚤 with K in (3), 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 δ is 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 , u, M, K
  • Ensure:  δ , u ( | a | = δ , if u is true on exit; otherwise M and δ are factors of | a | )
  •     if u then
  •         δ = α 2 + β 2
  •     else
  •         m = min ( | α | , | β | ) , δ = 1 + ( m / M ) 2 , u = M K / δ
  •        if u then
  •           δ = 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 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 performed, 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 4.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,
δ 1 , u 1 = absa a 1 , u 1 , M 1 , K
where | a 1 | = δ 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. If it is known in advance that u 1 will remain true on exit, then M 1 and K can be omitted as input arguments, and u 1 can be omitted as an output argument. This is possible in all cases when f =  true. For instance, if  M = M 1 and m > 1.1 / M , then d = 1 / | a 2 | and k 2 | a 2 | < K 2 , since | a 2 | | a 1 | . The first inequality assumes that min | α 2 | , | β 2 | k , with k the underflow threshold. With this assumption, | a 2 | k 2 ; hence, the factored form is not needed for numbers close to underflow. However, the computation of | a 2 | in such a case should still be performed using its factors M 2 and δ 2 , for accuracy. For instance, | k + k 𝚤 | = k 2 3 . 15 e 308 , while the naïve computation will return 0.

4.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 the 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 estimating their possible occurrence. This is performed in an algorithm 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 (Algorithm 3) below.
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 the sign function 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 a 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, σ = α γ .
Algorithm 3 subtract computes the difference of two real 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
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 succeeds in obtaining 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 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.

4.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 described in Section 4.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 (Algorithm 4) 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 last 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 exceed K ε / 4 , because otherwise the special case f = true , already detected by Algorithm chordal, appears.
Algorithm 4 d2byd1 computes d 2 in (1) using d 1
  • Require:  δ 1 , u 1 , M 1 , δ 2 , u 2 , M 2 , δ d , u d , M d , M , m
  • Ensure:  d 2 , M δ ( d 2 = d δ = d 1 if u 1 = u 2 = u d = true and M δ < 1 )
  •      M δ = 1
  •     if  u d  then
  •        if  u 1 u 2  then
  •           M δ = max ( δ 1 , δ 2 )
  •          if  M δ < 1  then
  •              d 2 = δ d
  •          else
  •              d 2 = ( δ d / M δ ) / min ( δ 1 , δ 2 )
  •          end if
  •        end if  u 1  then
  •           d 2 = ( δ d / δ 2 ) / M 2 / δ 1
  •        end if  u 2  then
  •           d 2 = ( δ d / δ 1 ) / M 1 / δ 2
  •        else
  •           d 2 = ( δ d / δ 1 / δ 2 ) / M / m
  •        end if
  •     else
  •        if  u 1 u 2  then
  •           d 2 = δ d / min ( δ 1 , δ 2 ) M d / max ( δ 1 , δ 2 )
  •        end if  u 1  then
  •           d 2 = ( δ d / δ 2 ) / δ 1 M d / M 2
  •        end if  u 2  then
  •           d 2 = ( δ d / δ 1 ) / δ 2 M d / M 1
  •        else
  •           d 2 = ( δ d / δ 1 / δ 2 ) / m M d / M
  •        end if
  •     end if
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 ∧, and a max operation, if  M δ < 1 , and another min operation, and two divisions, otherwise. If u d = false , an additional multiplication with M d is also required in all these four cases.
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.

4.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, as shown in Algorithm inva (Algorithm 5).
Algorithm 5 inva computes the reciprocal of a complex number given its modulus or factored representation
  • Require:  a = α + β 𝚤 C ¯ r , δ , u, M ( | a | = δ if u = true ; otherwise M and δ are factors of | a | )
  • Ensure:  μ , ν so that 1 / a = μ + ν 𝚤
  •     if u then
  •         μ = ( α / δ ) / δ , ν = ( β / δ ) / δ
  •     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. Therefore, 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 eight divisions if u = false , but it should be applied to both 1 / a 1 and 1 / a 2 . Therefore, two tests and eight, twelve or sixteen 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 applied, namely, when d 1 overflows.
Remark 5.
The implementation inlines the low level algorithms, except for Algorithm subtract, that is more involved and is called twice, 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  absais called at most four times, and Algorithm d2byd1 is inlined once. Inlining increases the efficiency, since it avoids passing input and output arguments, and duplicating some evaluations of internal variables. It may also increase the accuracy, since values stored in registers might be used.

5. 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 block diagonalization of matrix pencils is considered as an application, and two examples are shown. The performance of two solution approaches for a matrix pencil 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. The computations were performed in double precision on an Intel Core i7-3820QM portable computer (2.7 GHz, 16 GB RAM) under a Windows operating system and a recent version of MATLAB. The algorithms were implemented in Fortran and MATLAB, and a MEX-file calling the Fortran routines was used for the tests. The author’s preliminary implementations are already available in the SLICOT Library (Version v5.9) on GitHub (see https://github.com/SLICOT/SLICOT-Reference (accessed on 3 May 2025), and they will soon be updated.

5.1. Detailed Examples

The numerical results for four examples are presented and compared with those obtained through direct use of the 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 with 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 = I n f . 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 command1/agives 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
1 / a = a ¯ / | a | 2 = ( 1 . 1 6 e 30 8 1 . 6 6 e 30 8 𝚤 ) / M / δ / M / δ = 2 . 82844045645176 8 e 3 09 4 . 04759582561201 4 e 30 9 𝚤 ,
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 the 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 large 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 large 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, Algorithminva  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 ε .

5.2. Large Experiment with Randomly Generated Examples

In a run with 4,188,166 random examples, the first three examples had a 2 = 0 , a 1 = 0 , and  a 1 = a 2 = 0 . Specifically, all examples were 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 . 22507385850720 1 e 30 8 (realmin) and 8.988465674311580e+307, which is very close to, but smaller than K / 2 , K = 1 . 7976931348623 16 e + 3 08 (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 exceed 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 it is used to obtain a 1 ; a 2 is generated as above. The last part also sets s 2 = K , and uses it to obtain a 2 . Clearly, complex numbers with | a 1 | > K and/or | a 2 | > K are generated.
For reproducibility of the results, the command sequence above was 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 was run repeatedly several times, but the rng( ’default’ ) command was placed just before the first run. This way, a larger number of tests were performed.
After each of the first three MATLAB commands, inside the (internal) loops, and after the last command, 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 4. This is needed since using (1) directly might return inaccurate results, as shown in Section 5.1.
The maximum relative error in this run was 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. Note that with another definition, | d d ^ | / d , if  d 0 , and  | d d ^ | , otherwise, its maximum value was 0.2649. However, the value became zero when using the modified MATLAB code, based on algorithms described in the previous section. After ten consecutive runs (without reinitialization of the random number generator between runs), the maximum relative error and its mean value were 7.6144e-16 and 6.3663e-16, respectively, while using the second definition, the values were 0.73077 and 0.35080, and they became zero with the modified MATLAB code.
In this test sequence, there were 3,970,109 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, 1,985,994 and 1,984,115 examples have M = M 1 and M = M 2 , respectively. From those with M = M 1 , 987,937 have d = | a 1 | , 994,601 have d = 1 / | a 2 | , and 3456 have d = min | a 1 | , 1 / | a 2 | . From examples with M = M 2 , 987,834 have d = | a 2 | , 992,853 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 , were 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 were true. Using a factored representation has never been necessary for any of these 3,970,109 examples.
A summary of the number of examples needing only to compute | a 1 | and/or | a 2 | is presented in Table 1.
For the remaining 218,055 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 . All these examples needed both | a 1 | and | a 2 | values to compute d 1 and d 2 . A factored representation for | a 1 | was 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. Table 2 summarizes the number of examples with and without a factored representation for | a 1 | and | a 2 | .
To get d 1 (also denoted d δ in the pseudocodes), Algorithm subtract was used to obtain the real and imaginary parts, σ r and σ i , of  σ : = a 1 a 2 . For three and two examples, σ r and σ i , respectively, would exceed K in magnitude. For the other 218,050 examples, d 1 = | σ | was evaluated using Algorithm absa, and  d 2 could be obtained from d 1 via Algorithm d2byd1. Specifically, u d was true on input to absa for 217,980 examples, and it was false for the remaining 70 examples with expected overflow; but for 12 out of 70 examples, u d was reset to true, since d 1 = M d δ d K ; therefore, d 1 needed the factored representation defined by M d and δ d for only 58 examples. Moreover, 107,475 out of the 218,050 examples satisfied the conditions u d = u 1 = u 2 = true and M δ : = max | a 1 | , | a 2 | < 1 , which implies that d 2 > d 1 ; hence, d = d 1 , and  d 2 was not needed. For the remaining 110,575 examples, d = min d 1 , d 2 , with  d 2 evaluated using d 1 (or M δ and d δ ), | a 1 | (or M 1 and δ 1 ) and | a 2 | (or M 2 and δ 2 ). Specifically, for the four cases with u d = true in Algorithm d2byd1 ( u 1 u 2 = true and M δ 1 , u 1 = true and u 2 = false , u 1 = false and u 2 = true , and  u 1 = u 2 = false ), there were 110,514, zero, two, and one examples, respectively. Similarly, for the four cases with u d = false , there were zero, six, 51, and one examples, respectively.
Clearly, for the five examples for which d 1 could not be computed, d 1 > d 2 ; hence, d = d 2 = | 1 / a 1 1 / a 2 | was evaluated by calling twice Algorithm inva (for a 1 and a 2 ) and Algorithm subtract (for the real and imaginary parts of 1 / a 1 1 / 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 were applied. Then, τ = 1 / a 1 1 / a 2 was 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 = | τ | was found by Algorithm absa.
A summary of the number of examples needing to compute d 1 and/or d 2 is presented in Table 3. Table 4 shows the number of examples with/without a factored representation for d 1 and d 2 . Note that d 2 is always representable.
The results presented and summarized in the tables show that all examples were solved using the simplest possible formulas, which proves the efficiency of the implementation. Moreover, it was checked that the results were practically the same with those obtained when d 2 was always computed using (6).
This demonstrates that the accuracy was preserved using the simplified formulas.

5.3. Application: Block Diagonalization of Matrix Pencils

This subsection presents the results obtained for block diagonalization of matrix pencils. The approximate symmetric chordal metric is used to measure the “distances” between eigenvalues, and based on this, to reorder and group them in clusters for reducing the condition numbers of the transformation matrices involved in the process.
Two examples with different levels of difficulty are described.
A random example. A matrix pencil of order n = 100 was generated using normally distributed pseudorandom numbers produced by the following MATLAB commands:
  • rng( ’default’ );  n = 100;
  • A = randn( n );    B = randn( n );
  • p = 10^3*rand( n, 1 );  q = rand( n, 1 )/10^2;
  • P = diag( p );  Q =  diag( q );  A = P*A*Q;  B = P*B*Q;
The vectors p and q, drawn from a uniform distribution, are used to scale the rows and columns, respectively, of A and B. The spectrum of the scaled matrix pencil A λ B is shown in Figure 1.
The Euclidean norms of A and B and the ranges of their elements are listed in Table 5. The values are rounded to five significant digits.
A MATLAB-executable, developed by the author, was used to perform the block diagonalization of the scaled matrix pencil A λ B . The executable has an option to work on general matrices, or on matrices already reduced to the generalized Schur form [17], A ˜ , B ˜ , with A ˜ = Q T A Z , B ˜ = Q T B Z , where Q and Z are orthogonal (hence, Q T Q = Q Q T = I n and Z T Z = Z Z T = I n , with I n the identity matrix of order n); B ˜ is upper triangular, and A ˜ is block upper triangular with diagonal blocks of order 1 or 2, corresponding to real or complex conjugate eigenvalues, respectively. (All elements under the diagonal of B ˜ and under the diagonal blocks of A ˜ are zero.) The block diagonalization algorithm acts on A ˜ and B ˜ . An essential part of the computations is the solution of a generalized Sylvester equation. Since this involves non-unitary transformations, their elements should be bounded, to ensure good accuracy. Specifically, if any of these elements exceeds a given threshold θ , the process is stopped, and solving an enlarged Sylvester equation is tried. If many failed attempts are involved, the computational effort might be unacceptably high. Using the bound θ = 5000 and default options (the diagonal blocks are not reordered before each reduction step, the left and right transformations are updated), the algorithm computed the transformed matrix pencil A ^ λ B ^ , with A ^ : = Q ^ T A Z ^ , B ^ : = Q ^ T B Z ^ , Q ^ = Q ˜ Q , Z ^ = Z ˜ Z , where Q ˜ and Z ˜ are the global transformations applied to A ˜ and B ˜ by the block diagonalization algorithm. The reduced matrix A ^ is block diagonal (see Figure 2), with diagonal blocks of order 1 and 2, while matrix B ^ is diagonal. There are 14 block pairs of order 1 and 43 block pairs of order 2. Since the original pencil has 14 real eigenvalues, the maximal possible reduction (with real arithmetic) was obtained.
Let e a ( A ) : = A ^ Q ^ T A Z ^ and e a ( B ) : = B ^ Q ^ T B Z ^ be the absolute errors of A ^ and B ^ with respect to the transformed matrices Q ^ T A Z ^ and Q ^ T B Z ^ , respectively, and let e r ( A ) and e r ( B ) be their relative errors, i.e., e r ( A ) = e a ( A ) / A , e r ( B ) = e a ( B ) / B , with · the Euclidean norm. Similarly, let e a ( λ ) and e r ( λ ) be the absolute and relative errors of the eigenvalues λ ^ of the matrix pencil A ^ λ B ^ with respect to the eigenvalues λ ˜ of the matrix pencil A ˜ λ B ˜ . If the eigenvalue problem is well conditioned, then λ ˜ are very close to the true eigenvalues λ of the matrix pencil A λ B . These errors are reported in Table 6.
All these errors are as good as possible for such a problem, which shows that the block diagonalization was successful. The reduced matrix pencil can be used efficiently instead of the original pencil, e.g., for computing matrix functions or the responses of a linear descriptor system. In this case, the input and output matrices of the system should be updated with the computed transformation matrices Q ^ and Z ^ .
An example with dense clusters of eigenvalues. A matrix pencil of order n = 999 with many clustered eigenvalues is considered now. The matrices A and B are already reduced to the generalized real Schur form. The spectrum is shown in Figure 3. It has 107 real and 446 complex conjugate eigenvalues.
The Euclidean norms of A and B and the ranges of their elements are listed in Table 7. The values are rounded to five significant digits.
Using the approach described for the randomly generated example, a solution with 135 diagonal block pairs was computed in 62.68s (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 the pairwise “distances” between eigenvalues, measured by the approximate symmetric chordal metric, another solution was computed in 4.6905s; hence, the execution time was 13.36 times shorter. Specifically, 763 selected eigenvalues were moved to the leading positions, obtaining the matrices A ˜ and B ˜ . The needed transformation matrices, Q ˜ and Z ˜ , were computed. This reordering process, including the computation of Q ˜ and Z ˜ , needed 2.4826s. The block diagonalization was then applied to the matrices A ˜ and B ˜ , and it took 2.2078s. The relative errors in the transformed matrices and eigenvalues for the two computational stages are shown in Table 8.
Compared to the first approach, more block pairs, namely, 141, were 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; so, all real eigenvalues were available in the largest block pair. The efficiency gain is mainly due to better eigenvalue reordering, which reduced the number of failed attempts to solve the generalized Lyapunov equations. However, it is worth noting that the number of “distances” between eigenvalues is n ( n 1 ) / 2 = 498501 ; hence, it increases quadratically with the problem size. Therefore, it is important that the algorithms for computing the approximate symmetric chordal metric are as fast as possible.
The computed matrix A ^ has 140 2 × 2 diagonal blocks followed by a 719 × 719 diagonal block. The matrix B ^ is diagonal with positive diagonal elements.

6. 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 were performed to assess the performance of the associated implementation. The results were compared to those obtained in MATLAB, but with appropriate modifications for numbers very close to the bounds of the range of representable values, where the usual formulas give wrong results, as shown in several detailed numerical examples. As an application, the block diagonalization of matrix pencils is considered and two examples are investigated. The largest order example illustrates the efficiency improvement possible using a proper eigenvalue reordering strategy and fast algorithms for computing the approximate symmetric chordal metric. The algorithms can be used for applications using the chordal metric, if the triangle inequality is not required.

Funding

This research received no external funding.

Data Availability Statement

The raw data supporting the conclusions of this article will be made available by the authors on request.

Conflicts of Interest

The author declares 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_vn_r.pdf (accessed on 3 May 2025).
  4. Rainio, O.; Vuorinen, M. Lipschitz constants and quadruple symmetrization by Möbius transformations. Complex Anal. Its 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, USA, 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.05396. [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 Optim. 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, 4th ed.; The Johns Hopkins University Press: Baltimore, MD, USA, 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. Linear Algebra Its 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. Autom. Control 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, 3rd ed.; Software·Environments·Tools, SIAM: Philadelphia, PA, USA, 1999. [Google Scholar]
  18. MathWorks®. MATLAB™, Release R2024b; The MathWorks, Inc.: Natick, MA, USA, 2024. [Google Scholar]
  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. Wang, B.; Kestelyn, X.; Kharazian, E.; Grolet, A. Application of Normal Form Theory to Power Systems: A Proof of Concept of a Novel Structure-Preserving Approach. In Proceedings of the 2024 IEEE Power & Energy Society General Meeting (PESGM), Seattle, WA, USA, 21–25 July 2024; pp. 1–5. [Google Scholar] [CrossRef]
  21. Malcolm, M.A. Algorithms to reveal properties of floating-point arithmetic. Commun. ACM 1972, 15, 949–951. [Google Scholar] [CrossRef]
  22. 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]
  23. Boyd, S.; Vandenberghe, L. Convex Optimization; Cambridge University Press: Cambridge, UK, 2004. [Google Scholar]
Figure 1. The spectrum of the randomly generated matrix pencil A λ B of order 100.
Figure 1. The spectrum of the randomly generated matrix pencil A λ B of order 100.
Mathematics 13 02706 g001
Figure 2. The form of the reduced matrix A ^ of the matrix pencil of order 100.
Figure 2. The form of the reduced matrix A ^ of the matrix pencil of order 100.
Mathematics 13 02706 g002
Figure 3. The spectrum of the matrix pencil A λ B of order 999 with dense clusters.
Figure 3. The spectrum of the matrix pencil A λ B of order 999 with dense clusters.
Mathematics 13 02706 g003
Table 1. Number of examples needing only | a 1 | and/or | a 2 | (case f = true , 94.794% of all examples).
Table 1. Number of examples needing only | a 1 | and/or | a 2 | (case f = true , 94.794% of all examples).
| a 1 | | a 2 | 1 / | a 1 | 1 / | a 2 | min | a 1 | , 1 / | a 2 | min | a 2 | , 1 / | a 1 |
987,937987,834992,853994,60134563428
Table 2. Number of examples with/without a factored representation for | a 1 | and | a 2 | (case f = false , 5.206% of all examples).
Table 2. Number of examples with/without a factored representation for | a 1 | and | a 2 | (case f = false , 5.206% of all examples).
| a 1 | (Not Factored) | a 1 | Factors δ 1 , M 1 | a 2 | (Not Factored) | a 2 | Factors δ 2 , M 2
217,99956218,04312
Table 3. Number of examples needing to compute d 1 and/or d 2 (case f = false , 5.206% of all examples).
Table 3. Number of examples needing to compute d 1 and/or d 2 (case f = false , 5.206% of all examples).
d = d 1 = | a 1 a 2 | d = min d 1 , d 2 1 d = d 2 = | 1 / a 1 1 / a 2 | 2
107,475110,5755
1 Use Algorithms absa, subtract, and d2byd1. 2 Use Algorithms absa, inva, and subtract.
Table 4. Number of examples with/without a factored representation for d 1 and d 2 (case f = false , 5.206% of all examples).
Table 4. Number of examples with/without a factored representation for d 1 and d 2 (case f = false , 5.206% of all examples).
d 1 (Not Factored) d 1 Factors δ d , M d d 2 (Not Factored) d 2 (Factored)
217,99258110,5800
Table 5. Euclidean norms of A and B and the ranges of their elements for the randomly generated matrix pencil.
Table 5. Euclidean norms of A and B and the ranges of their elements for the randomly generated matrix pencil.
Norm of ANorm of BRange of A ElementsRange of B Elements
92.84497.028[3.0098e-05, 26.278][1.8548e-06, 30.360]
Table 6. Absolute and relative errors of the transformed matrices and eigenvalues.
Table 6. Absolute and relative errors of the transformed matrices and eigenvalues.
e a ( A ) e a ( B ) e r ( A ) e r ( B ) e a ( λ ) e r ( λ )
2.2752e-141.4259e-142.4506e-161.4696e-162.0081e-159.9933e-17
Table 7. Euclidean norms of A and B and the ranges of their elements for the matrix pencil of order 999 with dense clusters.
Table 7. Euclidean norms of A and B and the ranges of their elements for the matrix pencil of order 999 with dense clusters.
Norm of ANorm of BRange of A ElementsRange of B Elements
1.3936e-011.9073e-06[0, 2.5123e-02][0, 4.2904e-07]
Table 8. Relative errors of the transformed matrices and eigenvalues.
Table 8. Relative errors of the transformed matrices and eigenvalues.
Stage e r ( A ) e r ( B ) e r ( λ )
Reordering1.5935e-164.3898e-213.1502e-15
Block diagonalization1.1542e-171.0614e-213.195e-15
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.

Share and Cite

MDPI and ACS Style

Sima, V. Computation of the Approximate Symmetric Chordal Metric for Complex Numbers. Mathematics 2025, 13, 2706. https://doi.org/10.3390/math13172706

AMA Style

Sima V. Computation of the Approximate Symmetric Chordal Metric for Complex Numbers. Mathematics. 2025; 13(17):2706. https://doi.org/10.3390/math13172706

Chicago/Turabian Style

Sima, Vasile. 2025. "Computation of the Approximate Symmetric Chordal Metric for Complex Numbers" Mathematics 13, no. 17: 2706. https://doi.org/10.3390/math13172706

APA Style

Sima, V. (2025). Computation of the Approximate Symmetric Chordal Metric for Complex Numbers. Mathematics, 13(17), 2706. https://doi.org/10.3390/math13172706

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop