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

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.1
Target4.3
Herbie0.1
\[\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))) < -1.9999999999999999e-302 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 -1.9999999999999999e-302 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 0.0

    1. Initial program 59.6

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

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

      \[\leadsto \color{blue}{-\frac{\left(y + x\right) \cdot z}{y}} \]
      Proof
    4. Taylor expanded in y around 0 0.1

      \[\leadsto -\color{blue}{\left(\frac{z \cdot x}{y} + z\right)} \]
    5. Taylor expanded in z around 0 0.1

      \[\leadsto -\color{blue}{\left(1 + \frac{x}{y}\right) \cdot z} \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error17.3
Cost1040
\[\begin{array}{l} \mathbf{if}\;z \leq -5.2 \cdot 10^{-23}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-102}:\\ \;\;\;\;\frac{y \cdot z}{z - y}\\ \mathbf{elif}\;z \leq -9.4 \cdot 10^{-129}:\\ \;\;\;\;\frac{z \cdot x}{z - y}\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{-22}:\\ \;\;\;\;-\left(\frac{z \cdot x}{y} + z\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 2
Error22.2
Cost912
\[\begin{array}{l} \mathbf{if}\;y \leq -6.2 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.75 \cdot 10^{+27}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-5}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -2.6 \cdot 10^{-83}:\\ \;\;\;\;-\frac{x}{y} \cdot z\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+55}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 3
Error16.4
Cost712
\[\begin{array}{l} t_0 := \frac{y}{z - y} \cdot z\\ \mathbf{if}\;y \leq -8 \cdot 10^{-52}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+52}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error27.0
Cost656
\[\begin{array}{l} \mathbf{if}\;y \leq -1.4 \cdot 10^{+82}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{+30}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1.18 \cdot 10^{-57}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 5
Error20.6
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+137}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+56}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error38.0
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.15 \cdot 10^{-61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-180}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error41.7
Cost64
\[x \]

Error

Reproduce

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