?

Average Error: 11.83% → 0.45%
Time: 10.1s
Precision: binary64
Cost: 2248

?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{y}{t_0} + \frac{x}{t_0}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.83%
Target6.27%
Herbie0.45%
\[\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))) < -4.99999999999999992e-262

    1. Initial program 0.16

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

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

    1. Initial program 87.56

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

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

      [Start]87.56

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

      +-commutative [=>]87.56

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

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

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

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

      [Start]84.45

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

      associate-*r/ [=>]84.45

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

      mul-1-neg [=>]84.45

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

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

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

      [Start]5.09

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

      *-commutative [=>]5.09

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

      associate-*l/ [<=]84.45

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

      distribute-lft-in [=>]84.45

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

      associate-/r/ [<=]71.43

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

      associate-/l* [<=]71.78

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

      *-commutative [=>]71.78

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

      associate-*l/ [<=]71.42

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

      *-commutative [<=]71.42

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

      associate-*r/ [=>]4.92

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

      associate-*l/ [<=]2.43

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

      *-inverses [=>]2.43

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

      *-lft-identity [=>]2.43

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

      distribute-lft-out [<=]2.43

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

      mul-1-neg [=>]2.43

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

      unsub-neg [=>]2.43

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

      distribute-rgt-out-- [=>]2.44

      \[ \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.14

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

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

      [Start]0.14

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

      +-commutative [=>]0.14

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

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

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

      [Start]0.14

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

      +-commutative [=>]0.14

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

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

Alternatives

Alternative 1
Error0.46%
Cost1865
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-262} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \end{array} \]
Alternative 2
Error27.26%
Cost1108
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ t_3 := \frac{y}{t_0}\\ \mathbf{if}\;y \leq -4.5 \cdot 10^{-19}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-49}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.62 \cdot 10^{+165}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error27.24%
Cost1108
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -7.5 \cdot 10^{-19}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{-50}:\\ \;\;\;\;y \cdot \frac{1}{t_0}\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.62 \cdot 10^{+165}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error27.3%
Cost978
\[\begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{-82} \lor \neg \left(y \leq 3.6 \cdot 10^{+14} \lor \neg \left(y \leq 1.02 \cdot 10^{+135}\right) \land y \leq 6.2 \cdot 10^{+144}\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error25.75%
Cost977
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -4.1 \cdot 10^{-19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+17}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{+135} \lor \neg \left(y \leq 7.5 \cdot 10^{+144}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 6
Error36.29%
Cost853
\[\begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{+20}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-79}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+26} \lor \neg \left(y \leq 7.5 \cdot 10^{+133}\right) \land y \leq 7.2 \cdot 10^{+144}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error34.7%
Cost853
\[\begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{+17}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{-25}:\\ \;\;\;\;x \cdot \frac{-z}{y}\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+23} \lor \neg \left(y \leq 1.02 \cdot 10^{+135}\right) \land y \leq 6.2 \cdot 10^{+144}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Error33.55%
Cost721
\[\begin{array}{l} \mathbf{if}\;y \leq -2.25 \cdot 10^{+49}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+26} \lor \neg \left(y \leq 8.2 \cdot 10^{+133}\right) \land y \leq 2.6 \cdot 10^{+146}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Error42.25%
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -4.5 \cdot 10^{-20}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{+16}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Error60.69%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -8.6 \cdot 10^{-69}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.66 \cdot 10^{-121}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error66.53%
Cost64
\[x \]

Error

Reproduce?

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