?

Average Accuracy: 60.6% → 98.5%
Time: 6.0s
Precision: binary64
Cost: 7236

?

\[x \cdot \sqrt{y \cdot y - z \cdot z} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{-218}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \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 -2.3e-218) (* 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 <= -2.3e-218) {
		tmp = 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 <= -2.3e-218)
		tmp = Float64(y * Float64(-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, -2.3e-218], N[(y * (-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 -2.3 \cdot 10^{-218}:\\
\;\;\;\;y \cdot \left(-x\right)\\

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


\end{array}

Error?

Target

Original60.6%
Target99.0%
Herbie98.5%
\[\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 < -2.29999999999999995e-218

    1. Initial program 60.5%

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

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot x\right)} \]
    3. Simplified98.9%

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

      [Start]98.9

      \[ -1 \cdot \left(y \cdot x\right) \]

      associate-*r* [=>]98.9

      \[ \color{blue}{\left(-1 \cdot y\right) \cdot x} \]

      mul-1-neg [=>]98.9

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

    if -2.29999999999999995e-218 < y

    1. Initial program 60.7%

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

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

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

      [Start]93.6

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

      +-commutative [=>]93.6

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

      fma-def [=>]93.6

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

      associate-/l* [=>]90.0

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

      unpow2 [=>]90.0

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

      associate-/r/ [=>]94.3

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

      associate-/l* [=>]98.1

      \[ \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 simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{-218}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \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
Accuracy98.5%
Cost836
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{-218}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + z \cdot \left(z \cdot \frac{-0.5}{y}\right)\right)\\ \end{array} \]
Alternative 2
Accuracy98.2%
Cost388
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{-218}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 3
Accuracy52.5%
Cost192
\[y \cdot x \]

Error

Reproduce?

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