?

Average Error: 7.8 → 0.3
Time: 9.0s
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^{-251}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-300}:\\ \;\;\;\;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-251) t_0 (if (<= t_0 5e-300) (* 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-251) {
		tmp = t_0;
	} else if (t_0 <= 5e-300) {
		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-251)) then
        tmp = t_0
    else if (t_0 <= 5d-300) 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-251) {
		tmp = t_0;
	} else if (t_0 <= 5e-300) {
		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-251:
		tmp = t_0
	elif t_0 <= 5e-300:
		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-251)
		tmp = t_0;
	elseif (t_0 <= 5e-300)
		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-251)
		tmp = t_0;
	elseif (t_0 <= 5e-300)
		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-251], t$95$0, If[LessEqual[t$95$0, 5e-300], 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^{-251}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-300}:\\
\;\;\;\;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.8
Target4.2
Herbie0.3
\[\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.0000000000000003e-251 or 4.99999999999999996e-300 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 0.1

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

    if -5.0000000000000003e-251 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 4.99999999999999996e-300

    1. Initial program 54.9

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

      \[\leadsto \color{blue}{\frac{x}{1 - \frac{y}{z}} + \frac{y}{1 - \frac{y}{z}}} \]
    3. Simplified54.9

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

      [Start]54.9

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

      rational.json-simplify-1 [=>]54.9

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

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

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

      [Start]1.7

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

      rational.json-simplify-2 [=>]1.7

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

      rational.json-simplify-9 [=>]1.7

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

      rational.json-simplify-12 [=>]1.7

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

      rational.json-simplify-42 [=>]1.7

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

      metadata-eval [=>]1.7

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

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

Alternatives

Alternative 1
Error16.5
Cost1240
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ t_1 := \frac{x}{1 - \frac{y}{z}}\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -3.5 \cdot 10^{-36}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-41}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -4.7 \cdot 10^{-179}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-164}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 5.05 \cdot 10^{+17}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error21.4
Cost1176
\[\begin{array}{l} t_0 := \frac{z}{y} \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -1.7 \cdot 10^{+108}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-10}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 7.6 \cdot 10^{+15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.9 \cdot 10^{+21}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 9.8 \cdot 10^{+51}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+118}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 3
Error16.2
Cost1172
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ \mathbf{if}\;y \leq -4.5 \cdot 10^{+80}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{elif}\;y \leq -8.8 \cdot 10^{-42}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq -4.45 \cdot 10^{-181}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{-163}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+17}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{y} \cdot \left(-z\right)\\ \end{array} \]
Alternative 4
Error16.1
Cost1108
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := z \cdot \left(-1 - \frac{x}{y}\right)\\ t_2 := \frac{x}{t_0}\\ \mathbf{if}\;y \leq -5 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-41}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-178}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-164}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 5.05 \cdot 10^{+17}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error21.5
Cost780
\[\begin{array}{l} \mathbf{if}\;y \leq -4.1 \cdot 10^{+108}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-10}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+65}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+118}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error16.6
Cost712
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -4.5 \cdot 10^{+80}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-11}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error20.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -6.8 \cdot 10^{+107}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+118}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Error26.7
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -4.6 \cdot 10^{-42}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Error38.4
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-117}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-43}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error42.1
Cost64
\[x \]

Error

Reproduce?

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