?

Average Accuracy: 61.8% → 99.6%
Time: 9.9s
Precision: binary64
Cost: 7236

?

\[x \cdot \sqrt{y \cdot y - z \cdot z} \]
\[\begin{array}{l} t_0 := \frac{z}{\frac{y}{z}}\\ \mathbf{if}\;y \leq -2 \cdot 10^{-304}:\\ \;\;\;\;\left(0.5 \cdot t_0 - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, -0.5 \cdot \left(t_0 \cdot x\right)\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (sqrt (- (* y y) (* z z)))))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ z (/ y z))))
   (if (<= y -2e-304) (* (- (* 0.5 t_0) y) x) (fma y x (* -0.5 (* t_0 x))))))
double code(double x, double y, double z) {
	return x * sqrt(((y * y) - (z * z)));
}
double code(double x, double y, double z) {
	double t_0 = z / (y / z);
	double tmp;
	if (y <= -2e-304) {
		tmp = ((0.5 * t_0) - y) * x;
	} else {
		tmp = fma(y, x, (-0.5 * (t_0 * x)));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(x * sqrt(Float64(Float64(y * y) - Float64(z * z))))
end
function code(x, y, z)
	t_0 = Float64(z / Float64(y / z))
	tmp = 0.0
	if (y <= -2e-304)
		tmp = Float64(Float64(Float64(0.5 * t_0) - y) * x);
	else
		tmp = fma(y, x, Float64(-0.5 * Float64(t_0 * x)));
	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_] := Block[{t$95$0 = N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2e-304], N[(N[(N[(0.5 * t$95$0), $MachinePrecision] - y), $MachinePrecision] * x), $MachinePrecision], N[(y * x + N[(-0.5 * N[(t$95$0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x \cdot \sqrt{y \cdot y - z \cdot z}
\begin{array}{l}
t_0 := \frac{z}{\frac{y}{z}}\\
\mathbf{if}\;y \leq -2 \cdot 10^{-304}:\\
\;\;\;\;\left(0.5 \cdot t_0 - y\right) \cdot x\\

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


\end{array}

Error?

Target

Original61.8%
Target99.2%
Herbie99.6%
\[\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 < -1.99999999999999994e-304

    1. Initial program 61.8%

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

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

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

      [Start]95.8

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

      fma-def [=>]95.8

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

      unpow2 [=>]95.8

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

      associate-/l* [=>]99.7

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

      mul-1-neg [=>]99.7

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

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

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

      [Start]95.8

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

      unpow2 [=>]95.8

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

      associate-/l* [=>]99.7

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

    if -1.99999999999999994e-304 < y

    1. Initial program 61.8%

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

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

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

      [Start]94.3

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

      +-commutative [=>]94.3

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

      fma-def [=>]94.3

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

      associate-/l* [=>]89.8

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

      unpow2 [=>]89.8

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

      associate-/r/ [=>]94.7

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

      associate-/l* [=>]99.6

      \[ \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 simplification99.6%

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

Alternatives

Alternative 1
Accuracy99.6%
Cost964
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-304}:\\ \;\;\;\;\left(0.5 \cdot \frac{z}{\frac{y}{z}} - 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
Accuracy99.4%
Cost836
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-304}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + \frac{z \cdot -0.5}{\frac{y}{z}}\right)\\ \end{array} \]
Alternative 3
Accuracy99.6%
Cost836
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-304}:\\ \;\;\;\;\left(0.5 \cdot \frac{z}{\frac{y}{z}} - y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + \frac{z \cdot -0.5}{\frac{y}{z}}\right)\\ \end{array} \]
Alternative 4
Accuracy99.0%
Cost388
\[\begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{-257}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Accuracy52.6%
Cost192
\[y \cdot x \]

Error

Reproduce?

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