| Alternative 1 | |
|---|---|
| Accuracy | 46.2% |
| Cost | 21132 |

(FPCore (A B C F)
:precision binary64
(/
(-
(sqrt
(*
(* 2.0 (* (- (pow B 2.0) (* (* 4.0 A) C)) F))
(- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
(- (pow B 2.0) (* (* 4.0 A) C))))(FPCore (A B C F)
:precision binary64
(let* ((t_0 (fma B B (* C (* A -4.0)))) (t_1 (fma B B (* A (* C -4.0)))))
(if (<= B -2.2e+80)
(* (sqrt (/ F B)) (- (sqrt 2.0)))
(if (<= B -3.6e-60)
(/ (- (sqrt (* 2.0 (* (* F t_0) (+ A (- C (hypot B (- A C)))))))) t_0)
(if (<= B 3e-10)
(/ (- (sqrt (* t_1 (* (* F 2.0) (+ A A))))) t_1)
(* (/ (sqrt 2.0) B) (- (sqrt (* F (- A (hypot B A)))))))))))double code(double A, double B, double C, double F) {
return -sqrt(((2.0 * ((pow(B, 2.0) - ((4.0 * A) * C)) * F)) * ((A + C) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / (pow(B, 2.0) - ((4.0 * A) * C));
}
double code(double A, double B, double C, double F) {
double t_0 = fma(B, B, (C * (A * -4.0)));
double t_1 = fma(B, B, (A * (C * -4.0)));
double tmp;
if (B <= -2.2e+80) {
tmp = sqrt((F / B)) * -sqrt(2.0);
} else if (B <= -3.6e-60) {
tmp = -sqrt((2.0 * ((F * t_0) * (A + (C - hypot(B, (A - C))))))) / t_0;
} else if (B <= 3e-10) {
tmp = -sqrt((t_1 * ((F * 2.0) * (A + A)))) / t_1;
} else {
tmp = (sqrt(2.0) / B) * -sqrt((F * (A - hypot(B, A))));
}
return tmp;
}
function code(A, B, C, F) return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C))) end
function code(A, B, C, F) t_0 = fma(B, B, Float64(C * Float64(A * -4.0))) t_1 = fma(B, B, Float64(A * Float64(C * -4.0))) tmp = 0.0 if (B <= -2.2e+80) tmp = Float64(sqrt(Float64(F / B)) * Float64(-sqrt(2.0))); elseif (B <= -3.6e-60) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(F * t_0) * Float64(A + Float64(C - hypot(B, Float64(A - C)))))))) / t_0); elseif (B <= 3e-10) tmp = Float64(Float64(-sqrt(Float64(t_1 * Float64(Float64(F * 2.0) * Float64(A + A))))) / t_1); else tmp = Float64(Float64(sqrt(2.0) / B) * Float64(-sqrt(Float64(F * Float64(A - hypot(B, A)))))); end return tmp end
code[A_, B_, C_, F_] := N[((-N[Sqrt[N[(N[(2.0 * N[(N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(B * B + N[(C * N[(A * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, -2.2e+80], N[(N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision], If[LessEqual[B, -3.6e-60], N[((-N[Sqrt[N[(2.0 * N[(N[(F * t$95$0), $MachinePrecision] * N[(A + N[(C - N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], If[LessEqual[B, 3e-10], N[((-N[Sqrt[N[(t$95$1 * N[(N[(F * 2.0), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$1), $MachinePrecision], N[(N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision] * (-N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]]]]]]
\frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C}
\begin{array}{l}
t_0 := \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\\
t_1 := \mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)\\
\mathbf{if}\;B \leq -2.2 \cdot 10^{+80}:\\
\;\;\;\;\sqrt{\frac{F}{B}} \cdot \left(-\sqrt{2}\right)\\
\mathbf{elif}\;B \leq -3.6 \cdot 10^{-60}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(F \cdot t_0\right) \cdot \left(A + \left(C - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}{t_0}\\
\mathbf{elif}\;B \leq 3 \cdot 10^{-10}:\\
\;\;\;\;\frac{-\sqrt{t_1 \cdot \left(\left(F \cdot 2\right) \cdot \left(A + A\right)\right)}}{t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2}}{B} \cdot \left(-\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)}\right)\\
\end{array}
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if B < -2.20000000000000003e80Initial program 8.4%
Simplified8.4%
[Start]8.4 | \[ \frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C}
\] |
|---|
Taylor expanded in A around 0 8.4%
Simplified8.5%
[Start]8.4 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \left(C - \sqrt{{B}^{2} + {C}^{2}}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
+-commutative [=>]8.4 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \left(C - \sqrt{\color{blue}{{C}^{2} + {B}^{2}}}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]8.4 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \left(C - \sqrt{\color{blue}{C \cdot C} + {B}^{2}}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]8.4 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \left(C - \sqrt{C \cdot C + \color{blue}{B \cdot B}}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
hypot-def [=>]8.5 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \left(C - \color{blue}{\mathsf{hypot}\left(C, B\right)}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
Taylor expanded in B around -inf 8.1%
Taylor expanded in C around 0 51.1%
Simplified51.1%
[Start]51.1 | \[ -1 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{F}{B}}\right)
\] |
|---|---|
mul-1-neg [=>]51.1 | \[ \color{blue}{-\sqrt{2} \cdot \sqrt{\frac{F}{B}}}
\] |
*-commutative [=>]51.1 | \[ -\color{blue}{\sqrt{\frac{F}{B}} \cdot \sqrt{2}}
\] |
distribute-rgt-neg-in [=>]51.1 | \[ \color{blue}{\sqrt{\frac{F}{B}} \cdot \left(-\sqrt{2}\right)}
\] |
if -2.20000000000000003e80 < B < -3.6e-60Initial program 53.3%
Simplified61.2%
[Start]53.3 | \[ \frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C}
\] |
|---|
if -3.6e-60 < B < 3e-10Initial program 20.0%
Simplified34.4%
[Start]20.0 | \[ \frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C}
\] |
|---|
Taylor expanded in C around inf 25.5%
Simplified25.5%
[Start]25.5 | \[ \frac{-\sqrt{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right) \cdot \left(\left(2 \cdot F\right) \cdot \left(A - -1 \cdot A\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right)}
\] |
|---|---|
cancel-sign-sub-inv [=>]25.5 | \[ \frac{-\sqrt{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right) \cdot \left(\left(2 \cdot F\right) \cdot \color{blue}{\left(A + \left(--1\right) \cdot A\right)}\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right)}
\] |
metadata-eval [=>]25.5 | \[ \frac{-\sqrt{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right) \cdot \left(\left(2 \cdot F\right) \cdot \left(A + \color{blue}{1} \cdot A\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right)}
\] |
*-lft-identity [=>]25.5 | \[ \frac{-\sqrt{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right) \cdot \left(\left(2 \cdot F\right) \cdot \left(A + \color{blue}{A}\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(-4 \cdot C\right)\right)}
\] |
if 3e-10 < B Initial program 12.9%
Simplified10.6%
[Start]12.9 | \[ \frac{-\sqrt{\left(2 \cdot \left(\left({B}^{2} - \left(4 \cdot A\right) \cdot C\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{{B}^{2} - \left(4 \cdot A\right) \cdot C}
\] |
|---|
Taylor expanded in C around 0 18.9%
Simplified50.2%
[Start]18.9 | \[ -1 \cdot \left(\frac{\sqrt{2}}{B} \cdot \sqrt{\left(A - \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F}\right)
\] |
|---|---|
mul-1-neg [=>]18.9 | \[ \color{blue}{-\frac{\sqrt{2}}{B} \cdot \sqrt{\left(A - \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F}}
\] |
distribute-rgt-neg-in [=>]18.9 | \[ \color{blue}{\frac{\sqrt{2}}{B} \cdot \left(-\sqrt{\left(A - \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F}\right)}
\] |
*-commutative [=>]18.9 | \[ \frac{\sqrt{2}}{B} \cdot \left(-\sqrt{\color{blue}{F \cdot \left(A - \sqrt{{B}^{2} + {A}^{2}}\right)}}\right)
\] |
unpow2 [=>]18.9 | \[ \frac{\sqrt{2}}{B} \cdot \left(-\sqrt{F \cdot \left(A - \sqrt{\color{blue}{B \cdot B} + {A}^{2}}\right)}\right)
\] |
unpow2 [=>]18.9 | \[ \frac{\sqrt{2}}{B} \cdot \left(-\sqrt{F \cdot \left(A - \sqrt{B \cdot B + \color{blue}{A \cdot A}}\right)}\right)
\] |
hypot-def [=>]50.2 | \[ \frac{\sqrt{2}}{B} \cdot \left(-\sqrt{F \cdot \left(A - \color{blue}{\mathsf{hypot}\left(B, A\right)}\right)}\right)
\] |
Final simplification40.5%
| Alternative 1 | |
|---|---|
| Accuracy | 46.2% |
| Cost | 21132 |
| Alternative 2 | |
|---|---|
| Accuracy | 46.2% |
| Cost | 20300 |
| Alternative 3 | |
|---|---|
| Accuracy | 44.0% |
| Cost | 14924 |
| Alternative 4 | |
|---|---|
| Accuracy | 43.3% |
| Cost | 14792 |
| Alternative 5 | |
|---|---|
| Accuracy | 43.0% |
| Cost | 14664 |
| Alternative 6 | |
|---|---|
| Accuracy | 43.0% |
| Cost | 14216 |
| Alternative 7 | |
|---|---|
| Accuracy | 35.0% |
| Cost | 13316 |
| Alternative 8 | |
|---|---|
| Accuracy | 27.4% |
| Cost | 8460 |
| Alternative 9 | |
|---|---|
| Accuracy | 31.0% |
| Cost | 8460 |
| Alternative 10 | |
|---|---|
| Accuracy | 26.0% |
| Cost | 8201 |
| Alternative 11 | |
|---|---|
| Accuracy | 26.0% |
| Cost | 8009 |
| Alternative 12 | |
|---|---|
| Accuracy | 26.0% |
| Cost | 8009 |
| Alternative 13 | |
|---|---|
| Accuracy | 20.8% |
| Cost | 6656 |
herbie shell --seed 2023160
(FPCore (A B C F)
:name "ABCF->ab-angle b"
:precision binary64
(/ (- (sqrt (* (* 2.0 (* (- (pow B 2.0) (* (* 4.0 A) C)) F)) (- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0))))))) (- (pow B 2.0) (* (* 4.0 A) C))))