math.abs on complex

Percentage Accurate: 53.3% → 100.0%
Time: 1.8s
Alternatives: 4
Speedup: 0.8×

Specification

?
\[\begin{array}{l} \\ \sqrt{re \cdot re + im \cdot im} \end{array} \]
(FPCore modulus (re im) :precision binary64 (sqrt (+ (* re re) (* im im))))
double modulus(double re, double im) {
	return sqrt(((re * re) + (im * im)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function modulus(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    modulus = sqrt(((re * re) + (im * im)))
end function
public static double modulus(double re, double im) {
	return Math.sqrt(((re * re) + (im * im)));
}
def modulus(re, im):
	return math.sqrt(((re * re) + (im * im)))
function modulus(re, im)
	return sqrt(Float64(Float64(re * re) + Float64(im * im)))
end
function tmp = modulus(re, im)
	tmp = sqrt(((re * re) + (im * im)));
end
modulus[re_, im_] := N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{re \cdot re + im \cdot im}
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 53.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{re \cdot re + im \cdot im} \end{array} \]
(FPCore modulus (re im) :precision binary64 (sqrt (+ (* re re) (* im im))))
double modulus(double re, double im) {
	return sqrt(((re * re) + (im * im)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function modulus(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    modulus = sqrt(((re * re) + (im * im)))
end function
public static double modulus(double re, double im) {
	return Math.sqrt(((re * re) + (im * im)));
}
def modulus(re, im):
	return math.sqrt(((re * re) + (im * im)))
function modulus(re, im)
	return sqrt(Float64(Float64(re * re) + Float64(im * im)))
end
function tmp = modulus(re, im)
	tmp = sqrt(((re * re) + (im * im)));
end
modulus[re_, im_] := N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{re \cdot re + im \cdot im}
\end{array}

Alternative 1: 100.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \mathsf{hypot}\left(re, im\right) \end{array} \]
(FPCore modulus (re im) :precision binary64 (hypot re im))
double modulus(double re, double im) {
	return hypot(re, im);
}
public static double modulus(double re, double im) {
	return Math.hypot(re, im);
}
def modulus(re, im):
	return math.hypot(re, im)
function modulus(re, im)
	return hypot(re, im)
end
function tmp = modulus(re, im)
	tmp = hypot(re, im);
end
modulus[re_, im_] := N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]
\begin{array}{l}

\\
\mathsf{hypot}\left(re, im\right)
\end{array}
Derivation
  1. Initial program 53.3%

    \[\sqrt{re \cdot re + im \cdot im} \]
  2. Step-by-step derivation
    1. lift-sqrt.f64N/A

      \[\leadsto \color{blue}{\sqrt{re \cdot re + im \cdot im}} \]
    2. sqrt-fabs-revN/A

      \[\leadsto \color{blue}{\left|\sqrt{re \cdot re + im \cdot im}\right|} \]
    3. lift-sqrt.f64N/A

      \[\leadsto \left|\color{blue}{\sqrt{re \cdot re + im \cdot im}}\right| \]
    4. rem-sqrt-square-revN/A

      \[\leadsto \color{blue}{\sqrt{\sqrt{re \cdot re + im \cdot im} \cdot \sqrt{re \cdot re + im \cdot im}}} \]
    5. lift-sqrt.f64N/A

      \[\leadsto \sqrt{\color{blue}{\sqrt{re \cdot re + im \cdot im}} \cdot \sqrt{re \cdot re + im \cdot im}} \]
    6. lift-sqrt.f64N/A

      \[\leadsto \sqrt{\sqrt{re \cdot re + im \cdot im} \cdot \color{blue}{\sqrt{re \cdot re + im \cdot im}}} \]
    7. rem-square-sqrtN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re + im \cdot im}} \]
    8. lift-+.f64N/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re + im \cdot im}} \]
    9. add-flipN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(im \cdot im\right)\right)}} \]
    10. sub-flipN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im \cdot im\right)\right)\right)\right)}} \]
    11. remove-double-negN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{im \cdot im}} \]
    12. lift-*.f64N/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{im \cdot im}} \]
    13. sqr-abs-revN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}} \]
    14. sqr-neg-revN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}} \]
    15. fp-cancel-sign-sub-invN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}} \]
    16. fp-cancel-sub-sign-invN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}} \]
    17. lift-*.f64N/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)} \]
    18. distribute-lft-neg-inN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}} \]
    19. distribute-rgt-neg-outN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}} \]
    20. sqr-neg-revN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}} \]
    21. sqr-neg-revN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}} \]
    22. sqr-abs-revN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{im \cdot im}} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{hypot}\left(re, im\right)} \]
  4. Add Preprocessing

Alternative 2: 53.3% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} \end{array} \]
(FPCore modulus (re im) :precision binary64 (sqrt (fma re re (* im im))))
double modulus(double re, double im) {
	return sqrt(fma(re, re, (im * im)));
}
function modulus(re, im)
	return sqrt(fma(re, re, Float64(im * im)))
end
modulus[re_, im_] := N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)}
\end{array}
Derivation
  1. Initial program 53.3%

    \[\sqrt{re \cdot re + im \cdot im} \]
  2. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re + im \cdot im}} \]
    2. add-flipN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(im \cdot im\right)\right)}} \]
    3. sub-flipN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(im \cdot im\right)\right)\right)\right)}} \]
    4. remove-double-negN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{im \cdot im}} \]
    5. lift-*.f64N/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{im \cdot im}} \]
    6. sqr-abs-revN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left|im\right| \cdot \left|im\right|}} \]
    7. sqr-neg-revN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}} \]
    8. fp-cancel-sign-sub-invN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re - \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}} \]
    9. fp-cancel-sub-sign-invN/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)}} \]
    10. lift-*.f64N/A

      \[\leadsto \sqrt{\color{blue}{re \cdot re} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)} \]
    11. distribute-lft-neg-inN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}} \]
    12. distribute-lft-neg-inN/A

      \[\leadsto \sqrt{re \cdot re + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left|im\right|\right)\right) \cdot \left(\mathsf{neg}\left(\left|im\right|\right)\right)\right)\right)}\right)\right)} \]
    13. sqr-neg-revN/A

      \[\leadsto \sqrt{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{\left|im\right| \cdot \left|im\right|}\right)\right)\right)\right)} \]
    14. sqr-abs-revN/A

      \[\leadsto \sqrt{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{im \cdot im}\right)\right)\right)\right)} \]
    15. lift-*.f64N/A

      \[\leadsto \sqrt{re \cdot re + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\color{blue}{im \cdot im}\right)\right)\right)\right)} \]
    16. remove-double-negN/A

      \[\leadsto \sqrt{re \cdot re + \color{blue}{im \cdot im}} \]
    17. lower-fma.f6453.3

      \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(re, re, im \cdot im\right)}} \]
  3. Applied rewrites53.3%

    \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(re, re, im \cdot im\right)}} \]
  4. Add Preprocessing

Alternative 3: 26.4% accurate, 5.8× speedup?

\[\begin{array}{l} \\ -re \end{array} \]
(FPCore modulus (re im) :precision binary64 (- re))
double modulus(double re, double im) {
	return -re;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function modulus(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    modulus = -re
end function
public static double modulus(double re, double im) {
	return -re;
}
def modulus(re, im):
	return -re
function modulus(re, im)
	return Float64(-re)
end
function tmp = modulus(re, im)
	tmp = -re;
end
modulus[re_, im_] := (-re)
\begin{array}{l}

\\
-re
\end{array}
Derivation
  1. Initial program 53.3%

    \[\sqrt{re \cdot re + im \cdot im} \]
  2. Taylor expanded in re around -inf

    \[\leadsto \color{blue}{-1 \cdot re} \]
  3. Step-by-step derivation
    1. lower-*.f6426.3

      \[\leadsto -1 \cdot \color{blue}{re} \]
  4. Applied rewrites26.3%

    \[\leadsto \color{blue}{-1 \cdot re} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto -1 \cdot \color{blue}{re} \]
    2. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(re\right) \]
    3. lower-neg.f6426.3

      \[\leadsto -re \]
  6. Applied rewrites26.3%

    \[\leadsto -re \]
  7. Add Preprocessing

Alternative 4: 26.3% accurate, 5.8× speedup?

\[\begin{array}{l} \\ -im \end{array} \]
(FPCore modulus (re im) :precision binary64 (- im))
double modulus(double re, double im) {
	return -im;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function modulus(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    modulus = -im
end function
public static double modulus(double re, double im) {
	return -im;
}
def modulus(re, im):
	return -im
function modulus(re, im)
	return Float64(-im)
end
function tmp = modulus(re, im)
	tmp = -im;
end
modulus[re_, im_] := (-im)
\begin{array}{l}

\\
-im
\end{array}
Derivation
  1. Initial program 53.3%

    \[\sqrt{re \cdot re + im \cdot im} \]
  2. Taylor expanded in im around -inf

    \[\leadsto \color{blue}{-1 \cdot im} \]
  3. Step-by-step derivation
    1. lower-*.f6426.4

      \[\leadsto -1 \cdot \color{blue}{im} \]
  4. Applied rewrites26.4%

    \[\leadsto \color{blue}{-1 \cdot im} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto -1 \cdot \color{blue}{im} \]
    2. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(im\right) \]
    3. lower-neg.f6426.4

      \[\leadsto -im \]
  6. Applied rewrites26.4%

    \[\leadsto \color{blue}{-im} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2025164 
(FPCore modulus (re im)
  :name "math.abs on complex"
  :precision binary64
  (sqrt (+ (* re re) (* im im))))