Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A

Percentage Accurate: 69.5% → 99.8%
Time: 3.8s
Alternatives: 6
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
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, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z):
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z)
	return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0))
end
function tmp = code(x, y, z)
	tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\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 6 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: 69.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
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, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z):
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z)
	return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0))
end
function tmp = code(x, y, z)
	tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}

Alternative 1: 99.8% accurate, 1.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ z_m = \left|z\right| \\ \mathsf{fma}\left(y, 0.5, \left(\frac{x\_m - z\_m}{y} \cdot \left(z\_m + x\_m\right)\right) \cdot 0.5\right) \end{array} \]
x_m = (fabs.f64 x)
z_m = (fabs.f64 z)
(FPCore (x_m y z_m)
 :precision binary64
 (fma y 0.5 (* (* (/ (- x_m z_m) y) (+ z_m x_m)) 0.5)))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
	return fma(y, 0.5, ((((x_m - z_m) / y) * (z_m + x_m)) * 0.5));
}
x_m = abs(x)
z_m = abs(z)
function code(x_m, y, z_m)
	return fma(y, 0.5, Float64(Float64(Float64(Float64(x_m - z_m) / y) * Float64(z_m + x_m)) * 0.5))
end
x_m = N[Abs[x], $MachinePrecision]
z_m = N[Abs[z], $MachinePrecision]
code[x$95$m_, y_, z$95$m_] := N[(y * 0.5 + N[(N[(N[(N[(x$95$m - z$95$m), $MachinePrecision] / y), $MachinePrecision] * N[(z$95$m + x$95$m), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|

\\
\mathsf{fma}\left(y, 0.5, \left(\frac{x\_m - z\_m}{y} \cdot \left(z\_m + x\_m\right)\right) \cdot 0.5\right)
\end{array}
Derivation
  1. Initial program 66.7%

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Add Preprocessing
  3. Taylor expanded in y around inf

    \[\leadsto \color{blue}{y \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right)} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
    2. lower-*.f64N/A

      \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
  5. Applied rewrites82.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, 0.5, 0.5\right) \cdot y} \]
  6. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    2. lift-+.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    3. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    4. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    5. associate-/l*N/A

      \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    6. sub-divN/A

      \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    7. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    8. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    9. lower-+.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    10. sub-divN/A

      \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    11. lower-/.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
    12. lift--.f6494.8

      \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, 0.5, 0.5\right) \cdot y \]
  7. Applied rewrites94.8%

    \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, 0.5, 0.5\right) \cdot y \]
  8. Applied rewrites93.2%

    \[\leadsto \mathsf{fma}\left(y, \color{blue}{0.5}, \left(\left(z + x\right) \cdot \left(\frac{\frac{x - z}{y}}{y} \cdot 0.5\right)\right) \cdot y\right) \]
  9. Taylor expanded in y around 0

    \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \frac{1}{2} \cdot \frac{\left(x + z\right) \cdot \left(x - z\right)}{y}\right) \]
  10. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \frac{\left(x + z\right) \cdot \left(x - z\right)}{y} \cdot \frac{1}{2}\right) \]
    2. associate-/l*N/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \left(\left(x + z\right) \cdot \frac{x - z}{y}\right) \cdot \frac{1}{2}\right) \]
    3. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \left(\left(z + x\right) \cdot \frac{x - z}{y}\right) \cdot \frac{1}{2}\right) \]
    4. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \left(\left(z + x\right) \cdot \frac{x - z}{y}\right) \cdot \frac{1}{2}\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \left(\frac{x - z}{y} \cdot \left(z + x\right)\right) \cdot \frac{1}{2}\right) \]
    6. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \left(\frac{x - z}{y} \cdot \left(z + x\right)\right) \cdot \frac{1}{2}\right) \]
    7. lift-/.f64N/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \left(\frac{x - z}{y} \cdot \left(z + x\right)\right) \cdot \frac{1}{2}\right) \]
    8. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(y, \frac{1}{2}, \left(\frac{x - z}{y} \cdot \left(z + x\right)\right) \cdot \frac{1}{2}\right) \]
    9. lift-+.f6499.9

      \[\leadsto \mathsf{fma}\left(y, 0.5, \left(\frac{x - z}{y} \cdot \left(z + x\right)\right) \cdot 0.5\right) \]
  11. Applied rewrites99.9%

    \[\leadsto \mathsf{fma}\left(y, 0.5, \left(\frac{x - z}{y} \cdot \left(z + x\right)\right) \cdot 0.5\right) \]
  12. Add Preprocessing

Alternative 2: 35.4% accurate, 0.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ z_m = \left|z\right| \\ \begin{array}{l} t_0 := \frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-9}:\\ \;\;\;\;-0.5 \cdot \frac{z\_m \cdot z\_m}{y}\\ \mathbf{elif}\;t\_0 \leq 10^{+152} \lor \neg \left(t\_0 \leq 10^{+262}\right):\\ \;\;\;\;0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x\_m \cdot x\_m}{y + y}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
z_m = (fabs.f64 z)
(FPCore (x_m y z_m)
 :precision binary64
 (let* ((t_0 (/ (- (+ (* x_m x_m) (* y y)) (* z_m z_m)) (* y 2.0))))
   (if (<= t_0 -2e-9)
     (* -0.5 (/ (* z_m z_m) y))
     (if (or (<= t_0 1e+152) (not (<= t_0 1e+262)))
       (* 0.5 y)
       (/ (* x_m x_m) (+ y y))))))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
	double t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0);
	double tmp;
	if (t_0 <= -2e-9) {
		tmp = -0.5 * ((z_m * z_m) / y);
	} else if ((t_0 <= 1e+152) || !(t_0 <= 1e+262)) {
		tmp = 0.5 * y;
	} else {
		tmp = (x_m * x_m) / (y + y);
	}
	return tmp;
}
x_m =     private
z_m =     private
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_m, y, z_m)
use fmin_fmax_functions
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0d0)
    if (t_0 <= (-2d-9)) then
        tmp = (-0.5d0) * ((z_m * z_m) / y)
    else if ((t_0 <= 1d+152) .or. (.not. (t_0 <= 1d+262))) then
        tmp = 0.5d0 * y
    else
        tmp = (x_m * x_m) / (y + y)
    end if
    code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
	double t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0);
	double tmp;
	if (t_0 <= -2e-9) {
		tmp = -0.5 * ((z_m * z_m) / y);
	} else if ((t_0 <= 1e+152) || !(t_0 <= 1e+262)) {
		tmp = 0.5 * y;
	} else {
		tmp = (x_m * x_m) / (y + y);
	}
	return tmp;
}
x_m = math.fabs(x)
z_m = math.fabs(z)
def code(x_m, y, z_m):
	t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)
	tmp = 0
	if t_0 <= -2e-9:
		tmp = -0.5 * ((z_m * z_m) / y)
	elif (t_0 <= 1e+152) or not (t_0 <= 1e+262):
		tmp = 0.5 * y
	else:
		tmp = (x_m * x_m) / (y + y)
	return tmp
x_m = abs(x)
z_m = abs(z)
function code(x_m, y, z_m)
	t_0 = Float64(Float64(Float64(Float64(x_m * x_m) + Float64(y * y)) - Float64(z_m * z_m)) / Float64(y * 2.0))
	tmp = 0.0
	if (t_0 <= -2e-9)
		tmp = Float64(-0.5 * Float64(Float64(z_m * z_m) / y));
	elseif ((t_0 <= 1e+152) || !(t_0 <= 1e+262))
		tmp = Float64(0.5 * y);
	else
		tmp = Float64(Float64(x_m * x_m) / Float64(y + y));
	end
	return tmp
end
x_m = abs(x);
z_m = abs(z);
function tmp_2 = code(x_m, y, z_m)
	t_0 = (((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0);
	tmp = 0.0;
	if (t_0 <= -2e-9)
		tmp = -0.5 * ((z_m * z_m) / y);
	elseif ((t_0 <= 1e+152) || ~((t_0 <= 1e+262)))
		tmp = 0.5 * y;
	else
		tmp = (x_m * x_m) / (y + y);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
z_m = N[Abs[z], $MachinePrecision]
code[x$95$m_, y_, z$95$m_] := Block[{t$95$0 = N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-9], N[(-0.5 * N[(N[(z$95$m * z$95$m), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$0, 1e+152], N[Not[LessEqual[t$95$0, 1e+262]], $MachinePrecision]], N[(0.5 * y), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|

\\
\begin{array}{l}
t_0 := \frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-9}:\\
\;\;\;\;-0.5 \cdot \frac{z\_m \cdot z\_m}{y}\\

\mathbf{elif}\;t\_0 \leq 10^{+152} \lor \neg \left(t\_0 \leq 10^{+262}\right):\\
\;\;\;\;0.5 \cdot y\\

\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot x\_m}{y + y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -2.00000000000000012e-9

    1. Initial program 76.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{{z}^{2}}{y}} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{-1}{2} \cdot \color{blue}{\frac{{z}^{2}}{y}} \]
      2. lower-/.f64N/A

        \[\leadsto \frac{-1}{2} \cdot \frac{{z}^{2}}{\color{blue}{y}} \]
      3. pow2N/A

        \[\leadsto \frac{-1}{2} \cdot \frac{z \cdot z}{y} \]
      4. lift-*.f6432.3

        \[\leadsto -0.5 \cdot \frac{z \cdot z}{y} \]
    5. Applied rewrites32.3%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{z \cdot z}{y}} \]

    if -2.00000000000000012e-9 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 1e152 or 1e262 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 56.6%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot y} \]
    4. Step-by-step derivation
      1. lower-*.f6447.9

        \[\leadsto 0.5 \cdot \color{blue}{y} \]
    5. Applied rewrites47.9%

      \[\leadsto \color{blue}{0.5 \cdot y} \]

    if 1e152 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 1e262

    1. Initial program 99.7%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    4. Step-by-step derivation
      1. pow2N/A

        \[\leadsto \frac{x \cdot \color{blue}{x}}{y \cdot 2} \]
      2. lift-*.f6440.8

        \[\leadsto \frac{x \cdot \color{blue}{x}}{y \cdot 2} \]
    5. Applied rewrites40.8%

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot 2}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{x \cdot x}{\color{blue}{2 \cdot y}} \]
      3. count-2-revN/A

        \[\leadsto \frac{x \cdot x}{\color{blue}{y + y}} \]
      4. lower-+.f6440.8

        \[\leadsto \frac{x \cdot x}{\color{blue}{y + y}} \]
    7. Applied rewrites40.8%

      \[\leadsto \frac{x \cdot x}{\color{blue}{y + y}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification40.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \leq -2 \cdot 10^{-9}:\\ \;\;\;\;-0.5 \cdot \frac{z \cdot z}{y}\\ \mathbf{elif}\;\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \leq 10^{+152} \lor \neg \left(\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \leq 10^{+262}\right):\\ \;\;\;\;0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{y + y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 63.2% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ z_m = \left|z\right| \\ \begin{array}{l} \mathbf{if}\;\frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2} \leq 0:\\ \;\;\;\;\left(\left(z\_m + x\_m\right) \cdot \frac{x\_m - z\_m}{y}\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\frac{x\_m \cdot x\_m}{y} + y\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
z_m = (fabs.f64 z)
(FPCore (x_m y z_m)
 :precision binary64
 (if (<= (/ (- (+ (* x_m x_m) (* y y)) (* z_m z_m)) (* y 2.0)) 0.0)
   (* (* (+ z_m x_m) (/ (- x_m z_m) y)) 0.5)
   (* 0.5 (+ (/ (* x_m x_m) y) y))))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
	double tmp;
	if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0) {
		tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5;
	} else {
		tmp = 0.5 * (((x_m * x_m) / y) + y);
	}
	return tmp;
}
x_m =     private
z_m =     private
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_m, y, z_m)
use fmin_fmax_functions
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z_m
    real(8) :: tmp
    if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0d0)) <= 0.0d0) then
        tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5d0
    else
        tmp = 0.5d0 * (((x_m * x_m) / y) + y)
    end if
    code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
	double tmp;
	if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0) {
		tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5;
	} else {
		tmp = 0.5 * (((x_m * x_m) / y) + y);
	}
	return tmp;
}
x_m = math.fabs(x)
z_m = math.fabs(z)
def code(x_m, y, z_m):
	tmp = 0
	if ((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0:
		tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5
	else:
		tmp = 0.5 * (((x_m * x_m) / y) + y)
	return tmp
x_m = abs(x)
z_m = abs(z)
function code(x_m, y, z_m)
	tmp = 0.0
	if (Float64(Float64(Float64(Float64(x_m * x_m) + Float64(y * y)) - Float64(z_m * z_m)) / Float64(y * 2.0)) <= 0.0)
		tmp = Float64(Float64(Float64(z_m + x_m) * Float64(Float64(x_m - z_m) / y)) * 0.5);
	else
		tmp = Float64(0.5 * Float64(Float64(Float64(x_m * x_m) / y) + y));
	end
	return tmp
end
x_m = abs(x);
z_m = abs(z);
function tmp_2 = code(x_m, y, z_m)
	tmp = 0.0;
	if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= 0.0)
		tmp = ((z_m + x_m) * ((x_m - z_m) / y)) * 0.5;
	else
		tmp = 0.5 * (((x_m * x_m) / y) + y);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
z_m = N[Abs[z], $MachinePrecision]
code[x$95$m_, y_, z$95$m_] := If[LessEqual[N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[(z$95$m + x$95$m), $MachinePrecision] * N[(N[(x$95$m - z$95$m), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] / y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|

\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2} \leq 0:\\
\;\;\;\;\left(\left(z\_m + x\_m\right) \cdot \frac{x\_m - z\_m}{y}\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\frac{x\_m \cdot x\_m}{y} + y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < 0.0

    1. Initial program 74.2%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
    5. Applied rewrites84.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, 0.5, 0.5\right) \cdot y} \]
    6. Taylor expanded in y around 0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{{x}^{2} - {z}^{2}}{y} \cdot \color{blue}{\frac{1}{2}} \]
      2. pow2N/A

        \[\leadsto \frac{x \cdot x - {z}^{2}}{y} \cdot \frac{1}{2} \]
      3. pow2N/A

        \[\leadsto \frac{x \cdot x - z \cdot z}{y} \cdot \frac{1}{2} \]
      4. difference-of-squares-revN/A

        \[\leadsto \frac{\left(x + z\right) \cdot \left(x - z\right)}{y} \cdot \frac{1}{2} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\left(x + z\right) \cdot \left(x - z\right)}{y} \cdot \color{blue}{\frac{1}{2}} \]
      6. associate-/l*N/A

        \[\leadsto \left(\left(x + z\right) \cdot \frac{x - z}{y}\right) \cdot \frac{1}{2} \]
      7. sub-divN/A

        \[\leadsto \left(\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)\right) \cdot \frac{1}{2} \]
      8. lower-*.f64N/A

        \[\leadsto \left(\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)\right) \cdot \frac{1}{2} \]
      9. +-commutativeN/A

        \[\leadsto \left(\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)\right) \cdot \frac{1}{2} \]
      10. lower-+.f64N/A

        \[\leadsto \left(\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)\right) \cdot \frac{1}{2} \]
      11. sub-divN/A

        \[\leadsto \left(\left(z + x\right) \cdot \frac{x - z}{y}\right) \cdot \frac{1}{2} \]
      12. lower-/.f64N/A

        \[\leadsto \left(\left(z + x\right) \cdot \frac{x - z}{y}\right) \cdot \frac{1}{2} \]
      13. lift--.f6463.9

        \[\leadsto \left(\left(z + x\right) \cdot \frac{x - z}{y}\right) \cdot 0.5 \]
    8. Applied rewrites63.9%

      \[\leadsto \color{blue}{\left(\left(z + x\right) \cdot \frac{x - z}{y}\right) \cdot 0.5} \]

    if 0.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 60.3%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
    5. Applied rewrites80.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, 0.5, 0.5\right) \cdot y} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      2. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      3. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      4. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      5. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      6. sub-divN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      9. lower-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      10. sub-divN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      12. lift--.f6494.4

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, 0.5, 0.5\right) \cdot y \]
    7. Applied rewrites94.4%

      \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, 0.5, 0.5\right) \cdot y \]
    8. Applied rewrites93.0%

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{0.5}, \left(\left(z + x\right) \cdot \left(\frac{\frac{x - z}{y}}{y} \cdot 0.5\right)\right) \cdot y\right) \]
    9. Taylor expanded in z around 0

      \[\leadsto \frac{1}{2} \cdot y + \color{blue}{\frac{1}{2} \cdot \frac{{x}^{2}}{y}} \]
    10. Applied rewrites64.2%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x \cdot x}{y} + y\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 49.4% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ z_m = \left|z\right| \\ \begin{array}{l} \mathbf{if}\;\frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2} \leq -2 \cdot 10^{-9}:\\ \;\;\;\;-0.5 \cdot \frac{z\_m \cdot z\_m}{y}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\frac{x\_m \cdot x\_m}{y} + y\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
z_m = (fabs.f64 z)
(FPCore (x_m y z_m)
 :precision binary64
 (if (<= (/ (- (+ (* x_m x_m) (* y y)) (* z_m z_m)) (* y 2.0)) -2e-9)
   (* -0.5 (/ (* z_m z_m) y))
   (* 0.5 (+ (/ (* x_m x_m) y) y))))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
	double tmp;
	if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9) {
		tmp = -0.5 * ((z_m * z_m) / y);
	} else {
		tmp = 0.5 * (((x_m * x_m) / y) + y);
	}
	return tmp;
}
x_m =     private
z_m =     private
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_m, y, z_m)
use fmin_fmax_functions
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z_m
    real(8) :: tmp
    if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0d0)) <= (-2d-9)) then
        tmp = (-0.5d0) * ((z_m * z_m) / y)
    else
        tmp = 0.5d0 * (((x_m * x_m) / y) + y)
    end if
    code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
	double tmp;
	if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9) {
		tmp = -0.5 * ((z_m * z_m) / y);
	} else {
		tmp = 0.5 * (((x_m * x_m) / y) + y);
	}
	return tmp;
}
x_m = math.fabs(x)
z_m = math.fabs(z)
def code(x_m, y, z_m):
	tmp = 0
	if ((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9:
		tmp = -0.5 * ((z_m * z_m) / y)
	else:
		tmp = 0.5 * (((x_m * x_m) / y) + y)
	return tmp
x_m = abs(x)
z_m = abs(z)
function code(x_m, y, z_m)
	tmp = 0.0
	if (Float64(Float64(Float64(Float64(x_m * x_m) + Float64(y * y)) - Float64(z_m * z_m)) / Float64(y * 2.0)) <= -2e-9)
		tmp = Float64(-0.5 * Float64(Float64(z_m * z_m) / y));
	else
		tmp = Float64(0.5 * Float64(Float64(Float64(x_m * x_m) / y) + y));
	end
	return tmp
end
x_m = abs(x);
z_m = abs(z);
function tmp_2 = code(x_m, y, z_m)
	tmp = 0.0;
	if (((((x_m * x_m) + (y * y)) - (z_m * z_m)) / (y * 2.0)) <= -2e-9)
		tmp = -0.5 * ((z_m * z_m) / y);
	else
		tmp = 0.5 * (((x_m * x_m) / y) + y);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
z_m = N[Abs[z], $MachinePrecision]
code[x$95$m_, y_, z$95$m_] := If[LessEqual[N[(N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], -2e-9], N[(-0.5 * N[(N[(z$95$m * z$95$m), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] / y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|

\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(x\_m \cdot x\_m + y \cdot y\right) - z\_m \cdot z\_m}{y \cdot 2} \leq -2 \cdot 10^{-9}:\\
\;\;\;\;-0.5 \cdot \frac{z\_m \cdot z\_m}{y}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\frac{x\_m \cdot x\_m}{y} + y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -2.00000000000000012e-9

    1. Initial program 76.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \frac{{z}^{2}}{y}} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{-1}{2} \cdot \color{blue}{\frac{{z}^{2}}{y}} \]
      2. lower-/.f64N/A

        \[\leadsto \frac{-1}{2} \cdot \frac{{z}^{2}}{\color{blue}{y}} \]
      3. pow2N/A

        \[\leadsto \frac{-1}{2} \cdot \frac{z \cdot z}{y} \]
      4. lift-*.f6432.3

        \[\leadsto -0.5 \cdot \frac{z \cdot z}{y} \]
    5. Applied rewrites32.3%

      \[\leadsto \color{blue}{-0.5 \cdot \frac{z \cdot z}{y}} \]

    if -2.00000000000000012e-9 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64)))

    1. Initial program 59.6%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\frac{1}{2} + \frac{1}{2} \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right) \cdot \color{blue}{y} \]
    5. Applied rewrites79.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, 0.5, 0.5\right) \cdot y} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      2. lift-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      3. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      4. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\frac{\left(x + z\right) \cdot \left(x - z\right)}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      5. associate-/l*N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      6. sub-divN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(x + z\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      9. lower-+.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \left(\frac{x}{y} - \frac{z}{y}\right)}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      10. sub-divN/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, \frac{1}{2}, \frac{1}{2}\right) \cdot y \]
      12. lift--.f6494.6

        \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, 0.5, 0.5\right) \cdot y \]
    7. Applied rewrites94.6%

      \[\leadsto \mathsf{fma}\left(\frac{\left(z + x\right) \cdot \frac{x - z}{y}}{y}, 0.5, 0.5\right) \cdot y \]
    8. Applied rewrites92.0%

      \[\leadsto \mathsf{fma}\left(y, \color{blue}{0.5}, \left(\left(z + x\right) \cdot \left(\frac{\frac{x - z}{y}}{y} \cdot 0.5\right)\right) \cdot y\right) \]
    9. Taylor expanded in z around 0

      \[\leadsto \frac{1}{2} \cdot y + \color{blue}{\frac{1}{2} \cdot \frac{{x}^{2}}{y}} \]
    10. Applied rewrites64.3%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x \cdot x}{y} + y\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 50.9% accurate, 1.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ z_m = \left|z\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 4 \cdot 10^{+89}:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x\_m \cdot x\_m}{y + y}\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
z_m = (fabs.f64 z)
(FPCore (x_m y z_m)
 :precision binary64
 (if (<= x_m 4e+89) (* 0.5 y) (/ (* x_m x_m) (+ y y))))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
	double tmp;
	if (x_m <= 4e+89) {
		tmp = 0.5 * y;
	} else {
		tmp = (x_m * x_m) / (y + y);
	}
	return tmp;
}
x_m =     private
z_m =     private
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_m, y, z_m)
use fmin_fmax_functions
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z_m
    real(8) :: tmp
    if (x_m <= 4d+89) then
        tmp = 0.5d0 * y
    else
        tmp = (x_m * x_m) / (y + y)
    end if
    code = tmp
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
	double tmp;
	if (x_m <= 4e+89) {
		tmp = 0.5 * y;
	} else {
		tmp = (x_m * x_m) / (y + y);
	}
	return tmp;
}
x_m = math.fabs(x)
z_m = math.fabs(z)
def code(x_m, y, z_m):
	tmp = 0
	if x_m <= 4e+89:
		tmp = 0.5 * y
	else:
		tmp = (x_m * x_m) / (y + y)
	return tmp
x_m = abs(x)
z_m = abs(z)
function code(x_m, y, z_m)
	tmp = 0.0
	if (x_m <= 4e+89)
		tmp = Float64(0.5 * y);
	else
		tmp = Float64(Float64(x_m * x_m) / Float64(y + y));
	end
	return tmp
end
x_m = abs(x);
z_m = abs(z);
function tmp_2 = code(x_m, y, z_m)
	tmp = 0.0;
	if (x_m <= 4e+89)
		tmp = 0.5 * y;
	else
		tmp = (x_m * x_m) / (y + y);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
z_m = N[Abs[z], $MachinePrecision]
code[x$95$m_, y_, z$95$m_] := If[LessEqual[x$95$m, 4e+89], N[(0.5 * y), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] / N[(y + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 4 \cdot 10^{+89}:\\
\;\;\;\;0.5 \cdot y\\

\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot x\_m}{y + y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.99999999999999998e89

    1. Initial program 65.1%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot y} \]
    4. Step-by-step derivation
      1. lower-*.f6446.6

        \[\leadsto 0.5 \cdot \color{blue}{y} \]
    5. Applied rewrites46.6%

      \[\leadsto \color{blue}{0.5 \cdot y} \]

    if 3.99999999999999998e89 < x

    1. Initial program 73.2%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    4. Step-by-step derivation
      1. pow2N/A

        \[\leadsto \frac{x \cdot \color{blue}{x}}{y \cdot 2} \]
      2. lift-*.f6463.1

        \[\leadsto \frac{x \cdot \color{blue}{x}}{y \cdot 2} \]
    5. Applied rewrites63.1%

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    6. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{x \cdot x}{\color{blue}{y \cdot 2}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{x \cdot x}{\color{blue}{2 \cdot y}} \]
      3. count-2-revN/A

        \[\leadsto \frac{x \cdot x}{\color{blue}{y + y}} \]
      4. lower-+.f6463.1

        \[\leadsto \frac{x \cdot x}{\color{blue}{y + y}} \]
    7. Applied rewrites63.1%

      \[\leadsto \frac{x \cdot x}{\color{blue}{y + y}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 34.8% accurate, 6.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ z_m = \left|z\right| \\ 0.5 \cdot y \end{array} \]
x_m = (fabs.f64 x)
z_m = (fabs.f64 z)
(FPCore (x_m y z_m) :precision binary64 (* 0.5 y))
x_m = fabs(x);
z_m = fabs(z);
double code(double x_m, double y, double z_m) {
	return 0.5 * y;
}
x_m =     private
z_m =     private
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_m, y, z_m)
use fmin_fmax_functions
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z_m
    code = 0.5d0 * y
end function
x_m = Math.abs(x);
z_m = Math.abs(z);
public static double code(double x_m, double y, double z_m) {
	return 0.5 * y;
}
x_m = math.fabs(x)
z_m = math.fabs(z)
def code(x_m, y, z_m):
	return 0.5 * y
x_m = abs(x)
z_m = abs(z)
function code(x_m, y, z_m)
	return Float64(0.5 * y)
end
x_m = abs(x);
z_m = abs(z);
function tmp = code(x_m, y, z_m)
	tmp = 0.5 * y;
end
x_m = N[Abs[x], $MachinePrecision]
z_m = N[Abs[z], $MachinePrecision]
code[x$95$m_, y_, z$95$m_] := N[(0.5 * y), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
z_m = \left|z\right|

\\
0.5 \cdot y
\end{array}
Derivation
  1. Initial program 66.7%

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Add Preprocessing
  3. Taylor expanded in y around inf

    \[\leadsto \color{blue}{\frac{1}{2} \cdot y} \]
  4. Step-by-step derivation
    1. lower-*.f6440.4

      \[\leadsto 0.5 \cdot \color{blue}{y} \]
  5. Applied rewrites40.4%

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  6. Add Preprocessing

Developer Target 1: 99.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right) \end{array} \]
(FPCore (x y z)
 :precision binary64
 (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x))))
double code(double x, double y, double z) {
	return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
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, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (y * 0.5d0) - (((0.5d0 / y) * (z + x)) * (z - x))
end function
public static double code(double x, double y, double z) {
	return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
def code(x, y, z):
	return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x))
function code(x, y, z)
	return Float64(Float64(y * 0.5) - Float64(Float64(Float64(0.5 / y) * Float64(z + x)) * Float64(z - x)))
end
function tmp = code(x, y, z)
	tmp = (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
end
code[x_, y_, z_] := N[(N[(y * 0.5), $MachinePrecision] - N[(N[(N[(0.5 / y), $MachinePrecision] * N[(z + x), $MachinePrecision]), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right)
\end{array}

Reproduce

?
herbie shell --seed 2025051 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :alt
  (! :herbie-platform default (- (* y 1/2) (* (* (/ 1/2 y) (+ z x)) (- z x))))

  (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))