Average Error: 12.6 → 2.4
Time: 6.5s
Precision: binary64
Cost: 6852
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{-75}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;z \leq 10^{-218}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} + 1\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= z -1e-75)
   (fma x (/ y z) x)
   (if (<= z 1e-218) (+ x (/ (* x y) z)) (* x (+ (/ y z) 1.0)))))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1e-75) {
		tmp = fma(x, (y / z), x);
	} else if (z <= 1e-218) {
		tmp = x + ((x * y) / z);
	} else {
		tmp = x * ((y / z) + 1.0);
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) / z)
end
function code(x, y, z)
	tmp = 0.0
	if (z <= -1e-75)
		tmp = fma(x, Float64(y / z), x);
	elseif (z <= 1e-218)
		tmp = Float64(x + Float64(Float64(x * y) / z));
	else
		tmp = Float64(x * Float64(Float64(y / z) + 1.0));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[z, -1e-75], N[(x * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 1e-218], N[(x + N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y / z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-75}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

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

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


\end{array}

Error

Target

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

Derivation

  1. Split input into 3 regimes
  2. if z < -9.9999999999999996e-76

    1. Initial program 14.4

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

      \[\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): 38 points increase in error, 24 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 39 points increase in error, 30 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))): 62 points increase in error, 5 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 1 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 64 points increase in error, 89 points decrease in error

    if -9.9999999999999996e-76 < z < 1e-218

    1. Initial program 11.0

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

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

    if 1e-218 < z

    1. Initial program 12.0

      \[\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)): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 38 points increase in error, 24 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 39 points increase in error, 30 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))): 62 points increase in error, 5 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 1 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 64 points increase in error, 89 points decrease in error
    3. Taylor expanded in x around 0 2.1

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

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

Alternatives

Alternative 1
Error20.8
Cost848
\[\begin{array}{l} t_0 := \frac{x}{\frac{z}{y}}\\ \mathbf{if}\;z \leq -1.5 \cdot 10^{-124}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.001782469883468 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.8530160075359368 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error21.0
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{-124}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-40}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 5.001782469883468 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.8530160075359368 \cdot 10^{+70}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error19.3
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -6.2 \cdot 10^{-83}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-40}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;z \leq 5.001782469883468 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.8530160075359368 \cdot 10^{+70}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error19.2
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -6.2 \cdot 10^{-83}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-40}:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{elif}\;z \leq 5.001782469883468 \cdot 10^{+25}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.8530160075359368 \cdot 10^{+70}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error2.4
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(\frac{y}{z} + 1\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{-75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{-218}:\\ \;\;\;\;x + \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error4.7
Cost448
\[x + \frac{x \cdot y}{z} \]
Alternative 7
Error25.0
Cost64
\[x \]

Error

Reproduce

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