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

Percentage Accurate: 88.2% → 99.8%
Time: 9.5s
Alternatives: 11
Speedup: 0.6×

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 11 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.8% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.00000000000000029e-17 or 8.8000000000000001e-51 < z

    1. Initial program 82.9%

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

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

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

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

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

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

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

    if -4.00000000000000029e-17 < z < 8.8000000000000001e-51

    1. Initial program 99.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{-17} \lor \neg \left(z \leq 8.8 \cdot 10^{-51}\right):\\ \;\;\;\;x \cdot \frac{y - \left(z + -1\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + x \cdot y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 93.9% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 10000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}\\

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


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

    1. Initial program 93.7%

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

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

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

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

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

    if 1e7 < x

    1. Initial program 83.5%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 10000000:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y - z, x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - \left(z + -1\right)}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 65.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;z \leq -2 \cdot 10^{+55}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-12}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{-143}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{-252}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -4.4 \cdot 10^{-276}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 2.8 \cdot 10^{-169}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{-80}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+18}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (/ x z))))
   (if (<= z -2e+55)
     (- x)
     (if (<= z -1.7e-12)
       (* x (/ y z))
       (if (<= z -1.55e-143)
         (/ x z)
         (if (<= z -2.4e-252)
           t_0
           (if (<= z -4.4e-276)
             (/ x z)
             (if (<= z 2.8e-169)
               t_0
               (if (<= z 5.4e-80)
                 (/ x z)
                 (if (<= z 1.65e+18) t_0 (- x)))))))))))
double code(double x, double y, double z) {
	double t_0 = y * (x / z);
	double tmp;
	if (z <= -2e+55) {
		tmp = -x;
	} else if (z <= -1.7e-12) {
		tmp = x * (y / z);
	} else if (z <= -1.55e-143) {
		tmp = x / z;
	} else if (z <= -2.4e-252) {
		tmp = t_0;
	} else if (z <= -4.4e-276) {
		tmp = x / z;
	} else if (z <= 2.8e-169) {
		tmp = t_0;
	} else if (z <= 5.4e-80) {
		tmp = x / z;
	} else if (z <= 1.65e+18) {
		tmp = t_0;
	} 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 <= (-2d+55)) then
        tmp = -x
    else if (z <= (-1.7d-12)) then
        tmp = x * (y / z)
    else if (z <= (-1.55d-143)) then
        tmp = x / z
    else if (z <= (-2.4d-252)) then
        tmp = t_0
    else if (z <= (-4.4d-276)) then
        tmp = x / z
    else if (z <= 2.8d-169) then
        tmp = t_0
    else if (z <= 5.4d-80) then
        tmp = x / z
    else if (z <= 1.65d+18) then
        tmp = t_0
    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 <= -2e+55) {
		tmp = -x;
	} else if (z <= -1.7e-12) {
		tmp = x * (y / z);
	} else if (z <= -1.55e-143) {
		tmp = x / z;
	} else if (z <= -2.4e-252) {
		tmp = t_0;
	} else if (z <= -4.4e-276) {
		tmp = x / z;
	} else if (z <= 2.8e-169) {
		tmp = t_0;
	} else if (z <= 5.4e-80) {
		tmp = x / z;
	} else if (z <= 1.65e+18) {
		tmp = t_0;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (x / z)
	tmp = 0
	if z <= -2e+55:
		tmp = -x
	elif z <= -1.7e-12:
		tmp = x * (y / z)
	elif z <= -1.55e-143:
		tmp = x / z
	elif z <= -2.4e-252:
		tmp = t_0
	elif z <= -4.4e-276:
		tmp = x / z
	elif z <= 2.8e-169:
		tmp = t_0
	elif z <= 5.4e-80:
		tmp = x / z
	elif z <= 1.65e+18:
		tmp = t_0
	else:
		tmp = -x
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(x / z))
	tmp = 0.0
	if (z <= -2e+55)
		tmp = Float64(-x);
	elseif (z <= -1.7e-12)
		tmp = Float64(x * Float64(y / z));
	elseif (z <= -1.55e-143)
		tmp = Float64(x / z);
	elseif (z <= -2.4e-252)
		tmp = t_0;
	elseif (z <= -4.4e-276)
		tmp = Float64(x / z);
	elseif (z <= 2.8e-169)
		tmp = t_0;
	elseif (z <= 5.4e-80)
		tmp = Float64(x / z);
	elseif (z <= 1.65e+18)
		tmp = t_0;
	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 <= -2e+55)
		tmp = -x;
	elseif (z <= -1.7e-12)
		tmp = x * (y / z);
	elseif (z <= -1.55e-143)
		tmp = x / z;
	elseif (z <= -2.4e-252)
		tmp = t_0;
	elseif (z <= -4.4e-276)
		tmp = x / z;
	elseif (z <= 2.8e-169)
		tmp = t_0;
	elseif (z <= 5.4e-80)
		tmp = x / z;
	elseif (z <= 1.65e+18)
		tmp = t_0;
	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, -2e+55], (-x), If[LessEqual[z, -1.7e-12], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -1.55e-143], N[(x / z), $MachinePrecision], If[LessEqual[z, -2.4e-252], t$95$0, If[LessEqual[z, -4.4e-276], N[(x / z), $MachinePrecision], If[LessEqual[z, 2.8e-169], t$95$0, If[LessEqual[z, 5.4e-80], N[(x / z), $MachinePrecision], If[LessEqual[z, 1.65e+18], t$95$0, (-x)]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;z \leq -1.55 \cdot 10^{-143}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;z \leq -2.4 \cdot 10^{-252}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq -4.4 \cdot 10^{-276}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;z \leq 2.8 \cdot 10^{-169}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 5.4 \cdot 10^{-80}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;z \leq 1.65 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -2.00000000000000002e55 or 1.65e18 < z

    1. Initial program 78.5%

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

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

        \[\leadsto \color{blue}{-x} \]
    5. Simplified78.3%

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

    if -2.00000000000000002e55 < z < -1.7e-12

    1. Initial program 99.7%

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

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

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

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

    if -1.7e-12 < z < -1.55000000000000004e-143 or -2.4000000000000002e-252 < z < -4.39999999999999961e-276 or 2.79999999999999988e-169 < z < 5.4000000000000004e-80

    1. Initial program 99.9%

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

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

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

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

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

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

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

    if -1.55000000000000004e-143 < z < -2.4000000000000002e-252 or -4.39999999999999961e-276 < z < 2.79999999999999988e-169 or 5.4000000000000004e-80 < z < 1.65e18

    1. Initial program 99.9%

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

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

        \[\leadsto \frac{\color{blue}{y \cdot x}}{z} \]
      2. associate-/l*80.9%

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

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

Alternative 4: 62.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \frac{y}{z}\\ \mathbf{if}\;z \leq -1.9 \cdot 10^{+55}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -3.3 \cdot 10^{-12}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-277}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 1.95 \cdot 10^{-166}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-75}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 10^{+18}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (/ y z))))
   (if (<= z -1.9e+55)
     (- x)
     (if (<= z -3.3e-12)
       t_0
       (if (<= z -2.6e-277)
         (/ x z)
         (if (<= z 1.95e-166)
           t_0
           (if (<= z 2.5e-75) (/ x z) (if (<= z 1e+18) t_0 (- x)))))))))
double code(double x, double y, double z) {
	double t_0 = x * (y / z);
	double tmp;
	if (z <= -1.9e+55) {
		tmp = -x;
	} else if (z <= -3.3e-12) {
		tmp = t_0;
	} else if (z <= -2.6e-277) {
		tmp = x / z;
	} else if (z <= 1.95e-166) {
		tmp = t_0;
	} else if (z <= 2.5e-75) {
		tmp = x / z;
	} else if (z <= 1e+18) {
		tmp = t_0;
	} 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 = x * (y / z)
    if (z <= (-1.9d+55)) then
        tmp = -x
    else if (z <= (-3.3d-12)) then
        tmp = t_0
    else if (z <= (-2.6d-277)) then
        tmp = x / z
    else if (z <= 1.95d-166) then
        tmp = t_0
    else if (z <= 2.5d-75) then
        tmp = x / z
    else if (z <= 1d+18) then
        tmp = t_0
    else
        tmp = -x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (y / z);
	double tmp;
	if (z <= -1.9e+55) {
		tmp = -x;
	} else if (z <= -3.3e-12) {
		tmp = t_0;
	} else if (z <= -2.6e-277) {
		tmp = x / z;
	} else if (z <= 1.95e-166) {
		tmp = t_0;
	} else if (z <= 2.5e-75) {
		tmp = x / z;
	} else if (z <= 1e+18) {
		tmp = t_0;
	} else {
		tmp = -x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (y / z)
	tmp = 0
	if z <= -1.9e+55:
		tmp = -x
	elif z <= -3.3e-12:
		tmp = t_0
	elif z <= -2.6e-277:
		tmp = x / z
	elif z <= 1.95e-166:
		tmp = t_0
	elif z <= 2.5e-75:
		tmp = x / z
	elif z <= 1e+18:
		tmp = t_0
	else:
		tmp = -x
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(y / z))
	tmp = 0.0
	if (z <= -1.9e+55)
		tmp = Float64(-x);
	elseif (z <= -3.3e-12)
		tmp = t_0;
	elseif (z <= -2.6e-277)
		tmp = Float64(x / z);
	elseif (z <= 1.95e-166)
		tmp = t_0;
	elseif (z <= 2.5e-75)
		tmp = Float64(x / z);
	elseif (z <= 1e+18)
		tmp = t_0;
	else
		tmp = Float64(-x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (y / z);
	tmp = 0.0;
	if (z <= -1.9e+55)
		tmp = -x;
	elseif (z <= -3.3e-12)
		tmp = t_0;
	elseif (z <= -2.6e-277)
		tmp = x / z;
	elseif (z <= 1.95e-166)
		tmp = t_0;
	elseif (z <= 2.5e-75)
		tmp = x / z;
	elseif (z <= 1e+18)
		tmp = t_0;
	else
		tmp = -x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.9e+55], (-x), If[LessEqual[z, -3.3e-12], t$95$0, If[LessEqual[z, -2.6e-277], N[(x / z), $MachinePrecision], If[LessEqual[z, 1.95e-166], t$95$0, If[LessEqual[z, 2.5e-75], N[(x / z), $MachinePrecision], If[LessEqual[z, 1e+18], t$95$0, (-x)]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;z \leq -3.3 \cdot 10^{-12}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq -2.6 \cdot 10^{-277}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;z \leq 1.95 \cdot 10^{-166}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 2.5 \cdot 10^{-75}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;z \leq 10^{+18}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.9e55 or 1e18 < z

    1. Initial program 78.5%

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

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

        \[\leadsto \color{blue}{-x} \]
    5. Simplified78.3%

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

    if -1.9e55 < z < -3.3000000000000001e-12 or -2.6e-277 < z < 1.95e-166 or 2.49999999999999989e-75 < z < 1e18

    1. Initial program 99.8%

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

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

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

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

    if -3.3000000000000001e-12 < z < -2.6e-277 or 1.95e-166 < z < 2.49999999999999989e-75

    1. Initial program 99.9%

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

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

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

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

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

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

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

Alternative 5: 92.9% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.82e22 or 5e11 < y

    1. Initial program 91.2%

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutative91.2%

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

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

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

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

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

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

    if -1.82e22 < y < 5e11

    1. Initial program 91.6%

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

      \[\leadsto \frac{\color{blue}{x \cdot \left(1 - z\right)}}{z} \]
    4. Step-by-step derivation
      1. sub-neg90.0%

        \[\leadsto \frac{x \cdot \color{blue}{\left(1 + \left(-z\right)\right)}}{z} \]
      2. distribute-lft-in90.0%

        \[\leadsto \frac{\color{blue}{x \cdot 1 + x \cdot \left(-z\right)}}{z} \]
      3. *-rgt-identity90.0%

        \[\leadsto \frac{\color{blue}{x} + x \cdot \left(-z\right)}{z} \]
      4. distribute-rgt-neg-in90.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{x}{z} - x} \]
    8. Simplified98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.82 \cdot 10^{+22} \lor \neg \left(y \leq 500000000000\right):\\ \;\;\;\;\left(y - \left(z + -1\right)\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 84.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+50} \lor \neg \left(y \leq 1.7 \cdot 10^{+15}\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.2e+50) (not (<= y 1.7e+15))) (/ (* x y) z) (- (/ x z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -3.2e+50) || !(y <= 1.7e+15)) {
		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.2d+50)) .or. (.not. (y <= 1.7d+15))) 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.2e+50) || !(y <= 1.7e+15)) {
		tmp = (x * y) / z;
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -3.2e+50) or not (y <= 1.7e+15):
		tmp = (x * y) / z
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -3.2e+50) || !(y <= 1.7e+15))
		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.2e+50) || ~((y <= 1.7e+15)))
		tmp = (x * y) / z;
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.2e+50], N[Not[LessEqual[y, 1.7e+15]], $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.2 \cdot 10^{+50} \lor \neg \left(y \leq 1.7 \cdot 10^{+15}\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.19999999999999983e50 or 1.7e15 < y

    1. Initial program 92.6%

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

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

    if -3.19999999999999983e50 < y < 1.7e15

    1. Initial program 90.5%

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

      \[\leadsto \frac{\color{blue}{x \cdot \left(1 - z\right)}}{z} \]
    4. Step-by-step derivation
      1. sub-neg88.2%

        \[\leadsto \frac{x \cdot \color{blue}{\left(1 + \left(-z\right)\right)}}{z} \]
      2. distribute-lft-in88.2%

        \[\leadsto \frac{\color{blue}{x \cdot 1 + x \cdot \left(-z\right)}}{z} \]
      3. *-rgt-identity88.2%

        \[\leadsto \frac{\color{blue}{x} + x \cdot \left(-z\right)}{z} \]
      4. distribute-rgt-neg-in88.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(-x\right)} + \frac{x}{z} \]
      2. +-commutative97.6%

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

        \[\leadsto \color{blue}{\frac{x}{z} - x} \]
    8. Simplified97.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+50} \lor \neg \left(y \leq 1.7 \cdot 10^{+15}\right):\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 84.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{+50} \lor \neg \left(y \leq 9.5 \cdot 10^{+15}\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 -3.3e+50) (not (<= y 9.5e+15))) (* y (/ x z)) (- (/ x z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -3.3e+50) || !(y <= 9.5e+15)) {
		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 <= (-3.3d+50)) .or. (.not. (y <= 9.5d+15))) 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 <= -3.3e+50) || !(y <= 9.5e+15)) {
		tmp = y * (x / z);
	} else {
		tmp = (x / z) - x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -3.3e+50) or not (y <= 9.5e+15):
		tmp = y * (x / z)
	else:
		tmp = (x / z) - x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -3.3e+50) || !(y <= 9.5e+15))
		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 <= -3.3e+50) || ~((y <= 9.5e+15)))
		tmp = y * (x / z);
	else
		tmp = (x / z) - x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.3e+50], N[Not[LessEqual[y, 9.5e+15]], $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 -3.3 \cdot 10^{+50} \lor \neg \left(y \leq 9.5 \cdot 10^{+15}\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 < -3.3e50 or 9.5e15 < y

    1. Initial program 92.6%

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

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

        \[\leadsto \frac{\color{blue}{y \cdot x}}{z} \]
      2. associate-/l*81.4%

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

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

    if -3.3e50 < y < 9.5e15

    1. Initial program 90.5%

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

      \[\leadsto \frac{\color{blue}{x \cdot \left(1 - z\right)}}{z} \]
    4. Step-by-step derivation
      1. sub-neg88.2%

        \[\leadsto \frac{x \cdot \color{blue}{\left(1 + \left(-z\right)\right)}}{z} \]
      2. distribute-lft-in88.2%

        \[\leadsto \frac{\color{blue}{x \cdot 1 + x \cdot \left(-z\right)}}{z} \]
      3. *-rgt-identity88.2%

        \[\leadsto \frac{\color{blue}{x} + x \cdot \left(-z\right)}{z} \]
      4. distribute-rgt-neg-in88.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(-x\right)} + \frac{x}{z} \]
      2. +-commutative97.6%

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

        \[\leadsto \color{blue}{\frac{x}{z} - x} \]
    8. Simplified97.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{+50} \lor \neg \left(y \leq 9.5 \cdot 10^{+15}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 93.9% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 93.7%

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

    if 9.2e6 < x

    1. Initial program 83.5%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 9200000:\\ \;\;\;\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - \left(z + -1\right)}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 65.0% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1.26 \cdot 10^{-5}\right):\\
\;\;\;\;-x\\

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


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

    1. Initial program 81.3%

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

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

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

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

    if -1 < z < 1.25999999999999996e-5

    1. Initial program 99.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1.26 \cdot 10^{-5}\right):\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 39.0% 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.4%

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

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

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

    \[\leadsto \color{blue}{-x} \]
  6. Add Preprocessing

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{x \cdot \left(-z\right)}}{z} \]
  6. Step-by-step derivation
    1. *-commutative27.6%

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

      \[\leadsto \color{blue}{\left(-z\right) \cdot \frac{x}{z}} \]
    3. add-sqr-sqrt20.3%

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

      \[\leadsto \color{blue}{\sqrt{\left(-z\right) \cdot \left(-z\right)}} \cdot \frac{x}{z} \]
    5. sqr-neg13.0%

      \[\leadsto \sqrt{\color{blue}{z \cdot z}} \cdot \frac{x}{z} \]
    6. sqrt-unprod8.7%

      \[\leadsto \color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)} \cdot \frac{x}{z} \]
    7. add-sqr-sqrt10.8%

      \[\leadsto \color{blue}{z} \cdot \frac{x}{z} \]
  7. Applied egg-rr10.8%

    \[\leadsto \color{blue}{z \cdot \frac{x}{z}} \]
  8. Step-by-step derivation
    1. associate-*r/2.9%

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

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

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

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

    \[\leadsto \color{blue}{x} \]
  10. Add Preprocessing

Developer target: 99.4% accurate, 0.4× 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 2024097 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :alt
  (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))