Average Error: 7.5 → 0.9
Time: 6.8s
Precision: binary64
Cost: 1864
\[\frac{x + y}{1 - \frac{y}{z}} \]
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-201}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{-z}{\frac{y}{x + y}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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 (<= t_0 -5e-201) t_0 (if (<= t_0 0.0) (/ (- z) (/ y (+ x y))) t_0))))
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 <= -5e-201) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = -z / (y / (x + y));
	} 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
    code = (x + y) / (1.0d0 - (y / z))
end function
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 <= (-5d-201)) then
        tmp = t_0
    else if (t_0 <= 0.0d0) then
        tmp = -z / (y / (x + y))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x + y) / (1.0 - (y / z));
}
public static double code(double x, double y, double z) {
	double t_0 = (x + y) / (1.0 - (y / z));
	double tmp;
	if (t_0 <= -5e-201) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = -z / (y / (x + y));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return (x + y) / (1.0 - (y / z))
def code(x, y, z):
	t_0 = (x + y) / (1.0 - (y / z))
	tmp = 0
	if t_0 <= -5e-201:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = -z / (y / (x + y))
	else:
		tmp = t_0
	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 <= -5e-201)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(Float64(-z) / Float64(y / Float64(x + y)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x + y) / (1.0 - (y / z));
end
function tmp_2 = code(x, y, z)
	t_0 = (x + y) / (1.0 - (y / z));
	tmp = 0.0;
	if (t_0 <= -5e-201)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = -z / (y / (x + y));
	else
		tmp = t_0;
	end
	tmp_2 = 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[LessEqual[t$95$0, -5e-201], t$95$0, If[LessEqual[t$95$0, 0.0], N[((-z) / N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-201}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{-z}{\frac{y}{x + y}}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.5
Target3.8
Herbie0.9
\[\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))) < -4.9999999999999999e-201 or -0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 0.1

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

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

    1. Initial program 47.6

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Taylor expanded in z around 0 9.0

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

      \[\leadsto \color{blue}{\frac{y + x}{y} \cdot \left(-z\right)} \]
      Proof
      (*.f64 (/.f64 (+.f64 y x) y) (neg.f64 z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (/.f64 (+.f64 y x) y) z))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (+.f64 y x) z) y))): 62 points increase in error, 28 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 (+.f64 y x) z) y))): 0 points increase in error, 0 points decrease in error
    4. Applied egg-rr5.6

      \[\leadsto \color{blue}{{\left(\frac{y}{y + x}\right)}^{-1}} \cdot \left(-z\right) \]
    5. Applied egg-rr5.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -5 \cdot 10^{-201}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{elif}\;\frac{x + y}{1 - \frac{y}{z}} \leq 0:\\ \;\;\;\;\frac{-z}{\frac{y}{x + y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \end{array} \]

Alternatives

Alternative 1
Error16.8
Cost1040
\[\begin{array}{l} \mathbf{if}\;z \leq -3.0057694370324236 \cdot 10^{-43}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.5836852612595462 \cdot 10^{-57}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y} - z\\ \mathbf{elif}\;z \leq 4.9054715775803576 \cdot 10^{-33}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 6.014845664009336 \cdot 10^{+71}:\\ \;\;\;\;\frac{-z}{\frac{y}{x + y}}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 2
Error26.3
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -9.643093107417844 \cdot 10^{-50}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -1.3192549904598366 \cdot 10^{-274}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.9663908819537288 \cdot 10^{-195}:\\ \;\;\;\;\frac{x \cdot z}{-y}\\ \mathbf{elif}\;z \leq 1.5836852612595462 \cdot 10^{-57}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 4.9054715775803576 \cdot 10^{-33}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 3.437887669645677 \cdot 10^{+81}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 3
Error17.6
Cost976
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;z \leq -3.0057694370324236 \cdot 10^{-43}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.5836852612595462 \cdot 10^{-57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.9054715775803576 \cdot 10^{-33}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 6.014845664009336 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Error16.8
Cost976
\[\begin{array}{l} \mathbf{if}\;z \leq -3.0057694370324236 \cdot 10^{-43}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 1.5836852612595462 \cdot 10^{-57}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y} - z\\ \mathbf{elif}\;z \leq 4.9054715775803576 \cdot 10^{-33}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 6.014845664009336 \cdot 10^{+71}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error29.6
Cost788
\[\begin{array}{l} \mathbf{if}\;y \leq -1.8315509790497637 \cdot 10^{+96}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 9.312982468483618 \cdot 10^{-115}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.2216013860003254 \cdot 10^{-14}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 89912875158.15721:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.0387455609475687 \cdot 10^{+136}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error22.0
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.572709844382832 \cdot 10^{+100}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 9.312982468483618 \cdot 10^{-115}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 2.431603767878879 \cdot 10^{-76}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.0387455609475687 \cdot 10^{+136}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error38.7
Cost592
\[\begin{array}{l} \mathbf{if}\;x \leq -9.984834175420983 \cdot 10^{-144}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.638924803530347 \cdot 10^{-87}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 322478166637057.2:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.395128238784143 \cdot 10^{+64}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error52.0
Cost64
\[y \]

Error

Reproduce

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