Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A

Percentage Accurate: 87.9% → 99.0%
Time: 6.3s
Alternatives: 7
Speedup: 0.3×

Specification

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

\\
\frac{x + y}{1 - \frac{y}{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 7 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.9% accurate, 1.0× speedup?

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

\\
\frac{x + y}{1 - \frac{y}{z}}
\end{array}

Alternative 1: 99.0% accurate, 0.2× speedup?

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

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

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


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

    1. Initial program 99.8%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing

    if -9.99999999999999958e-234 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 0.0

    1. Initial program 13.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 100.0%

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

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

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

        \[\leadsto -1 \cdot z + \color{blue}{\frac{-1 \cdot \left(x \cdot z\right) - {z}^{2}}{y}} \]
      4. remove-double-neg100.0%

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

        \[\leadsto -1 \cdot z + \frac{-1 \cdot \left(x \cdot z\right) - \left(-\color{blue}{-1 \cdot {z}^{2}}\right)}{y} \]
      6. neg-mul-1100.0%

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

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

        \[\leadsto -1 \cdot z + \frac{\color{blue}{-\left(x \cdot z - -1 \cdot {z}^{2}\right)}}{y} \]
      9. distribute-neg-frac100.0%

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

        \[\leadsto \color{blue}{-1 \cdot z - \frac{x \cdot z - -1 \cdot {z}^{2}}{y}} \]
      11. mul-1-neg100.0%

        \[\leadsto \color{blue}{\left(-z\right)} - \frac{x \cdot z - -1 \cdot {z}^{2}}{y} \]
      12. sub-neg100.0%

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

        \[\leadsto \left(-z\right) - \frac{x \cdot z + \left(-\color{blue}{\left(-{z}^{2}\right)}\right)}{y} \]
      14. remove-double-neg100.0%

        \[\leadsto \left(-z\right) - \frac{x \cdot z + \color{blue}{{z}^{2}}}{y} \]
      15. unpow2100.0%

        \[\leadsto \left(-z\right) - \frac{x \cdot z + \color{blue}{z \cdot z}}{y} \]
      16. distribute-rgt-out100.0%

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

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

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

Alternative 2: 99.2% accurate, 0.3× speedup?

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

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

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


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

    1. Initial program 99.8%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing

    if -9.99999999999999958e-234 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 0.0

    1. Initial program 13.3%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num13.2%

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

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

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

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

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

        \[\leadsto -\color{blue}{\frac{z}{\frac{y}{x + y}}} \]
      3. +-commutative99.9%

        \[\leadsto -\frac{z}{\frac{y}{\color{blue}{y + x}}} \]
      4. associate-/r/14.9%

        \[\leadsto -\color{blue}{\frac{z}{y} \cdot \left(y + x\right)} \]
      5. distribute-rgt-in14.9%

        \[\leadsto -\color{blue}{\left(y \cdot \frac{z}{y} + x \cdot \frac{z}{y}\right)} \]
      6. distribute-neg-in14.9%

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

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

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

        \[\leadsto \left(-\color{blue}{\frac{z}{\frac{y}{y}}}\right) + \left(-x \cdot \frac{z}{y}\right) \]
      10. *-inverses87.3%

        \[\leadsto \left(-\frac{z}{\color{blue}{1}}\right) + \left(-x \cdot \frac{z}{y}\right) \]
      11. /-rgt-identity87.3%

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

        \[\leadsto \color{blue}{\left(-z\right) - x \cdot \frac{z}{y}} \]
      13. associate-*r/100.0%

        \[\leadsto \left(-z\right) - \color{blue}{\frac{x \cdot z}{y}} \]
      14. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(-z\right) + \left(-\frac{x \cdot z}{y}\right)} \]
      15. mul-1-neg100.0%

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

        \[\leadsto \color{blue}{-1 \cdot \frac{x \cdot z}{y} + \left(-z\right)} \]
      17. unsub-neg100.0%

        \[\leadsto \color{blue}{-1 \cdot \frac{x \cdot z}{y} - z} \]
      18. mul-1-neg100.0%

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

        \[\leadsto \left(-\color{blue}{\frac{x}{\frac{y}{z}}}\right) - z \]
      20. distribute-neg-frac87.3%

        \[\leadsto \color{blue}{\frac{-x}{\frac{y}{z}}} - z \]
    7. Simplified87.3%

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

      \[\leadsto \color{blue}{-1 \cdot z + -1 \cdot \frac{x \cdot z}{y}} \]
    9. Step-by-step derivation
      1. neg-mul-1100.0%

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

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

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

        \[\leadsto \left(-z\right) + \color{blue}{\left(-\frac{x}{y}\right) \cdot z} \]
      5. cancel-sign-sub-inv100.0%

        \[\leadsto \color{blue}{\left(-z\right) - \frac{x}{y} \cdot z} \]
      6. neg-mul-1100.0%

        \[\leadsto \color{blue}{-1 \cdot z} - \frac{x}{y} \cdot z \]
      7. distribute-rgt-out--99.9%

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

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

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

Alternative 3: 75.0% accurate, 0.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;x + y\\


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

    1. Initial program 81.4%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num81.3%

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

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

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

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

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

        \[\leadsto -\color{blue}{\frac{z}{\frac{y}{x + y}}} \]
      3. +-commutative80.0%

        \[\leadsto -\frac{z}{\frac{y}{\color{blue}{y + x}}} \]
      4. associate-/r/61.9%

        \[\leadsto -\color{blue}{\frac{z}{y} \cdot \left(y + x\right)} \]
      5. distribute-rgt-in61.9%

        \[\leadsto -\color{blue}{\left(y \cdot \frac{z}{y} + x \cdot \frac{z}{y}\right)} \]
      6. distribute-neg-in61.9%

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

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

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

        \[\leadsto \left(-\color{blue}{\frac{z}{\frac{y}{y}}}\right) + \left(-x \cdot \frac{z}{y}\right) \]
      10. *-inverses77.4%

        \[\leadsto \left(-\frac{z}{\color{blue}{1}}\right) + \left(-x \cdot \frac{z}{y}\right) \]
      11. /-rgt-identity77.4%

        \[\leadsto \left(-\color{blue}{z}\right) + \left(-x \cdot \frac{z}{y}\right) \]
      12. unsub-neg77.4%

        \[\leadsto \color{blue}{\left(-z\right) - x \cdot \frac{z}{y}} \]
      13. associate-*r/75.2%

        \[\leadsto \left(-z\right) - \color{blue}{\frac{x \cdot z}{y}} \]
      14. unsub-neg75.2%

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

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

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

        \[\leadsto \color{blue}{-1 \cdot \frac{x \cdot z}{y} - z} \]
      18. mul-1-neg75.2%

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

        \[\leadsto \left(-\color{blue}{\frac{x}{\frac{y}{z}}}\right) - z \]
      20. distribute-neg-frac77.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot z + -1 \cdot \frac{x \cdot z}{y}} \]
    9. Step-by-step derivation
      1. neg-mul-175.2%

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

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

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

        \[\leadsto \left(-z\right) + \color{blue}{\left(-\frac{x}{y}\right) \cdot z} \]
      5. cancel-sign-sub-inv80.2%

        \[\leadsto \color{blue}{\left(-z\right) - \frac{x}{y} \cdot z} \]
      6. neg-mul-180.2%

        \[\leadsto \color{blue}{-1 \cdot z} - \frac{x}{y} \cdot z \]
      7. distribute-rgt-out--80.1%

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

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

    if -0.095000000000000001 < y < 3e32

    1. Initial program 99.9%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 80.5%

      \[\leadsto \color{blue}{x + y} \]
    4. Step-by-step derivation
      1. +-commutative80.5%

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified80.5%

      \[\leadsto \color{blue}{y + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.4%

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

Alternative 4: 67.8% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.7 \cdot 10^{+21} \lor \neg \left(y \leq 5.5 \cdot 10^{+61}\right):\\
\;\;\;\;-z\\

\mathbf{else}:\\
\;\;\;\;x + y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.7e21 or 5.50000000000000036e61 < y

    1. Initial program 80.4%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 64.4%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. mul-1-neg64.4%

        \[\leadsto \color{blue}{-z} \]
    5. Simplified64.4%

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

    if -4.7e21 < y < 5.50000000000000036e61

    1. Initial program 99.9%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 78.7%

      \[\leadsto \color{blue}{x + y} \]
    4. Step-by-step derivation
      1. +-commutative78.7%

        \[\leadsto \color{blue}{y + x} \]
    5. Simplified78.7%

      \[\leadsto \color{blue}{y + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.7 \cdot 10^{+21} \lor \neg \left(y \leq 5.5 \cdot 10^{+61}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 58.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.075 \lor \neg \left(y \leq 3.7 \cdot 10^{+31}\right):\\
\;\;\;\;-z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.0749999999999999972 or 3.6999999999999998e31 < y

    1. Initial program 81.5%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 62.5%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. mul-1-neg62.5%

        \[\leadsto \color{blue}{-z} \]
    5. Simplified62.5%

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

    if -0.0749999999999999972 < y < 3.6999999999999998e31

    1. Initial program 99.9%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 60.7%

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

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

Alternative 6: 39.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-15}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-46}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -7.5e-15) x (if (<= x 2.7e-46) y x)))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -7.5e-15) {
		tmp = x;
	} else if (x <= 2.7e-46) {
		tmp = y;
	} 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 (x <= (-7.5d-15)) then
        tmp = x
    else if (x <= 2.7d-46) then
        tmp = y
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -7.5e-15) {
		tmp = x;
	} else if (x <= 2.7e-46) {
		tmp = y;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -7.5e-15:
		tmp = x
	elif x <= 2.7e-46:
		tmp = y
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -7.5e-15)
		tmp = x;
	elseif (x <= 2.7e-46)
		tmp = y;
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -7.5e-15)
		tmp = x;
	elseif (x <= 2.7e-46)
		tmp = y;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -7.5e-15], x, If[LessEqual[x, 2.7e-46], y, x]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 2.7 \cdot 10^{-46}:\\
\;\;\;\;y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.4999999999999996e-15 or 2.7e-46 < x

    1. Initial program 90.0%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 50.3%

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

    if -7.4999999999999996e-15 < x < 2.7e-46

    1. Initial program 93.2%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 78.4%

      \[\leadsto \color{blue}{\frac{y}{1 - \frac{y}{z}}} \]
    4. Taylor expanded in y around 0 39.7%

      \[\leadsto \color{blue}{y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification45.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-15}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-46}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 34.2% 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 + y}{1 - \frac{y}{z}} \]
  2. Add Preprocessing
  3. Taylor expanded in y around 0 35.7%

    \[\leadsto \color{blue}{x} \]
  4. Final simplification35.7%

    \[\leadsto x \]
  5. Add Preprocessing

Developer target: 94.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y + x}{-y} \cdot z\\ \mathbf{if}\;y < -3.7429310762689856 \cdot 10^{+171}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y < 3.5534662456086734 \cdot 10^{+168}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (/ (+ y x) (- y)) z)))
   (if (< y -3.7429310762689856e+171)
     t_0
     (if (< y 3.5534662456086734e+168) (/ (+ x y) (- 1.0 (/ y z))) t_0))))
double code(double x, double y, double z) {
	double t_0 = ((y + x) / -y) * z;
	double tmp;
	if (y < -3.7429310762689856e+171) {
		tmp = t_0;
	} else if (y < 3.5534662456086734e+168) {
		tmp = (x + y) / (1.0 - (y / 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 = ((y + x) / -y) * z
    if (y < (-3.7429310762689856d+171)) then
        tmp = t_0
    else if (y < 3.5534662456086734d+168) then
        tmp = (x + y) / (1.0d0 - (y / z))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = ((y + x) / -y) * z;
	double tmp;
	if (y < -3.7429310762689856e+171) {
		tmp = t_0;
	} else if (y < 3.5534662456086734e+168) {
		tmp = (x + y) / (1.0 - (y / z));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = ((y + x) / -y) * z
	tmp = 0
	if y < -3.7429310762689856e+171:
		tmp = t_0
	elif y < 3.5534662456086734e+168:
		tmp = (x + y) / (1.0 - (y / z))
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(Float64(y + x) / Float64(-y)) * z)
	tmp = 0.0
	if (y < -3.7429310762689856e+171)
		tmp = t_0;
	elseif (y < 3.5534662456086734e+168)
		tmp = Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = ((y + x) / -y) * z;
	tmp = 0.0;
	if (y < -3.7429310762689856e+171)
		tmp = t_0;
	elseif (y < 3.5534662456086734e+168)
		tmp = (x + y) / (1.0 - (y / z));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(y + x), $MachinePrecision] / (-y)), $MachinePrecision] * z), $MachinePrecision]}, If[Less[y, -3.7429310762689856e+171], t$95$0, If[Less[y, 3.5534662456086734e+168], N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y + x}{-y} \cdot z\\
\mathbf{if}\;y < -3.7429310762689856 \cdot 10^{+171}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y < 3.5534662456086734 \cdot 10^{+168}:\\
\;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024018 
(FPCore (x y z)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"
  :precision binary64

  :herbie-target
  (if (< y -3.7429310762689856e+171) (* (/ (+ y x) (- y)) z) (if (< y 3.5534662456086734e+168) (/ (+ x y) (- 1.0 (/ y z))) (* (/ (+ y x) (- y)) z)))

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