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

Percentage Accurate: 87.8% → 99.3%
Time: 7.5s
Alternatives: 12
Speedup: 1.0×

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: 87.8% 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.3% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.40000000000000002 or 3.8000000000000001e-161 < z

    1. Initial program 86.6%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
      2. associate-/r/75.8%

        \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(\left(y - z\right) + 1\right)} \]
    3. Applied egg-rr75.8%

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

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

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

        \[\leadsto \frac{x}{\frac{z}{\color{blue}{y - \left(z - 1\right)}}} \]
      4. sub-neg99.9%

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

        \[\leadsto \frac{x}{\frac{z}{y - \left(z + \color{blue}{-1}\right)}} \]
    5. Applied egg-rr99.9%

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

    if -0.40000000000000002 < z < 3.8000000000000001e-161

    1. Initial program 100.0%

      \[\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 -0.4 \lor \neg \left(z \leq 3.8 \cdot 10^{-161}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y - \left(z + -1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(1 + \left(y - z\right)\right)}{z}\\ \end{array} \]

Alternative 2: 66.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;z \leq -4.5 \cdot 10^{+17}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -2.45 \cdot 10^{-218}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-227}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-116}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-6}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (/ x z))))
   (if (<= z -4.5e+17)
     (- x)
     (if (<= z -2.45e-218)
       t_0
       (if (<= z 7e-227)
         (/ x z)
         (if (<= z 7e-116) t_0 (if (<= z 4.2e-6) (/ x z) (- x))))))))
double code(double x, double y, double z) {
	double t_0 = y * (x / z);
	double tmp;
	if (z <= -4.5e+17) {
		tmp = -x;
	} else if (z <= -2.45e-218) {
		tmp = t_0;
	} else if (z <= 7e-227) {
		tmp = x / z;
	} else if (z <= 7e-116) {
		tmp = t_0;
	} else if (z <= 4.2e-6) {
		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) :: t_0
    real(8) :: tmp
    t_0 = y * (x / z)
    if (z <= (-4.5d+17)) then
        tmp = -x
    else if (z <= (-2.45d-218)) then
        tmp = t_0
    else if (z <= 7d-227) then
        tmp = x / z
    else if (z <= 7d-116) then
        tmp = t_0
    else if (z <= 4.2d-6) then
        tmp = x / z
    else
        tmp = -x
    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 (z <= -4.5e+17) {
		tmp = -x;
	} else if (z <= -2.45e-218) {
		tmp = t_0;
	} else if (z <= 7e-227) {
		tmp = x / z;
	} else if (z <= 7e-116) {
		tmp = t_0;
	} else if (z <= 4.2e-6) {
		tmp = x / z;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (x / z)
	tmp = 0
	if z <= -4.5e+17:
		tmp = -x
	elif z <= -2.45e-218:
		tmp = t_0
	elif z <= 7e-227:
		tmp = x / z
	elif z <= 7e-116:
		tmp = t_0
	elif z <= 4.2e-6:
		tmp = x / z
	else:
		tmp = -x
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(x / z))
	tmp = 0.0
	if (z <= -4.5e+17)
		tmp = Float64(-x);
	elseif (z <= -2.45e-218)
		tmp = t_0;
	elseif (z <= 7e-227)
		tmp = Float64(x / z);
	elseif (z <= 7e-116)
		tmp = t_0;
	elseif (z <= 4.2e-6)
		tmp = Float64(x / z);
	else
		tmp = Float64(-x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (x / z);
	tmp = 0.0;
	if (z <= -4.5e+17)
		tmp = -x;
	elseif (z <= -2.45e-218)
		tmp = t_0;
	elseif (z <= 7e-227)
		tmp = x / z;
	elseif (z <= 7e-116)
		tmp = t_0;
	elseif (z <= 4.2e-6)
		tmp = x / z;
	else
		tmp = -x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4.5e+17], (-x), If[LessEqual[z, -2.45e-218], t$95$0, If[LessEqual[z, 7e-227], N[(x / z), $MachinePrecision], If[LessEqual[z, 7e-116], t$95$0, If[LessEqual[z, 4.2e-6], N[(x / z), $MachinePrecision], (-x)]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;z \leq -4.5 \cdot 10^{+17}:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq -2.45 \cdot 10^{-218}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 7 \cdot 10^{-227}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;z \leq 7 \cdot 10^{-116}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4.2 \cdot 10^{-6}:\\
\;\;\;\;\frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -4.5e17 or 4.1999999999999996e-6 < z

    1. Initial program 82.9%

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

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

        \[\leadsto \color{blue}{-x} \]
    4. Simplified76.4%

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

    if -4.5e17 < z < -2.44999999999999989e-218 or 7.0000000000000002e-227 < z < 6.99999999999999968e-116

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
      2. div-inv67.0%

        \[\leadsto \color{blue}{y \cdot \frac{1}{\frac{z}{x}}} \]
      3. clear-num67.0%

        \[\leadsto y \cdot \color{blue}{\frac{x}{z}} \]
    4. Applied egg-rr67.0%

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

    if -2.44999999999999989e-218 < z < 7.0000000000000002e-227 or 6.99999999999999968e-116 < z < 4.1999999999999996e-6

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot x + \frac{x}{z}} \]
    4. Step-by-step derivation
      1. +-commutative69.3%

        \[\leadsto \color{blue}{\frac{x}{z} + -1 \cdot x} \]
      2. mul-1-neg69.3%

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

        \[\leadsto \color{blue}{\frac{x}{z} - x} \]
    5. Simplified69.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{+17}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -2.45 \cdot 10^{-218}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-227}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-116}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-6}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]

Alternative 3: 95.8% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -7.5e18 or 5.5000000000000001e113 < z

    1. Initial program 81.6%

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

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

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

    if -7.5e18 < z < 5.5000000000000001e113

    1. Initial program 98.3%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
      2. associate-/r/99.3%

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

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

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

Alternative 4: 99.3% accurate, 0.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -6.59999999999999976e-16 or 4.9999999999999999e-161 < z

    1. Initial program 86.8%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
      2. associate-/r/76.2%

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

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

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

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

        \[\leadsto \frac{x}{\frac{z}{\color{blue}{y - \left(z - 1\right)}}} \]
      4. sub-neg99.9%

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

        \[\leadsto \frac{x}{\frac{z}{y - \left(z + \color{blue}{-1}\right)}} \]
    5. Applied egg-rr99.9%

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

    if -6.59999999999999976e-16 < z < 4.9999999999999999e-161

    1. Initial program 99.9%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. distribute-lft-in100.0%

        \[\leadsto \frac{\color{blue}{x \cdot \left(y - z\right) + x \cdot 1}}{z} \]
      2. fma-def100.0%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, y - z, x \cdot 1\right)}}{z} \]
      3. *-rgt-identity100.0%

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

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

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

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

Alternative 5: 94.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{+142}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+132}:\\ \;\;\;\;\left(1 + \left(y - z\right)\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -7.5e+142)
   (- x)
   (if (<= z 4.6e+132) (* (+ 1.0 (- y z)) (/ x z)) (- (/ x z) x))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -7.5e+142) {
		tmp = -x;
	} else if (z <= 4.6e+132) {
		tmp = (1.0 + (y - z)) * (x / 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 (z <= (-7.5d+142)) then
        tmp = -x
    else if (z <= 4.6d+132) then
        tmp = (1.0d0 + (y - z)) * (x / 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 (z <= -7.5e+142) {
		tmp = -x;
	} else if (z <= 4.6e+132) {
		tmp = (1.0 + (y - z)) * (x / z);
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -7.5e+142:
		tmp = -x
	elif z <= 4.6e+132:
		tmp = (1.0 + (y - z)) * (x / z)
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -7.5e+142)
		tmp = Float64(-x);
	elseif (z <= 4.6e+132)
		tmp = Float64(Float64(1.0 + Float64(y - z)) * Float64(x / z));
	else
		tmp = Float64(Float64(x / z) - x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -7.5e+142)
		tmp = -x;
	elseif (z <= 4.6e+132)
		tmp = (1.0 + (y - z)) * (x / z);
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -7.5e+142], (-x), If[LessEqual[z, 4.6e+132], N[(N[(1.0 + N[(y - z), $MachinePrecision]), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{+142}:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq 4.6 \cdot 10^{+132}:\\
\;\;\;\;\left(1 + \left(y - z\right)\right) \cdot \frac{x}{z}\\

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


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

    1. Initial program 70.1%

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

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

        \[\leadsto \color{blue}{-x} \]
    4. Simplified90.3%

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

    if -7.5000000000000002e142 < z < 4.6000000000000003e132

    1. Initial program 98.0%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
      2. associate-/r/97.0%

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

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

    if 4.6000000000000003e132 < z

    1. Initial program 84.1%

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

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

      \[\leadsto \color{blue}{-1 \cdot x + \frac{x}{z}} \]
    4. Step-by-step derivation
      1. +-commutative88.0%

        \[\leadsto \color{blue}{\frac{x}{z} + -1 \cdot x} \]
      2. mul-1-neg88.0%

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

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

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

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

Alternative 6: 85.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -160 \lor \neg \left(y \leq 9.8 \cdot 10^{+55}\right):\\ \;\;\;\;\frac{x + y \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -160.0) (not (<= y 9.8e+55)))
   (/ (+ x (* y x)) z)
   (- (/ x z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -160.0) || !(y <= 9.8e+55)) {
		tmp = (x + (y * x)) / 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 <= (-160.0d0)) .or. (.not. (y <= 9.8d+55))) then
        tmp = (x + (y * x)) / 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 <= -160.0) || !(y <= 9.8e+55)) {
		tmp = (x + (y * x)) / z;
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -160.0) or not (y <= 9.8e+55):
		tmp = (x + (y * x)) / z
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -160.0) || !(y <= 9.8e+55))
		tmp = Float64(Float64(x + Float64(y * x)) / z);
	else
		tmp = Float64(Float64(x / z) - x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -160.0) || ~((y <= 9.8e+55)))
		tmp = (x + (y * x)) / z;
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -160.0], N[Not[LessEqual[y, 9.8e+55]], $MachinePrecision]], N[(N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -160 or 9.80000000000000029e55 < y

    1. Initial program 94.2%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Step-by-step derivation
      1. distribute-lft-in94.2%

        \[\leadsto \frac{\color{blue}{x \cdot \left(y - z\right) + x \cdot 1}}{z} \]
      2. fma-def94.2%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, y - z, x \cdot 1\right)}}{z} \]
      3. *-rgt-identity94.2%

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

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

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

    if -160 < y < 9.80000000000000029e55

    1. Initial program 90.6%

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

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

      \[\leadsto \color{blue}{-1 \cdot x + \frac{x}{z}} \]
    4. Step-by-step derivation
      1. +-commutative97.0%

        \[\leadsto \color{blue}{\frac{x}{z} + -1 \cdot x} \]
      2. mul-1-neg97.0%

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

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

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

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

Alternative 7: 85.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -14000 \lor \neg \left(y \leq 1.7 \cdot 10^{+53}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -14000.0) (not (<= y 1.7e+53))) (* y (/ x z)) (- (/ x z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -14000.0) || !(y <= 1.7e+53)) {
		tmp = y * (x / 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 <= (-14000.0d0)) .or. (.not. (y <= 1.7d+53))) then
        tmp = y * (x / 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 <= -14000.0) || !(y <= 1.7e+53)) {
		tmp = y * (x / z);
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -14000.0) or not (y <= 1.7e+53):
		tmp = y * (x / z)
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -14000.0) || !(y <= 1.7e+53))
		tmp = Float64(y * Float64(x / z));
	else
		tmp = Float64(Float64(x / z) - x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -14000.0) || ~((y <= 1.7e+53)))
		tmp = y * (x / z);
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -14000.0], N[Not[LessEqual[y, 1.7e+53]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -14000 or 1.69999999999999999e53 < y

    1. Initial program 94.0%

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

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

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
      2. div-inv78.1%

        \[\leadsto \color{blue}{y \cdot \frac{1}{\frac{z}{x}}} \]
      3. clear-num78.4%

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

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

    if -14000 < y < 1.69999999999999999e53

    1. Initial program 90.9%

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

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

      \[\leadsto \color{blue}{-1 \cdot x + \frac{x}{z}} \]
    4. Step-by-step derivation
      1. +-commutative95.7%

        \[\leadsto \color{blue}{\frac{x}{z} + -1 \cdot x} \]
      2. mul-1-neg95.7%

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

        \[\leadsto \color{blue}{\frac{x}{z} - x} \]
    5. Simplified95.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 -14000 \lor \neg \left(y \leq 1.7 \cdot 10^{+53}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]

Alternative 8: 85.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -11000 \lor \neg \left(y \leq 1.5 \cdot 10^{+54}\right):\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -11000.0) (not (<= y 1.5e+54))) (/ (* y x) z) (- (/ x z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -11000.0) || !(y <= 1.5e+54)) {
		tmp = (y * x) / 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 <= (-11000.0d0)) .or. (.not. (y <= 1.5d+54))) then
        tmp = (y * x) / 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 <= -11000.0) || !(y <= 1.5e+54)) {
		tmp = (y * x) / z;
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -11000.0) or not (y <= 1.5e+54):
		tmp = (y * x) / z
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -11000.0) || !(y <= 1.5e+54))
		tmp = Float64(Float64(y * x) / z);
	else
		tmp = Float64(Float64(x / z) - x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -11000.0) || ~((y <= 1.5e+54)))
		tmp = (y * x) / z;
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -11000.0], N[Not[LessEqual[y, 1.5e+54]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -11000 or 1.4999999999999999e54 < y

    1. Initial program 94.0%

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

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

    if -11000 < y < 1.4999999999999999e54

    1. Initial program 90.9%

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

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

      \[\leadsto \color{blue}{-1 \cdot x + \frac{x}{z}} \]
    4. Step-by-step derivation
      1. +-commutative95.7%

        \[\leadsto \color{blue}{\frac{x}{z} + -1 \cdot x} \]
      2. mul-1-neg95.7%

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

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

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

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

Alternative 9: 96.1% accurate, 1.0× speedup?

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

\\
\frac{\left(1 + y\right) \cdot x}{z} - x
\end{array}
Derivation
  1. Initial program 92.2%

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

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

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

Alternative 10: 65.1% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -32000000000:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-6}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -32000000000.0) (- x) (if (<= z 4.2e-6) (/ x z) (- x))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -32000000000.0) {
		tmp = -x;
	} else if (z <= 4.2e-6) {
		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 <= (-32000000000.0d0)) then
        tmp = -x
    else if (z <= 4.2d-6) 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 <= -32000000000.0) {
		tmp = -x;
	} else if (z <= 4.2e-6) {
		tmp = x / z;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -32000000000.0:
		tmp = -x
	elif z <= 4.2e-6:
		tmp = x / z
	else:
		tmp = -x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -32000000000.0)
		tmp = Float64(-x);
	elseif (z <= 4.2e-6)
		tmp = Float64(x / z);
	else
		tmp = Float64(-x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -32000000000.0)
		tmp = -x;
	elseif (z <= 4.2e-6)
		tmp = x / z;
	else
		tmp = -x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -32000000000.0], (-x), If[LessEqual[z, 4.2e-6], N[(x / z), $MachinePrecision], (-x)]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq 4.2 \cdot 10^{-6}:\\
\;\;\;\;\frac{x}{z}\\

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


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

    1. Initial program 83.2%

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

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

        \[\leadsto \color{blue}{-x} \]
    4. Simplified75.9%

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

    if -3.2e10 < z < 4.1999999999999996e-6

    1. Initial program 99.9%

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

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

      \[\leadsto \color{blue}{-1 \cdot x + \frac{x}{z}} \]
    4. Step-by-step derivation
      1. +-commutative57.5%

        \[\leadsto \color{blue}{\frac{x}{z} + -1 \cdot x} \]
      2. mul-1-neg57.5%

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

        \[\leadsto \color{blue}{\frac{x}{z} - x} \]
    5. Simplified57.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -32000000000:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-6}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]

Alternative 11: 39.7% 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 92.2%

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

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

      \[\leadsto \color{blue}{-x} \]
  4. Simplified36.7%

    \[\leadsto \color{blue}{-x} \]
  5. Final simplification36.7%

    \[\leadsto -x \]

Alternative 12: 3.0% accurate, 9.0× 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 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 92.2%

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

    \[\leadsto \frac{\color{blue}{-1 \cdot \left(z \cdot x\right)}}{z} \]
  3. Step-by-step derivation
    1. mul-1-neg31.5%

      \[\leadsto \frac{\color{blue}{-z \cdot x}}{z} \]
    2. distribute-rgt-neg-in31.5%

      \[\leadsto \frac{\color{blue}{z \cdot \left(-x\right)}}{z} \]
  4. Simplified31.5%

    \[\leadsto \frac{\color{blue}{z \cdot \left(-x\right)}}{z} \]
  5. Step-by-step derivation
    1. expm1-log1p-u26.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{z \cdot \left(-x\right)}{z}\right)\right)} \]
    2. expm1-udef7.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{z \cdot \left(-x\right)}{z}\right)} - 1} \]
    3. div-inv7.9%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(z \cdot \left(-x\right)\right) \cdot \frac{1}{z}}\right)} - 1 \]
    4. associate-*l*12.6%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{z \cdot \left(\left(-x\right) \cdot \frac{1}{z}\right)}\right)} - 1 \]
    5. add-sqr-sqrt11.1%

      \[\leadsto e^{\mathsf{log1p}\left(z \cdot \left(\color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \cdot \frac{1}{z}\right)\right)} - 1 \]
    6. sqrt-unprod11.7%

      \[\leadsto e^{\mathsf{log1p}\left(z \cdot \left(\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}} \cdot \frac{1}{z}\right)\right)} - 1 \]
    7. sqr-neg11.7%

      \[\leadsto e^{\mathsf{log1p}\left(z \cdot \left(\sqrt{\color{blue}{x \cdot x}} \cdot \frac{1}{z}\right)\right)} - 1 \]
    8. sqrt-unprod4.1%

      \[\leadsto e^{\mathsf{log1p}\left(z \cdot \left(\color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \frac{1}{z}\right)\right)} - 1 \]
    9. add-sqr-sqrt5.0%

      \[\leadsto e^{\mathsf{log1p}\left(z \cdot \left(\color{blue}{x} \cdot \frac{1}{z}\right)\right)} - 1 \]
    10. div-inv5.0%

      \[\leadsto e^{\mathsf{log1p}\left(z \cdot \color{blue}{\frac{x}{z}}\right)} - 1 \]
  6. Applied egg-rr5.0%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(z \cdot \frac{x}{z}\right)} - 1} \]
  7. Step-by-step derivation
    1. expm1-def5.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(z \cdot \frac{x}{z}\right)\right)} \]
    2. expm1-log1p8.9%

      \[\leadsto \color{blue}{z \cdot \frac{x}{z}} \]
    3. associate-*r/2.8%

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

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

      \[\leadsto \color{blue}{1} \cdot x \]
    6. *-lft-identity2.9%

      \[\leadsto \color{blue}{x} \]
  8. Simplified2.9%

    \[\leadsto \color{blue}{x} \]
  9. Final simplification2.9%

    \[\leadsto x \]

Developer target: 99.5% 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 2023279 
(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))