Average Error: 12.5 → 1.7
Time: 7.4s
Precision: binary64
Cost: 7236
\[\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 10^{+59}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;t_0 \leq 10^{+292}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{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+59)
     (fma x (/ y z) x)
     (if (<= t_0 1e+292) (+ x (/ (* x y) z)) (+ x (* x (/ y 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+59) {
		tmp = fma(x, (y / z), x);
	} else if (t_0 <= 1e+292) {
		tmp = x + ((x * y) / z);
	} else {
		tmp = x + (x * (y / 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+59)
		tmp = fma(x, Float64(y / z), x);
	elseif (t_0 <= 1e+292)
		tmp = Float64(x + Float64(Float64(x * y) / z));
	else
		tmp = Float64(x + Float64(x * Float64(y / 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+59], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 1e+292], N[(x + N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(y / z), $MachinePrecision]), $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 10^{+59}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

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

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


\end{array}

Error

Target

Original12.5
Target3.0
Herbie1.7
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < 9.99999999999999972e58

    1. Initial program 10.2

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

      \[\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)): 5 points increase in error, 2 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 37 points increase in error, 17 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 31 points increase in error, 41 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))): 38 points increase in error, 4 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 4 points increase in error, 1 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 82 points increase in error, 61 points decrease in error

    if 9.99999999999999972e58 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1e292

    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 1e292 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 58.0

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

      \[\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)): 5 points increase in error, 2 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 37 points increase in error, 17 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 31 points increase in error, 41 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))): 38 points increase in error, 4 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 4 points increase in error, 1 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 82 points increase in error, 61 points decrease in error
    3. Taylor expanded in x around 0 1.2

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

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x + x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq 10^{+59}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \leq 10^{+292}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error1.7
Cost1480
\[\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 10^{+59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+292}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error20.5
Cost584
\[\begin{array}{l} t_0 := x \cdot \frac{y}{z}\\ \mathbf{if}\;y \leq -1.75 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.1908953161612574 \cdot 10^{+27}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error18.9
Cost584
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;y \leq -1.35 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.1908953161612574 \cdot 10^{+27}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error18.8
Cost584
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -1.35 \cdot 10^{+51}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.1908953161612574 \cdot 10^{+27}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error3.2
Cost448
\[x + x \cdot \frac{y}{z} \]
Alternative 6
Error25.9
Cost64
\[x \]

Error

Reproduce

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