| Alternative 1 | |
|---|---|
| Error | 36.7 |
| Cost | 21576 |
(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 (* C (* A -4.0)))
(t_1 (* -4.0 (* A C)))
(t_2 (+ (* B B) t_1))
(t_3 (+ (pow B 2.0) t_0))
(t_4
(/
(-
(sqrt
(*
(* 2.0 (* t_3 F))
(+ (+ A C) (sqrt (+ (pow B 2.0) (pow (- A C) 2.0)))))))
t_3))
(t_5 (sqrt (+ A (+ C (hypot B (- A C)))))))
(if (<= t_4 0.0)
(/ (* t_5 (* (sqrt (fma B B t_0)) (- (sqrt (* 2.0 F))))) t_2)
(if (<= t_4 INFINITY)
(/ (* t_5 (- (sqrt (* 2.0 (* F t_1))))) t_2)
(* (/ (sqrt 2.0) B) (sqrt (* F (+ C (hypot B C)))))))))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 = C * (A * -4.0);
double t_1 = -4.0 * (A * C);
double t_2 = (B * B) + t_1;
double t_3 = pow(B, 2.0) + t_0;
double t_4 = -sqrt(((2.0 * (t_3 * F)) * ((A + C) + sqrt((pow(B, 2.0) + pow((A - C), 2.0)))))) / t_3;
double t_5 = sqrt((A + (C + hypot(B, (A - C)))));
double tmp;
if (t_4 <= 0.0) {
tmp = (t_5 * (sqrt(fma(B, B, t_0)) * -sqrt((2.0 * F)))) / t_2;
} else if (t_4 <= ((double) INFINITY)) {
tmp = (t_5 * -sqrt((2.0 * (F * t_1)))) / t_2;
} else {
tmp = (sqrt(2.0) / B) * sqrt((F * (C + hypot(B, C))));
}
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 = Float64(C * Float64(A * -4.0)) t_1 = Float64(-4.0 * Float64(A * C)) t_2 = Float64(Float64(B * B) + t_1) t_3 = Float64((B ^ 2.0) + t_0) t_4 = Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_3 * F)) * Float64(Float64(A + C) + sqrt(Float64((B ^ 2.0) + (Float64(A - C) ^ 2.0))))))) / t_3) t_5 = sqrt(Float64(A + Float64(C + hypot(B, Float64(A - C))))) tmp = 0.0 if (t_4 <= 0.0) tmp = Float64(Float64(t_5 * Float64(sqrt(fma(B, B, t_0)) * Float64(-sqrt(Float64(2.0 * F))))) / t_2); elseif (t_4 <= Inf) tmp = Float64(Float64(t_5 * Float64(-sqrt(Float64(2.0 * Float64(F * t_1))))) / t_2); else tmp = Float64(Float64(sqrt(2.0) / B) * sqrt(Float64(F * Float64(C + hypot(B, C))))); 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[(C * N[(A * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(B * B), $MachinePrecision] + t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[B, 2.0], $MachinePrecision] + t$95$0), $MachinePrecision]}, Block[{t$95$4 = N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$3 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] + N[Sqrt[N[(N[Power[B, 2.0], $MachinePrecision] + N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$3), $MachinePrecision]}, Block[{t$95$5 = N[Sqrt[N[(A + N[(C + N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$4, 0.0], N[(N[(t$95$5 * N[(N[Sqrt[N[(B * B + t$95$0), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(2.0 * F), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], If[LessEqual[t$95$4, Infinity], N[(N[(t$95$5 * (-N[Sqrt[N[(2.0 * N[(F * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$2), $MachinePrecision], N[(N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision] * N[Sqrt[N[(F * N[(C + N[Sqrt[B ^ 2 + C ^ 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 := C \cdot \left(A \cdot -4\right)\\
t_1 := -4 \cdot \left(A \cdot C\right)\\
t_2 := B \cdot B + t_1\\
t_3 := {B}^{2} + t_0\\
t_4 := \frac{-\sqrt{\left(2 \cdot \left(t_3 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{t_3}\\
t_5 := \sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)}\\
\mathbf{if}\;t_4 \leq 0:\\
\;\;\;\;\frac{t_5 \cdot \left(\sqrt{\mathsf{fma}\left(B, B, t_0\right)} \cdot \left(-\sqrt{2 \cdot F}\right)\right)}{t_2}\\
\mathbf{elif}\;t_4 \leq \infty:\\
\;\;\;\;\frac{t_5 \cdot \left(-\sqrt{2 \cdot \left(F \cdot t_1\right)}\right)}{t_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(C + \mathsf{hypot}\left(B, C\right)\right)}\\
\end{array}
if (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < -0.0Initial program 44.4
Simplified44.4
[Start]44.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}
\] |
|---|
Applied egg-rr33.7
Simplified33.7
[Start]33.7 | \[ \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 [=>]33.7 | \[ \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 [=>]33.7 | \[ \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)}
\] |
Applied egg-rr33.7
Applied egg-rr27.1
Simplified27.1
[Start]27.1 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(\sqrt{2 \cdot F} \cdot \sqrt{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
*-commutative [=>]27.1 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \color{blue}{\left(\sqrt{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{2 \cdot F}\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
if -0.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < +inf.0Initial program 39.8
Simplified39.8
[Start]39.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-rr13.9
Simplified13.9
[Start]13.9 | \[ \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 [=>]13.9 | \[ \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 [=>]13.9 | \[ \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)}
\] |
Taylor expanded in B around 0 14.6
Simplified14.6
[Start]14.6 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \left(F \cdot \left(-4 \cdot \left(A \cdot C\right)\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
*-commutative [=>]14.6 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{2 \cdot \left(F \cdot \left(-4 \cdot \color{blue}{\left(C \cdot A\right)}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
if +inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) Initial program 64.0
Simplified64.0
[Start]64.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}
\] |
|---|
Applied egg-rr64.0
Simplified64.0
[Start]64.0 | \[ \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 [=>]64.0 | \[ \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 [=>]64.0 | \[ \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)}
\] |
Taylor expanded in B around -inf 62.7
Simplified62.7
[Start]62.7 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(-1 \cdot \left(\left(\sqrt{2} \cdot B\right) \cdot \sqrt{F}\right)\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
|---|---|
mul-1-neg [=>]62.7 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \color{blue}{\left(-\left(\sqrt{2} \cdot B\right) \cdot \sqrt{F}\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
associate-*l* [=>]62.7 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(-\color{blue}{\sqrt{2} \cdot \left(B \cdot \sqrt{F}\right)}\right)}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
distribute-lft-neg-in [=>]62.7 | \[ \frac{-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \color{blue}{\left(\left(-\sqrt{2}\right) \cdot \left(B \cdot \sqrt{F}\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\] |
Taylor expanded in A around 0 63.6
Simplified52.8
[Start]63.6 | \[ \frac{\sqrt{2}}{B} \cdot \sqrt{\left(C + \sqrt{{B}^{2} + {C}^{2}}\right) \cdot F}
\] |
|---|---|
unpow2 [=>]63.6 | \[ \frac{\sqrt{2}}{B} \cdot \sqrt{\left(C + \sqrt{\color{blue}{B \cdot B} + {C}^{2}}\right) \cdot F}
\] |
unpow2 [=>]63.6 | \[ \frac{\sqrt{2}}{B} \cdot \sqrt{\left(C + \sqrt{B \cdot B + \color{blue}{C \cdot C}}\right) \cdot F}
\] |
hypot-def [=>]52.8 | \[ \frac{\sqrt{2}}{B} \cdot \sqrt{\left(C + \color{blue}{\mathsf{hypot}\left(B, C\right)}\right) \cdot F}
\] |
Final simplification36.9
| Alternative 1 | |
|---|---|
| Error | 36.7 |
| Cost | 21576 |
| Alternative 2 | |
|---|---|
| Error | 39.4 |
| Cost | 21320 |
| Alternative 3 | |
|---|---|
| Error | 40.7 |
| Cost | 21192 |
| Alternative 4 | |
|---|---|
| Error | 40.4 |
| Cost | 19972 |
| Alternative 5 | |
|---|---|
| Error | 39.8 |
| Cost | 19972 |
| Alternative 6 | |
|---|---|
| Error | 44.6 |
| Cost | 15308 |
| Alternative 7 | |
|---|---|
| Error | 47.1 |
| Cost | 14988 |
| Alternative 8 | |
|---|---|
| Error | 47.2 |
| Cost | 14856 |
| Alternative 9 | |
|---|---|
| Error | 47.0 |
| Cost | 14856 |
| Alternative 10 | |
|---|---|
| Error | 47.2 |
| Cost | 14660 |
| Alternative 11 | |
|---|---|
| Error | 47.4 |
| Cost | 14216 |
| Alternative 12 | |
|---|---|
| Error | 47.5 |
| Cost | 14216 |
| Alternative 13 | |
|---|---|
| Error | 49.8 |
| Cost | 13448 |
| Alternative 14 | |
|---|---|
| Error | 54.8 |
| Cost | 8584 |
| Alternative 15 | |
|---|---|
| Error | 57.1 |
| Cost | 8452 |
| Alternative 16 | |
|---|---|
| Error | 56.5 |
| Cost | 8452 |
| Alternative 17 | |
|---|---|
| Error | 55.6 |
| Cost | 8452 |
| Alternative 18 | |
|---|---|
| Error | 59.6 |
| Cost | 8064 |
| Alternative 19 | |
|---|---|
| Error | 59.8 |
| Cost | 8064 |
| Alternative 20 | |
|---|---|
| Error | 59.2 |
| Cost | 8064 |
| Alternative 21 | |
|---|---|
| Error | 61.8 |
| Cost | 7808 |
| Alternative 22 | |
|---|---|
| Error | 62.1 |
| Cost | 7808 |
| Alternative 23 | |
|---|---|
| Error | 58.8 |
| Cost | 7808 |
| Alternative 24 | |
|---|---|
| Error | 62.4 |
| Cost | 7488 |
| Alternative 25 | |
|---|---|
| Error | 63.1 |
| Cost | 7104 |
| Alternative 26 | |
|---|---|
| Error | 63.1 |
| Cost | 6976 |
herbie shell --seed 2023045
(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))))