| Alternative 1 | |
|---|---|
| Error | 41.1 |
| Cost | 34120 |
(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 (hypot B (- A C)))
(t_1 (fma -4.0 (* C A) (* B B)))
(t_2 (+ (* B B) (* (* C A) -4.0)))
(t_3 (* t_2 F)))
(if (<= C -5.8e+26)
(/ (- (sqrt (* 2.0 (* t_3 (fma 2.0 A (* -0.5 (/ (* B B) C))))))) t_2)
(if (<= C -5.8e-148)
(/ (* (sqrt (* (* 2.0 F) (+ A (+ C t_0)))) (- (sqrt t_1))) t_1)
(if (<= C -3.2e-179)
(* (sqrt (/ F B)) (- (sqrt 2.0)))
(/ (* (sqrt (+ C (+ A t_0))) (- (sqrt (* 2.0 t_3)))) t_2))))))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 = hypot(B, (A - C));
double t_1 = fma(-4.0, (C * A), (B * B));
double t_2 = (B * B) + ((C * A) * -4.0);
double t_3 = t_2 * F;
double tmp;
if (C <= -5.8e+26) {
tmp = -sqrt((2.0 * (t_3 * fma(2.0, A, (-0.5 * ((B * B) / C)))))) / t_2;
} else if (C <= -5.8e-148) {
tmp = (sqrt(((2.0 * F) * (A + (C + t_0)))) * -sqrt(t_1)) / t_1;
} else if (C <= -3.2e-179) {
tmp = sqrt((F / B)) * -sqrt(2.0);
} else {
tmp = (sqrt((C + (A + t_0))) * -sqrt((2.0 * t_3))) / t_2;
}
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 = hypot(B, Float64(A - C)) t_1 = fma(-4.0, Float64(C * A), Float64(B * B)) t_2 = Float64(Float64(B * B) + Float64(Float64(C * A) * -4.0)) t_3 = Float64(t_2 * F) tmp = 0.0 if (C <= -5.8e+26) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(t_3 * fma(2.0, A, Float64(-0.5 * Float64(Float64(B * B) / C))))))) / t_2); elseif (C <= -5.8e-148) tmp = Float64(Float64(sqrt(Float64(Float64(2.0 * F) * Float64(A + Float64(C + t_0)))) * Float64(-sqrt(t_1))) / t_1); elseif (C <= -3.2e-179) tmp = Float64(sqrt(Float64(F / B)) * Float64(-sqrt(2.0))); else tmp = Float64(Float64(sqrt(Float64(C + Float64(A + t_0))) * Float64(-sqrt(Float64(2.0 * t_3)))) / t_2); 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[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[(C * A), $MachinePrecision] + N[(B * B), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(B * B), $MachinePrecision] + N[(N[(C * A), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * F), $MachinePrecision]}, If[LessEqual[C, -5.8e+26], N[((-N[Sqrt[N[(2.0 * N[(t$95$3 * N[(2.0 * A + N[(-0.5 * N[(N[(B * B), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$2), $MachinePrecision], If[LessEqual[C, -5.8e-148], N[(N[(N[Sqrt[N[(N[(2.0 * F), $MachinePrecision] * N[(A + N[(C + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[t$95$1], $MachinePrecision])), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[C, -3.2e-179], N[(N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision], N[(N[(N[Sqrt[N[(C + N[(A + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(2.0 * t$95$3), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$2), $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{hypot}\left(B, A - C\right)\\
t_1 := \mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)\\
t_2 := B \cdot B + \left(C \cdot A\right) \cdot -4\\
t_3 := t_2 \cdot F\\
\mathbf{if}\;C \leq -5.8 \cdot 10^{+26}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(t_3 \cdot \mathsf{fma}\left(2, A, -0.5 \cdot \frac{B \cdot B}{C}\right)\right)}}{t_2}\\
\mathbf{elif}\;C \leq -5.8 \cdot 10^{-148}:\\
\;\;\;\;\frac{\sqrt{\left(2 \cdot F\right) \cdot \left(A + \left(C + t_0\right)\right)} \cdot \left(-\sqrt{t_1}\right)}{t_1}\\
\mathbf{elif}\;C \leq -3.2 \cdot 10^{-179}:\\
\;\;\;\;\sqrt{\frac{F}{B}} \cdot \left(-\sqrt{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{C + \left(A + t_0\right)} \cdot \left(-\sqrt{2 \cdot t_3}\right)}{t_2}\\
\end{array}
if C < -5.8e26Initial program 61.6
Simplified61.6
[Start]61.6 | \[ \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}
\] |
|---|
Applied egg-rr61.4
Taylor expanded in C around -inf 45.1
Simplified45.1
[Start]45.1 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \left(2 \cdot A + -0.5 \cdot \frac{{B}^{2}}{C}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
fma-def [=>]45.1 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \color{blue}{\mathsf{fma}\left(2, A, -0.5 \cdot \frac{{B}^{2}}{C}\right)}\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]45.1 | \[ \frac{-\sqrt{2 \cdot \left(\left(\left(B \cdot B - 4 \cdot \left(A \cdot C\right)\right) \cdot F\right) \cdot \mathsf{fma}\left(2, A, -0.5 \cdot \frac{\color{blue}{B \cdot B}}{C}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
if -5.8e26 < C < -5.7999999999999997e-148Initial program 49.7
Simplified46.8
[Start]49.7 | \[ \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}
\] |
|---|
Applied egg-rr42.0
Simplified41.5
[Start]42.0 | \[ \frac{-\sqrt{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)} \cdot \sqrt{\left(F \cdot 2\right) \cdot \left(\mathsf{hypot}\left(B, A - C\right) + \left(A + C\right)\right)}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
|---|---|
*-commutative [=>]42.0 | \[ \frac{-\sqrt{\mathsf{fma}\left(-4, \color{blue}{C \cdot A}, B \cdot B\right)} \cdot \sqrt{\left(F \cdot 2\right) \cdot \left(\mathsf{hypot}\left(B, A - C\right) + \left(A + C\right)\right)}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
*-commutative [=>]42.0 | \[ \frac{-\sqrt{\mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)} \cdot \sqrt{\color{blue}{\left(2 \cdot F\right)} \cdot \left(\mathsf{hypot}\left(B, A - C\right) + \left(A + C\right)\right)}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
+-commutative [=>]42.0 | \[ \frac{-\sqrt{\mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)} \cdot \sqrt{\left(2 \cdot F\right) \cdot \color{blue}{\left(\left(A + C\right) + \mathsf{hypot}\left(B, A - C\right)\right)}}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
associate-+r+ [<=]41.5 | \[ \frac{-\sqrt{\mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)} \cdot \sqrt{\left(2 \cdot F\right) \cdot \color{blue}{\left(A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)\right)}}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
if -5.7999999999999997e-148 < C < -3.2000000000000001e-179Initial program 48.7
Simplified48.7
[Start]48.7 | \[ \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 54.6
Simplified54.6
[Start]54.6 | \[ \frac{-\left(\sqrt{2} \cdot B\right) \cdot \sqrt{\left(A + \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
associate-*l* [=>]54.6 | \[ \frac{-\color{blue}{\sqrt{2} \cdot \left(B \cdot \sqrt{\left(A + \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F}\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
*-commutative [=>]54.6 | \[ \frac{-\sqrt{2} \cdot \left(B \cdot \sqrt{\color{blue}{F \cdot \left(A + \sqrt{{B}^{2} + {A}^{2}}\right)}}\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]54.6 | \[ \frac{-\sqrt{2} \cdot \left(B \cdot \sqrt{F \cdot \left(A + \sqrt{\color{blue}{B \cdot B} + {A}^{2}}\right)}\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]54.6 | \[ \frac{-\sqrt{2} \cdot \left(B \cdot \sqrt{F \cdot \left(A + \sqrt{B \cdot B + \color{blue}{A \cdot A}}\right)}\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
Taylor expanded in A around 0 51.5
Simplified51.5
[Start]51.5 | \[ -1 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{F}{B}}\right)
\] |
|---|---|
associate-*r* [=>]51.5 | \[ \color{blue}{\left(-1 \cdot \sqrt{2}\right) \cdot \sqrt{\frac{F}{B}}}
\] |
neg-mul-1 [<=]51.5 | \[ \color{blue}{\left(-\sqrt{2}\right)} \cdot \sqrt{\frac{F}{B}}
\] |
*-commutative [=>]51.5 | \[ \color{blue}{\sqrt{\frac{F}{B}} \cdot \left(-\sqrt{2}\right)}
\] |
if -3.2000000000000001e-179 < C Initial program 49.9
Simplified49.9
[Start]49.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}
\] |
|---|
Applied egg-rr46.2
Applied egg-rr39.8
Simplified39.1
[Start]39.8 | \[ \frac{-\sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, \left(A \cdot C\right) \cdot -4\right) \cdot F\right)} \cdot \sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
*-commutative [=>]39.8 | \[ \frac{-\color{blue}{\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, \left(A \cdot C\right) \cdot -4\right) \cdot F\right)}}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
associate-+r+ [=>]39.8 | \[ \frac{-\sqrt{\color{blue}{\left(A + C\right) + \mathsf{hypot}\left(B, A - C\right)}} \cdot \sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, \left(A \cdot C\right) \cdot -4\right) \cdot F\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
+-commutative [=>]39.8 | \[ \frac{-\sqrt{\color{blue}{\left(C + A\right)} + \mathsf{hypot}\left(B, A - C\right)} \cdot \sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, \left(A \cdot C\right) \cdot -4\right) \cdot F\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
associate-+l+ [=>]39.1 | \[ \frac{-\sqrt{\color{blue}{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)}} \cdot \sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, \left(A \cdot C\right) \cdot -4\right) \cdot F\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
*-commutative [=>]39.1 | \[ \frac{-\sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \color{blue}{\left(F \cdot \mathsf{fma}\left(B, B, \left(A \cdot C\right) \cdot -4\right)\right)}}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
associate-*l* [=>]39.1 | \[ \frac{-\sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \left(F \cdot \mathsf{fma}\left(B, B, \color{blue}{A \cdot \left(C \cdot -4\right)}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
Taylor expanded in F around 0 39.1
Simplified39.1
[Start]39.1 | \[ \frac{-\sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \left(\left({B}^{2} + -4 \cdot \left(A \cdot C\right)\right) \cdot F\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
*-commutative [=>]39.1 | \[ \frac{-\sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \color{blue}{\left(F \cdot \left({B}^{2} + -4 \cdot \left(A \cdot C\right)\right)\right)}}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]39.1 | \[ \frac{-\sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \left(F \cdot \left(\color{blue}{B \cdot B} + -4 \cdot \left(A \cdot C\right)\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
Final simplification41.2
| Alternative 1 | |
|---|---|
| Error | 41.1 |
| Cost | 34120 |
| Alternative 2 | |
|---|---|
| Error | 41.2 |
| Cost | 27976 |
| Alternative 3 | |
|---|---|
| Error | 41.3 |
| Cost | 27848 |
| Alternative 4 | |
|---|---|
| Error | 41.4 |
| Cost | 21709 |
| Alternative 5 | |
|---|---|
| Error | 45.0 |
| Cost | 21588 |
| Alternative 6 | |
|---|---|
| Error | 44.0 |
| Cost | 21588 |
| Alternative 7 | |
|---|---|
| Error | 45.0 |
| Cost | 21388 |
| Alternative 8 | |
|---|---|
| Error | 45.8 |
| Cost | 21324 |
| Alternative 9 | |
|---|---|
| Error | 47.0 |
| Cost | 15637 |
| Alternative 10 | |
|---|---|
| Error | 46.0 |
| Cost | 15637 |
| Alternative 11 | |
|---|---|
| Error | 46.2 |
| Cost | 15044 |
| Alternative 12 | |
|---|---|
| Error | 48.0 |
| Cost | 14240 |
| Alternative 13 | |
|---|---|
| Error | 53.1 |
| Cost | 9376 |
| Alternative 14 | |
|---|---|
| Error | 53.2 |
| Cost | 9248 |
| Alternative 15 | |
|---|---|
| Error | 53.4 |
| Cost | 8456 |
| Alternative 16 | |
|---|---|
| Error | 56.9 |
| Cost | 8328 |
| Alternative 17 | |
|---|---|
| Error | 55.3 |
| Cost | 8328 |
| Alternative 18 | |
|---|---|
| Error | 56.7 |
| Cost | 8196 |
| Alternative 19 | |
|---|---|
| Error | 57.6 |
| Cost | 7940 |
| Alternative 20 | |
|---|---|
| Error | 60.6 |
| Cost | 7040 |
| Alternative 21 | |
|---|---|
| Error | 62.0 |
| Cost | 6848 |
herbie shell --seed 2023187
(FPCore (A B C F)
:name "ABCF->ab-angle a"
: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))))