?

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

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.8
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 3 regimes
  2. if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -5.00000000000000011e-288

    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

      [Start]0.1

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

      +-commutative [=>]0.1

      \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}} \]
    3. Applied egg-rr0.1

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

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

    1. Initial program 58.7

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

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

      [Start]58.7

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

      +-commutative [=>]58.7

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

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

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

      [Start]1.1

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

      associate-/l* [=>]58.8

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

      associate-*r/ [=>]58.8

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

      neg-mul-1 [<=]58.8

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

      distribute-neg-in [=>]58.8

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

      sub-neg [<=]58.8

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

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

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

      [Start]0.4

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

      mul-1-neg [=>]0.4

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

      associate-*r/ [<=]0.2

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

      mul-1-neg [=>]0.2

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

      unsub-neg [=>]0.2

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

      mul-1-neg [<=]0.2

      \[ \color{blue}{-1 \cdot z} - z \cdot \frac{x}{y} \]

      *-commutative [=>]0.2

      \[ \color{blue}{z \cdot -1} - z \cdot \frac{x}{y} \]

      distribute-lft-out-- [=>]0.2

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

    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.1

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

Alternatives

Alternative 1
Error0.1
Cost1865
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-288} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \end{array} \]
Alternative 2
Error17.2
Cost1243
\[\begin{array}{l} \mathbf{if}\;y \leq -3950 \lor \neg \left(y \leq 2.45 \cdot 10^{-53} \lor \neg \left(y \leq 4.1 \cdot 10^{-22}\right) \land \left(y \leq 0.002 \lor \neg \left(y \leq 10^{+118}\right) \land y \leq 1.2 \cdot 10^{+141}\right)\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 3
Error17.5
Cost1241
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -5400:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-54}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.42 \cdot 10^{-21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+83}:\\ \;\;\;\;\frac{y}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+117} \lor \neg \left(y \leq 1.25 \cdot 10^{+141}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 4
Error17.5
Cost1241
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -3150:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-60}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 9.6 \cdot 10^{-21}:\\ \;\;\;\;\frac{\left(-y\right) - x}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{+83}:\\ \;\;\;\;\frac{y}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 10^{+118} \lor \neg \left(y \leq 1.2 \cdot 10^{+141}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error28.6
Cost524
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{-40}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 5.1 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{+178}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error22.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -3500:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{+178}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error37.6
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -8 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-129}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error41.2
Cost64
\[x \]

Error

Reproduce?

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