
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
(/
(-
(sqrt
(*
(* 2.0 (* t_0 F))
(+ (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
t_0)))
double code(double A, double B, double C, double F) {
double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
return -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_0;
}
real(8) function code(a, b, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: t_0
t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) + sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F): t_0 = math.pow(B, 2.0) - ((4.0 * A) * C) return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F) t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) + sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0) end
function tmp = code(A, B, C, F) t_0 = (B ^ 2.0) - ((4.0 * A) * C); tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0; end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * 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]) / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
(/
(-
(sqrt
(*
(* 2.0 (* t_0 F))
(+ (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
t_0)))
double code(double A, double B, double C, double F) {
double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
return -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_0;
}
real(8) function code(a, b, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: t_0
t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) + sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F): t_0 = math.pow(B, 2.0) - ((4.0 * A) * C) return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) + math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F) t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) + sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0) end
function tmp = code(A, B, C, F) t_0 = (B ^ 2.0) - ((4.0 * A) * C); tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) + sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0; end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * 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]) / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t\_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t\_0}
\end{array}
\end{array}
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(let* ((t_0 (fma A (* C -4.0) (* B_m B_m)))
(t_1 (* 2.0 t_0))
(t_2 (* t_0 (* 2.0 F)))
(t_3 (fma B_m (* (/ B_m A) -0.5) (* 2.0 C)))
(t_4 (* (* 4.0 A) C))
(t_5 (- t_4 (pow B_m 2.0)))
(t_6
(/
(sqrt
(*
(* 2.0 (* (- (pow B_m 2.0) t_4) F))
(+ (+ A C) (sqrt (+ (pow B_m 2.0) (pow (- A C) 2.0))))))
t_5)))
(if (<= t_6 (- INFINITY))
(/ (* (sqrt t_1) (sqrt (* F t_3))) t_5)
(if (<= t_6 -1e-186)
(/ (sqrt (* t_2 (+ C (sqrt (fma B_m B_m (* C C)))))) (- t_0))
(if (<= t_6 0.0)
(/ (* (sqrt F) (sqrt (* t_1 t_3))) t_5)
(if (<= t_6 INFINITY)
(* (* (sqrt t_2) (/ -1.0 t_0)) (sqrt (* 2.0 C)))
(- (/ (sqrt F) (sqrt (* B_m 0.5))))))))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double t_0 = fma(A, (C * -4.0), (B_m * B_m));
double t_1 = 2.0 * t_0;
double t_2 = t_0 * (2.0 * F);
double t_3 = fma(B_m, ((B_m / A) * -0.5), (2.0 * C));
double t_4 = (4.0 * A) * C;
double t_5 = t_4 - pow(B_m, 2.0);
double t_6 = sqrt(((2.0 * ((pow(B_m, 2.0) - t_4) * F)) * ((A + C) + sqrt((pow(B_m, 2.0) + pow((A - C), 2.0)))))) / t_5;
double tmp;
if (t_6 <= -((double) INFINITY)) {
tmp = (sqrt(t_1) * sqrt((F * t_3))) / t_5;
} else if (t_6 <= -1e-186) {
tmp = sqrt((t_2 * (C + sqrt(fma(B_m, B_m, (C * C)))))) / -t_0;
} else if (t_6 <= 0.0) {
tmp = (sqrt(F) * sqrt((t_1 * t_3))) / t_5;
} else if (t_6 <= ((double) INFINITY)) {
tmp = (sqrt(t_2) * (-1.0 / t_0)) * sqrt((2.0 * C));
} else {
tmp = -(sqrt(F) / sqrt((B_m * 0.5)));
}
return tmp;
}
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) t_0 = fma(A, Float64(C * -4.0), Float64(B_m * B_m)) t_1 = Float64(2.0 * t_0) t_2 = Float64(t_0 * Float64(2.0 * F)) t_3 = fma(B_m, Float64(Float64(B_m / A) * -0.5), Float64(2.0 * C)) t_4 = Float64(Float64(4.0 * A) * C) t_5 = Float64(t_4 - (B_m ^ 2.0)) t_6 = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64((B_m ^ 2.0) - t_4) * F)) * Float64(Float64(A + C) + sqrt(Float64((B_m ^ 2.0) + (Float64(A - C) ^ 2.0)))))) / t_5) tmp = 0.0 if (t_6 <= Float64(-Inf)) tmp = Float64(Float64(sqrt(t_1) * sqrt(Float64(F * t_3))) / t_5); elseif (t_6 <= -1e-186) tmp = Float64(sqrt(Float64(t_2 * Float64(C + sqrt(fma(B_m, B_m, Float64(C * C)))))) / Float64(-t_0)); elseif (t_6 <= 0.0) tmp = Float64(Float64(sqrt(F) * sqrt(Float64(t_1 * t_3))) / t_5); elseif (t_6 <= Inf) tmp = Float64(Float64(sqrt(t_2) * Float64(-1.0 / t_0)) * sqrt(Float64(2.0 * C))); else tmp = Float64(-Float64(sqrt(F) / sqrt(Float64(B_m * 0.5)))); end return tmp end
B_m = N[Abs[B], $MachinePrecision]
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
code[A_, B$95$m_, C_, F_] := Block[{t$95$0 = N[(A * N[(C * -4.0), $MachinePrecision] + N[(B$95$m * B$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(2.0 * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 * N[(2.0 * F), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(B$95$m * N[(N[(B$95$m / A), $MachinePrecision] * -0.5), $MachinePrecision] + N[(2.0 * C), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$4 - N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[Power[B$95$m, 2.0], $MachinePrecision] - t$95$4), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] + N[Sqrt[N[(N[Power[B$95$m, 2.0], $MachinePrecision] + N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$5), $MachinePrecision]}, If[LessEqual[t$95$6, (-Infinity)], N[(N[(N[Sqrt[t$95$1], $MachinePrecision] * N[Sqrt[N[(F * t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$5), $MachinePrecision], If[LessEqual[t$95$6, -1e-186], N[(N[Sqrt[N[(t$95$2 * N[(C + N[Sqrt[N[(B$95$m * B$95$m + N[(C * C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-t$95$0)), $MachinePrecision], If[LessEqual[t$95$6, 0.0], N[(N[(N[Sqrt[F], $MachinePrecision] * N[Sqrt[N[(t$95$1 * t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$5), $MachinePrecision], If[LessEqual[t$95$6, Infinity], N[(N[(N[Sqrt[t$95$2], $MachinePrecision] * N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(2.0 * C), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], (-N[(N[Sqrt[F], $MachinePrecision] / N[Sqrt[N[(B$95$m * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])]]]]]]]]]]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(A, C \cdot -4, B\_m \cdot B\_m\right)\\
t_1 := 2 \cdot t\_0\\
t_2 := t\_0 \cdot \left(2 \cdot F\right)\\
t_3 := \mathsf{fma}\left(B\_m, \frac{B\_m}{A} \cdot -0.5, 2 \cdot C\right)\\
t_4 := \left(4 \cdot A\right) \cdot C\\
t_5 := t\_4 - {B\_m}^{2}\\
t_6 := \frac{\sqrt{\left(2 \cdot \left(\left({B\_m}^{2} - t\_4\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{B\_m}^{2} + {\left(A - C\right)}^{2}}\right)}}{t\_5}\\
\mathbf{if}\;t\_6 \leq -\infty:\\
\;\;\;\;\frac{\sqrt{t\_1} \cdot \sqrt{F \cdot t\_3}}{t\_5}\\
\mathbf{elif}\;t\_6 \leq -1 \cdot 10^{-186}:\\
\;\;\;\;\frac{\sqrt{t\_2 \cdot \left(C + \sqrt{\mathsf{fma}\left(B\_m, B\_m, C \cdot C\right)}\right)}}{-t\_0}\\
\mathbf{elif}\;t\_6 \leq 0:\\
\;\;\;\;\frac{\sqrt{F} \cdot \sqrt{t\_1 \cdot t\_3}}{t\_5}\\
\mathbf{elif}\;t\_6 \leq \infty:\\
\;\;\;\;\left(\sqrt{t\_2} \cdot \frac{-1}{t\_0}\right) \cdot \sqrt{2 \cdot C}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\sqrt{F}}{\sqrt{B\_m \cdot 0.5}}\\
\end{array}
\end{array}
if (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -inf.0Initial program 3.1%
Taylor expanded in A around -inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6431.3
Applied rewrites31.3%
Applied rewrites59.4%
if -inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -9.9999999999999991e-187Initial program 97.9%
Taylor expanded in A around 0
lower-+.f64N/A
lower-sqrt.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.1
Applied rewrites98.1%
Applied rewrites98.1%
if -9.9999999999999991e-187 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -0.0Initial program 3.4%
Taylor expanded in A around -inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6465.8
Applied rewrites65.8%
Applied rewrites70.2%
if -0.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < +inf.0Initial program 43.9%
Applied rewrites43.9%
Taylor expanded in C around inf
distribute-lft1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
lower-*.f6469.3
Applied rewrites69.3%
Applied rewrites79.1%
if +inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) Initial program 0.0%
Taylor expanded in B around inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6427.3
Applied rewrites27.3%
Applied rewrites27.5%
Applied rewrites27.5%
Applied rewrites39.3%
Final simplification58.2%
B_m = (fabs.f64 B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
(FPCore (A B_m C F)
:precision binary64
(let* ((t_0 (fma A (* C -4.0) (* B_m B_m)))
(t_1 (* t_0 (* 2.0 F)))
(t_2 (fma B_m (* (/ B_m A) -0.5) (* 2.0 C)))
(t_3 (* (* 4.0 A) C))
(t_4 (- t_3 (pow B_m 2.0)))
(t_5
(/
(sqrt
(*
(* 2.0 (* (- (pow B_m 2.0) t_3) F))
(+ (+ A C) (sqrt (+ (pow B_m 2.0) (pow (- A C) 2.0))))))
t_4)))
(if (<= t_5 (- INFINITY))
(/ (* (sqrt (* 2.0 t_0)) (sqrt (* F t_2))) t_4)
(if (<= t_5 -1e-186)
(/ (sqrt (* t_1 (+ C (sqrt (fma B_m B_m (* C C)))))) (- t_0))
(if (<= t_5 INFINITY)
(/ (* (sqrt t_1) (sqrt t_2)) t_4)
(- (/ (sqrt F) (sqrt (* B_m 0.5)))))))))B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
double t_0 = fma(A, (C * -4.0), (B_m * B_m));
double t_1 = t_0 * (2.0 * F);
double t_2 = fma(B_m, ((B_m / A) * -0.5), (2.0 * C));
double t_3 = (4.0 * A) * C;
double t_4 = t_3 - pow(B_m, 2.0);
double t_5 = sqrt(((2.0 * ((pow(B_m, 2.0) - t_3) * F)) * ((A + C) + sqrt((pow(B_m, 2.0) + pow((A - C), 2.0)))))) / t_4;
double tmp;
if (t_5 <= -((double) INFINITY)) {
tmp = (sqrt((2.0 * t_0)) * sqrt((F * t_2))) / t_4;
} else if (t_5 <= -1e-186) {
tmp = sqrt((t_1 * (C + sqrt(fma(B_m, B_m, (C * C)))))) / -t_0;
} else if (t_5 <= ((double) INFINITY)) {
tmp = (sqrt(t_1) * sqrt(t_2)) / t_4;
} else {
tmp = -(sqrt(F) / sqrt((B_m * 0.5)));
}
return tmp;
}
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) t_0 = fma(A, Float64(C * -4.0), Float64(B_m * B_m)) t_1 = Float64(t_0 * Float64(2.0 * F)) t_2 = fma(B_m, Float64(Float64(B_m / A) * -0.5), Float64(2.0 * C)) t_3 = Float64(Float64(4.0 * A) * C) t_4 = Float64(t_3 - (B_m ^ 2.0)) t_5 = Float64(sqrt(Float64(Float64(2.0 * Float64(Float64((B_m ^ 2.0) - t_3) * F)) * Float64(Float64(A + C) + sqrt(Float64((B_m ^ 2.0) + (Float64(A - C) ^ 2.0)))))) / t_4) tmp = 0.0 if (t_5 <= Float64(-Inf)) tmp = Float64(Float64(sqrt(Float64(2.0 * t_0)) * sqrt(Float64(F * t_2))) / t_4); elseif (t_5 <= -1e-186) tmp = Float64(sqrt(Float64(t_1 * Float64(C + sqrt(fma(B_m, B_m, Float64(C * C)))))) / Float64(-t_0)); elseif (t_5 <= Inf) tmp = Float64(Float64(sqrt(t_1) * sqrt(t_2)) / t_4); else tmp = Float64(-Float64(sqrt(F) / sqrt(Float64(B_m * 0.5)))); end return tmp end
B_m = N[Abs[B], $MachinePrecision]
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
code[A_, B$95$m_, C_, F_] := Block[{t$95$0 = N[(A * N[(C * -4.0), $MachinePrecision] + N[(B$95$m * B$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(2.0 * F), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(B$95$m * N[(N[(B$95$m / A), $MachinePrecision] * -0.5), $MachinePrecision] + N[(2.0 * C), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 - N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[Sqrt[N[(N[(2.0 * N[(N[(N[Power[B$95$m, 2.0], $MachinePrecision] - t$95$3), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] + N[Sqrt[N[(N[Power[B$95$m, 2.0], $MachinePrecision] + N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t$95$4), $MachinePrecision]}, If[LessEqual[t$95$5, (-Infinity)], N[(N[(N[Sqrt[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(F * t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$4), $MachinePrecision], If[LessEqual[t$95$5, -1e-186], N[(N[Sqrt[N[(t$95$1 * N[(C + N[Sqrt[N[(B$95$m * B$95$m + N[(C * C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-t$95$0)), $MachinePrecision], If[LessEqual[t$95$5, Infinity], N[(N[(N[Sqrt[t$95$1], $MachinePrecision] * N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] / t$95$4), $MachinePrecision], (-N[(N[Sqrt[F], $MachinePrecision] / N[Sqrt[N[(B$95$m * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])]]]]]]]]]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(A, C \cdot -4, B\_m \cdot B\_m\right)\\
t_1 := t\_0 \cdot \left(2 \cdot F\right)\\
t_2 := \mathsf{fma}\left(B\_m, \frac{B\_m}{A} \cdot -0.5, 2 \cdot C\right)\\
t_3 := \left(4 \cdot A\right) \cdot C\\
t_4 := t\_3 - {B\_m}^{2}\\
t_5 := \frac{\sqrt{\left(2 \cdot \left(\left({B\_m}^{2} - t\_3\right) \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{B\_m}^{2} + {\left(A - C\right)}^{2}}\right)}}{t\_4}\\
\mathbf{if}\;t\_5 \leq -\infty:\\
\;\;\;\;\frac{\sqrt{2 \cdot t\_0} \cdot \sqrt{F \cdot t\_2}}{t\_4}\\
\mathbf{elif}\;t\_5 \leq -1 \cdot 10^{-186}:\\
\;\;\;\;\frac{\sqrt{t\_1 \cdot \left(C + \sqrt{\mathsf{fma}\left(B\_m, B\_m, C \cdot C\right)}\right)}}{-t\_0}\\
\mathbf{elif}\;t\_5 \leq \infty:\\
\;\;\;\;\frac{\sqrt{t\_1} \cdot \sqrt{t\_2}}{t\_4}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\sqrt{F}}{\sqrt{B\_m \cdot 0.5}}\\
\end{array}
\end{array}
if (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -inf.0Initial program 3.2%
Taylor expanded in A around -inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6433.8
Applied rewrites33.8%
Applied rewrites47.4%
if -inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < -9.9999999999999991e-187Initial program 97.6%
Taylor expanded in A around 0
lower-+.f64N/A
lower-sqrt.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6496.3
Applied rewrites96.3%
Applied rewrites96.2%
if -9.9999999999999991e-187 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) < +inf.0Initial program 20.4%
Taylor expanded in A around -inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6455.1
Applied rewrites55.1%
Applied rewrites57.0%
if +inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 #s(literal 2 binary64) (*.f64 (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C)) F)) (+.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) #s(literal 2 binary64)) (pow.f64 B #s(literal 2 binary64)))))))) (-.f64 (pow.f64 B #s(literal 2 binary64)) (*.f64 (*.f64 #s(literal 4 binary64) A) C))) Initial program 0.0%
Taylor expanded in B around inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6432.0
Applied rewrites32.0%
Applied rewrites32.2%
Applied rewrites32.2%
Applied rewrites48.6%
Final simplification56.9%
herbie shell --seed 2024228
(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))))