Average Error: 12.7 → 0.5
Time: 3.8s
Precision: binary64
Cost: 2512
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ t_1 := x + x \cdot \frac{y}{z}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-124}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+252}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (+ y z)) z)) (t_1 (+ x (* x (/ y z)))))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -2e-124)
       t_0
       (if (<= t_0 5e-73) t_1 (if (<= t_0 1e+252) t_0 (* x (/ (+ y z) z))))))))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double t_0 = (x * (y + z)) / z;
	double t_1 = x + (x * (y / z));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -2e-124) {
		tmp = t_0;
	} else if (t_0 <= 5e-73) {
		tmp = t_1;
	} else if (t_0 <= 1e+252) {
		tmp = t_0;
	} else {
		tmp = x * ((y + z) / z);
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
public static double code(double x, double y, double z) {
	double t_0 = (x * (y + z)) / z;
	double t_1 = x + (x * (y / z));
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= -2e-124) {
		tmp = t_0;
	} else if (t_0 <= 5e-73) {
		tmp = t_1;
	} else if (t_0 <= 1e+252) {
		tmp = t_0;
	} else {
		tmp = x * ((y + z) / z);
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y + z)) / z
def code(x, y, z):
	t_0 = (x * (y + z)) / z
	t_1 = x + (x * (y / z))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= -2e-124:
		tmp = t_0
	elif t_0 <= 5e-73:
		tmp = t_1
	elif t_0 <= 1e+252:
		tmp = t_0
	else:
		tmp = x * ((y + z) / z)
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) / z)
end
function code(x, y, z)
	t_0 = Float64(Float64(x * Float64(y + z)) / z)
	t_1 = Float64(x + Float64(x * Float64(y / z)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -2e-124)
		tmp = t_0;
	elseif (t_0 <= 5e-73)
		tmp = t_1;
	elseif (t_0 <= 1e+252)
		tmp = t_0;
	else
		tmp = Float64(x * Float64(Float64(y + z) / z));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) / z;
end
function tmp_2 = code(x, y, z)
	t_0 = (x * (y + z)) / z;
	t_1 = x + (x * (y / z));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= -2e-124)
		tmp = t_0;
	elseif (t_0 <= 5e-73)
		tmp = t_1;
	elseif (t_0 <= 1e+252)
		tmp = t_0;
	else
		tmp = x * ((y + z) / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -2e-124], t$95$0, If[LessEqual[t$95$0, 5e-73], t$95$1, If[LessEqual[t$95$0, 1e+252], t$95$0, N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
t_1 := x + x \cdot \frac{y}{z}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-124}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-73}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 10^{+252}:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.7
Target2.6
Herbie0.5
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -inf.0 or -1.99999999999999987e-124 < (/.f64 (*.f64 x (+.f64 y z)) z) < 4.9999999999999998e-73

    1. Initial program 21.9

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Taylor expanded in y around 0 9.0

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

      \[\leadsto \color{blue}{x + \frac{y}{z} \cdot x} \]
      Proof
      (+.f64 x (*.f64 (/.f64 y z) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite<= associate-/r/_binary64 (/.f64 y (/.f64 z x)))): 32 points increase in error, 32 points decrease in error
      (+.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) z))): 31 points increase in error, 31 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 (*.f64 y x) z) x)): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -1.99999999999999987e-124 or 4.9999999999999998e-73 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.0000000000000001e252

    1. Initial program 0.3

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

    if 1.0000000000000001e252 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 46.2

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Simplified3.2

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
      Proof
      (*.f64 x (/.f64 (+.f64 y z) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 75 points increase in error, 33 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -\infty:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq -2 \cdot 10^{-124}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 5 \cdot 10^{-73}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 10^{+252}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error3.2
Cost712
\[\begin{array}{l} t_0 := x \cdot \frac{y + z}{z}\\ \mathbf{if}\;z \leq -2 \cdot 10^{-131}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-92}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error3.2
Cost712
\[\begin{array}{l} t_0 := x + x \cdot \frac{y}{z}\\ \mathbf{if}\;z \leq -2.1 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.46 \cdot 10^{-94}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error19.6
Cost584
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -3 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.6
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{-25}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq 1.82 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]
Alternative 5
Error2.8
Cost448
\[x \cdot \frac{y + z}{z} \]
Alternative 6
Error24.8
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022329 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (/ x (/ z (+ y z)))

  (/ (* x (+ y z)) z))