?

Average Error: 11.74% → 0.2%
Time: 9.5s
Precision: binary64
Cost: 1865

?

\[\frac{x + y}{1 - \frac{y}{z}} \]
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{-284} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \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 (or (<= t_0 -4e-284) (not (<= t_0 0.0))) t_0 (* z (- -1.0 (/ x y))))))
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 <= -4e-284) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = z * (-1.0 - (x / y));
	}
	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 <= (-4d-284)) .or. (.not. (t_0 <= 0.0d0))) then
        tmp = t_0
    else
        tmp = z * ((-1.0d0) - (x / y))
    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 <= -4e-284) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = z * (-1.0 - (x / y));
	}
	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 <= -4e-284) or not (t_0 <= 0.0):
		tmp = t_0
	else:
		tmp = z * (-1.0 - (x / y))
	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 <= -4e-284) || !(t_0 <= 0.0))
		tmp = t_0;
	else
		tmp = Float64(z * Float64(-1.0 - Float64(x / y)));
	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 <= -4e-284) || ~((t_0 <= 0.0)))
		tmp = t_0;
	else
		tmp = z * (-1.0 - (x / y));
	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[Or[LessEqual[t$95$0, -4e-284], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[(z * N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t_0 \leq -4 \cdot 10^{-284} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.74%
Target6.14%
Herbie0.2%
\[\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.00000000000000015e-284 or -0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 0.13

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

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

    1. Initial program 91.83

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

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

      [Start]91.83

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

      +-commutative [=>]91.83

      \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}} \]
    3. Taylor expanded in y around inf 0.77

      \[\leadsto \color{blue}{\left(-1 \cdot z + -1 \cdot \frac{z \cdot x}{y}\right) - \frac{{z}^{2}}{y}} \]
    4. Simplified16.28

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

      [Start]0.77

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

      mul-1-neg [=>]0.77

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

      unsub-neg [=>]0.77

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

      mul-1-neg [=>]0.77

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

      associate-/l* [=>]0.65

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

      associate-/r/ [=>]16.28

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

      unpow2 [=>]16.28

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

      associate-/l* [=>]16.28

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

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

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

      [Start]0.64

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

      mul-1-neg [=>]0.64

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

      *-commutative [=>]0.64

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

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

Alternatives

Alternative 1
Error40.34%
Cost1768
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := \frac{y}{t_0}\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+27}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-65}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.35 \cdot 10^{-86}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-220}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{-272}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-241}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-31}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{+135}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 2
Error39.96%
Cost1108
\[\begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{-85}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -2.25 \cdot 10^{-220}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -1.5 \cdot 10^{-272}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{-239}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{-112}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{+55}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 3
Error41.37%
Cost1044
\[\begin{array}{l} t_0 := \frac{z}{y} \cdot \left(-x\right)\\ \mathbf{if}\;z \leq -8.2 \cdot 10^{-87}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -2 \cdot 10^{-220}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-273}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-240}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-162}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+55}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Error41.35%
Cost1044
\[\begin{array}{l} \mathbf{if}\;z \leq -3.9 \cdot 10^{-86}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-220}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-272}:\\ \;\;\;\;\frac{z}{y} \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 4.9 \cdot 10^{-241}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-162}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{+55}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error41.11%
Cost1044
\[\begin{array}{l} \mathbf{if}\;z \leq -2.45 \cdot 10^{-85}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-220}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{-272}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-240}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-162}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+55}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 6
Error26.55%
Cost777
\[\begin{array}{l} \mathbf{if}\;z \leq -6.7 \cdot 10^{-9} \lor \neg \left(z \leq 9.5 \cdot 10^{+55}\right):\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) - \frac{x \cdot z}{y}\\ \end{array} \]
Alternative 7
Error34.5%
Cost721
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+95}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.95 \cdot 10^{+40} \lor \neg \left(y \leq -3.35 \cdot 10^{-47}\right) \land y \leq 8 \cdot 10^{+139}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Error27.39%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -7 \cdot 10^{-9} \lor \neg \left(z \leq 8.2 \cdot 10^{+55}\right):\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \end{array} \]
Alternative 9
Error43.54%
Cost656
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+94}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.95 \cdot 10^{+39}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -2.75 \cdot 10^{-58}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-33}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Error58.22%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -8 \cdot 10^{-121}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-153}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error64.7%
Cost64
\[x \]

Error

Reproduce?

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