Average Error: 7.5 → 0.5
Time: 6.7s
Precision: binary64
Cost: 1864
\[\frac{x + y}{1 - \frac{y}{z}} \]
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x + y}{t_0}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-241}:\\ \;\;\;\;\frac{y}{t_0} + \frac{x}{t_0}\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\left(-z\right) - \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;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 (- 1.0 (/ y z))) (t_1 (/ (+ x y) t_0)))
   (if (<= t_1 -1e-241)
     (+ (/ y t_0) (/ x t_0))
     (if (<= t_1 0.0) (- (- z) (/ z (/ y 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 = 1.0 - (y / z);
	double t_1 = (x + y) / t_0;
	double tmp;
	if (t_1 <= -1e-241) {
		tmp = (y / t_0) + (x / t_0);
	} else if (t_1 <= 0.0) {
		tmp = -z - (z / (y / x));
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = 1.0d0 - (y / z)
    t_1 = (x + y) / t_0
    if (t_1 <= (-1d-241)) then
        tmp = (y / t_0) + (x / t_0)
    else if (t_1 <= 0.0d0) then
        tmp = -z - (z / (y / x))
    else
        tmp = t_1
    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 = 1.0 - (y / z);
	double t_1 = (x + y) / t_0;
	double tmp;
	if (t_1 <= -1e-241) {
		tmp = (y / t_0) + (x / t_0);
	} else if (t_1 <= 0.0) {
		tmp = -z - (z / (y / x));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	return (x + y) / (1.0 - (y / z))
def code(x, y, z):
	t_0 = 1.0 - (y / z)
	t_1 = (x + y) / t_0
	tmp = 0
	if t_1 <= -1e-241:
		tmp = (y / t_0) + (x / t_0)
	elif t_1 <= 0.0:
		tmp = -z - (z / (y / x))
	else:
		tmp = 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 = Float64(1.0 - Float64(y / z))
	t_1 = Float64(Float64(x + y) / t_0)
	tmp = 0.0
	if (t_1 <= -1e-241)
		tmp = Float64(Float64(y / t_0) + Float64(x / t_0));
	elseif (t_1 <= 0.0)
		tmp = Float64(Float64(-z) - Float64(z / Float64(y / x)));
	else
		tmp = t_1;
	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 = 1.0 - (y / z);
	t_1 = (x + y) / t_0;
	tmp = 0.0;
	if (t_1 <= -1e-241)
		tmp = (y / t_0) + (x / t_0);
	elseif (t_1 <= 0.0)
		tmp = -z - (z / (y / x));
	else
		tmp = t_1;
	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[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] / t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-241], N[(N[(y / t$95$0), $MachinePrecision] + N[(x / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[((-z) - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := 1 - \frac{y}{z}\\
t_1 := \frac{x + y}{t_0}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-241}:\\
\;\;\;\;\frac{y}{t_0} + \frac{x}{t_0}\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\left(-z\right) - \frac{z}{\frac{y}{x}}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.5
Target3.7
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 3 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -9.9999999999999997e-242

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{y + x}{1 - \frac{y}{z}}} \]
      Proof
      (/.f64 (+.f64 y x) (-.f64 1 (/.f64 y z))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x y)) (-.f64 1 (/.f64 y z))): 2 points increase in error, 0 points decrease in error
    3. Taylor expanded in x around 0 0.1

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

      \[\leadsto \color{blue}{\frac{y}{1 - \frac{y}{z}} + \frac{x}{1 - \frac{y}{z}}} \]
      Proof
      (+.f64 (/.f64 y (-.f64 1 (/.f64 y z))) (/.f64 x (-.f64 1 (/.f64 y z)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 x (-.f64 1 (/.f64 y z))) (/.f64 y (-.f64 1 (/.f64 y z))))): 2 points increase in error, 0 points decrease in error

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

    1. Initial program 53.1

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

      \[\leadsto \color{blue}{\frac{y + x}{1 - \frac{y}{z}}} \]
      Proof
      (/.f64 (+.f64 y x) (-.f64 1 (/.f64 y z))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x y)) (-.f64 1 (/.f64 y z))): 2 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around 0 5.5

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

      \[\leadsto \color{blue}{\frac{\left(-y\right) - x}{\frac{y}{z}}} \]
      Proof
      (+.f64 (/.f64 y (-.f64 1 (/.f64 y z))) (/.f64 x (-.f64 1 (/.f64 y z)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 x (-.f64 1 (/.f64 y z))) (/.f64 y (-.f64 1 (/.f64 y z))))): 2 points increase in error, 0 points decrease in error
    5. Taylor expanded in y around 0 3.3

      \[\leadsto \color{blue}{-1 \cdot z + -1 \cdot \frac{z \cdot x}{y}} \]
    6. Simplified2.9

      \[\leadsto \color{blue}{z \cdot \frac{-x}{y} - z} \]
      Proof
      (-.f64 (*.f64 z (/.f64 (neg.f64 x) y)) z): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 z (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 x y)))) z): 0 points increase in error, 8 points decrease in error
      (-.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 z (/.f64 x y)))) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (*.f64 z (/.f64 x y))) (neg.f64 z))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 z) (neg.f64 (*.f64 z (/.f64 x y))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 z)) (neg.f64 (*.f64 z (/.f64 x y)))): 8 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 -1 z) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 z (/.f64 x y))))): 0 points increase in error, 8 points decrease in error
      (+.f64 (*.f64 -1 z) (*.f64 -1 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 z x) y)))): 8 points increase in error, 0 points decrease in error
    7. Taylor expanded in z around 0 3.3

      \[\leadsto \color{blue}{-1 \cdot \frac{z \cdot x}{y}} - z \]
    8. Simplified2.8

      \[\leadsto \color{blue}{\frac{-z}{\frac{y}{x}}} - z \]
      Proof
      (-.f64 (/.f64 (neg.f64 z) (/.f64 y x)) z): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> distribute-frac-neg_binary64 (neg.f64 (/.f64 z (/.f64 y x)))) z): 0 points increase in error, 4 points decrease in error
      (-.f64 (neg.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 z x) y))) z): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 z x) y))) z): 0 points increase in error, 0 points decrease in error

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

    1. Initial program 0.1

      \[\frac{x + y}{1 - \frac{y}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost1865
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{-241} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) - \frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 2
Error20.6
Cost780
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{+34}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+50}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+96}:\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 3
Error20.6
Cost780
\[\begin{array}{l} \mathbf{if}\;y \leq -1.35 \cdot 10^{+34}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+50}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+92}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 4
Error16.2
Cost777
\[\begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{+30} \lor \neg \left(y \leq 1.9 \cdot 10^{+50}\right):\\ \;\;\;\;\left(-z\right) - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error16.2
Cost777
\[\begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{+31} \lor \neg \left(y \leq 1.45 \cdot 10^{+50}\right):\\ \;\;\;\;\left(-z\right) - \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 6
Error16.2
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+33} \lor \neg \left(y \leq 10^{+50}\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Error20.4
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.25 \cdot 10^{+34}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{+78}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Error26.1
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -1.55 \cdot 10^{+33}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+60}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Error37.5
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{-127}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-115}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error41.1
Cost64
\[x \]

Error

Reproduce

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