?

Average Accuracy: 88.4% → 99.7%
Time: 10.4s
Precision: binary64
Cost: 22984

?

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

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\left(\frac{-z}{\frac{y}{x}} - \left(\frac{t_0}{\frac{{y}^{3}}{z \cdot z}} + \left(z + \frac{t_0}{y} \cdot \frac{z}{y}\right)\right)\right) - \frac{z}{\frac{y}{z}}\\

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


\end{array}

Error?

Target

Original88.4%
Target93.6%
Herbie99.7%
\[\begin{array}{l} \mathbf{if}\;y < -3.7429310762689856 \cdot 10^{+171}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \mathbf{elif}\;y < 3.5534662456086734 \cdot 10^{+168}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{-y} \cdot z\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -9.99999999999999969e-278

    1. Initial program 99.9%

      \[\frac{x + y}{1 - \frac{y}{z}} \]

    if -9.99999999999999969e-278 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 0.0

    1. Initial program 9.2%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Simplified9.2%

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

      [Start]9.2

      \[ \frac{x + y}{1 - \frac{y}{z}} \]

      +-commutative [=>]9.2

      \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}} \]
    3. Taylor expanded in y around inf 98.2%

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

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

      [Start]98.2

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

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

    1. Initial program 99.9%

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Simplified99.9%

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

      [Start]99.9

      \[ \frac{x + y}{1 - \frac{y}{z}} \]

      +-commutative [=>]99.9

      \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}} \]
    3. Taylor expanded in x around 0 99.9%

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}} + \frac{y}{1 - \frac{y}{z}}} \]
    4. Simplified99.9%

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

      [Start]99.9

      \[ \frac{x}{1 - \frac{y}{z}} + \frac{y}{1 - \frac{y}{z}} \]

      +-commutative [=>]99.9

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

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

Alternatives

Alternative 1
Accuracy99.8%
Cost2248
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x + y}{t_0}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-277}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{z}{\frac{-y}{x + y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{t_0} + \frac{x}{t_0}\\ \end{array} \]
Alternative 2
Accuracy99.8%
Cost1865
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{-277} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{-y}{x + y}}\\ \end{array} \]
Alternative 3
Accuracy71.6%
Cost1243
\[\begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+65} \lor \neg \left(y \leq 9 \cdot 10^{-77}\right) \land \left(y \leq 2.2 \cdot 10^{-45} \lor \neg \left(y \leq 7.5 \cdot 10^{+39}\right) \land \left(y \leq 4.5 \cdot 10^{+122} \lor \neg \left(y \leq 1.75 \cdot 10^{+156}\right)\right)\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Accuracy71.7%
Cost1241
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.22 \cdot 10^{+178}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{-21}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+40}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+122} \lor \neg \left(y \leq 3.8 \cdot 10^{+156}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Accuracy71.7%
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \left(-z\right) - z \cdot \frac{x}{y}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.75 \cdot 10^{+176}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-21}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-57}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+40}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+122}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+156}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Accuracy71.7%
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -4.4 \cdot 10^{+172}:\\ \;\;\;\;\left(-z\right) - z \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-21}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{+40}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+122}:\\ \;\;\;\;\frac{z}{\frac{-y}{x + y}}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+156}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy72.2%
Cost977
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -3.2 \cdot 10^{-58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{+40}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{+122} \lor \neg \left(y \leq 1.75 \cdot 10^{+156}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 8
Accuracy66.7%
Cost721
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{+127}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+42} \lor \neg \left(y \leq 5.5 \cdot 10^{+121}\right) \land y \leq 2 \cdot 10^{+156}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Accuracy57.5%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -1.85 \cdot 10^{-57}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 7 \cdot 10^{+40}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Accuracy41.5%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.9 \cdot 10^{-182}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-122}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Accuracy34.7%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023129 
(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))))