_multiplyComplex, imaginary part

Percentage Accurate: 99.0% → 99.5%
Time: 3.6s
Alternatives: 4
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ x.re \cdot y.im + x.im \cdot y.re \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (+ (* x.re y.im) (* x.im y.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return (x_46_re * y_46_im) + (x_46_im * y_46_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 code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    code = (x_46re * y_46im) + (x_46im * y_46re)
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return (x_46_re * y_46_im) + (x_46_im * y_46_re);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return (x_46_re * y_46_im) + (x_46_im * y_46_re)
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(x_46_re * y_46_im) + Float64(x_46_im * y_46_re))
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = (x_46_re * y_46_im) + (x_46_im * y_46_re);
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$im), $MachinePrecision] + N[(x$46$im * y$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x.re \cdot y.im + x.im \cdot y.re
\end{array}

Sampling outcomes in binary64 precision:

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: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x.re \cdot y.im + x.im \cdot y.re \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (+ (* x.re y.im) (* x.im y.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return (x_46_re * y_46_im) + (x_46_im * y_46_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 code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    code = (x_46re * y_46im) + (x_46im * y_46re)
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return (x_46_re * y_46_im) + (x_46_im * y_46_re);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return (x_46_re * y_46_im) + (x_46_im * y_46_re)
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(Float64(x_46_re * y_46_im) + Float64(x_46_im * y_46_re))
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = (x_46_re * y_46_im) + (x_46_im * y_46_re);
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$im), $MachinePrecision] + N[(x$46$im * y$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x.re \cdot y.im + x.im \cdot y.re
\end{array}

Alternative 1: 99.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(y.im, x.re, y.re \cdot x.im\right) \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (fma y.im x.re (* y.re x.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return fma(y_46_im, x_46_re, (y_46_re * x_46_im));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return fma(y_46_im, x_46_re, Float64(y_46_re * x_46_im))
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(y$46$im * x$46$re + N[(y$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[x.re \cdot y.im + x.im \cdot y.re \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x.re \cdot y.im + x.im \cdot y.re} \]
    2. lift-*.f64N/A

      \[\leadsto x.re \cdot y.im + \color{blue}{x.im \cdot y.re} \]
    3. fp-cancel-sign-sub-invN/A

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

      \[\leadsto \color{blue}{x.re \cdot y.im + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x.im\right)\right)\right)\right) \cdot y.re} \]
    5. unpow1N/A

      \[\leadsto \color{blue}{{\left(x.re \cdot y.im\right)}^{1}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x.im\right)\right)\right)\right) \cdot y.re \]
    6. metadata-evalN/A

      \[\leadsto {\left(x.re \cdot y.im\right)}^{\color{blue}{\left(\frac{2}{2}\right)}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x.im\right)\right)\right)\right) \cdot y.re \]
    7. sqrt-pow1N/A

      \[\leadsto \color{blue}{\sqrt{{\left(x.re \cdot y.im\right)}^{2}}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x.im\right)\right)\right)\right) \cdot y.re \]
    8. pow2N/A

      \[\leadsto \sqrt{\color{blue}{\left(x.re \cdot y.im\right) \cdot \left(x.re \cdot y.im\right)}} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x.im\right)\right)\right)\right) \cdot y.re \]
    9. rem-sqrt-square-revN/A

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

      \[\leadsto \left|x.re \cdot y.im\right| + \color{blue}{x.im} \cdot y.re \]
    11. lift-*.f64N/A

      \[\leadsto \left|x.re \cdot y.im\right| + \color{blue}{x.im \cdot y.re} \]
    12. unpow1N/A

      \[\leadsto \left|x.re \cdot y.im\right| + \color{blue}{{\left(x.im \cdot y.re\right)}^{1}} \]
    13. metadata-evalN/A

      \[\leadsto \left|x.re \cdot y.im\right| + {\left(x.im \cdot y.re\right)}^{\color{blue}{\left(\frac{2}{2}\right)}} \]
    14. sqrt-pow1N/A

      \[\leadsto \left|x.re \cdot y.im\right| + \color{blue}{\sqrt{{\left(x.im \cdot y.re\right)}^{2}}} \]
    15. pow2N/A

      \[\leadsto \left|x.re \cdot y.im\right| + \sqrt{\color{blue}{\left(x.im \cdot y.re\right) \cdot \left(x.im \cdot y.re\right)}} \]
    16. rem-sqrt-square-revN/A

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

      \[\leadsto \left|x.re \cdot y.im\right| + \color{blue}{\sqrt{\left(x.im \cdot y.re\right) \cdot \left(x.im \cdot y.re\right)}} \]
    18. pow2N/A

      \[\leadsto \left|x.re \cdot y.im\right| + \sqrt{\color{blue}{{\left(x.im \cdot y.re\right)}^{2}}} \]
    19. sqrt-pow1N/A

      \[\leadsto \left|x.re \cdot y.im\right| + \color{blue}{{\left(x.im \cdot y.re\right)}^{\left(\frac{2}{2}\right)}} \]
    20. metadata-evalN/A

      \[\leadsto \left|x.re \cdot y.im\right| + {\left(x.im \cdot y.re\right)}^{\color{blue}{1}} \]
    21. unpow1N/A

      \[\leadsto \left|x.re \cdot y.im\right| + \color{blue}{x.im \cdot y.re} \]
  4. Applied rewrites99.6%

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

Alternative 2: 75.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \cdot y.re \leq -4 \cdot 10^{+94}:\\ \;\;\;\;y.re \cdot x.im\\ \mathbf{elif}\;x.im \cdot y.re \leq 2 \cdot 10^{+36}:\\ \;\;\;\;y.im \cdot x.re\\ \mathbf{else}:\\ \;\;\;\;\left|y.re \cdot x.im\right|\\ \end{array} \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (if (<= (* x.im y.re) -4e+94)
   (* y.re x.im)
   (if (<= (* x.im y.re) 2e+36) (* y.im x.re) (fabs (* y.re x.im)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((x_46_im * y_46_re) <= -4e+94) {
		tmp = y_46_re * x_46_im;
	} else if ((x_46_im * y_46_re) <= 2e+36) {
		tmp = y_46_im * x_46_re;
	} else {
		tmp = fabs((y_46_re * x_46_im));
	}
	return tmp;
}
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 code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: tmp
    if ((x_46im * y_46re) <= (-4d+94)) then
        tmp = y_46re * x_46im
    else if ((x_46im * y_46re) <= 2d+36) then
        tmp = y_46im * x_46re
    else
        tmp = abs((y_46re * x_46im))
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double tmp;
	if ((x_46_im * y_46_re) <= -4e+94) {
		tmp = y_46_re * x_46_im;
	} else if ((x_46_im * y_46_re) <= 2e+36) {
		tmp = y_46_im * x_46_re;
	} else {
		tmp = Math.abs((y_46_re * x_46_im));
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	tmp = 0
	if (x_46_im * y_46_re) <= -4e+94:
		tmp = y_46_re * x_46_im
	elif (x_46_im * y_46_re) <= 2e+36:
		tmp = y_46_im * x_46_re
	else:
		tmp = math.fabs((y_46_re * x_46_im))
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0
	if (Float64(x_46_im * y_46_re) <= -4e+94)
		tmp = Float64(y_46_re * x_46_im);
	elseif (Float64(x_46_im * y_46_re) <= 2e+36)
		tmp = Float64(y_46_im * x_46_re);
	else
		tmp = abs(Float64(y_46_re * x_46_im));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = 0.0;
	if ((x_46_im * y_46_re) <= -4e+94)
		tmp = y_46_re * x_46_im;
	elseif ((x_46_im * y_46_re) <= 2e+36)
		tmp = y_46_im * x_46_re;
	else
		tmp = abs((y_46_re * x_46_im));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[N[(x$46$im * y$46$re), $MachinePrecision], -4e+94], N[(y$46$re * x$46$im), $MachinePrecision], If[LessEqual[N[(x$46$im * y$46$re), $MachinePrecision], 2e+36], N[(y$46$im * x$46$re), $MachinePrecision], N[Abs[N[(y$46$re * x$46$im), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \cdot y.re \leq -4 \cdot 10^{+94}:\\
\;\;\;\;y.re \cdot x.im\\

\mathbf{elif}\;x.im \cdot y.re \leq 2 \cdot 10^{+36}:\\
\;\;\;\;y.im \cdot x.re\\

\mathbf{else}:\\
\;\;\;\;\left|y.re \cdot x.im\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x.im y.re) < -4.0000000000000001e94

    1. Initial program 98.2%

      \[x.re \cdot y.im + x.im \cdot y.re \]
    2. Add Preprocessing
    3. Taylor expanded in x.re around 0

      \[\leadsto \color{blue}{x.im \cdot y.re} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y.re \cdot x.im} \]
      2. lower-*.f6484.7

        \[\leadsto \color{blue}{y.re \cdot x.im} \]
    5. Applied rewrites84.7%

      \[\leadsto \color{blue}{y.re \cdot x.im} \]

    if -4.0000000000000001e94 < (*.f64 x.im y.re) < 2.00000000000000008e36

    1. Initial program 100.0%

      \[x.re \cdot y.im + x.im \cdot y.re \]
    2. Add Preprocessing
    3. Taylor expanded in x.re around 0

      \[\leadsto \color{blue}{x.im \cdot y.re} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y.re \cdot x.im} \]
      2. lower-*.f6427.9

        \[\leadsto \color{blue}{y.re \cdot x.im} \]
    5. Applied rewrites27.9%

      \[\leadsto \color{blue}{y.re \cdot x.im} \]
    6. Step-by-step derivation
      1. Applied rewrites12.0%

        \[\leadsto \left|y.re \cdot x.im\right| \]
      2. Taylor expanded in x.re around inf

        \[\leadsto \color{blue}{x.re \cdot y.im} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{y.im \cdot x.re} \]
        2. lower-*.f6475.8

          \[\leadsto \color{blue}{y.im \cdot x.re} \]
      4. Applied rewrites75.8%

        \[\leadsto \color{blue}{y.im \cdot x.re} \]

      if 2.00000000000000008e36 < (*.f64 x.im y.re)

      1. Initial program 98.0%

        \[x.re \cdot y.im + x.im \cdot y.re \]
      2. Add Preprocessing
      3. Taylor expanded in x.re around 0

        \[\leadsto \color{blue}{x.im \cdot y.re} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{y.re \cdot x.im} \]
        2. lower-*.f6481.2

          \[\leadsto \color{blue}{y.re \cdot x.im} \]
      5. Applied rewrites81.2%

        \[\leadsto \color{blue}{y.re \cdot x.im} \]
      6. Step-by-step derivation
        1. Applied rewrites81.2%

          \[\leadsto \left|y.re \cdot x.im\right| \]
      7. Recombined 3 regimes into one program.
      8. Add Preprocessing

      Alternative 3: 75.4% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \cdot y.re \leq -4 \cdot 10^{+94} \lor \neg \left(x.im \cdot y.re \leq 2 \cdot 10^{+36}\right):\\ \;\;\;\;y.re \cdot x.im\\ \mathbf{else}:\\ \;\;\;\;y.im \cdot x.re\\ \end{array} \end{array} \]
      (FPCore (x.re x.im y.re y.im)
       :precision binary64
       (if (or (<= (* x.im y.re) -4e+94) (not (<= (* x.im y.re) 2e+36)))
         (* y.re x.im)
         (* y.im x.re)))
      double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
      	double tmp;
      	if (((x_46_im * y_46_re) <= -4e+94) || !((x_46_im * y_46_re) <= 2e+36)) {
      		tmp = y_46_re * x_46_im;
      	} else {
      		tmp = y_46_im * x_46_re;
      	}
      	return tmp;
      }
      
      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 code(x_46re, x_46im, y_46re, y_46im)
      use fmin_fmax_functions
          real(8), intent (in) :: x_46re
          real(8), intent (in) :: x_46im
          real(8), intent (in) :: y_46re
          real(8), intent (in) :: y_46im
          real(8) :: tmp
          if (((x_46im * y_46re) <= (-4d+94)) .or. (.not. ((x_46im * y_46re) <= 2d+36))) then
              tmp = y_46re * x_46im
          else
              tmp = y_46im * x_46re
          end if
          code = tmp
      end function
      
      public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
      	double tmp;
      	if (((x_46_im * y_46_re) <= -4e+94) || !((x_46_im * y_46_re) <= 2e+36)) {
      		tmp = y_46_re * x_46_im;
      	} else {
      		tmp = y_46_im * x_46_re;
      	}
      	return tmp;
      }
      
      def code(x_46_re, x_46_im, y_46_re, y_46_im):
      	tmp = 0
      	if ((x_46_im * y_46_re) <= -4e+94) or not ((x_46_im * y_46_re) <= 2e+36):
      		tmp = y_46_re * x_46_im
      	else:
      		tmp = y_46_im * x_46_re
      	return tmp
      
      function code(x_46_re, x_46_im, y_46_re, y_46_im)
      	tmp = 0.0
      	if ((Float64(x_46_im * y_46_re) <= -4e+94) || !(Float64(x_46_im * y_46_re) <= 2e+36))
      		tmp = Float64(y_46_re * x_46_im);
      	else
      		tmp = Float64(y_46_im * x_46_re);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
      	tmp = 0.0;
      	if (((x_46_im * y_46_re) <= -4e+94) || ~(((x_46_im * y_46_re) <= 2e+36)))
      		tmp = y_46_re * x_46_im;
      	else
      		tmp = y_46_im * x_46_re;
      	end
      	tmp_2 = tmp;
      end
      
      code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[N[(x$46$im * y$46$re), $MachinePrecision], -4e+94], N[Not[LessEqual[N[(x$46$im * y$46$re), $MachinePrecision], 2e+36]], $MachinePrecision]], N[(y$46$re * x$46$im), $MachinePrecision], N[(y$46$im * x$46$re), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x.im \cdot y.re \leq -4 \cdot 10^{+94} \lor \neg \left(x.im \cdot y.re \leq 2 \cdot 10^{+36}\right):\\
      \;\;\;\;y.re \cdot x.im\\
      
      \mathbf{else}:\\
      \;\;\;\;y.im \cdot x.re\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 x.im y.re) < -4.0000000000000001e94 or 2.00000000000000008e36 < (*.f64 x.im y.re)

        1. Initial program 98.1%

          \[x.re \cdot y.im + x.im \cdot y.re \]
        2. Add Preprocessing
        3. Taylor expanded in x.re around 0

          \[\leadsto \color{blue}{x.im \cdot y.re} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{y.re \cdot x.im} \]
          2. lower-*.f6483.1

            \[\leadsto \color{blue}{y.re \cdot x.im} \]
        5. Applied rewrites83.1%

          \[\leadsto \color{blue}{y.re \cdot x.im} \]

        if -4.0000000000000001e94 < (*.f64 x.im y.re) < 2.00000000000000008e36

        1. Initial program 100.0%

          \[x.re \cdot y.im + x.im \cdot y.re \]
        2. Add Preprocessing
        3. Taylor expanded in x.re around 0

          \[\leadsto \color{blue}{x.im \cdot y.re} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{y.re \cdot x.im} \]
          2. lower-*.f6427.9

            \[\leadsto \color{blue}{y.re \cdot x.im} \]
        5. Applied rewrites27.9%

          \[\leadsto \color{blue}{y.re \cdot x.im} \]
        6. Step-by-step derivation
          1. Applied rewrites12.0%

            \[\leadsto \left|y.re \cdot x.im\right| \]
          2. Taylor expanded in x.re around inf

            \[\leadsto \color{blue}{x.re \cdot y.im} \]
          3. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{y.im \cdot x.re} \]
            2. lower-*.f6475.8

              \[\leadsto \color{blue}{y.im \cdot x.re} \]
          4. Applied rewrites75.8%

            \[\leadsto \color{blue}{y.im \cdot x.re} \]
        7. Recombined 2 regimes into one program.
        8. Final simplification78.8%

          \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \cdot y.re \leq -4 \cdot 10^{+94} \lor \neg \left(x.im \cdot y.re \leq 2 \cdot 10^{+36}\right):\\ \;\;\;\;y.re \cdot x.im\\ \mathbf{else}:\\ \;\;\;\;y.im \cdot x.re\\ \end{array} \]
        9. Add Preprocessing

        Alternative 4: 51.6% accurate, 2.3× speedup?

        \[\begin{array}{l} \\ y.im \cdot x.re \end{array} \]
        (FPCore (x.re x.im y.re y.im) :precision binary64 (* y.im x.re))
        double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
        	return y_46_im * x_46_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 code(x_46re, x_46im, y_46re, y_46im)
        use fmin_fmax_functions
            real(8), intent (in) :: x_46re
            real(8), intent (in) :: x_46im
            real(8), intent (in) :: y_46re
            real(8), intent (in) :: y_46im
            code = y_46im * x_46re
        end function
        
        public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
        	return y_46_im * x_46_re;
        }
        
        def code(x_46_re, x_46_im, y_46_re, y_46_im):
        	return y_46_im * x_46_re
        
        function code(x_46_re, x_46_im, y_46_re, y_46_im)
        	return Float64(y_46_im * x_46_re)
        end
        
        function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
        	tmp = y_46_im * x_46_re;
        end
        
        code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(y$46$im * x$46$re), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        y.im \cdot x.re
        \end{array}
        
        Derivation
        1. Initial program 99.2%

          \[x.re \cdot y.im + x.im \cdot y.re \]
        2. Add Preprocessing
        3. Taylor expanded in x.re around 0

          \[\leadsto \color{blue}{x.im \cdot y.re} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{y.re \cdot x.im} \]
          2. lower-*.f6451.0

            \[\leadsto \color{blue}{y.re \cdot x.im} \]
        5. Applied rewrites51.0%

          \[\leadsto \color{blue}{y.re \cdot x.im} \]
        6. Step-by-step derivation
          1. Applied rewrites23.7%

            \[\leadsto \left|y.re \cdot x.im\right| \]
          2. Taylor expanded in x.re around inf

            \[\leadsto \color{blue}{x.re \cdot y.im} \]
          3. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{y.im \cdot x.re} \]
            2. lower-*.f6453.6

              \[\leadsto \color{blue}{y.im \cdot x.re} \]
          4. Applied rewrites53.6%

            \[\leadsto \color{blue}{y.im \cdot x.re} \]
          5. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025015 
          (FPCore (x.re x.im y.re y.im)
            :name "_multiplyComplex, imaginary part"
            :precision binary64
            (+ (* x.re y.im) (* x.im y.re)))