Average Error: 12.8 → 0.7
Time: 6.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 -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{+125}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 10^{-22}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;t_0 \leq 10^{+267}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{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 (- INFINITY))
     (fma y (/ x z) x)
     (if (<= t_0 -2e+125)
       t_0
       (if (<= t_0 1e-22)
         (fma x (/ y z) x)
         (if (<= t_0 1e+267) t_0 (/ x (/ z (+ 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 <= -((double) INFINITY)) {
		tmp = fma(y, (x / z), x);
	} else if (t_0 <= -2e+125) {
		tmp = t_0;
	} else if (t_0 <= 1e-22) {
		tmp = fma(x, (y / z), x);
	} else if (t_0 <= 1e+267) {
		tmp = t_0;
	} else {
		tmp = x / (z / (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 <= Float64(-Inf))
		tmp = fma(y, Float64(x / z), x);
	elseif (t_0 <= -2e+125)
		tmp = t_0;
	elseif (t_0 <= 1e-22)
		tmp = fma(x, Float64(y / z), x);
	elseif (t_0 <= 1e+267)
		tmp = t_0;
	else
		tmp = Float64(x / Float64(z / 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, (-Infinity)], N[(y * N[(x / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, -2e+125], t$95$0, If[LessEqual[t$95$0, 1e-22], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 1e+267], t$95$0, N[(x / N[(z / 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 -\infty:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

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

\mathbf{elif}\;t_0 \leq 10^{-22}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

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

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


\end{array}

Error

Target

Original12.8
Target3.1
Herbie0.7
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

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

    1. Initial program 64.0

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

      \[\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)): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 39 points increase in error, 31 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 29 points increase in error, 39 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))): 53 points increase in error, 1 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 4 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 69 points increase in error, 76 points decrease in error
    3. Taylor expanded in x around 0 0.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{x}{z}, x\right)} \]
      Proof
      (fma.f64 y (/.f64 x z) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 x z)) x)): 2 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y x) z)) x): 39 points increase in error, 29 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 y z) x)) x): 31 points increase in error, 39 points decrease in error
      (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 x (/.f64 y z))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite=> +-commutative_binary64 (+.f64 x (*.f64 x (/.f64 y z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 x 1)) (*.f64 x (/.f64 y z))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-lft-out_binary64 (*.f64 x (+.f64 1 (/.f64 y z)))): 2 points increase in error, 1 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 1 (/.f64 y z)) x)): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -1.9999999999999998e125 or 1e-22 < (/.f64 (*.f64 x (+.f64 y z)) z) < 9.9999999999999997e266

    1. Initial program 0.2

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

    if -1.9999999999999998e125 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1e-22

    1. Initial program 5.5

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

      \[\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)): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 39 points increase in error, 31 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 29 points increase in error, 39 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))): 53 points increase in error, 1 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 4 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 69 points increase in error, 76 points decrease in error

    if 9.9999999999999997e266 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 51.4

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

      \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{z}{y + z}}} \]
    3. Applied egg-rr3.5

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

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

Alternatives

Alternative 1
Error0.6
Cost7236
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ t_1 := \frac{x}{\frac{z}{y + z}}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{+80}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+267}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error2.0
Cost1996
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ t_1 := \left(y + z\right) \cdot \frac{x}{z}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{+138}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 1:\\ \;\;\;\;x \cdot \left(\frac{y}{z} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error20.5
Cost848
\[\begin{array}{l} t_0 := \frac{x}{\frac{z}{y}}\\ \mathbf{if}\;z \leq -1.25 \cdot 10^{-112}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{-113}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.16462268622581 \cdot 10^{+22}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.0830570044916294 \cdot 10^{+33}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error4.0
Cost712
\[\begin{array}{l} t_0 := \frac{x}{\frac{z}{y + z}}\\ \mathbf{if}\;z \leq -1 \cdot 10^{-235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{-161}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error4.3
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(\frac{y}{z} + 1\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{-235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{-150}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error3.3
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(\frac{y}{z} + 1\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{-235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.538515907494069 \cdot 10^{+22}:\\ \;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error19.2
Cost584
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;y \leq -4.871856419037473 \cdot 10^{+34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.344647289790902 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error19.1
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -4.871856419037473 \cdot 10^{+34}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq 8.344647289790902 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \end{array} \]
Alternative 9
Error25.1
Cost64
\[x \]

Error

Reproduce

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