?

Average Accuracy: 88.2% → 98.2%
Time: 9.0s
Precision: binary64
Cost: 8969

?

\[\frac{x + y}{1 - \frac{y}{z}} \]
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{-201} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(z \cdot z, \frac{1}{y} + \frac{x}{y \cdot y}, z \cdot \frac{x + y}{y}\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x y) (- 1.0 (/ y z)))))
   (if (or (<= t_0 -1e-201) (not (<= t_0 0.0)))
     t_0
     (- (fma (* z z) (+ (/ 1.0 y) (/ x (* y y))) (* z (/ (+ x y) y)))))))
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 = (x + y) / (1.0 - (y / z));
	double tmp;
	if ((t_0 <= -1e-201) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = -fma((z * z), ((1.0 / y) + (x / (y * y))), (z * ((x + y) / y)));
	}
	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 = Float64(Float64(x + y) / Float64(1.0 - Float64(y / z)))
	tmp = 0.0
	if ((t_0 <= -1e-201) || !(t_0 <= 0.0))
		tmp = t_0;
	else
		tmp = Float64(-fma(Float64(z * z), Float64(Float64(1.0 / y) + Float64(x / Float64(y * y))), Float64(z * Float64(Float64(x + y) / y))));
	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[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e-201], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, (-N[(N[(z * z), $MachinePrecision] * N[(N[(1.0 / y), $MachinePrecision] + N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z * N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])]]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{-201} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original88.2%
Target94.1%
Herbie98.2%
\[\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 2 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -9.99999999999999946e-202 or 0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 99.9%

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

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

    1. Initial program 25.5%

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

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

      [Start]25.5

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

      +-commutative [=>]25.5

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

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

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

      [Start]86.1

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

      distribute-lft-out [=>]86.1

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

      mul-1-neg [=>]86.1

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

      *-commutative [=>]86.1

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

      fma-def [=>]86.1

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

      unpow2 [=>]86.1

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

      unpow2 [=>]86.1

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

      associate-/l* [=>]14.7

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

      associate-/r/ [=>]89.1

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

      +-commutative [=>]89.1

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

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

Alternatives

Alternative 1
Accuracy99.8%
Cost1865
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-285} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-z\right) - z\\ \end{array} \]
Alternative 2
Accuracy75.8%
Cost972
\[\begin{array}{l} t_0 := \frac{x}{y} \cdot \left(-z\right) - z\\ \mathbf{if}\;y \leq -1.1 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-126}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.52 \cdot 10^{-10}:\\ \;\;\;\;\left(1 + \frac{y}{z}\right) \cdot \left(x + y\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy75.8%
Cost908
\[\begin{array}{l} t_0 := \frac{x}{y} \cdot \left(-z\right) - z\\ \mathbf{if}\;y \leq -1.05 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2 \cdot 10^{-126}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{-10}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy75.8%
Cost844
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.4 \cdot 10^{-126}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-10}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy68.3%
Cost780
\[\begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{+52}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+45}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+84}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{+102}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Accuracy75.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+25} \lor \neg \left(y \leq 2.5 \cdot 10^{-10}\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Accuracy69.0%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{+50}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+102}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Accuracy59.6%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+24}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 12000000000000:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Accuracy41.2%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-121}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Accuracy35.9%
Cost64
\[x \]

Error

Reproduce?

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