| Alternative 1 | |
|---|---|
| Error | 41.8 |
| 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 (fma B B (* C (* A -4.0))))
(t_1 (hypot B (- A C)))
(t_2 (* -4.0 (* A C))))
(if (<= A -1.4)
(/
(*
(sqrt (* (fma 2.0 C (/ (* B (* -0.5 B)) A)) t_0))
(- (sqrt (* 2.0 F))))
t_0)
(if (<= A 4e-296)
(/ (* (sqrt (* F (+ C (+ A t_1)))) (- (sqrt (* 2.0 t_0)))) t_0)
(if (<= A 7.4e-202)
(* (sqrt 2.0) (- (sqrt (/ F B))))
(/
(* (sqrt (+ A (+ C t_1))) (- (sqrt (* 2.0 (* F (fma B B t_2))))))
(+ t_2 (* B 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(B, B, (C * (A * -4.0)));
double t_1 = hypot(B, (A - C));
double t_2 = -4.0 * (A * C);
double tmp;
if (A <= -1.4) {
tmp = (sqrt((fma(2.0, C, ((B * (-0.5 * B)) / A)) * t_0)) * -sqrt((2.0 * F))) / t_0;
} else if (A <= 4e-296) {
tmp = (sqrt((F * (C + (A + t_1)))) * -sqrt((2.0 * t_0))) / t_0;
} else if (A <= 7.4e-202) {
tmp = sqrt(2.0) * -sqrt((F / B));
} else {
tmp = (sqrt((A + (C + t_1))) * -sqrt((2.0 * (F * fma(B, B, t_2))))) / (t_2 + (B * 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(B, B, Float64(C * Float64(A * -4.0))) t_1 = hypot(B, Float64(A - C)) t_2 = Float64(-4.0 * Float64(A * C)) tmp = 0.0 if (A <= -1.4) tmp = Float64(Float64(sqrt(Float64(fma(2.0, C, Float64(Float64(B * Float64(-0.5 * B)) / A)) * t_0)) * Float64(-sqrt(Float64(2.0 * F)))) / t_0); elseif (A <= 4e-296) tmp = Float64(Float64(sqrt(Float64(F * Float64(C + Float64(A + t_1)))) * Float64(-sqrt(Float64(2.0 * t_0)))) / t_0); elseif (A <= 7.4e-202) tmp = Float64(sqrt(2.0) * Float64(-sqrt(Float64(F / B)))); else tmp = Float64(Float64(sqrt(Float64(A + Float64(C + t_1))) * Float64(-sqrt(Float64(2.0 * Float64(F * fma(B, B, t_2)))))) / Float64(t_2 + Float64(B * 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[(B * B + N[(C * N[(A * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(-4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[A, -1.4], N[(N[(N[Sqrt[N[(N[(2.0 * C + N[(N[(B * N[(-0.5 * B), $MachinePrecision]), $MachinePrecision] / A), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(2.0 * F), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[A, 4e-296], N[(N[(N[Sqrt[N[(F * N[(C + N[(A + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[A, 7.4e-202], N[(N[Sqrt[2.0], $MachinePrecision] * (-N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(N[(N[Sqrt[N[(A + N[(C + t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(2.0 * N[(F * N[(B * B + t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / N[(t$95$2 + N[(B * B), $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{hypot}\left(B, A - C\right)\\
t_2 := -4 \cdot \left(A \cdot C\right)\\
\mathbf{if}\;A \leq -1.4:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(2, C, \frac{B \cdot \left(-0.5 \cdot B\right)}{A}\right) \cdot t_0} \cdot \left(-\sqrt{2 \cdot F}\right)}{t_0}\\
\mathbf{elif}\;A \leq 4 \cdot 10^{-296}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(C + \left(A + t_1\right)\right)} \cdot \left(-\sqrt{2 \cdot t_0}\right)}{t_0}\\
\mathbf{elif}\;A \leq 7.4 \cdot 10^{-202}:\\
\;\;\;\;\sqrt{2} \cdot \left(-\sqrt{\frac{F}{B}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{A + \left(C + t_1\right)} \cdot \left(-\sqrt{2 \cdot \left(F \cdot \mathsf{fma}\left(B, B, t_2\right)\right)}\right)}{t_2 + B \cdot B}\\
\end{array}
if A < -1.3999999999999999Initial program 61.3
Simplified60.1
[Start]61.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}
\] |
|---|
Taylor expanded in A around -inf 45.1
Simplified45.1
[Start]45.1 | \[ \frac{-\sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right) \cdot \left(F \cdot \left(2 \cdot C + -0.5 \cdot \frac{{B}^{2}}{A}\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
|---|---|
fma-def [=>]45.1 | \[ \frac{-\sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right) \cdot \left(F \cdot \color{blue}{\mathsf{fma}\left(2, C, -0.5 \cdot \frac{{B}^{2}}{A}\right)}\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
associate-*r/ [=>]45.1 | \[ \frac{-\sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right) \cdot \left(F \cdot \mathsf{fma}\left(2, C, \color{blue}{\frac{-0.5 \cdot {B}^{2}}{A}}\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
unpow2 [=>]45.1 | \[ \frac{-\sqrt{2 \cdot \left(\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right) \cdot \left(F \cdot \mathsf{fma}\left(2, C, \frac{-0.5 \cdot \color{blue}{\left(B \cdot B\right)}}{A}\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
Applied egg-rr60.5
Simplified47.3
[Start]60.5 | \[ \left(0 - e^{\mathsf{log1p}\left(\frac{\sqrt{2 \cdot \left(F \cdot \left(\mathsf{fma}\left(2, C, \frac{-0.5}{A} \cdot \left(B \cdot B\right)\right) \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}\right)}\right) + 1
\] |
|---|---|
associate-+l- [=>]60.5 | \[ \color{blue}{0 - \left(e^{\mathsf{log1p}\left(\frac{\sqrt{2 \cdot \left(F \cdot \left(\mathsf{fma}\left(2, C, \frac{-0.5}{A} \cdot \left(B \cdot B\right)\right) \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}\right)} - 1\right)}
\] |
expm1-def [=>]48.9 | \[ 0 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sqrt{2 \cdot \left(F \cdot \left(\mathsf{fma}\left(2, C, \frac{-0.5}{A} \cdot \left(B \cdot B\right)\right) \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}\right)\right)}
\] |
expm1-log1p [=>]47.3 | \[ 0 - \color{blue}{\frac{\sqrt{2 \cdot \left(F \cdot \left(\mathsf{fma}\left(2, C, \frac{-0.5}{A} \cdot \left(B \cdot B\right)\right) \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}}
\] |
sub0-neg [=>]47.3 | \[ \color{blue}{-\frac{\sqrt{2 \cdot \left(F \cdot \left(\mathsf{fma}\left(2, C, \frac{-0.5}{A} \cdot \left(B \cdot B\right)\right) \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}}
\] |
distribute-neg-frac [=>]47.3 | \[ \color{blue}{\frac{-\sqrt{2 \cdot \left(F \cdot \left(\mathsf{fma}\left(2, C, \frac{-0.5}{A} \cdot \left(B \cdot B\right)\right) \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}}
\] |
Applied egg-rr42.2
if -1.3999999999999999 < A < 4e-296Initial program 49.6
Simplified45.6
[Start]49.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-rr41.7
Simplified41.5
[Start]41.7 | \[ \frac{-\sqrt{2 \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{F \cdot \left(\mathsf{hypot}\left(B, A - C\right) + \left(C + A\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
|---|---|
*-commutative [=>]41.7 | \[ \frac{-\color{blue}{\sqrt{F \cdot \left(\mathsf{hypot}\left(B, A - C\right) + \left(C + A\right)\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
associate-+r+ [=>]41.8 | \[ \frac{-\sqrt{F \cdot \color{blue}{\left(\left(\mathsf{hypot}\left(B, A - C\right) + C\right) + A\right)}} \cdot \sqrt{2 \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
+-commutative [<=]41.8 | \[ \frac{-\sqrt{F \cdot \left(\color{blue}{\left(C + \mathsf{hypot}\left(B, A - C\right)\right)} + A\right)} \cdot \sqrt{2 \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
associate-+l+ [=>]41.5 | \[ \frac{-\sqrt{F \cdot \color{blue}{\left(C + \left(\mathsf{hypot}\left(B, A - C\right) + A\right)\right)}} \cdot \sqrt{2 \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
if 4e-296 < A < 7.39999999999999982e-202Initial program 49.1
Simplified49.1
[Start]49.1 | \[ \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 56.6
Simplified56.6
[Start]56.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)}
\] |
|---|---|
*-commutative [=>]56.6 | \[ \frac{-\color{blue}{\sqrt{\left(A + \sqrt{{B}^{2} + {A}^{2}}\right) \cdot F} \cdot \left(\sqrt{2} \cdot B\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
*-commutative [=>]56.6 | \[ \frac{-\sqrt{\color{blue}{F \cdot \left(A + \sqrt{{B}^{2} + {A}^{2}}\right)}} \cdot \left(\sqrt{2} \cdot B\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]56.6 | \[ \frac{-\sqrt{F \cdot \left(A + \sqrt{\color{blue}{B \cdot B} + {A}^{2}}\right)} \cdot \left(\sqrt{2} \cdot B\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
unpow2 [=>]56.6 | \[ \frac{-\sqrt{F \cdot \left(A + \sqrt{B \cdot B + \color{blue}{A \cdot A}}\right)} \cdot \left(\sqrt{2} \cdot B\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
*-commutative [=>]56.6 | \[ \frac{-\sqrt{F \cdot \left(A + \sqrt{B \cdot B + A \cdot A}\right)} \cdot \color{blue}{\left(B \cdot \sqrt{2}\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
Taylor expanded in A around 0 50.9
Simplified50.9
[Start]50.9 | \[ -1 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{F}{B}}\right)
\] |
|---|---|
mul-1-neg [=>]50.9 | \[ \color{blue}{-\sqrt{2} \cdot \sqrt{\frac{F}{B}}}
\] |
distribute-rgt-neg-in [=>]50.9 | \[ \color{blue}{\sqrt{2} \cdot \left(-\sqrt{\frac{F}{B}}\right)}
\] |
if 7.39999999999999982e-202 < A Initial program 49.8
Simplified49.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}
\] |
|---|
Applied egg-rr38.3
Simplified38.3
[Start]38.3 | \[ \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 [=>]38.3 | \[ \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)}
\] |
*-commutative [=>]38.3 | \[ \frac{-\sqrt{A + \left(C + \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)}
\] |
Final simplification41.0
| Alternative 1 | |
|---|---|
| Error | 41.8 |
| Cost | 34120 |
| Alternative 2 | |
|---|---|
| Error | 45.4 |
| Cost | 28116 |
| Alternative 3 | |
|---|---|
| Error | 45.6 |
| Cost | 27984 |
| Alternative 4 | |
|---|---|
| Error | 44.7 |
| Cost | 27984 |
| Alternative 5 | |
|---|---|
| Error | 42.5 |
| Cost | 27980 |
| Alternative 6 | |
|---|---|
| Error | 45.7 |
| Cost | 21524 |
| Alternative 7 | |
|---|---|
| Error | 45.5 |
| Cost | 21000 |
| Alternative 8 | |
|---|---|
| Error | 45.3 |
| Cost | 20356 |
| Alternative 9 | |
|---|---|
| Error | 44.8 |
| Cost | 15044 |
| Alternative 10 | |
|---|---|
| Error | 50.4 |
| Cost | 14344 |
| Alternative 11 | |
|---|---|
| Error | 50.4 |
| Cost | 13448 |
| Alternative 12 | |
|---|---|
| Error | 55.5 |
| Cost | 8716 |
| Alternative 13 | |
|---|---|
| Error | 56.9 |
| Cost | 8584 |
| Alternative 14 | |
|---|---|
| Error | 53.4 |
| Cost | 8584 |
| Alternative 15 | |
|---|---|
| Error | 56.1 |
| Cost | 8452 |
| Alternative 16 | |
|---|---|
| Error | 58.0 |
| Cost | 7940 |
| Alternative 17 | |
|---|---|
| Error | 62.2 |
| Cost | 6848 |
herbie shell --seed 2023073
(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))))