| Alternative 1 | |
|---|---|
| Error | 39.9 |
| Cost | 155788 |
(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 A (* C -4.0) (* B B))) (t_1 (hypot B (- A C))))
(if (<= B -4.4e+61)
(* (sqrt 2.0) (- (sqrt (/ F B))))
(if (<= B 4.8e-199)
(/ (- (sqrt (* t_0 (* (- (- t_1 C) A) (* F -2.0))))) t_0)
(if (<= B 1.4e-148)
(/ (- (sqrt (* -8.0 (* (* A (+ C C)) (* C F))))) t_0)
(if (<= B 5.5e-15)
(/ (- (sqrt (* (* A -8.0) (* (* C F) (+ A A))))) t_0)
(/
(- (sqrt (* (- t_1 (+ A C)) (* F -2.0))))
(fma -2.0 (/ A (/ B C)) B))))))))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(A, (C * -4.0), (B * B));
double t_1 = hypot(B, (A - C));
double tmp;
if (B <= -4.4e+61) {
tmp = sqrt(2.0) * -sqrt((F / B));
} else if (B <= 4.8e-199) {
tmp = -sqrt((t_0 * (((t_1 - C) - A) * (F * -2.0)))) / t_0;
} else if (B <= 1.4e-148) {
tmp = -sqrt((-8.0 * ((A * (C + C)) * (C * F)))) / t_0;
} else if (B <= 5.5e-15) {
tmp = -sqrt(((A * -8.0) * ((C * F) * (A + A)))) / t_0;
} else {
tmp = -sqrt(((t_1 - (A + C)) * (F * -2.0))) / fma(-2.0, (A / (B / C)), B);
}
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(A, Float64(C * -4.0), Float64(B * B)) t_1 = hypot(B, Float64(A - C)) tmp = 0.0 if (B <= -4.4e+61) tmp = Float64(sqrt(2.0) * Float64(-sqrt(Float64(F / B)))); elseif (B <= 4.8e-199) tmp = Float64(Float64(-sqrt(Float64(t_0 * Float64(Float64(Float64(t_1 - C) - A) * Float64(F * -2.0))))) / t_0); elseif (B <= 1.4e-148) tmp = Float64(Float64(-sqrt(Float64(-8.0 * Float64(Float64(A * Float64(C + C)) * Float64(C * F))))) / t_0); elseif (B <= 5.5e-15) tmp = Float64(Float64(-sqrt(Float64(Float64(A * -8.0) * Float64(Float64(C * F) * Float64(A + A))))) / t_0); else tmp = Float64(Float64(-sqrt(Float64(Float64(t_1 - Float64(A + C)) * Float64(F * -2.0)))) / fma(-2.0, Float64(A / Float64(B / C)), B)); 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[(A * N[(C * -4.0), $MachinePrecision] + N[(B * B), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]}, If[LessEqual[B, -4.4e+61], N[(N[Sqrt[2.0], $MachinePrecision] * (-N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], If[LessEqual[B, 4.8e-199], N[((-N[Sqrt[N[(t$95$0 * N[(N[(N[(t$95$1 - C), $MachinePrecision] - A), $MachinePrecision] * N[(F * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], If[LessEqual[B, 1.4e-148], N[((-N[Sqrt[N[(-8.0 * N[(N[(A * N[(C + C), $MachinePrecision]), $MachinePrecision] * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], If[LessEqual[B, 5.5e-15], N[((-N[Sqrt[N[(N[(A * -8.0), $MachinePrecision] * N[(N[(C * F), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[((-N[Sqrt[N[(N[(t$95$1 - N[(A + C), $MachinePrecision]), $MachinePrecision] * N[(F * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(-2.0 * N[(A / N[(B / C), $MachinePrecision]), $MachinePrecision] + B), $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(A, C \cdot -4, B \cdot B\right)\\
t_1 := \mathsf{hypot}\left(B, A - C\right)\\
\mathbf{if}\;B \leq -4.4 \cdot 10^{+61}:\\
\;\;\;\;\sqrt{2} \cdot \left(-\sqrt{\frac{F}{B}}\right)\\
\mathbf{elif}\;B \leq 4.8 \cdot 10^{-199}:\\
\;\;\;\;\frac{-\sqrt{t_0 \cdot \left(\left(\left(t_1 - C\right) - A\right) \cdot \left(F \cdot -2\right)\right)}}{t_0}\\
\mathbf{elif}\;B \leq 1.4 \cdot 10^{-148}:\\
\;\;\;\;\frac{-\sqrt{-8 \cdot \left(\left(A \cdot \left(C + C\right)\right) \cdot \left(C \cdot F\right)\right)}}{t_0}\\
\mathbf{elif}\;B \leq 5.5 \cdot 10^{-15}:\\
\;\;\;\;\frac{-\sqrt{\left(A \cdot -8\right) \cdot \left(\left(C \cdot F\right) \cdot \left(A + A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{\left(t_1 - \left(A + C\right)\right) \cdot \left(F \cdot -2\right)}}{\mathsf{fma}\left(-2, \frac{A}{\frac{B}{C}}, B\right)}\\
\end{array}
if B < -4.4000000000000001e61Initial program 58.0
Simplified57.0
[Start]58.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 B around -inf 58.8
Taylor expanded in C around 0 63.1
Simplified63.1
[Start]63.1 | \[ \frac{-\left(\sqrt{2} \cdot B\right) \cdot \sqrt{\left(A + \left(0.5 \cdot \frac{{A}^{2}}{B} + B\right)\right) \cdot F}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
|---|---|
associate-*l* [=>]63.1 | \[ \frac{-\color{blue}{\sqrt{2} \cdot \left(B \cdot \sqrt{\left(A + \left(0.5 \cdot \frac{{A}^{2}}{B} + B\right)\right) \cdot F}\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
*-commutative [=>]63.1 | \[ \frac{-\sqrt{2} \cdot \left(B \cdot \sqrt{\color{blue}{F \cdot \left(A + \left(0.5 \cdot \frac{{A}^{2}}{B} + B\right)\right)}}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
fma-def [=>]63.1 | \[ \frac{-\sqrt{2} \cdot \left(B \cdot \sqrt{F \cdot \left(A + \color{blue}{\mathsf{fma}\left(0.5, \frac{{A}^{2}}{B}, B\right)}\right)}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
unpow2 [=>]63.1 | \[ \frac{-\sqrt{2} \cdot \left(B \cdot \sqrt{F \cdot \left(A + \mathsf{fma}\left(0.5, \frac{\color{blue}{A \cdot A}}{B}, B\right)\right)}\right)}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
Taylor expanded in A around 0 33.9
Simplified33.9
[Start]33.9 | \[ -1 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{F}{B}}\right)
\] |
|---|---|
associate-*r* [=>]33.9 | \[ \color{blue}{\left(-1 \cdot \sqrt{2}\right) \cdot \sqrt{\frac{F}{B}}}
\] |
neg-mul-1 [<=]33.9 | \[ \color{blue}{\left(-\sqrt{2}\right)} \cdot \sqrt{\frac{F}{B}}
\] |
*-commutative [=>]33.9 | \[ \color{blue}{\sqrt{\frac{F}{B}} \cdot \left(-\sqrt{2}\right)}
\] |
if -4.4000000000000001e61 < B < 4.79999999999999991e-199Initial program 49.8
Simplified44.8
[Start]49.8 | \[ \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 4.79999999999999991e-199 < B < 1.4e-148Initial program 51.4
Simplified46.6
[Start]51.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 inf 50.9
Simplified48.8
[Start]50.9 | \[ \frac{-\sqrt{-8 \cdot \left(A \cdot \left(\left(C - -1 \cdot C\right) \cdot \left(C \cdot F\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
|---|---|
associate-*r* [=>]48.8 | \[ \frac{-\sqrt{-8 \cdot \color{blue}{\left(\left(A \cdot \left(C - -1 \cdot C\right)\right) \cdot \left(C \cdot F\right)\right)}}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
mul-1-neg [=>]48.8 | \[ \frac{-\sqrt{-8 \cdot \left(\left(A \cdot \left(C - \color{blue}{\left(-C\right)}\right)\right) \cdot \left(C \cdot F\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
if 1.4e-148 < B < 5.5000000000000002e-15Initial program 46.8
Simplified41.3
[Start]46.8 | \[ \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 53.0
Simplified53.0
[Start]53.0 | \[ \frac{-\sqrt{-8 \cdot \left(A \cdot \left(\left(A - -1 \cdot A\right) \cdot \left(C \cdot F\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
|---|---|
associate-*r* [=>]53.0 | \[ \frac{-\sqrt{\color{blue}{\left(-8 \cdot A\right) \cdot \left(\left(A - -1 \cdot A\right) \cdot \left(C \cdot F\right)\right)}}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
*-commutative [=>]53.0 | \[ \frac{-\sqrt{\left(-8 \cdot A\right) \cdot \color{blue}{\left(\left(C \cdot F\right) \cdot \left(A - -1 \cdot A\right)\right)}}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
mul-1-neg [=>]53.0 | \[ \frac{-\sqrt{\left(-8 \cdot A\right) \cdot \left(\left(C \cdot F\right) \cdot \left(A - \color{blue}{\left(-A\right)}\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
if 5.5000000000000002e-15 < B Initial program 55.6
Simplified53.1
[Start]55.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-rr48.8
Simplified48.7
[Start]48.8 | \[ \frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{\left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(2 \cdot F\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
|---|---|
+-commutative [=>]48.8 | \[ \frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{\left(\color{blue}{\left(C + A\right)} - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(2 \cdot F\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
associate--l+ [=>]48.7 | \[ \frac{-\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)} \cdot \sqrt{\color{blue}{\left(C + \left(A - \mathsf{hypot}\left(B, A - C\right)\right)\right)} \cdot \left(2 \cdot F\right)}}{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}
\] |
Applied egg-rr48.8
Simplified47.6
[Start]48.8 | \[ \frac{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \cdot \frac{-\sqrt{\left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(2 \cdot F\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}
\] |
|---|---|
*-commutative [=>]48.8 | \[ \color{blue}{\frac{-\sqrt{\left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(2 \cdot F\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \cdot \frac{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}}
\] |
*-inverses [=>]47.6 | \[ \frac{-\sqrt{\left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(2 \cdot F\right)}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}} \cdot \color{blue}{1}
\] |
associate-/r/ [<=]47.6 | \[ \color{blue}{\frac{-\sqrt{\left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(2 \cdot F\right)}}{\frac{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}{1}}}
\] |
/-rgt-identity [=>]47.6 | \[ \frac{-\sqrt{\left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right) \cdot \left(2 \cdot F\right)}}{\color{blue}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}}
\] |
*-commutative [=>]47.6 | \[ \frac{-\sqrt{\color{blue}{\left(2 \cdot F\right) \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)}}}{\sqrt{\mathsf{fma}\left(A, C \cdot -4, B \cdot B\right)}}
\] |
Taylor expanded in A around 0 34.2
Simplified33.3
[Start]34.2 | \[ \frac{-\sqrt{\left(2 \cdot F\right) \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)}}{-2 \cdot \frac{A \cdot C}{B} + B}
\] |
|---|---|
fma-def [=>]34.2 | \[ \frac{-\sqrt{\left(2 \cdot F\right) \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)}}{\color{blue}{\mathsf{fma}\left(-2, \frac{A \cdot C}{B}, B\right)}}
\] |
associate-/l* [=>]33.3 | \[ \frac{-\sqrt{\left(2 \cdot F\right) \cdot \left(\left(A + C\right) - \mathsf{hypot}\left(B, A - C\right)\right)}}{\mathsf{fma}\left(-2, \color{blue}{\frac{A}{\frac{B}{C}}}, B\right)}
\] |
Final simplification40.6
| Alternative 1 | |
|---|---|
| Error | 39.9 |
| Cost | 155788 |
| Alternative 2 | |
|---|---|
| Error | 40.2 |
| Cost | 28172 |
| Alternative 3 | |
|---|---|
| Error | 39.4 |
| Cost | 27720 |
| Alternative 4 | |
|---|---|
| Error | 40.1 |
| Cost | 27208 |
| Alternative 5 | |
|---|---|
| Error | 40.8 |
| Cost | 21704 |
| Alternative 6 | |
|---|---|
| Error | 41.9 |
| Cost | 21072 |
| Alternative 7 | |
|---|---|
| Error | 41.9 |
| Cost | 21072 |
| Alternative 8 | |
|---|---|
| Error | 41.6 |
| Cost | 21000 |
| Alternative 9 | |
|---|---|
| Error | 41.5 |
| Cost | 21000 |
| Alternative 10 | |
|---|---|
| Error | 42.7 |
| Cost | 14608 |
| Alternative 11 | |
|---|---|
| Error | 42.4 |
| Cost | 14608 |
| Alternative 12 | |
|---|---|
| Error | 42.0 |
| Cost | 14608 |
| Alternative 13 | |
|---|---|
| Error | 42.0 |
| Cost | 14608 |
| Alternative 14 | |
|---|---|
| Error | 41.7 |
| Cost | 14156 |
| Alternative 15 | |
|---|---|
| Error | 42.7 |
| Cost | 14024 |
| Alternative 16 | |
|---|---|
| Error | 49.3 |
| Cost | 13316 |
| Alternative 17 | |
|---|---|
| Error | 52.7 |
| Cost | 8716 |
| Alternative 18 | |
|---|---|
| Error | 53.1 |
| Cost | 8584 |
| Alternative 19 | |
|---|---|
| Error | 55.8 |
| Cost | 8452 |
| Alternative 20 | |
|---|---|
| Error | 57.0 |
| Cost | 7552 |
| Alternative 21 | |
|---|---|
| Error | 61.6 |
| Cost | 64 |
herbie shell --seed 2023016
(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))))