?

Average Error: 39% → 0.67%
Time: 5.8s
Precision: binary64
Cost: 7236

?

\[x \cdot \sqrt{y \cdot y - z \cdot z} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-251}:\\ \;\;\;\;\left(\frac{z}{y} \cdot \left(z \cdot 0.5\right) - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, -0.5 \cdot \left(x \cdot \frac{z}{\frac{y}{z}}\right)\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (sqrt (- (* y y) (* z z)))))
(FPCore (x y z)
 :precision binary64
 (if (<= y -4.8e-251)
   (* (- (* (/ z y) (* z 0.5)) y) x)
   (fma y x (* -0.5 (* x (/ z (/ y z)))))))
double code(double x, double y, double z) {
	return x * sqrt(((y * y) - (z * z)));
}
double code(double x, double y, double z) {
	double tmp;
	if (y <= -4.8e-251) {
		tmp = (((z / y) * (z * 0.5)) - y) * x;
	} else {
		tmp = fma(y, x, (-0.5 * (x * (z / (y / z)))));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(x * sqrt(Float64(Float64(y * y) - Float64(z * z))))
end
function code(x, y, z)
	tmp = 0.0
	if (y <= -4.8e-251)
		tmp = Float64(Float64(Float64(Float64(z / y) * Float64(z * 0.5)) - y) * x);
	else
		tmp = fma(y, x, Float64(-0.5 * Float64(x * Float64(z / Float64(y / z)))));
	end
	return tmp
end
code[x_, y_, z_] := N[(x * N[Sqrt[N[(N[(y * y), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, -4.8e-251], N[(N[(N[(N[(z / y), $MachinePrecision] * N[(z * 0.5), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] * x), $MachinePrecision], N[(y * x + N[(-0.5 * N[(x * N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x \cdot \sqrt{y \cdot y - z \cdot z}
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{-251}:\\
\;\;\;\;\left(\frac{z}{y} \cdot \left(z \cdot 0.5\right) - y\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, -0.5 \cdot \left(x \cdot \frac{z}{\frac{y}{z}}\right)\right)\\


\end{array}

Error?

Target

Original39%
Target0.9%
Herbie0.67%
\[\begin{array}{l} \mathbf{if}\;y < 2.5816096488251695 \cdot 10^{-278}:\\ \;\;\;\;-x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\sqrt{y + z} \cdot \sqrt{y - z}\right)\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if y < -4.79999999999999992e-251

    1. Initial program 38.79

      \[x \cdot \sqrt{y \cdot y - z \cdot z} \]
    2. Taylor expanded in y around -inf 4.65

      \[\leadsto x \cdot \color{blue}{\left(0.5 \cdot \frac{{z}^{2}}{y} + -1 \cdot y\right)} \]
    3. Simplified0.42

      \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(0.5, \frac{z}{\frac{y}{z}}, -y\right)} \]
      Proof

      [Start]4.65

      \[ x \cdot \left(0.5 \cdot \frac{{z}^{2}}{y} + -1 \cdot y\right) \]

      fma-def [=>]4.65

      \[ x \cdot \color{blue}{\mathsf{fma}\left(0.5, \frac{{z}^{2}}{y}, -1 \cdot y\right)} \]

      unpow2 [=>]4.65

      \[ x \cdot \mathsf{fma}\left(0.5, \frac{\color{blue}{z \cdot z}}{y}, -1 \cdot y\right) \]

      associate-/l* [=>]0.42

      \[ x \cdot \mathsf{fma}\left(0.5, \color{blue}{\frac{z}{\frac{y}{z}}}, -1 \cdot y\right) \]

      mul-1-neg [=>]0.42

      \[ x \cdot \mathsf{fma}\left(0.5, \frac{z}{\frac{y}{z}}, \color{blue}{-y}\right) \]
    4. Taylor expanded in x around 0 4.65

      \[\leadsto \color{blue}{\left(0.5 \cdot \frac{{z}^{2}}{y} - y\right) \cdot x} \]
    5. Simplified0.42

      \[\leadsto \color{blue}{\left(\frac{z}{y} \cdot \left(z \cdot 0.5\right) - y\right) \cdot x} \]
      Proof

      [Start]4.65

      \[ \left(0.5 \cdot \frac{{z}^{2}}{y} - y\right) \cdot x \]

      *-commutative [=>]4.65

      \[ \left(\color{blue}{\frac{{z}^{2}}{y} \cdot 0.5} - y\right) \cdot x \]

      unpow2 [=>]4.65

      \[ \left(\frac{\color{blue}{z \cdot z}}{y} \cdot 0.5 - y\right) \cdot x \]

      associate-*l/ [<=]0.42

      \[ \left(\color{blue}{\left(\frac{z}{y} \cdot z\right)} \cdot 0.5 - y\right) \cdot x \]

      associate-*l* [=>]0.42

      \[ \left(\color{blue}{\frac{z}{y} \cdot \left(z \cdot 0.5\right)} - y\right) \cdot x \]

    if -4.79999999999999992e-251 < y

    1. Initial program 39.2

      \[x \cdot \sqrt{y \cdot y - z \cdot z} \]
    2. Taylor expanded in y around inf 6.02

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2} \cdot x}{y} + y \cdot x} \]
    3. Simplified0.91

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, -0.5 \cdot \left(\frac{z}{\frac{y}{z}} \cdot x\right)\right)} \]
      Proof

      [Start]6.02

      \[ -0.5 \cdot \frac{{z}^{2} \cdot x}{y} + y \cdot x \]

      +-commutative [=>]6.02

      \[ \color{blue}{y \cdot x + -0.5 \cdot \frac{{z}^{2} \cdot x}{y}} \]

      fma-def [=>]6.02

      \[ \color{blue}{\mathsf{fma}\left(y, x, -0.5 \cdot \frac{{z}^{2} \cdot x}{y}\right)} \]

      associate-/l* [=>]10.59

      \[ \mathsf{fma}\left(y, x, -0.5 \cdot \color{blue}{\frac{{z}^{2}}{\frac{y}{x}}}\right) \]

      unpow2 [=>]10.59

      \[ \mathsf{fma}\left(y, x, -0.5 \cdot \frac{\color{blue}{z \cdot z}}{\frac{y}{x}}\right) \]

      associate-/r/ [=>]5.39

      \[ \mathsf{fma}\left(y, x, -0.5 \cdot \color{blue}{\left(\frac{z \cdot z}{y} \cdot x\right)}\right) \]

      associate-/l* [=>]0.91

      \[ \mathsf{fma}\left(y, x, -0.5 \cdot \left(\color{blue}{\frac{z}{\frac{y}{z}}} \cdot x\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.67

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-251}:\\ \;\;\;\;\left(\frac{z}{y} \cdot \left(z \cdot 0.5\right) - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, -0.5 \cdot \left(x \cdot \frac{z}{\frac{y}{z}}\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.67%
Cost964
\[\begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-251}:\\ \;\;\;\;\left(\frac{z}{y} \cdot \left(z \cdot 0.5\right) - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot \left(x \cdot -0.5\right) + y \cdot x\\ \end{array} \]
Alternative 2
Error0.93%
Cost836
\[\begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-251}:\\ \;\;\;\;\left(\frac{z}{y} \cdot \left(z \cdot 0.5\right) - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 3
Error1.16%
Cost388
\[\begin{array}{l} \mathbf{if}\;y \leq -4.8 \cdot 10^{-251}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 4
Error46.97%
Cost192
\[y \cdot x \]

Error

Reproduce?

herbie shell --seed 2023088 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, B"
  :precision binary64

  :herbie-target
  (if (< y 2.5816096488251695e-278) (- (* x y)) (* x (* (sqrt (+ y z)) (sqrt (- y z)))))

  (* x (sqrt (- (* y y) (* z z)))))