Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3

Percentage Accurate: 88.2% → 99.6%
Time: 6.0s
Alternatives: 12
Speedup: 0.8×

Specification

?
\[\begin{array}{l} \\ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * ((y - z) + 1.0d0)) / z
end function
public static double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
def code(x, y, z):
	return (x * ((y - z) + 1.0)) / z
function code(x, y, z)
	return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z)
end
function tmp = code(x, y, z)
	tmp = (x * ((y - z) + 1.0)) / z;
end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

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

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

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

Alternative 1: 99.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.65 \cdot 10^{+71} \lor \neg \left(z \leq 4 \cdot 10^{+15}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -3.65e+71) (not (<= z 4e+15)))
   (* x (+ (/ y z) -1.0))
   (/ (* x (+ (- y z) 1.0)) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -3.65e+71) || !(z <= 4e+15)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x * ((y - z) + 1.0)) / z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-3.65d+71)) .or. (.not. (z <= 4d+15))) then
        tmp = x * ((y / z) + (-1.0d0))
    else
        tmp = (x * ((y - z) + 1.0d0)) / z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -3.65e+71) || !(z <= 4e+15)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x * ((y - z) + 1.0)) / z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -3.65e+71) or not (z <= 4e+15):
		tmp = x * ((y / z) + -1.0)
	else:
		tmp = (x * ((y - z) + 1.0)) / z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -3.65e+71) || !(z <= 4e+15))
		tmp = Float64(x * Float64(Float64(y / z) + -1.0));
	else
		tmp = Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -3.65e+71) || ~((z <= 4e+15)))
		tmp = x * ((y / z) + -1.0);
	else
		tmp = (x * ((y - z) + 1.0)) / z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.65e+71], N[Not[LessEqual[z, 4e+15]], $MachinePrecision]], N[(x * N[(N[(y / z), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.65 \cdot 10^{+71} \lor \neg \left(z \leq 4 \cdot 10^{+15}\right):\\
\;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.64999999999999998e71 or 4e15 < z

    1. Initial program 79.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified94.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around inf 94.0%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    4. Step-by-step derivation
      1. associate-/l*93.3%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} - x \]
      2. associate-/r/100.0%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    6. Taylor expanded in x around 0 100.0%

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

    if -3.64999999999999998e71 < z < 4e15

    1. Initial program 99.9%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.65 \cdot 10^{+71} \lor \neg \left(z \leq 4 \cdot 10^{+15}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\ \end{array} \]

Alternative 2: 98.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(y - z\right) + 1\\ \mathbf{if}\;\frac{x \cdot t_0}{z} \leq 10^{+296}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{t_0}}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (- y z) 1.0)))
   (if (<= (/ (* x t_0) z) 1e+296) (- (/ (fma x y x) z) x) (/ x (/ z t_0)))))
double code(double x, double y, double z) {
	double t_0 = (y - z) + 1.0;
	double tmp;
	if (((x * t_0) / z) <= 1e+296) {
		tmp = (fma(x, y, x) / z) - x;
	} else {
		tmp = x / (z / t_0);
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(y - z) + 1.0)
	tmp = 0.0
	if (Float64(Float64(x * t_0) / z) <= 1e+296)
		tmp = Float64(Float64(fma(x, y, x) / z) - x);
	else
		tmp = Float64(x / Float64(z / t_0));
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[N[(N[(x * t$95$0), $MachinePrecision] / z), $MachinePrecision], 1e+296], N[(N[(N[(x * y + x), $MachinePrecision] / z), $MachinePrecision] - x), $MachinePrecision], N[(x / N[(z / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(y - z\right) + 1\\
\mathbf{if}\;\frac{x \cdot t_0}{z} \leq 10^{+296}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x\\

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


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

    1. Initial program 96.3%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]

    if 9.99999999999999981e295 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z)

    1. Initial program 66.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \leq 10^{+296}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \end{array} \]

Alternative 3: 99.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -12200000000 \lor \neg \left(z \leq 6 \cdot 10^{+15}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(\left(y + 1\right) - z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -12200000000.0) (not (<= z 6e+15)))
   (* x (+ (/ y z) -1.0))
   (* (/ x z) (- (+ y 1.0) z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -12200000000.0) || !(z <= 6e+15)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x / z) * ((y + 1.0) - z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-12200000000.0d0)) .or. (.not. (z <= 6d+15))) then
        tmp = x * ((y / z) + (-1.0d0))
    else
        tmp = (x / z) * ((y + 1.0d0) - z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -12200000000.0) || !(z <= 6e+15)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x / z) * ((y + 1.0) - z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -12200000000.0) or not (z <= 6e+15):
		tmp = x * ((y / z) + -1.0)
	else:
		tmp = (x / z) * ((y + 1.0) - z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -12200000000.0) || !(z <= 6e+15))
		tmp = Float64(x * Float64(Float64(y / z) + -1.0));
	else
		tmp = Float64(Float64(x / z) * Float64(Float64(y + 1.0) - z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -12200000000.0) || ~((z <= 6e+15)))
		tmp = x * ((y / z) + -1.0);
	else
		tmp = (x / z) * ((y + 1.0) - z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -12200000000.0], N[Not[LessEqual[z, 6e+15]], $MachinePrecision]], N[(x * N[(N[(y / z), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * N[(N[(y + 1.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -12200000000 \lor \neg \left(z \leq 6 \cdot 10^{+15}\right):\\
\;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot \left(\left(y + 1\right) - z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.22e10 or 6e15 < z

    1. Initial program 81.8%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified94.6%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around inf 94.6%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    4. Step-by-step derivation
      1. associate-/l*92.5%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} - x \]
      2. associate-/r/100.0%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    6. Taylor expanded in x around 0 100.0%

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

    if -1.22e10 < z < 6e15

    1. Initial program 99.9%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*92.9%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    3. Simplified92.9%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    4. Taylor expanded in x around 0 99.9%

      \[\leadsto \color{blue}{\frac{x \cdot \left(\left(1 + y\right) - z\right)}{z}} \]
    5. Step-by-step derivation
      1. associate-*l/99.8%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(\left(1 + y\right) - z\right)} \]
    6. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(\left(1 + y\right) - z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -12200000000 \lor \neg \left(z \leq 6 \cdot 10^{+15}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(\left(y + 1\right) - z\right)\\ \end{array} \]

Alternative 4: 60.0% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -5 \cdot 10^{-295}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;y \leq 2.4 \cdot 10^{-13}:\\
\;\;\;\;-x\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1 or 2.3999999999999999e-13 < y

    1. Initial program 92.2%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*92.5%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    3. Simplified92.5%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    4. Taylor expanded in y around inf 71.0%

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{y}}} \]
    5. Step-by-step derivation
      1. associate-/r/72.1%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
    6. Applied egg-rr72.1%

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

    if -1 < y < -5.00000000000000008e-295

    1. Initial program 96.1%

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

      \[\leadsto \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} \]
    3. Taylor expanded in y around 0 60.1%

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

    if -5.00000000000000008e-295 < y < 2.3999999999999999e-13

    1. Initial program 82.9%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in z around inf 64.9%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    4. Step-by-step derivation
      1. neg-mul-164.9%

        \[\leadsto \color{blue}{-x} \]
    5. Simplified64.9%

      \[\leadsto \color{blue}{-x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-295}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-13}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternative 5: 59.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{-294}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-13}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.0)
   (* x (/ y z))
   (if (<= y -2.1e-294) (/ x z) (if (<= y 2.4e-13) (- x) (* y (/ x z))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.0) {
		tmp = x * (y / z);
	} else if (y <= -2.1e-294) {
		tmp = x / z;
	} else if (y <= 2.4e-13) {
		tmp = -x;
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.0d0)) then
        tmp = x * (y / z)
    else if (y <= (-2.1d-294)) then
        tmp = x / z
    else if (y <= 2.4d-13) then
        tmp = -x
    else
        tmp = y * (x / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.0) {
		tmp = x * (y / z);
	} else if (y <= -2.1e-294) {
		tmp = x / z;
	} else if (y <= 2.4e-13) {
		tmp = -x;
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.0:
		tmp = x * (y / z)
	elif y <= -2.1e-294:
		tmp = x / z
	elif y <= 2.4e-13:
		tmp = -x
	else:
		tmp = y * (x / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.0)
		tmp = Float64(x * Float64(y / z));
	elseif (y <= -2.1e-294)
		tmp = Float64(x / z);
	elseif (y <= 2.4e-13)
		tmp = Float64(-x);
	else
		tmp = Float64(y * Float64(x / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.0)
		tmp = x * (y / z);
	elseif (y <= -2.1e-294)
		tmp = x / z;
	elseif (y <= 2.4e-13)
		tmp = -x;
	else
		tmp = y * (x / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -2.1e-294], N[(x / z), $MachinePrecision], If[LessEqual[y, 2.4e-13], (-x), N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot \frac{y}{z}\\

\mathbf{elif}\;y \leq -2.1 \cdot 10^{-294}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;y \leq 2.4 \cdot 10^{-13}:\\
\;\;\;\;-x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -1

    1. Initial program 93.3%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*96.6%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    3. Simplified96.6%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    4. Taylor expanded in y around inf 74.1%

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{y}}} \]
    5. Step-by-step derivation
      1. div-inv74.1%

        \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{z}{y}}} \]
      2. clear-num74.2%

        \[\leadsto x \cdot \color{blue}{\frac{y}{z}} \]
      3. *-commutative74.2%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
    6. Applied egg-rr74.2%

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

    if -1 < y < -2.09999999999999984e-294

    1. Initial program 96.1%

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

      \[\leadsto \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} \]
    3. Taylor expanded in y around 0 60.1%

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

    if -2.09999999999999984e-294 < y < 2.3999999999999999e-13

    1. Initial program 82.9%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in z around inf 64.9%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    4. Step-by-step derivation
      1. neg-mul-164.9%

        \[\leadsto \color{blue}{-x} \]
    5. Simplified64.9%

      \[\leadsto \color{blue}{-x} \]

    if 2.3999999999999999e-13 < y

    1. Initial program 91.2%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*88.7%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    3. Simplified88.7%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    4. Taylor expanded in y around inf 68.2%

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{y}}} \]
    5. Step-by-step derivation
      1. associate-/r/72.6%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
    6. Applied egg-rr72.6%

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification67.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -2.1 \cdot 10^{-294}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-13}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternative 6: 94.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 9.2 \cdot 10^{-18}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.0) (not (<= y 9.2e-18)))
   (* x (+ (/ y z) -1.0))
   (- (/ x z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.0) || !(y <= 9.2e-18)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-1.0d0)) .or. (.not. (y <= 9.2d-18))) then
        tmp = x * ((y / z) + (-1.0d0))
    else
        tmp = (x / z) - x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.0) || !(y <= 9.2e-18)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.0) or not (y <= 9.2e-18):
		tmp = x * ((y / z) + -1.0)
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.0) || !(y <= 9.2e-18))
		tmp = Float64(x * Float64(Float64(y / z) + -1.0));
	else
		tmp = Float64(Float64(x / z) - x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1.0) || ~((y <= 9.2e-18)))
		tmp = x * ((y / z) + -1.0);
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 9.2e-18]], $MachinePrecision]], N[(x * N[(N[(y / z), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 9.2 \cdot 10^{-18}\right):\\
\;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1 or 9.2000000000000004e-18 < y

    1. Initial program 92.5%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified94.7%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around inf 93.0%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    4. Step-by-step derivation
      1. associate-/l*90.9%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} - x \]
      2. associate-/r/90.9%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    5. Simplified90.9%

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    6. Taylor expanded in x around 0 90.9%

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

    if -1 < y < 9.2000000000000004e-18

    1. Initial program 89.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around 0 99.8%

      \[\leadsto \color{blue}{\frac{x}{z}} - x \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 9.2 \cdot 10^{-18}\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]

Alternative 7: 98.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + 1\right)}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.1) (not (<= z 1.0)))
   (* x (+ (/ y z) -1.0))
   (/ (* x (+ y 1.0)) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.1) || !(z <= 1.0)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x * (y + 1.0)) / z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-1.1d0)) .or. (.not. (z <= 1.0d0))) then
        tmp = x * ((y / z) + (-1.0d0))
    else
        tmp = (x * (y + 1.0d0)) / z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.1) || !(z <= 1.0)) {
		tmp = x * ((y / z) + -1.0);
	} else {
		tmp = (x * (y + 1.0)) / z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.1) or not (z <= 1.0):
		tmp = x * ((y / z) + -1.0)
	else:
		tmp = (x * (y + 1.0)) / z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.1) || !(z <= 1.0))
		tmp = Float64(x * Float64(Float64(y / z) + -1.0));
	else
		tmp = Float64(Float64(x * Float64(y + 1.0)) / z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.1) || ~((z <= 1.0)))
		tmp = x * ((y / z) + -1.0);
	else
		tmp = (x * (y + 1.0)) / z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.1], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(x * N[(N[(y / z), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.1000000000000001 or 1 < z

    1. Initial program 82.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified94.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around inf 93.1%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    4. Step-by-step derivation
      1. associate-/l*91.1%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} - x \]
      2. associate-/r/98.2%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    5. Simplified98.2%

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    6. Taylor expanded in x around 0 98.2%

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

    if -1.1000000000000001 < z < 1

    1. Initial program 99.9%

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

      \[\leadsto \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + 1\right)}{z}\\ \end{array} \]

Alternative 8: 96.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-18}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}} - x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.0)
   (* x (+ (/ y z) -1.0))
   (if (<= y 9.2e-18) (- (/ x z) x) (- (/ y (/ z x)) x))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.0) {
		tmp = x * ((y / z) + -1.0);
	} else if (y <= 9.2e-18) {
		tmp = (x / z) - x;
	} else {
		tmp = (y / (z / x)) - x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.0d0)) then
        tmp = x * ((y / z) + (-1.0d0))
    else if (y <= 9.2d-18) then
        tmp = (x / z) - x
    else
        tmp = (y / (z / x)) - x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.0) {
		tmp = x * ((y / z) + -1.0);
	} else if (y <= 9.2e-18) {
		tmp = (x / z) - x;
	} else {
		tmp = (y / (z / x)) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.0:
		tmp = x * ((y / z) + -1.0)
	elif y <= 9.2e-18:
		tmp = (x / z) - x
	else:
		tmp = (y / (z / x)) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.0)
		tmp = Float64(x * Float64(Float64(y / z) + -1.0));
	elseif (y <= 9.2e-18)
		tmp = Float64(Float64(x / z) - x);
	else
		tmp = Float64(Float64(y / Float64(z / x)) - x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.0)
		tmp = x * ((y / z) + -1.0);
	elseif (y <= 9.2e-18)
		tmp = (x / z) - x;
	else
		tmp = (y / (z / x)) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(x * N[(N[(y / z), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9.2e-18], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision], N[(N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 9.2 \cdot 10^{-18}:\\
\;\;\;\;\frac{x}{z} - x\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}} - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1

    1. Initial program 93.3%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified98.2%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around inf 97.0%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    4. Step-by-step derivation
      1. associate-/l*92.2%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} - x \]
      2. associate-/r/95.5%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    5. Simplified95.5%

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} - x \]
    6. Taylor expanded in x around 0 95.5%

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

    if -1 < y < 9.2000000000000004e-18

    1. Initial program 89.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around 0 99.8%

      \[\leadsto \color{blue}{\frac{x}{z}} - x \]

    if 9.2000000000000004e-18 < y

    1. Initial program 91.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified91.6%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around inf 89.5%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    4. Step-by-step derivation
      1. associate-/l*89.8%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} - x \]
    5. Simplified89.8%

      \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} - x \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x \cdot \left(\frac{y}{z} + -1\right)\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-18}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}} - x\\ \end{array} \]

Alternative 9: 85.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+34} \lor \neg \left(y \leq 49\right):\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -3.5e+34) (not (<= y 49.0))) (/ (* x y) z) (- (/ x z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -3.5e+34) || !(y <= 49.0)) {
		tmp = (x * y) / z;
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-3.5d+34)) .or. (.not. (y <= 49.0d0))) then
        tmp = (x * y) / z
    else
        tmp = (x / z) - x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -3.5e+34) || !(y <= 49.0)) {
		tmp = (x * y) / z;
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -3.5e+34) or not (y <= 49.0):
		tmp = (x * y) / z
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -3.5e+34) || !(y <= 49.0))
		tmp = Float64(Float64(x * y) / z);
	else
		tmp = Float64(Float64(x / z) - x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -3.5e+34) || ~((y <= 49.0)))
		tmp = (x * y) / z;
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e+34], N[Not[LessEqual[y, 49.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+34} \lor \neg \left(y \leq 49\right):\\
\;\;\;\;\frac{x \cdot y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.49999999999999998e34 or 49 < y

    1. Initial program 91.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Taylor expanded in y around inf 76.7%

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

    if -3.49999999999999998e34 < y < 49

    1. Initial program 90.6%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around 0 97.7%

      \[\leadsto \color{blue}{\frac{x}{z}} - x \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.5 \cdot 10^{+34} \lor \neg \left(y \leq 49\right):\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]

Alternative 10: 84.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -7.3 \cdot 10^{+37}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 49:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -7.3e+37)
   (* x (/ y z))
   (if (<= y 49.0) (- (/ x z) x) (* y (/ x z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -7.3e+37) {
		tmp = x * (y / z);
	} else if (y <= 49.0) {
		tmp = (x / z) - x;
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-7.3d+37)) then
        tmp = x * (y / z)
    else if (y <= 49.0d0) then
        tmp = (x / z) - x
    else
        tmp = y * (x / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -7.3e+37) {
		tmp = x * (y / z);
	} else if (y <= 49.0) {
		tmp = (x / z) - x;
	} else {
		tmp = y * (x / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -7.3e+37:
		tmp = x * (y / z)
	elif y <= 49.0:
		tmp = (x / z) - x
	else:
		tmp = y * (x / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -7.3e+37)
		tmp = Float64(x * Float64(y / z));
	elseif (y <= 49.0)
		tmp = Float64(Float64(x / z) - x);
	else
		tmp = Float64(y * Float64(x / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -7.3e+37)
		tmp = x * (y / z);
	elseif (y <= 49.0)
		tmp = (x / z) - x;
	else
		tmp = y * (x / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -7.3e+37], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 49.0], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.3 \cdot 10^{+37}:\\
\;\;\;\;x \cdot \frac{y}{z}\\

\mathbf{elif}\;y \leq 49:\\
\;\;\;\;\frac{x}{z} - x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -7.30000000000000038e37

    1. Initial program 92.5%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*96.3%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    3. Simplified96.3%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    4. Taylor expanded in y around inf 77.9%

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{y}}} \]
    5. Step-by-step derivation
      1. div-inv77.9%

        \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{z}{y}}} \]
      2. clear-num77.9%

        \[\leadsto x \cdot \color{blue}{\frac{y}{z}} \]
      3. *-commutative77.9%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
    6. Applied egg-rr77.9%

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

    if -7.30000000000000038e37 < y < 49

    1. Initial program 90.6%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in y around 0 97.7%

      \[\leadsto \color{blue}{\frac{x}{z}} - x \]

    if 49 < y

    1. Initial program 90.9%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. associate-/l*88.3%

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    3. Simplified88.3%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
    4. Taylor expanded in y around inf 68.8%

      \[\leadsto \frac{x}{\color{blue}{\frac{z}{y}}} \]
    5. Step-by-step derivation
      1. associate-/r/73.3%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.3 \cdot 10^{+37}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq 49:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternative 11: 65.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -0.9:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 880:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -0.9) (- x) (if (<= z 880.0) (/ x z) (- x))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -0.9) {
		tmp = -x;
	} else if (z <= 880.0) {
		tmp = x / z;
	} else {
		tmp = -x;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-0.9d0)) then
        tmp = -x
    else if (z <= 880.0d0) then
        tmp = x / z
    else
        tmp = -x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -0.9) {
		tmp = -x;
	} else if (z <= 880.0) {
		tmp = x / z;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -0.9:
		tmp = -x
	elif z <= 880.0:
		tmp = x / z
	else:
		tmp = -x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -0.9)
		tmp = Float64(-x);
	elseif (z <= 880.0)
		tmp = Float64(x / z);
	else
		tmp = Float64(-x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -0.9)
		tmp = -x;
	elseif (z <= 880.0)
		tmp = x / z;
	else
		tmp = -x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -0.9], (-x), If[LessEqual[z, 880.0], N[(x / z), $MachinePrecision], (-x)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.9:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq 880:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{else}:\\
\;\;\;\;-x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.900000000000000022 or 880 < z

    1. Initial program 82.7%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Simplified94.9%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Taylor expanded in z around inf 69.0%

      \[\leadsto \color{blue}{-1 \cdot x} \]
    4. Step-by-step derivation
      1. neg-mul-169.0%

        \[\leadsto \color{blue}{-x} \]
    5. Simplified69.0%

      \[\leadsto \color{blue}{-x} \]

    if -0.900000000000000022 < z < 880

    1. Initial program 99.9%

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

      \[\leadsto \frac{\color{blue}{\left(1 + y\right) \cdot x}}{z} \]
    3. Taylor expanded in y around 0 60.0%

      \[\leadsto \color{blue}{\frac{x}{z}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -0.9:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 880:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]

Alternative 12: 39.4% accurate, 4.5× speedup?

\[\begin{array}{l} \\ -x \end{array} \]
(FPCore (x y z) :precision binary64 (- x))
double code(double x, double y, double z) {
	return -x;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = -x
end function
public static double code(double x, double y, double z) {
	return -x;
}
def code(x, y, z):
	return -x
function code(x, y, z)
	return Float64(-x)
end
function tmp = code(x, y, z)
	tmp = -x;
end
code[x_, y_, z_] := (-x)
\begin{array}{l}

\\
-x
\end{array}
Derivation
  1. Initial program 91.1%

    \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
  2. Simplified97.3%

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
  3. Taylor expanded in z around inf 37.0%

    \[\leadsto \color{blue}{-1 \cdot x} \]
  4. Step-by-step derivation
    1. neg-mul-137.0%

      \[\leadsto \color{blue}{-x} \]
  5. Simplified37.0%

    \[\leadsto \color{blue}{-x} \]
  6. Final simplification37.0%

    \[\leadsto -x \]

Developer target: 99.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (* (+ 1.0 y) (/ x z)) x)))
   (if (< x -2.71483106713436e-162)
     t_0
     (if (< x 3.874108816439546e-197)
       (* (* x (+ (- y z) 1.0)) (/ 1.0 z))
       t_0))))
double code(double x, double y, double z) {
	double t_0 = ((1.0 + y) * (x / z)) - x;
	double tmp;
	if (x < -2.71483106713436e-162) {
		tmp = t_0;
	} else if (x < 3.874108816439546e-197) {
		tmp = (x * ((y - z) + 1.0)) * (1.0 / z);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((1.0d0 + y) * (x / z)) - x
    if (x < (-2.71483106713436d-162)) then
        tmp = t_0
    else if (x < 3.874108816439546d-197) then
        tmp = (x * ((y - z) + 1.0d0)) * (1.0d0 / z)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = ((1.0 + y) * (x / z)) - x;
	double tmp;
	if (x < -2.71483106713436e-162) {
		tmp = t_0;
	} else if (x < 3.874108816439546e-197) {
		tmp = (x * ((y - z) + 1.0)) * (1.0 / z);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = ((1.0 + y) * (x / z)) - x
	tmp = 0
	if x < -2.71483106713436e-162:
		tmp = t_0
	elif x < 3.874108816439546e-197:
		tmp = (x * ((y - z) + 1.0)) * (1.0 / z)
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(Float64(1.0 + y) * Float64(x / z)) - x)
	tmp = 0.0
	if (x < -2.71483106713436e-162)
		tmp = t_0;
	elseif (x < 3.874108816439546e-197)
		tmp = Float64(Float64(x * Float64(Float64(y - z) + 1.0)) * Float64(1.0 / z));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = ((1.0 + y) * (x / z)) - x;
	tmp = 0.0;
	if (x < -2.71483106713436e-162)
		tmp = t_0;
	elseif (x < 3.874108816439546e-197)
		tmp = (x * ((y - z) + 1.0)) * (1.0 / z);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(1.0 + y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]}, If[Less[x, -2.71483106713436e-162], t$95$0, If[Less[x, 3.874108816439546e-197], N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * N[(1.0 / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(1 + y\right) \cdot \frac{x}{z} - x\\
\mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\
\;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023221 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

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