| Alternative 1 | |
|---|---|
| Error | 32.9 |
| Cost | 27724 |
(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 (hypot B (- A C))))))
(if (<= B -5.2e+38)
(* (sqrt t_0) (* (sqrt F) (/ (sqrt 2.0) B)))
(if (<= B 3.5e+49)
(/
(* (sqrt (* t_0 2.0)) (- (sqrt (* F (fma -4.0 (* C A) (* B B))))))
(+ (* B B) (* -4.0 (* C A))))
(* (/ (- (sqrt 2.0)) B) (* (sqrt F) (sqrt (+ C (hypot 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 = C + (A + hypot(B, (A - C)));
double tmp;
if (B <= -5.2e+38) {
tmp = sqrt(t_0) * (sqrt(F) * (sqrt(2.0) / B));
} else if (B <= 3.5e+49) {
tmp = (sqrt((t_0 * 2.0)) * -sqrt((F * fma(-4.0, (C * A), (B * B))))) / ((B * B) + (-4.0 * (C * A)));
} else {
tmp = (-sqrt(2.0) / B) * (sqrt(F) * sqrt((C + hypot(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 = Float64(C + Float64(A + hypot(B, Float64(A - C)))) tmp = 0.0 if (B <= -5.2e+38) tmp = Float64(sqrt(t_0) * Float64(sqrt(F) * Float64(sqrt(2.0) / B))); elseif (B <= 3.5e+49) tmp = Float64(Float64(sqrt(Float64(t_0 * 2.0)) * Float64(-sqrt(Float64(F * fma(-4.0, Float64(C * A), Float64(B * B)))))) / Float64(Float64(B * B) + Float64(-4.0 * Float64(C * A)))); else tmp = Float64(Float64(Float64(-sqrt(2.0)) / B) * Float64(sqrt(F) * sqrt(Float64(C + hypot(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[(C + N[(A + N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, -5.2e+38], N[(N[Sqrt[t$95$0], $MachinePrecision] * N[(N[Sqrt[F], $MachinePrecision] * N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[B, 3.5e+49], N[(N[(N[Sqrt[N[(t$95$0 * 2.0), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(F * N[(-4.0 * N[(C * A), $MachinePrecision] + N[(B * B), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / N[(N[(B * B), $MachinePrecision] + N[(-4.0 * N[(C * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision] * N[(N[Sqrt[F], $MachinePrecision] * N[Sqrt[N[(C + N[Sqrt[C ^ 2 + B ^ 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 + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)\\
\mathbf{if}\;B \leq -5.2 \cdot 10^{+38}:\\
\;\;\;\;\sqrt{t_0} \cdot \left(\sqrt{F} \cdot \frac{\sqrt{2}}{B}\right)\\
\mathbf{elif}\;B \leq 3.5 \cdot 10^{+49}:\\
\;\;\;\;\frac{\sqrt{t_0 \cdot 2} \cdot \left(-\sqrt{F \cdot \mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)}\right)}{B \cdot B + -4 \cdot \left(C \cdot A\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{2}}{B} \cdot \left(\sqrt{F} \cdot \sqrt{C + \mathsf{hypot}\left(C, B\right)}\right)\\
\end{array}
if B < -5.1999999999999998e38Initial program 56.4
Simplified55.1
[Start]56.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-rr49.5
Simplified49.4
[Start]49.5 | \[ \frac{-\sqrt{2 \cdot \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)} \cdot \sqrt{F \cdot \left(\left(A + C\right) + \mathsf{hypot}\left(B, A - C\right)\right)}}{\mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)}
\] |
|---|---|
*-commutative [=>]49.5 | \[ \frac{-\color{blue}{\sqrt{F \cdot \left(\left(A + C\right) + \mathsf{hypot}\left(B, A - C\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-+l+ [=>]49.4 | \[ \frac{-\sqrt{F \cdot \color{blue}{\left(A + \left(C + \mathsf{hypot}\left(B, A - C\right)\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)}
\] |
Applied egg-rr47.3
Applied egg-rr62.9
Simplified46.0
[Start]62.9 | \[ e^{\mathsf{log1p}\left(\frac{-\left(\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{F}\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)}\right)} - 1
\] |
|---|---|
expm1-def [=>]52.2 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-\left(\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{F}\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)}\right)\right)}
\] |
expm1-log1p [=>]47.3 | \[ \color{blue}{\frac{-\left(\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{F}\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)}}
\] |
distribute-lft-neg-in [=>]47.3 | \[ \frac{\color{blue}{\left(-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{F}\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/ [<=]46.0 | \[ \color{blue}{\left(-\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \sqrt{F}\right) \cdot \frac{\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)}}
\] |
distribute-rgt-neg-in [=>]46.0 | \[ \color{blue}{\left(\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(-\sqrt{F}\right)\right)} \cdot \frac{\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* [=>]46.0 | \[ \color{blue}{\sqrt{A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(\left(-\sqrt{F}\right) \cdot \frac{\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)}\right)}
\] |
Taylor expanded in B around -inf 22.0
Simplified22.0
[Start]22.0 | \[ \sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(\left(-\sqrt{F}\right) \cdot \left(-1 \cdot \frac{\sqrt{2}}{B}\right)\right)
\] |
|---|---|
mul-1-neg [=>]22.0 | \[ \sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(\left(-\sqrt{F}\right) \cdot \color{blue}{\left(-\frac{\sqrt{2}}{B}\right)}\right)
\] |
distribute-neg-frac [=>]22.0 | \[ \sqrt{C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)} \cdot \left(\left(-\sqrt{F}\right) \cdot \color{blue}{\frac{-\sqrt{2}}{B}}\right)
\] |
if -5.1999999999999998e38 < B < 3.49999999999999975e49Initial program 48.8
Simplified42.9
[Start]48.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.2
Simplified38.1
[Start]38.2 | \[ \frac{-\sqrt{2 \cdot \left(A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)\right)} \cdot \sqrt{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right) \cdot F}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
|---|---|
*-commutative [<=]38.2 | \[ \frac{-\color{blue}{\sqrt{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right) \cdot F} \cdot \sqrt{2 \cdot \left(A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)\right)}}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
*-commutative [=>]38.2 | \[ \frac{-\sqrt{\color{blue}{F \cdot \mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}} \cdot \sqrt{2 \cdot \left(A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)\right)}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
*-commutative [=>]38.2 | \[ \frac{-\sqrt{F \cdot \mathsf{fma}\left(-4, \color{blue}{C \cdot A}, B \cdot B\right)} \cdot \sqrt{2 \cdot \left(A + \left(C + \mathsf{hypot}\left(B, A - C\right)\right)\right)}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
associate-+r+ [=>]38.8 | \[ \frac{-\sqrt{F \cdot \mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)} \cdot \sqrt{2 \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)}
\] |
+-commutative [=>]38.8 | \[ \frac{-\sqrt{F \cdot \mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)} \cdot \sqrt{2 \cdot \left(\color{blue}{\left(C + A\right)} + \mathsf{hypot}\left(B, A - C\right)\right)}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
associate-+l+ [=>]38.1 | \[ \frac{-\sqrt{F \cdot \mathsf{fma}\left(-4, C \cdot A, B \cdot B\right)} \cdot \sqrt{2 \cdot \color{blue}{\left(C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)\right)}}}{\mathsf{fma}\left(-4, A \cdot C, B \cdot B\right)}
\] |
Applied egg-rr38.1
if 3.49999999999999975e49 < B Initial program 57.6
Simplified55.9
[Start]57.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}
\] |
|---|
Taylor expanded in A around 0 54.1
Simplified54.1
[Start]54.1 | \[ -1 \cdot \left(\frac{\sqrt{2}}{B} \cdot \sqrt{\left(C + \sqrt{{B}^{2} + {C}^{2}}\right) \cdot F}\right)
\] |
|---|---|
associate-*r* [=>]54.1 | \[ \color{blue}{\left(-1 \cdot \frac{\sqrt{2}}{B}\right) \cdot \sqrt{\left(C + \sqrt{{B}^{2} + {C}^{2}}\right) \cdot F}}
\] |
associate-*r/ [=>]54.1 | \[ \color{blue}{\frac{-1 \cdot \sqrt{2}}{B}} \cdot \sqrt{\left(C + \sqrt{{B}^{2} + {C}^{2}}\right) \cdot F}
\] |
mul-1-neg [=>]54.1 | \[ \frac{\color{blue}{-\sqrt{2}}}{B} \cdot \sqrt{\left(C + \sqrt{{B}^{2} + {C}^{2}}\right) \cdot F}
\] |
*-commutative [=>]54.1 | \[ \frac{-\sqrt{2}}{B} \cdot \sqrt{\color{blue}{F \cdot \left(C + \sqrt{{B}^{2} + {C}^{2}}\right)}}
\] |
+-commutative [=>]54.1 | \[ \frac{-\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(C + \sqrt{\color{blue}{{C}^{2} + {B}^{2}}}\right)}
\] |
unpow2 [=>]54.1 | \[ \frac{-\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(C + \sqrt{\color{blue}{C \cdot C} + {B}^{2}}\right)}
\] |
unpow2 [=>]54.1 | \[ \frac{-\sqrt{2}}{B} \cdot \sqrt{F \cdot \left(C + \sqrt{C \cdot C + \color{blue}{B \cdot B}}\right)}
\] |
Applied egg-rr51.8
Simplified19.1
[Start]51.8 | \[ \frac{-\sqrt{2}}{B} \cdot \left(\sqrt{C + \sqrt{C \cdot C + B \cdot B}} \cdot \sqrt{F}\right)
\] |
|---|---|
hypot-def [=>]19.1 | \[ \frac{-\sqrt{2}}{B} \cdot \left(\sqrt{C + \color{blue}{\mathsf{hypot}\left(C, B\right)}} \cdot \sqrt{F}\right)
\] |
Final simplification30.4
| Alternative 1 | |
|---|---|
| Error | 32.9 |
| Cost | 27724 |
| Alternative 2 | |
|---|---|
| Error | 33.6 |
| Cost | 27592 |
| Alternative 3 | |
|---|---|
| Error | 39.5 |
| Cost | 26700 |
| Alternative 4 | |
|---|---|
| Error | 33.8 |
| Cost | 26628 |
| Alternative 5 | |
|---|---|
| Error | 44.9 |
| Cost | 21132 |
| Alternative 6 | |
|---|---|
| Error | 43.7 |
| Cost | 21000 |
| Alternative 7 | |
|---|---|
| Error | 44.8 |
| Cost | 20816 |
| Alternative 8 | |
|---|---|
| Error | 44.8 |
| Cost | 20752 |
| Alternative 9 | |
|---|---|
| Error | 44.8 |
| Cost | 20036 |
| Alternative 10 | |
|---|---|
| Error | 48.9 |
| Cost | 15380 |
| Alternative 11 | |
|---|---|
| Error | 49.1 |
| Cost | 15120 |
| Alternative 12 | |
|---|---|
| Error | 45.5 |
| Cost | 15044 |
| Alternative 13 | |
|---|---|
| Error | 50.5 |
| Cost | 14348 |
| Alternative 14 | |
|---|---|
| Error | 49.2 |
| Cost | 14348 |
| Alternative 15 | |
|---|---|
| Error | 50.6 |
| Cost | 14233 |
| Alternative 16 | |
|---|---|
| Error | 50.1 |
| Cost | 13576 |
| Alternative 17 | |
|---|---|
| Error | 51.8 |
| Cost | 8712 |
| Alternative 18 | |
|---|---|
| Error | 51.8 |
| Cost | 8712 |
| Alternative 19 | |
|---|---|
| Error | 51.8 |
| Cost | 8584 |
| Alternative 20 | |
|---|---|
| Error | 54.5 |
| Cost | 8452 |
| Alternative 21 | |
|---|---|
| Error | 55.9 |
| Cost | 8196 |
| Alternative 22 | |
|---|---|
| Error | 55.4 |
| Cost | 8196 |
| Alternative 23 | |
|---|---|
| Error | 57.3 |
| Cost | 7236 |
| Alternative 24 | |
|---|---|
| Error | 57.8 |
| Cost | 6784 |
herbie shell --seed 2023011
(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))))