Average Error: 12.1 → 2.1
Time: 7.5s
Precision: binary64
Cost: 8268
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+301}:\\ \;\;\;\;x \cdot \left(1 + \frac{y}{z}\right)\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-25}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+64}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{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)))
   (if (<= t_0 -1e+301)
     (* x (+ 1.0 (/ y z)))
     (if (<= t_0 -2e-25)
       (+ x (/ (* x y) z))
       (if (<= t_0 4e+64) (fma x (/ y z) x) (* (+ y z) (/ x 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 tmp;
	if (t_0 <= -1e+301) {
		tmp = x * (1.0 + (y / z));
	} else if (t_0 <= -2e-25) {
		tmp = x + ((x * y) / z);
	} else if (t_0 <= 4e+64) {
		tmp = fma(x, (y / z), x);
	} else {
		tmp = (y + z) * (x / 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)
	tmp = 0.0
	if (t_0 <= -1e+301)
		tmp = Float64(x * Float64(1.0 + Float64(y / z)));
	elseif (t_0 <= -2e-25)
		tmp = Float64(x + Float64(Float64(x * y) / z));
	elseif (t_0 <= 4e+64)
		tmp = fma(x, Float64(y / z), x);
	else
		tmp = Float64(Float64(y + z) * Float64(x / z));
	end
	return 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]}, If[LessEqual[t$95$0, -1e+301], N[(x * N[(1.0 + N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -2e-25], N[(x + N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+64], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+301}:\\
\;\;\;\;x \cdot \left(1 + \frac{y}{z}\right)\\

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-25}:\\
\;\;\;\;x + \frac{x \cdot y}{z}\\

\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+64}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

\mathbf{else}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\


\end{array}

Error

Target

Original12.1
Target3.2
Herbie2.1
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -1.00000000000000005e301

    1. Initial program 60.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
      Proof
      (fma.f64 x (/.f64 y z) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (/.f64 y z)) x)): 3 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 31 points increase in error, 23 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 37 points increase in error, 32 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (/.f64 x (Rewrite<= *-inverses_binary64 (/.f64 z z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 x z) z))): 57 points increase in error, 3 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 2 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 67 points increase in error, 83 points decrease in error
    3. Taylor expanded in x around 0 0.9

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

    if -1.00000000000000005e301 < (/.f64 (*.f64 x (+.f64 y z)) z) < -2.00000000000000008e-25

    1. Initial program 0.2

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

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

    if -2.00000000000000008e-25 < (/.f64 (*.f64 x (+.f64 y z)) z) < 4.00000000000000009e64

    1. Initial program 6.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
      Proof
      (fma.f64 x (/.f64 y z) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (/.f64 y z)) x)): 3 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 31 points increase in error, 23 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 37 points increase in error, 32 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (/.f64 x (Rewrite<= *-inverses_binary64 (/.f64 z z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 x z) z))): 57 points increase in error, 3 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 2 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 67 points increase in error, 83 points decrease in error

    if 4.00000000000000009e64 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 19.7

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Applied egg-rr7.5

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -1 \cdot 10^{+301}:\\ \;\;\;\;x \cdot \left(1 + \frac{y}{z}\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq -2 \cdot 10^{-25}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 4 \cdot 10^{+64}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error2.1
Cost1996
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ t_1 := x \cdot \left(1 + \frac{y}{z}\right)\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+301}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-25}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{elif}\;t_0 \leq 10^{+58}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \end{array} \]
Alternative 2
Error20.7
Cost848
\[\begin{array}{l} t_0 := \frac{x}{\frac{z}{y}}\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 12585843413552300:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+104}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error19.7
Cost848
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 12585843413552300:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+104}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.6
Cost848
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 12585843413552300:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+104}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error21.0
Cost848
\[\begin{array}{l} t_0 := \frac{x \cdot y}{z}\\ \mathbf{if}\;y \leq -1.4 \cdot 10^{+224}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 12585843413552300:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+104}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error4.6
Cost712
\[\begin{array}{l} t_0 := x + \frac{x \cdot y}{z}\\ \mathbf{if}\;x \leq -1 \cdot 10^{+157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.63124111330247 \cdot 10^{+33}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error4.5
Cost448
\[x + \frac{x \cdot y}{z} \]
Alternative 8
Error24.9
Cost64
\[x \]

Error

Reproduce

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