?

Average Accuracy: 60.9% → 99.4%
Time: 10.1s
Precision: binary64
Cost: 7236

?

\[x \cdot \sqrt{y \cdot y - z \cdot z} \]
\[\begin{array}{l} t_0 := \frac{z}{\frac{y}{z}} \cdot x\\ \mathbf{if}\;y \leq -5 \cdot 10^{-278}:\\ \;\;\;\;0.5 \cdot t_0 - y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t_0 \cdot -0.5\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)) x)))
   (if (<= y -5e-278) (- (* 0.5 t_0) (* y x)) (fma y x (* t_0 -0.5)))))
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)) * x;
	double tmp;
	if (y <= -5e-278) {
		tmp = (0.5 * t_0) - (y * x);
	} else {
		tmp = fma(y, x, (t_0 * -0.5));
	}
	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(Float64(z / Float64(y / z)) * x)
	tmp = 0.0
	if (y <= -5e-278)
		tmp = Float64(Float64(0.5 * t_0) - Float64(y * x));
	else
		tmp = fma(y, x, Float64(t_0 * -0.5));
	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[(N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -5e-278], N[(N[(0.5 * t$95$0), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(t$95$0 * -0.5), $MachinePrecision]), $MachinePrecision]]]
x \cdot \sqrt{y \cdot y - z \cdot z}
\begin{array}{l}
t_0 := \frac{z}{\frac{y}{z}} \cdot x\\
\mathbf{if}\;y \leq -5 \cdot 10^{-278}:\\
\;\;\;\;0.5 \cdot t_0 - y \cdot x\\

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


\end{array}

Error?

Target

Original60.9%
Target99.1%
Herbie99.4%
\[\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.99999999999999985e-278

    1. Initial program 60.6%

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

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

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

      [Start]93.8

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

      mul-1-neg [=>]93.8

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

      unsub-neg [=>]93.8

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

      unpow2 [=>]93.8

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

      associate-/l* [=>]90.1

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

      associate-/r/ [=>]94.6

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

      associate-/l* [=>]99.5

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

    if -4.99999999999999985e-278 < y

    1. Initial program 61.3%

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

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

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

      [Start]94.0

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

      +-commutative [=>]94.0

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

      fma-def [=>]94.0

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

      unpow2 [=>]94.0

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

      associate-/l* [=>]90.4

      \[ \mathsf{fma}\left(y, x, -0.5 \cdot \color{blue}{\frac{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.3

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

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

Alternatives

Alternative 1
Accuracy99.4%
Cost964
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-278}:\\ \;\;\;\;x \cdot \left(0.5 \cdot \frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x + \left(z \cdot \frac{z}{y}\right) \cdot \left(x \cdot -0.5\right)\\ \end{array} \]
Alternative 2
Accuracy99.4%
Cost964
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-278}:\\ \;\;\;\;0.5 \cdot \left(\frac{z}{\frac{y}{z}} \cdot x\right) - y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x + \left(z \cdot \frac{z}{y}\right) \cdot \left(x \cdot -0.5\right)\\ \end{array} \]
Alternative 3
Accuracy99.1%
Cost836
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-278}:\\ \;\;\;\;x \cdot \left(0.5 \cdot \frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 4
Accuracy98.9%
Cost388
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-278}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Accuracy53.6%
Cost192
\[y \cdot x \]

Error

Reproduce?

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