
(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 7 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}
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (fma A (* C -4.0) (pow B 2.0))))
(if (<= (pow B 2.0) 5e-61)
(* (sqrt (* 2.0 (* t_0 (* F (* 2.0 A))))) (/ -1.0 t_0))
(* (sqrt (* F (- A (hypot B A)))) (/ (- (sqrt 2.0)) B)))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = fma(A, (C * -4.0), pow(B, 2.0));
double tmp;
if (pow(B, 2.0) <= 5e-61) {
tmp = sqrt((2.0 * (t_0 * (F * (2.0 * A))))) * (-1.0 / t_0);
} else {
tmp = sqrt((F * (A - hypot(B, A)))) * (-sqrt(2.0) / B);
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = fma(A, Float64(C * -4.0), (B ^ 2.0)) tmp = 0.0 if ((B ^ 2.0) <= 5e-61) tmp = Float64(sqrt(Float64(2.0 * Float64(t_0 * Float64(F * Float64(2.0 * A))))) * Float64(-1.0 / t_0)); else tmp = Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * Float64(Float64(-sqrt(2.0)) / B)); end return tmp end
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 5e-61], N[(N[Sqrt[N[(2.0 * N[(t$95$0 * N[(F * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(A, C \cdot -4, {B}^{2}\right)\\
\mathbf{if}\;{B}^{2} \leq 5 \cdot 10^{-61}:\\
\;\;\;\;\sqrt{2 \cdot \left(t_0 \cdot \left(F \cdot \left(2 \cdot A\right)\right)\right)} \cdot \frac{-1}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 4.9999999999999999e-61Initial program 20.3%
Simplified31.2%
Taylor expanded in C around inf 28.8%
cancel-sign-sub-inv28.8%
metadata-eval28.8%
*-lft-identity28.8%
Simplified28.8%
div-inv28.6%
associate-*l*31.1%
count-231.1%
Applied egg-rr31.1%
if 4.9999999999999999e-61 < (pow.f64 B 2) Initial program 23.0%
Simplified25.8%
Taylor expanded in C around 0 16.4%
mul-1-neg16.4%
distribute-rgt-neg-in16.4%
+-commutative16.4%
unpow216.4%
unpow216.4%
hypot-def27.1%
Simplified27.1%
Final simplification28.8%
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(if (or (<= (pow B 2.0) 2e-56)
(and (not (<= (pow B 2.0) 4e+55)) (<= (pow B 2.0) 2e+116)))
(/
(- (sqrt (* 2.0 (* -4.0 (* (* A C) (* F (+ A A)))))))
(fma B B (* A (* C -4.0))))
(* (sqrt (* F (- C (hypot B C)))) (/ (- (sqrt 2.0)) B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double tmp;
if ((pow(B, 2.0) <= 2e-56) || (!(pow(B, 2.0) <= 4e+55) && (pow(B, 2.0) <= 2e+116))) {
tmp = -sqrt((2.0 * (-4.0 * ((A * C) * (F * (A + A)))))) / fma(B, B, (A * (C * -4.0)));
} else {
tmp = sqrt((F * (C - hypot(B, C)))) * (-sqrt(2.0) / B);
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) tmp = 0.0 if (((B ^ 2.0) <= 2e-56) || (!((B ^ 2.0) <= 4e+55) && ((B ^ 2.0) <= 2e+116))) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(-4.0 * Float64(Float64(A * C) * Float64(F * Float64(A + A))))))) / fma(B, B, Float64(A * Float64(C * -4.0)))); else tmp = Float64(sqrt(Float64(F * Float64(C - hypot(B, C)))) * Float64(Float64(-sqrt(2.0)) / B)); end return tmp end
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := If[Or[LessEqual[N[Power[B, 2.0], $MachinePrecision], 2e-56], And[N[Not[LessEqual[N[Power[B, 2.0], $MachinePrecision], 4e+55]], $MachinePrecision], LessEqual[N[Power[B, 2.0], $MachinePrecision], 2e+116]]], N[((-N[Sqrt[N[(2.0 * N[(-4.0 * N[(N[(A * C), $MachinePrecision] * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(C - N[Sqrt[B ^ 2 + C ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;{B}^{2} \leq 2 \cdot 10^{-56} \lor \neg \left({B}^{2} \leq 4 \cdot 10^{+55}\right) \land {B}^{2} \leq 2 \cdot 10^{+116}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(-4 \cdot \left(\left(A \cdot C\right) \cdot \left(F \cdot \left(A + A\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(C - \mathsf{hypot}\left(B, C\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 2.0000000000000001e-56 or 4.00000000000000004e55 < (pow.f64 B 2) < 2.00000000000000003e116Initial program 21.7%
Simplified33.2%
Taylor expanded in C around inf 25.0%
associate-*r*26.3%
*-commutative26.3%
cancel-sign-sub-inv26.3%
metadata-eval26.3%
*-lft-identity26.3%
Simplified26.3%
if 2.0000000000000001e-56 < (pow.f64 B 2) < 4.00000000000000004e55 or 2.00000000000000003e116 < (pow.f64 B 2) Initial program 22.0%
Simplified23.6%
Taylor expanded in A around 0 17.1%
mul-1-neg17.1%
*-commutative17.1%
distribute-rgt-neg-in17.1%
unpow217.1%
unpow217.1%
hypot-def30.8%
Simplified30.8%
Final simplification28.5%
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(if (<= (pow B 2.0) 2e-81)
(/
(- (sqrt (* 2.0 (* (* F (+ (pow B 2.0) (* -4.0 (* A C)))) (+ A A)))))
(fma A (* C -4.0) (pow B 2.0)))
(* (sqrt (* F (- A (hypot B A)))) (/ (- (sqrt 2.0)) B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double tmp;
if (pow(B, 2.0) <= 2e-81) {
tmp = -sqrt((2.0 * ((F * (pow(B, 2.0) + (-4.0 * (A * C)))) * (A + A)))) / fma(A, (C * -4.0), pow(B, 2.0));
} else {
tmp = sqrt((F * (A - hypot(B, A)))) * (-sqrt(2.0) / B);
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) tmp = 0.0 if ((B ^ 2.0) <= 2e-81) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(F * Float64((B ^ 2.0) + Float64(-4.0 * Float64(A * C)))) * Float64(A + A))))) / fma(A, Float64(C * -4.0), (B ^ 2.0))); else tmp = Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * Float64(Float64(-sqrt(2.0)) / B)); end return tmp end
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 2e-81], N[((-N[Sqrt[N[(2.0 * N[(N[(F * N[(N[Power[B, 2.0], $MachinePrecision] + N[(-4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;{B}^{2} \leq 2 \cdot 10^{-81}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(F \cdot \left({B}^{2} + -4 \cdot \left(A \cdot C\right)\right)\right) \cdot \left(A + A\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, {B}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 1.9999999999999999e-81Initial program 20.8%
Simplified31.1%
Taylor expanded in C around inf 28.6%
cancel-sign-sub-inv28.6%
metadata-eval28.6%
*-lft-identity28.6%
Simplified28.6%
Taylor expanded in F around 0 28.6%
if 1.9999999999999999e-81 < (pow.f64 B 2) Initial program 22.5%
Simplified26.6%
Taylor expanded in C around 0 16.1%
mul-1-neg16.1%
distribute-rgt-neg-in16.1%
+-commutative16.1%
unpow216.1%
unpow216.1%
hypot-def26.6%
Simplified26.6%
Final simplification27.4%
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(if (<= (pow B 2.0) 5e-156)
(/
(- (sqrt (* 2.0 (* -4.0 (* (* A C) (* F (+ A A)))))))
(fma B B (* A (* C -4.0))))
(* (sqrt (* F (- A (hypot B A)))) (/ (- (sqrt 2.0)) B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double tmp;
if (pow(B, 2.0) <= 5e-156) {
tmp = -sqrt((2.0 * (-4.0 * ((A * C) * (F * (A + A)))))) / fma(B, B, (A * (C * -4.0)));
} else {
tmp = sqrt((F * (A - hypot(B, A)))) * (-sqrt(2.0) / B);
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) tmp = 0.0 if ((B ^ 2.0) <= 5e-156) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(-4.0 * Float64(Float64(A * C) * Float64(F * Float64(A + A))))))) / fma(B, B, Float64(A * Float64(C * -4.0)))); else tmp = Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * Float64(Float64(-sqrt(2.0)) / B)); end return tmp end
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 5e-156], N[((-N[Sqrt[N[(2.0 * N[(-4.0 * N[(N[(A * C), $MachinePrecision] * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;{B}^{2} \leq 5 \cdot 10^{-156}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(-4 \cdot \left(\left(A \cdot C\right) \cdot \left(F \cdot \left(A + A\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \frac{-\sqrt{2}}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 5.00000000000000007e-156Initial program 19.0%
Simplified29.6%
Taylor expanded in C around inf 26.5%
associate-*r*28.3%
*-commutative28.3%
cancel-sign-sub-inv28.3%
metadata-eval28.3%
*-lft-identity28.3%
Simplified28.3%
if 5.00000000000000007e-156 < (pow.f64 B 2) Initial program 23.5%
Simplified27.9%
Taylor expanded in C around 0 15.6%
mul-1-neg15.6%
distribute-rgt-neg-in15.6%
+-commutative15.6%
unpow215.6%
unpow215.6%
hypot-def25.3%
Simplified25.3%
Final simplification26.5%
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(if (<= (pow B 2.0) 2e-8)
(/
(- (sqrt (* 2.0 (* -4.0 (* (* A C) (* F (+ A A)))))))
(fma B B (* A (* C -4.0))))
(* (* 2.0 (pow (* A F) 0.5)) (/ -1.0 B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double tmp;
if (pow(B, 2.0) <= 2e-8) {
tmp = -sqrt((2.0 * (-4.0 * ((A * C) * (F * (A + A)))))) / fma(B, B, (A * (C * -4.0)));
} else {
tmp = (2.0 * pow((A * F), 0.5)) * (-1.0 / B);
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) tmp = 0.0 if ((B ^ 2.0) <= 2e-8) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(-4.0 * Float64(Float64(A * C) * Float64(F * Float64(A + A))))))) / fma(B, B, Float64(A * Float64(C * -4.0)))); else tmp = Float64(Float64(2.0 * (Float64(A * F) ^ 0.5)) * Float64(-1.0 / B)); end return tmp end
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 2e-8], N[((-N[Sqrt[N[(2.0 * N[(-4.0 * N[(N[(A * C), $MachinePrecision] * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[Power[N[(A * F), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / B), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;{B}^{2} \leq 2 \cdot 10^{-8}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(-4 \cdot \left(\left(A \cdot C\right) \cdot \left(F \cdot \left(A + A\right)\right)\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(2 \cdot {\left(A \cdot F\right)}^{0.5}\right) \cdot \frac{-1}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 2e-8Initial program 21.3%
Simplified32.1%
Taylor expanded in C around inf 24.2%
associate-*r*25.7%
*-commutative25.7%
cancel-sign-sub-inv25.7%
metadata-eval25.7%
*-lft-identity25.7%
Simplified25.7%
if 2e-8 < (pow.f64 B 2) Initial program 22.3%
Simplified25.5%
Taylor expanded in C around inf 5.8%
cancel-sign-sub-inv5.8%
metadata-eval5.8%
*-lft-identity5.8%
Simplified5.8%
Taylor expanded in C around 0 3.7%
associate-*r*3.7%
Simplified3.7%
pow1/23.9%
Applied egg-rr3.9%
Final simplification14.4%
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. (FPCore (A B C F) :precision binary64 (* (* 2.0 (pow (* A F) 0.5)) (/ -1.0 B)))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return (2.0 * pow((A * F), 0.5)) * (-1.0 / B);
}
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
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
code = (2.0d0 * ((a * f) ** 0.5d0)) * ((-1.0d0) / b)
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return (2.0 * Math.pow((A * F), 0.5)) * (-1.0 / B);
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return (2.0 * math.pow((A * F), 0.5)) * (-1.0 / B)
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(2.0 * (Float64(A * F) ^ 0.5)) * Float64(-1.0 / B)) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = (2.0 * ((A * F) ^ 0.5)) * (-1.0 / B);
end
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := N[(N[(2.0 * N[Power[N[(A * F), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / B), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\left(2 \cdot {\left(A \cdot F\right)}^{0.5}\right) \cdot \frac{-1}{B}
\end{array}
Initial program 21.8%
Simplified28.3%
Taylor expanded in C around inf 16.2%
cancel-sign-sub-inv16.2%
metadata-eval16.2%
*-lft-identity16.2%
Simplified16.2%
Taylor expanded in C around 0 2.8%
associate-*r*2.8%
Simplified2.8%
pow1/23.0%
Applied egg-rr3.0%
Final simplification3.0%
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. (FPCore (A B C F) :precision binary64 (/ (- 2.0) (/ B (sqrt (* A F)))))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -2.0 / (B / sqrt((A * F)));
}
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
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
code = -2.0d0 / (b / sqrt((a * f)))
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return -2.0 / (B / Math.sqrt((A * F)));
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -2.0 / (B / math.sqrt((A * F)))
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(-2.0) / Float64(B / sqrt(Float64(A * F)))) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -2.0 / (B / sqrt((A * F)));
end
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. code[A_, B_, C_, F_] := N[((-2.0) / N[(B / N[Sqrt[N[(A * F), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\frac{-2}{\frac{B}{\sqrt{A \cdot F}}}
\end{array}
Initial program 21.8%
Simplified28.3%
Taylor expanded in C around inf 16.2%
cancel-sign-sub-inv16.2%
metadata-eval16.2%
*-lft-identity16.2%
Simplified16.2%
Taylor expanded in C around 0 2.8%
associate-*r*2.8%
Simplified2.8%
expm1-log1p-u2.7%
expm1-udef2.1%
un-div-inv2.1%
Applied egg-rr2.1%
expm1-def2.7%
expm1-log1p2.8%
associate-/l*2.8%
Simplified2.8%
Final simplification2.8%
herbie shell --seed 2023318
(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))))