Average Error: 7.4 → 0.2
Time: 12.4s
Precision: binary64
Cost: 1864
\[\frac{x + y}{1 - \frac{y}{z}} \]
\[\begin{array}{l} t_0 := \frac{x + y}{1 - \frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-270}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;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 (/ (+ x y) (- 1.0 (/ y z)))))
   (if (<= t_0 -2e-270) t_0 (if (<= t_0 0.0) (* z (- -1.0 (/ x y))) 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 = (x + y) / (1.0 - (y / z));
	double tmp;
	if (t_0 <= -2e-270) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = z * (-1.0 - (x / y));
	} else {
		tmp = 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) :: tmp
    t_0 = (x + y) / (1.0d0 - (y / z))
    if (t_0 <= (-2d-270)) then
        tmp = t_0
    else if (t_0 <= 0.0d0) then
        tmp = z * ((-1.0d0) - (x / y))
    else
        tmp = 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 = (x + y) / (1.0 - (y / z));
	double tmp;
	if (t_0 <= -2e-270) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = z * (-1.0 - (x / y));
	} else {
		tmp = t_0;
	}
	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 <= -2e-270:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = z * (-1.0 - (x / y))
	else:
		tmp = 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(Float64(x + y) / Float64(1.0 - Float64(y / z)))
	tmp = 0.0
	if (t_0 <= -2e-270)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(z * Float64(-1.0 - Float64(x / y)));
	else
		tmp = 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 = (x + y) / (1.0 - (y / z));
	tmp = 0.0;
	if (t_0 <= -2e-270)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = z * (-1.0 - (x / y));
	else
		tmp = 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[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-270], t$95$0, If[LessEqual[t$95$0, 0.0], N[(z * N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := \frac{x + y}{1 - \frac{y}{z}}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-270}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.4
Target3.9
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))) < -2.0000000000000001e-270 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 -2.0000000000000001e-270 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -0.0

    1. Initial program 57.3

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

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

      \[\leadsto \color{blue}{\frac{y + x}{y} \cdot \left(-z\right)} \]
      Proof
      (*.f64 (/.f64 (+.f64 y x) y) (neg.f64 z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (/.f64 (+.f64 y x) y) z))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (+.f64 y x) z) y))): 52 points increase in error, 40 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 (+.f64 y x) z) y))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in y around 0 0.7

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

      \[\leadsto \color{blue}{\left(\frac{x}{y} + 1\right)} \cdot \left(-z\right) \]
      Proof
      (+.f64 (/.f64 x y) 1): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 1 (/.f64 x y))): 0 points increase in error, 0 points decrease in error
  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 -2 \cdot 10^{-270}:\\ \;\;\;\;\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{x + y}{1 - \frac{y}{z}}\\ \end{array} \]

Alternatives

Alternative 1
Error17.5
Cost1504
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{y}{t_0}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.0122510527443077 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.618137979804634 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.5921406242441663 \cdot 10^{-25}:\\ \;\;\;\;\frac{\left(-y\right) - x}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq -2.1884013741315337 \cdot 10^{-88}:\\ \;\;\;\;\frac{1}{\frac{t_0}{x}}\\ \mathbf{elif}\;y \leq -1.6874223298986472 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.794517148793256 \cdot 10^{-223}:\\ \;\;\;\;\left(x + y\right) \cdot \left(1 + \frac{y}{z}\right)\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 1.038434824892838 \cdot 10^{+158}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error17.6
Cost1504
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{y}{t_0}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.0122510527443077 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.618137979804634 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.1138889027325928 \cdot 10^{-42}:\\ \;\;\;\;\frac{\left(-z\right) \cdot \left(x + y\right)}{y}\\ \mathbf{elif}\;y \leq -2.1884013741315337 \cdot 10^{-88}:\\ \;\;\;\;\frac{1}{\frac{t_0}{x}}\\ \mathbf{elif}\;y \leq -1.6874223298986472 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.794517148793256 \cdot 10^{-223}:\\ \;\;\;\;\left(x + y\right) \cdot \left(1 + \frac{y}{z}\right)\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 1.038434824892838 \cdot 10^{+158}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error17.3
Cost1372
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{y}{t_0}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ t_3 := \frac{x}{t_0}\\ \mathbf{if}\;y \leq -1.0122510527443077 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.618137979804634 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.5921406242441663 \cdot 10^{-25}:\\ \;\;\;\;\frac{\left(-y\right) - x}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq -2.1884013741315337 \cdot 10^{-88}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -1.3056514582392357 \cdot 10^{-132}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.038434824892838 \cdot 10^{+158}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error17.3
Cost1372
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{y}{t_0}\\ t_2 := z \cdot \left(-1 - \frac{x}{y}\right)\\ \mathbf{if}\;y \leq -1.0122510527443077 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -5.618137979804634 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.5921406242441663 \cdot 10^{-25}:\\ \;\;\;\;\frac{\left(-y\right) - x}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq -2.1884013741315337 \cdot 10^{-88}:\\ \;\;\;\;\frac{1}{\frac{t_0}{x}}\\ \mathbf{elif}\;y \leq -1.3056514582392357 \cdot 10^{-132}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;\frac{x}{t_0}\\ \mathbf{elif}\;y \leq 1.038434824892838 \cdot 10^{+158}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error18.3
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := \frac{y}{t_0}\\ \mathbf{if}\;y \leq -2.1914007429903957 \cdot 10^{+139}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -5.0239239993837986 \cdot 10^{+48}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2.1884013741315337 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.794517148793256 \cdot 10^{-223}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7936551151492585 \cdot 10^{+182}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 6
Error19.9
Cost1240
\[\begin{array}{l} t_0 := 1 - \frac{y}{z}\\ t_1 := \frac{x}{t_0}\\ t_2 := \frac{y}{t_0}\\ \mathbf{if}\;y \leq -1.191019838640093 \cdot 10^{+207}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -3.5921406242441663 \cdot 10^{-25}:\\ \;\;\;\;\frac{\left(-y\right) - x}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq -2.1884013741315337 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.3056514582392357 \cdot 10^{-132}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7936551151492585 \cdot 10^{+182}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 7
Error22.7
Cost1044
\[\begin{array}{l} \mathbf{if}\;y \leq -3.6439652861975735 \cdot 10^{+123}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.9387386823586905 \cdot 10^{+51}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -1.1138889027325928 \cdot 10^{-42}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 6.971568326076583 \cdot 10^{-98}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{elif}\;y \leq 1.9930269368753715 \cdot 10^{+64}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 8
Error22.7
Cost1044
\[\begin{array}{l} \mathbf{if}\;y \leq -3.6439652861975735 \cdot 10^{+123}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.9387386823586905 \cdot 10^{+51}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -1.1138889027325928 \cdot 10^{-42}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 6.971568326076583 \cdot 10^{-98}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.60720239147973 \cdot 10^{-15}:\\ \;\;\;\;x \cdot \frac{z}{-y}\\ \mathbf{elif}\;y \leq 1.9930269368753715 \cdot 10^{+64}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 9
Error19.7
Cost976
\[\begin{array}{l} t_0 := \frac{y}{1 - \frac{y}{z}}\\ \mathbf{if}\;y \leq -2.1914007429903957 \cdot 10^{+139}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.1138889027325928 \cdot 10^{-42}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.913759828764581 \cdot 10^{-111}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq 1.7936551151492585 \cdot 10^{+182}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 10
Error21.1
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -3.6439652861975735 \cdot 10^{+123}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq -1.9387386823586905 \cdot 10^{+51}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;y \leq -1.1138889027325928 \cdot 10^{-42}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 1.9930269368753715 \cdot 10^{+64}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 11
Error27.0
Cost524
\[\begin{array}{l} \mathbf{if}\;y \leq -1.1138889027325928 \cdot 10^{-42}:\\ \;\;\;\;-z\\ \mathbf{elif}\;y \leq 5.875432168007007 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.490946543427594 \cdot 10^{-9}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
Alternative 12
Error37.7
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.010737796273422 \cdot 10^{-47}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.472723373780831 \cdot 10^{-102}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error52.2
Cost64
\[y \]

Error

Reproduce

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