?

Average Error: 7.5 → 0.4
Time: 7.9s
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 -4 \cdot 10^{-256}:\\ \;\;\;\;\frac{y}{t_0} + \frac{x}{t_0}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-284}:\\ \;\;\;\;-\left(z + \frac{z}{\frac{y}{x}}\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 -4e-256)
     (+ (/ y t_0) (/ x t_0))
     (if (<= t_1 5e-284) (- (+ z (/ z (/ y x)))) 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 <= -4e-256) {
		tmp = (y / t_0) + (x / t_0);
	} else if (t_1 <= 5e-284) {
		tmp = -(z + (z / (y / x)));
	} 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 <= (-4d-256)) then
        tmp = (y / t_0) + (x / t_0)
    else if (t_1 <= 5d-284) then
        tmp = -(z + (z / (y / x)))
    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 <= -4e-256) {
		tmp = (y / t_0) + (x / t_0);
	} else if (t_1 <= 5e-284) {
		tmp = -(z + (z / (y / x)));
	} 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 <= -4e-256:
		tmp = (y / t_0) + (x / t_0)
	elif t_1 <= 5e-284:
		tmp = -(z + (z / (y / x)))
	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 <= -4e-256)
		tmp = Float64(Float64(y / t_0) + Float64(x / t_0));
	elseif (t_1 <= 5e-284)
		tmp = Float64(-Float64(z + Float64(z / Float64(y / x))));
	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 <= -4e-256)
		tmp = (y / t_0) + (x / t_0);
	elseif (t_1 <= 5e-284)
		tmp = -(z + (z / (y / x)));
	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, -4e-256], N[(N[(y / t$95$0), $MachinePrecision] + N[(x / t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e-284], (-N[(z + N[(z / N[(y / x), $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 -4 \cdot 10^{-256}:\\
\;\;\;\;\frac{y}{t_0} + \frac{x}{t_0}\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{-284}:\\
\;\;\;\;-\left(z + \frac{z}{\frac{y}{x}}\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.5
Target4.0
Herbie0.4
\[\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))) < -3.99999999999999991e-256

    1. Initial program 0.1

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

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

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

      [Start]0.1

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

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

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

    if -3.99999999999999991e-256 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 4.99999999999999973e-284

    1. Initial program 52.7

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

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

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

      [Start]5.5

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

      rational.json-simplify-1 [<=]5.5

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

      rational.json-simplify-49 [=>]2.5

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

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

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

      rational.json-simplify-43 [=>]2.5

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

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

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

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

      \[ \frac{y + x}{y} \cdot \color{blue}{\left(-z\right)} \]
    4. Applied egg-rr55.2

      \[\leadsto \color{blue}{\frac{y + x}{-\frac{y}{z}}} \]
    5. Taylor expanded in y around 0 3.0

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

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

      [Start]3.0

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

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

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

      rational.json-simplify-51 [=>]3.0

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

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

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

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

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

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

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

      rational.json-simplify-49 [=>]11.8

      \[ -\left(z + \color{blue}{x \cdot \frac{z}{y}}\right) \]
    7. Applied egg-rr2.5

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

    if 4.99999999999999973e-284 < (/.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.4

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

Alternatives

Alternative 1
Error0.4
Cost1864
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{-256}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-284}:\\ \;\;\;\;-\left(z + \frac{z}{\frac{y}{x}}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error20.3
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ \mathbf{if}\;y \leq -4 \cdot 10^{+39}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-221}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-115}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+97}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+110}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 3
Error17.9
Cost1040
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := -\left(z + x \cdot \frac{z}{y}\right)\\ \mathbf{if}\;y \leq -16500000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.66 \cdot 10^{+100}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+110}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error16.7
Cost1040
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := -\left(z + \frac{z}{\frac{y}{x}}\right)\\ \mathbf{if}\;y \leq -7800000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+100}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+110}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error16.7
Cost1040
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ \mathbf{if}\;y \leq -100000:\\ \;\;\;\;-\left(z + \frac{z}{\frac{y}{x}}\right)\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+100}:\\ \;\;\;\;\frac{y}{t_0}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+110}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y + x}{y} \cdot \left(-z\right)\\ \end{array} \]
Alternative 6
Error17.4
Cost1040
\[\begin{array}{l} \mathbf{if}\;z \leq -1.65 \cdot 10^{+28}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-41}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-240}:\\ \;\;\;\;-1 \cdot \frac{\left(y + x\right) \cdot z}{y}\\ \mathbf{elif}\;z \leq 2.85 \cdot 10^{+69}:\\ \;\;\;\;-\left(z + x \cdot \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 7
Error20.7
Cost976
\[\begin{array}{l} t_0 := \frac{x}{1 - \frac{y}{z}}\\ \mathbf{if}\;y \leq -8.4 \cdot 10^{+40}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.36 \cdot 10^{-222}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-115}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;y \leq 10^{+111}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Error21.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -86000000:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+111}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Error26.8
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -1.26 \cdot 10^{-20}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+59}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Error37.8
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-62}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error41.3
Cost64
\[x \]

Error

Reproduce?

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