Numeric.SpecFunctions:choose from math-functions-0.1.5.2

Percentage Accurate: 84.3% → 96.1%
Time: 2.8s
Alternatives: 5
Speedup: 1.1×

Specification

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

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

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

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

Alternative 1: 96.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{y}{z}, x, x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (/ y z) x x))
double code(double x, double y, double z) {
	return fma((y / z), x, x);
}
function code(x, y, z)
	return fma(Float64(y / z), x, x)
end
code[x_, y_, z_] := N[(N[(y / z), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{y}{z}, x, x\right)
\end{array}
Derivation
  1. Initial program 84.3%

    \[\frac{x \cdot \left(y + z\right)}{z} \]
  2. Step-by-step derivation
    1. lift-/.f64N/A

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

      \[\leadsto \frac{\color{blue}{x \cdot \left(y + z\right)}}{z} \]
    3. lift-+.f64N/A

      \[\leadsto \frac{x \cdot \color{blue}{\left(y + z\right)}}{z} \]
    4. distribute-lft-inN/A

      \[\leadsto \frac{\color{blue}{x \cdot y + x \cdot z}}{z} \]
    5. div-addN/A

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + \frac{x \cdot z}{z}} \]
    6. common-denominatorN/A

      \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot z + \left(x \cdot z\right) \cdot z}{z \cdot z}} \]
    7. div-addN/A

      \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot z}{z \cdot z} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z}} \]
    8. times-fracN/A

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} \cdot \frac{z}{z}} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    9. *-inversesN/A

      \[\leadsto \frac{x \cdot y}{z} \cdot \color{blue}{1} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    10. mult-flipN/A

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

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(\frac{1}{z} \cdot 1\right)} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    12. *-rgt-identityN/A

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

      \[\leadsto \color{blue}{x \cdot \left(y \cdot \frac{1}{z}\right)} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    14. mult-flipN/A

      \[\leadsto x \cdot \color{blue}{\frac{y}{z}} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    15. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    16. times-fracN/A

      \[\leadsto \frac{y}{z} \cdot x + \color{blue}{\frac{x \cdot z}{z} \cdot \frac{z}{z}} \]
    17. associate-/l*N/A

      \[\leadsto \frac{y}{z} \cdot x + \color{blue}{\left(x \cdot \frac{z}{z}\right)} \cdot \frac{z}{z} \]
    18. *-inversesN/A

      \[\leadsto \frac{y}{z} \cdot x + \left(x \cdot \color{blue}{1}\right) \cdot \frac{z}{z} \]
    19. *-rgt-identityN/A

      \[\leadsto \frac{y}{z} \cdot x + \color{blue}{x} \cdot \frac{z}{z} \]
    20. *-inversesN/A

      \[\leadsto \frac{y}{z} \cdot x + x \cdot \color{blue}{1} \]
    21. *-rgt-identityN/A

      \[\leadsto \frac{y}{z} \cdot x + \color{blue}{x} \]
    22. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)} \]
    23. lower-/.f6496.1

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{z}}, x, x\right) \]
  3. Applied rewrites96.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)} \]
  4. Add Preprocessing

Alternative 2: 94.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\frac{x}{z}, y, x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (/ x z) y x))
double code(double x, double y, double z) {
	return fma((x / z), y, x);
}
function code(x, y, z)
	return fma(Float64(x / z), y, x)
end
code[x_, y_, z_] := N[(N[(x / z), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\frac{x}{z}, y, x\right)
\end{array}
Derivation
  1. Initial program 84.3%

    \[\frac{x \cdot \left(y + z\right)}{z} \]
  2. Step-by-step derivation
    1. lift-/.f64N/A

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

      \[\leadsto \frac{\color{blue}{x \cdot \left(y + z\right)}}{z} \]
    3. lift-+.f64N/A

      \[\leadsto \frac{x \cdot \color{blue}{\left(y + z\right)}}{z} \]
    4. distribute-lft-inN/A

      \[\leadsto \frac{\color{blue}{x \cdot y + x \cdot z}}{z} \]
    5. div-addN/A

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + \frac{x \cdot z}{z}} \]
    6. common-denominatorN/A

      \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot z + \left(x \cdot z\right) \cdot z}{z \cdot z}} \]
    7. div-addN/A

      \[\leadsto \color{blue}{\frac{\left(x \cdot y\right) \cdot z}{z \cdot z} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z}} \]
    8. times-fracN/A

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} \cdot \frac{z}{z}} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    9. *-inversesN/A

      \[\leadsto \frac{x \cdot y}{z} \cdot \color{blue}{1} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    10. mult-flipN/A

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

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \left(\frac{1}{z} \cdot 1\right)} + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    12. *-rgt-identityN/A

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

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

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

      \[\leadsto \color{blue}{\left(x \cdot \frac{1}{z}\right)} \cdot y + \frac{\left(x \cdot z\right) \cdot z}{z \cdot z} \]
    16. times-fracN/A

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

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

      \[\leadsto \left(x \cdot \frac{1}{z}\right) \cdot y + \left(x \cdot \color{blue}{1}\right) \cdot \frac{z}{z} \]
    19. *-rgt-identityN/A

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

      \[\leadsto \left(x \cdot \frac{1}{z}\right) \cdot y + x \cdot \color{blue}{1} \]
    21. *-rgt-identityN/A

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \frac{1}{z}, y, x\right)} \]
    23. mult-flip-revN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{x}{z}}, y, x\right) \]
    24. lower-/.f6494.1

      \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{x}{z}}, y, x\right) \]
  3. Applied rewrites94.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)} \]
  4. Add Preprocessing

Alternative 3: 51.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+292}:\\ \;\;\;\;1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (+ y z)) z)))
   (if (<= t_0 0.0)
     (* (/ y z) x)
     (if (<= t_0 5e+292) (* 1.0 x) (* (/ x z) z)))))
double code(double x, double y, double z) {
	double t_0 = (x * (y + z)) / z;
	double tmp;
	if (t_0 <= 0.0) {
		tmp = (y / z) * x;
	} else if (t_0 <= 5e+292) {
		tmp = 1.0 * x;
	} else {
		tmp = (x / z) * z;
	}
	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, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x * (y + z)) / z
    if (t_0 <= 0.0d0) then
        tmp = (y / z) * x
    else if (t_0 <= 5d+292) then
        tmp = 1.0d0 * x
    else
        tmp = (x / z) * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (x * (y + z)) / z;
	double tmp;
	if (t_0 <= 0.0) {
		tmp = (y / z) * x;
	} else if (t_0 <= 5e+292) {
		tmp = 1.0 * x;
	} else {
		tmp = (x / z) * z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x * (y + z)) / z
	tmp = 0
	if t_0 <= 0.0:
		tmp = (y / z) * x
	elif t_0 <= 5e+292:
		tmp = 1.0 * x
	else:
		tmp = (x / z) * z
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x * Float64(y + z)) / z)
	tmp = 0.0
	if (t_0 <= 0.0)
		tmp = Float64(Float64(y / z) * x);
	elseif (t_0 <= 5e+292)
		tmp = Float64(1.0 * x);
	else
		tmp = Float64(Float64(x / z) * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x * (y + z)) / z;
	tmp = 0.0;
	if (t_0 <= 0.0)
		tmp = (y / z) * x;
	elseif (t_0 <= 5e+292)
		tmp = 1.0 * x;
	else
		tmp = (x / z) * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 5e+292], N[(1.0 * x), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * z), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{y}{z} \cdot x\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+292}:\\
\;\;\;\;1 \cdot x\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot z\\


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

    1. Initial program 84.3%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Taylor expanded in y around 0

      \[\leadsto \frac{x \cdot \color{blue}{z}}{z} \]
    3. Step-by-step derivation
      1. Applied rewrites40.9%

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

          \[\leadsto \color{blue}{\frac{x \cdot z}{z}} \]
        2. lift-*.f64N/A

          \[\leadsto \frac{\color{blue}{x \cdot z}}{z} \]
        3. associate-/l*N/A

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

          \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
        5. lower-*.f64N/A

          \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
        6. lower-/.f6451.8

          \[\leadsto \color{blue}{\frac{z}{z}} \cdot x \]
      3. Applied rewrites51.8%

        \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
      4. Taylor expanded in y around inf

        \[\leadsto \color{blue}{\frac{y}{z}} \cdot x \]
      5. Step-by-step derivation
        1. lower-/.f6446.3

          \[\leadsto \frac{y}{\color{blue}{z}} \cdot x \]
      6. Applied rewrites46.3%

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

      if -0.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < 4.9999999999999996e292

      1. Initial program 84.3%

        \[\frac{x \cdot \left(y + z\right)}{z} \]
      2. Taylor expanded in y around 0

        \[\leadsto \frac{x \cdot \color{blue}{z}}{z} \]
      3. Step-by-step derivation
        1. Applied rewrites40.9%

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

            \[\leadsto \color{blue}{\frac{x \cdot z}{z}} \]
          2. lift-*.f64N/A

            \[\leadsto \frac{\color{blue}{x \cdot z}}{z} \]
          3. associate-/l*N/A

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

            \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
          5. lower-*.f64N/A

            \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
          6. lower-/.f6451.8

            \[\leadsto \color{blue}{\frac{z}{z}} \cdot x \]
        3. Applied rewrites51.8%

          \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
        4. Taylor expanded in y around 0

          \[\leadsto \color{blue}{1} \cdot x \]
        5. Step-by-step derivation
          1. Applied rewrites51.8%

            \[\leadsto \color{blue}{1} \cdot x \]

          if 4.9999999999999996e292 < (/.f64 (*.f64 x (+.f64 y z)) z)

          1. Initial program 84.3%

            \[\frac{x \cdot \left(y + z\right)}{z} \]
          2. Taylor expanded in y around 0

            \[\leadsto \frac{x \cdot \color{blue}{z}}{z} \]
          3. Step-by-step derivation
            1. Applied rewrites40.9%

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

                \[\leadsto \color{blue}{\frac{x \cdot z}{z}} \]
              2. lift-*.f64N/A

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

                \[\leadsto \frac{\color{blue}{z \cdot x}}{z} \]
              4. associate-/l*N/A

                \[\leadsto \color{blue}{z \cdot \frac{x}{z}} \]
              5. lift-/.f64N/A

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

                \[\leadsto \color{blue}{\frac{x}{z} \cdot z} \]
              7. lower-*.f6444.7

                \[\leadsto \color{blue}{\frac{x}{z} \cdot z} \]
            3. Applied rewrites44.7%

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

          Alternative 4: 50.9% accurate, 0.5× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 0:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (<= (/ (* x (+ y z)) z) 0.0) (* (/ y z) x) (* 1.0 x)))
          double code(double x, double y, double z) {
          	double tmp;
          	if (((x * (y + z)) / z) <= 0.0) {
          		tmp = (y / z) * x;
          	} else {
          		tmp = 1.0 * x;
          	}
          	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, y, z)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              real(8) :: tmp
              if (((x * (y + z)) / z) <= 0.0d0) then
                  tmp = (y / z) * x
              else
                  tmp = 1.0d0 * x
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double tmp;
          	if (((x * (y + z)) / z) <= 0.0) {
          		tmp = (y / z) * x;
          	} else {
          		tmp = 1.0 * x;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	tmp = 0
          	if ((x * (y + z)) / z) <= 0.0:
          		tmp = (y / z) * x
          	else:
          		tmp = 1.0 * x
          	return tmp
          
          function code(x, y, z)
          	tmp = 0.0
          	if (Float64(Float64(x * Float64(y + z)) / z) <= 0.0)
          		tmp = Float64(Float64(y / z) * x);
          	else
          		tmp = Float64(1.0 * x);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	tmp = 0.0;
          	if (((x * (y + z)) / z) <= 0.0)
          		tmp = (y / z) * x;
          	else
          		tmp = 1.0 * x;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := If[LessEqual[N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 0.0], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 0:\\
          \;\;\;\;\frac{y}{z} \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;1 \cdot x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -0.0

            1. Initial program 84.3%

              \[\frac{x \cdot \left(y + z\right)}{z} \]
            2. Taylor expanded in y around 0

              \[\leadsto \frac{x \cdot \color{blue}{z}}{z} \]
            3. Step-by-step derivation
              1. Applied rewrites40.9%

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

                  \[\leadsto \color{blue}{\frac{x \cdot z}{z}} \]
                2. lift-*.f64N/A

                  \[\leadsto \frac{\color{blue}{x \cdot z}}{z} \]
                3. associate-/l*N/A

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

                  \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                5. lower-*.f64N/A

                  \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                6. lower-/.f6451.8

                  \[\leadsto \color{blue}{\frac{z}{z}} \cdot x \]
              3. Applied rewrites51.8%

                \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
              4. Taylor expanded in y around inf

                \[\leadsto \color{blue}{\frac{y}{z}} \cdot x \]
              5. Step-by-step derivation
                1. lower-/.f6446.3

                  \[\leadsto \frac{y}{\color{blue}{z}} \cdot x \]
              6. Applied rewrites46.3%

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

              if -0.0 < (/.f64 (*.f64 x (+.f64 y z)) z)

              1. Initial program 84.3%

                \[\frac{x \cdot \left(y + z\right)}{z} \]
              2. Taylor expanded in y around 0

                \[\leadsto \frac{x \cdot \color{blue}{z}}{z} \]
              3. Step-by-step derivation
                1. Applied rewrites40.9%

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

                    \[\leadsto \color{blue}{\frac{x \cdot z}{z}} \]
                  2. lift-*.f64N/A

                    \[\leadsto \frac{\color{blue}{x \cdot z}}{z} \]
                  3. associate-/l*N/A

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

                    \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                  5. lower-*.f64N/A

                    \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                  6. lower-/.f6451.8

                    \[\leadsto \color{blue}{\frac{z}{z}} \cdot x \]
                3. Applied rewrites51.8%

                  \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                4. Taylor expanded in y around 0

                  \[\leadsto \color{blue}{1} \cdot x \]
                5. Step-by-step derivation
                  1. Applied rewrites51.8%

                    \[\leadsto \color{blue}{1} \cdot x \]
                6. Recombined 2 regimes into one program.
                7. Add Preprocessing

                Alternative 5: 49.2% accurate, 2.5× speedup?

                \[\begin{array}{l} \\ 1 \cdot x \end{array} \]
                (FPCore (x y z) :precision binary64 (* 1.0 x))
                double code(double x, double y, double z) {
                	return 1.0 * 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 = 1.0d0 * x
                end function
                
                public static double code(double x, double y, double z) {
                	return 1.0 * x;
                }
                
                def code(x, y, z):
                	return 1.0 * x
                
                function code(x, y, z)
                	return Float64(1.0 * x)
                end
                
                function tmp = code(x, y, z)
                	tmp = 1.0 * x;
                end
                
                code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
                
                \begin{array}{l}
                
                \\
                1 \cdot x
                \end{array}
                
                Derivation
                1. Initial program 84.3%

                  \[\frac{x \cdot \left(y + z\right)}{z} \]
                2. Taylor expanded in y around 0

                  \[\leadsto \frac{x \cdot \color{blue}{z}}{z} \]
                3. Step-by-step derivation
                  1. Applied rewrites40.9%

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

                      \[\leadsto \color{blue}{\frac{x \cdot z}{z}} \]
                    2. lift-*.f64N/A

                      \[\leadsto \frac{\color{blue}{x \cdot z}}{z} \]
                    3. associate-/l*N/A

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

                      \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                    5. lower-*.f64N/A

                      \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                    6. lower-/.f6451.8

                      \[\leadsto \color{blue}{\frac{z}{z}} \cdot x \]
                  3. Applied rewrites51.8%

                    \[\leadsto \color{blue}{\frac{z}{z} \cdot x} \]
                  4. Taylor expanded in y around 0

                    \[\leadsto \color{blue}{1} \cdot x \]
                  5. Step-by-step derivation
                    1. Applied rewrites51.8%

                      \[\leadsto \color{blue}{1} \cdot x \]
                    2. Add Preprocessing

                    Reproduce

                    ?
                    herbie shell --seed 2025143 
                    (FPCore (x y z)
                      :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
                      :precision binary64
                      (/ (* x (+ y z)) z))