Average Error: 7.9 → 0.5
Time: 9.2s
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^{-298}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{-241}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \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-298) t_0 (if (<= t_0 4e-241) (* z (- -1.0 (/ 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-298) {
		tmp = t_0;
	} else if (t_0 <= 4e-241) {
		tmp = z * (-1.0 - (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-298)) then
        tmp = t_0
    else if (t_0 <= 4d-241) then
        tmp = z * ((-1.0d0) - (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-298) {
		tmp = t_0;
	} else if (t_0 <= 4e-241) {
		tmp = z * (-1.0 - (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-298:
		tmp = t_0
	elif t_0 <= 4e-241:
		tmp = z * (-1.0 - (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-298)
		tmp = t_0;
	elseif (t_0 <= 4e-241)
		tmp = Float64(z * Float64(-1.0 - 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-298)
		tmp = t_0;
	elseif (t_0 <= 4e-241)
		tmp = z * (-1.0 - (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-298], t$95$0, If[LessEqual[t$95$0, 4e-241], N[(z * N[(-1.0 - 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^{-298}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-241}:\\
\;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.9
Target4.2
Herbie0.5
\[\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))) < -5.0000000000000002e-298 or 3.9999999999999999e-241 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 0.1

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

    if -5.0000000000000002e-298 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 3.9999999999999999e-241

    1. Initial program 53.5

      \[\frac{x + y}{1 - \frac{y}{z}} \]
    2. Applied egg-rr53.5

      \[\leadsto \color{blue}{\frac{1}{1 - \frac{y}{z}} \cdot \left(x + y\right)} \]
    3. Taylor expanded in y around inf 53.5

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

      \[\leadsto \color{blue}{\frac{-z}{y}} \cdot \left(x + y\right) \]
      Proof
      (/.f64 (neg.f64 z) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 z)) y): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 z y))): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in z around 0 5.3

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

      \[\leadsto \color{blue}{z \cdot \left(-1 - \frac{x}{y}\right)} \]
      Proof
      (*.f64 z (-.f64 -1 (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (-.f64 -1 (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 x)) y))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (-.f64 -1 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 y) x)))): 12 points increase in error, 7 points decrease in error
      (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 -1 z) (*.f64 (*.f64 (/.f64 1 y) x) z))): 2 points increase in error, 2 points decrease in error
      (-.f64 (*.f64 (Rewrite<= metadata-eval (neg.f64 1)) z) (*.f64 (*.f64 (/.f64 1 y) x) z)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 1 z))) (*.f64 (*.f64 (/.f64 1 y) x) z)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 (Rewrite<= lft-mult-inverse_binary64 (*.f64 (/.f64 1 y) y)) z)) (*.f64 (*.f64 (/.f64 1 y) x) z)): 14 points increase in error, 3 points decrease in error
      (-.f64 (neg.f64 (Rewrite=> associate-*l*_binary64 (*.f64 (/.f64 1 y) (*.f64 y z)))) (*.f64 (*.f64 (/.f64 1 y) x) z)): 40 points increase in error, 12 points decrease in error
      (-.f64 (neg.f64 (*.f64 (/.f64 1 y) (*.f64 y z))) (Rewrite<= *-commutative_binary64 (*.f64 z (*.f64 (/.f64 1 y) x)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> distribute-rgt-neg-in_binary64 (*.f64 (/.f64 1 y) (neg.f64 (*.f64 y z)))) (*.f64 z (*.f64 (/.f64 1 y) x))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (/.f64 1 y) (neg.f64 (*.f64 y z))) (*.f64 z (Rewrite=> *-commutative_binary64 (*.f64 x (/.f64 1 y))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (/.f64 1 y) (neg.f64 (*.f64 y z))) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z x) (/.f64 1 y)))): 23 points increase in error, 26 points decrease in error
      (-.f64 (*.f64 (/.f64 1 y) (neg.f64 (*.f64 y z))) (*.f64 (Rewrite=> *-commutative_binary64 (*.f64 x z)) (/.f64 1 y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (/.f64 1 y) (neg.f64 (*.f64 y z))) (Rewrite=> *-commutative_binary64 (*.f64 (/.f64 1 y) (*.f64 x z)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-lft-out--_binary64 (*.f64 (/.f64 1 y) (-.f64 (neg.f64 (*.f64 y z)) (*.f64 x z)))): 0 points increase in error, 4 points decrease in error
      (*.f64 (/.f64 1 y) (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (*.f64 y z)) (neg.f64 (*.f64 x z))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1 y) (Rewrite=> distribute-neg-out_binary64 (neg.f64 (+.f64 (*.f64 y z) (*.f64 x z))))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1 y) (neg.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 y x))))): 2 points increase in error, 2 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (/.f64 1 y) (*.f64 z (+.f64 y x))))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite<= associate-/r/_binary64 (/.f64 1 (/.f64 y (*.f64 z (+.f64 y x)))))): 26 points increase in error, 21 points decrease in error
      (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 1) (/.f64 y (*.f64 z (+.f64 y x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite=> metadata-eval -1) (/.f64 y (*.f64 z (+.f64 y x)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 -1 (*.f64 z (+.f64 y x))) y)): 13 points increase in error, 24 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 (*.f64 z (+.f64 y x)) y))): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 (+.f64 y x) z)) y)): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y}{1 - \frac{y}{z}} \leq -5 \cdot 10^{-298}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{elif}\;\frac{x + y}{1 - \frac{y}{z}} \leq 4 \cdot 10^{-241}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y}{1 - \frac{y}{z}}\\ \end{array} \]

Alternatives

Alternative 1
Error27.5
Cost1836
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -6.8 \cdot 10^{-5}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-72}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-112}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.7 \cdot 10^{-144}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.48 \cdot 10^{-167}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-176}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-188}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{-243}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-284}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-260}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-176}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 400000000000:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 2
Error27.3
Cost1836
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -0.000122:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-73}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -1.15 \cdot 10^{-112}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.16 \cdot 10^{-144}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{-168}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{-178}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{-185}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-242}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -4.9 \cdot 10^{-284}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{-256}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-172}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 320000000000:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 3
Error27.2
Cost1836
\[\begin{array}{l} t_0 := \frac{-z}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -0.00024:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-74}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-112}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.6 \cdot 10^{-144}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-168}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-177}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-185}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-242}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -4.9 \cdot 10^{-284}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-261}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.75 \cdot 10^{-176}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3200000000000:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Error27.3
Cost1836
\[\begin{array}{l} t_0 := \frac{-z}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -0.00098:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-72}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -2.1 \cdot 10^{-112}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-144}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.95 \cdot 10^{-168}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -9.2 \cdot 10^{-178}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-184}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-242}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -4.5 \cdot 10^{-284}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{-260}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-176}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 650000000000:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error17.4
Cost776
\[\begin{array}{l} \mathbf{if}\;z \leq -0.0138:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 650000000000:\\ \;\;\;\;\left(-z\right) - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 6
Error26.4
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -9.8 \cdot 10^{-5}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -3.9 \cdot 10^{-69}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -9 \cdot 10^{-182}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 350000000000:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Error17.7
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -0.000206:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq 750000000000:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 8
Error39.0
Cost592
\[\begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-191}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-187}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-165}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{-87}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error26.5
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{-44}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3.7:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Error41.9
Cost64
\[x \]

Error

Reproduce

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