Average Error: 7.8 → 0.5
Time: 6.7s
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 -5 \cdot 10^{-237} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-x}{y} - z\\ \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 -5e-237) (not (<= t_0 0.0))) t_0 (- (* z (/ (- x) y)) z))))
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-237) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = (z * (-x / y)) - z;
	}
	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-237)) .or. (.not. (t_0 <= 0.0d0))) then
        tmp = t_0
    else
        tmp = (z * (-x / y)) - z
    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-237) || !(t_0 <= 0.0)) {
		tmp = t_0;
	} else {
		tmp = (z * (-x / y)) - z;
	}
	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-237) or not (t_0 <= 0.0):
		tmp = t_0
	else:
		tmp = (z * (-x / y)) - z
	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-237) || !(t_0 <= 0.0))
		tmp = t_0;
	else
		tmp = Float64(Float64(z * Float64(Float64(-x) / y)) - z);
	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-237) || ~((t_0 <= 0.0)))
		tmp = t_0;
	else
		tmp = (z * (-x / y)) - z;
	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, -5e-237], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], t$95$0, N[(N[(z * N[((-x) / y), $MachinePrecision]), $MachinePrecision] - z), $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 -5 \cdot 10^{-237} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;z \cdot \frac{-x}{y} - z\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.8
Target4.3
Herbie0.5
\[\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.0000000000000002e-237 or 0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z)))

    1. Initial program 0.1

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

    if -5.0000000000000002e-237 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < 0.0

    1. Initial program 53.7

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

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

      [Start]53.7

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

      +-commutative [=>]53.7

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

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

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

      [Start]5.0

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

      associate-/l* [=>]56.4

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

      associate-*r/ [=>]56.4

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

      neg-mul-1 [<=]56.4

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

      distribute-neg-in [=>]56.4

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

      sub-neg [<=]56.4

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

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

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

      [Start]3.2

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

      mul-1-neg [=>]3.2

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

      associate-*r/ [<=]2.8

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

      mul-1-neg [=>]2.8

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

      +-commutative [<=]2.8

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

      unsub-neg [=>]2.8

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

      distribute-rgt-neg-in [=>]2.8

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

      distribute-neg-frac [=>]2.8

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

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

Alternatives

Alternative 1
Error16.0
Cost1304
\[\begin{array}{l} t_0 := \frac{x}{1 - \frac{y}{z}}\\ \mathbf{if}\;y \leq -9 \cdot 10^{+23}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{elif}\;y \leq -8.8 \cdot 10^{-60}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -6.9 \cdot 10^{-183}:\\ \;\;\;\;\left(x + y\right) \cdot \left(1 + \frac{y}{z}\right)\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{-126}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1700:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-x}{y} - z\\ \end{array} \]
Alternative 2
Error16.0
Cost908
\[\begin{array}{l} \mathbf{if}\;y \leq -1.52 \cdot 10^{+35}:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 2800:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-x}{y} - z\\ \end{array} \]
Alternative 3
Error16.1
Cost844
\[\begin{array}{l} t_0 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.52 \cdot 10^{+35}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-127}:\\ \;\;\;\;\frac{x}{1 - \frac{y}{z}}\\ \mathbf{elif}\;y \leq 13500:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error15.9
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+24} \lor \neg \left(y \leq 5500\right):\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error20.1
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{+100}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+61}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error26.5
Cost392
\[\begin{array}{l} \mathbf{if}\;y \leq -2.85 \cdot 10^{+25}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-18}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error37.5
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-102}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error41.4
Cost64
\[x \]

Error

Reproduce

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