
(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 6 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 (- (pow B_m 2.0) (* (* 4.0 A) C)))
(t_1 (- (+ A C) (hypot B_m (- A C))))
(t_2 (fma B_m B_m (* A (* C -4.0))))
(t_3
(/
(-
(sqrt
(*
(* 2.0 (* t_0 F))
(- (+ A C) (sqrt (+ (pow B_m 2.0) (pow (- A C) 2.0)))))))
t_0))
(t_4 (fma A (* C -4.0) (pow B_m 2.0))))
(if (<= t_3 -2e-201)
(/ (* (sqrt (* F t_1)) (- (sqrt (* 2.0 t_4)))) t_4)
(if (<= t_3 1e-78)
(/
(-
(sqrt
(*
(* F t_2)
(*
2.0
(+
A
(+
A
(/
(* -0.5 (- (+ (pow B_m 2.0) (pow A 2.0)) (pow (- A) 2.0)))
C)))))))
t_2)
(if (<= t_3 INFINITY)
(/ (- (pow (pow (* t_2 (* F (* 2.0 t_1))) 0.25) 2.0)) t_2)
(* (- (/ (sqrt 2.0) B_m)) (sqrt (* F (- A (hypot B_m A))))))))))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 = pow(B_m, 2.0) - ((4.0 * A) * C);
double t_1 = (A + C) - hypot(B_m, (A - C));
double t_2 = fma(B_m, B_m, (A * (C * -4.0)));
double t_3 = -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((pow(B_m, 2.0) + pow((A - C), 2.0)))))) / t_0;
double t_4 = fma(A, (C * -4.0), pow(B_m, 2.0));
double tmp;
if (t_3 <= -2e-201) {
tmp = (sqrt((F * t_1)) * -sqrt((2.0 * t_4))) / t_4;
} else if (t_3 <= 1e-78) {
tmp = -sqrt(((F * t_2) * (2.0 * (A + (A + ((-0.5 * ((pow(B_m, 2.0) + pow(A, 2.0)) - pow(-A, 2.0))) / C)))))) / t_2;
} else if (t_3 <= ((double) INFINITY)) {
tmp = -pow(pow((t_2 * (F * (2.0 * t_1))), 0.25), 2.0) / t_2;
} else {
tmp = -(sqrt(2.0) / B_m) * sqrt((F * (A - hypot(B_m, A))));
}
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 = Float64((B_m ^ 2.0) - Float64(Float64(4.0 * A) * C)) t_1 = Float64(Float64(A + C) - hypot(B_m, Float64(A - C))) t_2 = fma(B_m, B_m, Float64(A * Float64(C * -4.0))) t_3 = Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) - sqrt(Float64((B_m ^ 2.0) + (Float64(A - C) ^ 2.0))))))) / t_0) t_4 = fma(A, Float64(C * -4.0), (B_m ^ 2.0)) tmp = 0.0 if (t_3 <= -2e-201) tmp = Float64(Float64(sqrt(Float64(F * t_1)) * Float64(-sqrt(Float64(2.0 * t_4)))) / t_4); elseif (t_3 <= 1e-78) tmp = Float64(Float64(-sqrt(Float64(Float64(F * t_2) * Float64(2.0 * Float64(A + Float64(A + Float64(Float64(-0.5 * Float64(Float64((B_m ^ 2.0) + (A ^ 2.0)) - (Float64(-A) ^ 2.0))) / C))))))) / t_2); elseif (t_3 <= Inf) tmp = Float64(Float64(-((Float64(t_2 * Float64(F * Float64(2.0 * t_1))) ^ 0.25) ^ 2.0)) / t_2); else tmp = Float64(Float64(-Float64(sqrt(2.0) / B_m)) * sqrt(Float64(F * Float64(A - hypot(B_m, A))))); 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[(N[Power[B$95$m, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(A + C), $MachinePrecision] - N[Sqrt[B$95$m ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(B$95$m * B$95$m + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * 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$0), $MachinePrecision]}, Block[{t$95$4 = N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -2e-201], N[(N[(N[Sqrt[N[(F * t$95$1), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(2.0 * t$95$4), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$4), $MachinePrecision], If[LessEqual[t$95$3, 1e-78], N[((-N[Sqrt[N[(N[(F * t$95$2), $MachinePrecision] * N[(2.0 * N[(A + N[(A + N[(N[(-0.5 * N[(N[(N[Power[B$95$m, 2.0], $MachinePrecision] + N[Power[A, 2.0], $MachinePrecision]), $MachinePrecision] - N[Power[(-A), 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$2), $MachinePrecision], If[LessEqual[t$95$3, Infinity], N[((-N[Power[N[Power[N[(t$95$2 * N[(F * N[(2.0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.25], $MachinePrecision], 2.0], $MachinePrecision]) / t$95$2), $MachinePrecision], N[((-N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $MachinePrecision]) * N[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $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 := {B_m}^{2} - \left(4 \cdot A\right) \cdot C\\
t_1 := \left(A + C\right) - \mathsf{hypot}\left(B_m, A - C\right)\\
t_2 := \mathsf{fma}\left(B_m, B_m, A \cdot \left(C \cdot -4\right)\right)\\
t_3 := \frac{-\sqrt{\left(2 \cdot \left(t_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{B_m}^{2} + {\left(A - C\right)}^{2}}\right)}}{t_0}\\
t_4 := \mathsf{fma}\left(A, C \cdot -4, {B_m}^{2}\right)\\
\mathbf{if}\;t_3 \leq -2 \cdot 10^{-201}:\\
\;\;\;\;\frac{\sqrt{F \cdot t_1} \cdot \left(-\sqrt{2 \cdot t_4}\right)}{t_4}\\
\mathbf{elif}\;t_3 \leq 10^{-78}:\\
\;\;\;\;\frac{-\sqrt{\left(F \cdot t_2\right) \cdot \left(2 \cdot \left(A + \left(A + \frac{-0.5 \cdot \left(\left({B_m}^{2} + {A}^{2}\right) - {\left(-A\right)}^{2}\right)}{C}\right)\right)\right)}}{t_2}\\
\mathbf{elif}\;t_3 \leq \infty:\\
\;\;\;\;\frac{-{\left({\left(t_2 \cdot \left(F \cdot \left(2 \cdot t_1\right)\right)\right)}^{0.25}\right)}^{2}}{t_2}\\
\mathbf{else}:\\
\;\;\;\;\left(-\frac{\sqrt{2}}{B_m}\right) \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)}\\
\end{array}
\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))) < -1.99999999999999989e-201Initial program 44.0%
Simplified47.7%
pow1/247.7%
associate-*r*60.0%
unpow-prod-down77.4%
pow1/277.4%
Applied egg-rr77.4%
unpow1/277.4%
associate-+r-76.6%
+-commutative76.6%
Simplified76.6%
if -1.99999999999999989e-201 < (/.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))) < 9.99999999999999999e-79Initial program 11.3%
Simplified14.3%
Taylor expanded in C around inf 31.9%
associate-*r/31.9%
mul-1-neg31.9%
Simplified31.9%
if 9.99999999999999999e-79 < (/.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 28.3%
Simplified54.5%
add-sqr-sqrt54.6%
pow254.6%
pow1/254.6%
sqrt-pow154.7%
associate-*l*56.5%
associate-+r-56.5%
metadata-eval56.5%
Applied egg-rr56.5%
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 0.0%
Simplified1.2%
Taylor expanded in C around 0 1.8%
associate-*r*1.8%
mul-1-neg1.8%
+-commutative1.8%
unpow21.8%
unpow21.8%
hypot-def8.3%
Simplified8.3%
Final simplification38.3%
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 B_m B_m (* A (* C -4.0)))))
(if (<= (pow B_m 2.0) 2e-109)
(/ (- (sqrt (* (* F t_0) (* 2.0 (+ A A))))) t_0)
(* (- (/ (sqrt 2.0) B_m)) (sqrt (* F (- A (hypot B_m A))))))))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(B_m, B_m, (A * (C * -4.0)));
double tmp;
if (pow(B_m, 2.0) <= 2e-109) {
tmp = -sqrt(((F * t_0) * (2.0 * (A + A)))) / t_0;
} else {
tmp = -(sqrt(2.0) / B_m) * sqrt((F * (A - hypot(B_m, A))));
}
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(B_m, B_m, Float64(A * Float64(C * -4.0))) tmp = 0.0 if ((B_m ^ 2.0) <= 2e-109) tmp = Float64(Float64(-sqrt(Float64(Float64(F * t_0) * Float64(2.0 * Float64(A + A))))) / t_0); else tmp = Float64(Float64(-Float64(sqrt(2.0) / B_m)) * sqrt(Float64(F * Float64(A - hypot(B_m, A))))); 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[(B$95$m * B$95$m + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 2e-109], N[((-N[Sqrt[N[(N[(F * t$95$0), $MachinePrecision] * N[(2.0 * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[((-N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $MachinePrecision]) * N[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $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(B_m, B_m, A \cdot \left(C \cdot -4\right)\right)\\
\mathbf{if}\;{B_m}^{2} \leq 2 \cdot 10^{-109}:\\
\;\;\;\;\frac{-\sqrt{\left(F \cdot t_0\right) \cdot \left(2 \cdot \left(A + A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\left(-\frac{\sqrt{2}}{B_m}\right) \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 2e-109Initial program 19.9%
Simplified32.8%
Taylor expanded in C around inf 24.6%
if 2e-109 < (pow.f64 B 2) Initial program 17.2%
Simplified16.7%
Taylor expanded in C around 0 13.9%
associate-*r*13.9%
mul-1-neg13.9%
+-commutative13.9%
unpow213.9%
unpow213.9%
hypot-def20.5%
Simplified20.5%
Final simplification22.4%
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
(if (<= (pow B_m 2.0) 4e-116)
(/
(- (sqrt (* -8.0 (* A (* C (* F (+ A A)))))))
(fma A (* C -4.0) (pow B_m 2.0)))
(* (- (/ (sqrt 2.0) B_m)) (sqrt (* F (- A (hypot B_m A)))))))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 tmp;
if (pow(B_m, 2.0) <= 4e-116) {
tmp = -sqrt((-8.0 * (A * (C * (F * (A + A)))))) / fma(A, (C * -4.0), pow(B_m, 2.0));
} else {
tmp = -(sqrt(2.0) / B_m) * sqrt((F * (A - hypot(B_m, A))));
}
return tmp;
}
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if ((B_m ^ 2.0) <= 4e-116) tmp = Float64(Float64(-sqrt(Float64(-8.0 * Float64(A * Float64(C * Float64(F * Float64(A + A))))))) / fma(A, Float64(C * -4.0), (B_m ^ 2.0))); else tmp = Float64(Float64(-Float64(sqrt(2.0) / B_m)) * sqrt(Float64(F * Float64(A - hypot(B_m, A))))); 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_] := If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 4e-116], N[((-N[Sqrt[N[(-8.0 * N[(A * N[(C * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $MachinePrecision]) * N[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $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}
\mathbf{if}\;{B_m}^{2} \leq 4 \cdot 10^{-116}:\\
\;\;\;\;\frac{-\sqrt{-8 \cdot \left(A \cdot \left(C \cdot \left(F \cdot \left(A + A\right)\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, {B_m}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(-\frac{\sqrt{2}}{B_m}\right) \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 4e-116Initial program 19.3%
Simplified26.6%
Taylor expanded in C around inf 23.9%
if 4e-116 < (pow.f64 B 2) Initial program 17.8%
Simplified17.3%
Taylor expanded in C around 0 13.8%
associate-*r*13.8%
mul-1-neg13.8%
+-commutative13.8%
unpow213.8%
unpow213.8%
hypot-def20.3%
Simplified20.3%
Final simplification22.0%
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
(if (<= B_m 1.7e-57)
(/
(- (sqrt (* (* A -8.0) (* (+ A A) (* C F)))))
(fma A (* C -4.0) (pow B_m 2.0)))
(* (- (/ (sqrt 2.0) B_m)) (sqrt (* F (- A (hypot B_m A)))))))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 tmp;
if (B_m <= 1.7e-57) {
tmp = -sqrt(((A * -8.0) * ((A + A) * (C * F)))) / fma(A, (C * -4.0), pow(B_m, 2.0));
} else {
tmp = -(sqrt(2.0) / B_m) * sqrt((F * (A - hypot(B_m, A))));
}
return tmp;
}
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) tmp = 0.0 if (B_m <= 1.7e-57) tmp = Float64(Float64(-sqrt(Float64(Float64(A * -8.0) * Float64(Float64(A + A) * Float64(C * F))))) / fma(A, Float64(C * -4.0), (B_m ^ 2.0))); else tmp = Float64(Float64(-Float64(sqrt(2.0) / B_m)) * sqrt(Float64(F * Float64(A - hypot(B_m, A))))); 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_] := If[LessEqual[B$95$m, 1.7e-57], N[((-N[Sqrt[N[(N[(A * -8.0), $MachinePrecision] * N[(N[(A + A), $MachinePrecision] * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $MachinePrecision]) * N[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $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}
\mathbf{if}\;B_m \leq 1.7 \cdot 10^{-57}:\\
\;\;\;\;\frac{-\sqrt{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(C \cdot F\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, {B_m}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(-\frac{\sqrt{2}}{B_m}\right) \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)}\\
\end{array}
\end{array}
if B < 1.70000000000000008e-57Initial program 16.9%
Simplified21.6%
Taylor expanded in C around inf 16.3%
associate-*r*16.3%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt16.3%
associate-*r*12.1%
*-commutative12.1%
sub-neg12.1%
mul-1-neg12.1%
remove-double-neg12.1%
Simplified12.1%
if 1.70000000000000008e-57 < B Initial program 23.2%
Simplified22.0%
Taylor expanded in C around 0 28.3%
associate-*r*28.3%
mul-1-neg28.3%
+-commutative28.3%
unpow228.3%
unpow228.3%
hypot-def41.4%
Simplified41.4%
Final simplification19.3%
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 (* (/ (- (sqrt 2.0)) B_m) (sqrt (* F (- A (hypot B_m A))))))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
return (-sqrt(2.0) / B_m) * sqrt((F * (A - hypot(B_m, A))));
}
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
return (-Math.sqrt(2.0) / B_m) * Math.sqrt((F * (A - Math.hypot(B_m, A))));
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): return (-math.sqrt(2.0) / B_m) * math.sqrt((F * (A - math.hypot(B_m, A))))
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) return Float64(Float64(Float64(-sqrt(2.0)) / B_m) * sqrt(Float64(F * Float64(A - hypot(B_m, A))))) end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp = code(A, B_m, C, F)
tmp = (-sqrt(2.0) / B_m) * sqrt((F * (A - hypot(B_m, A))));
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_] := N[(N[((-N[Sqrt[2.0], $MachinePrecision]) / B$95$m), $MachinePrecision] * N[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\frac{-\sqrt{2}}{B_m} \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)}
\end{array}
Initial program 18.5%
Simplified21.7%
Taylor expanded in C around 0 8.9%
associate-*r*8.9%
mul-1-neg8.9%
+-commutative8.9%
unpow28.9%
unpow28.9%
hypot-def12.6%
Simplified12.6%
Final simplification12.6%
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 (* (* (sqrt 2.0) (sqrt -0.5)) (- (sqrt (/ F C)))))
B_m = fabs(B);
assert(A < B_m && B_m < C && C < F);
double code(double A, double B_m, double C, double F) {
return (sqrt(2.0) * sqrt(-0.5)) * -sqrt((F / C));
}
B_m = abs(B)
NOTE: A, B_m, C, and F should be sorted in increasing order before calling this function.
real(8) function code(a, b_m, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
code = (sqrt(2.0d0) * sqrt((-0.5d0))) * -sqrt((f / c))
end function
B_m = Math.abs(B);
assert A < B_m && B_m < C && C < F;
public static double code(double A, double B_m, double C, double F) {
return (Math.sqrt(2.0) * Math.sqrt(-0.5)) * -Math.sqrt((F / C));
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): return (math.sqrt(2.0) * math.sqrt(-0.5)) * -math.sqrt((F / C))
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) return Float64(Float64(sqrt(2.0) * sqrt(-0.5)) * Float64(-sqrt(Float64(F / C)))) end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp = code(A, B_m, C, F)
tmp = (sqrt(2.0) * sqrt(-0.5)) * -sqrt((F / C));
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_] := N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[-0.5], $MachinePrecision]), $MachinePrecision] * (-N[Sqrt[N[(F / C), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
\left(\sqrt{2} \cdot \sqrt{-0.5}\right) \cdot \left(-\sqrt{\frac{F}{C}}\right)
\end{array}
Initial program 18.5%
Simplified21.7%
Taylor expanded in A around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
distribute-lft-neg-in0.0%
*-commutative0.0%
Simplified0.0%
Final simplification0.0%
herbie shell --seed 2023319
(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))))