
(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}
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) (pow B_m 2.0))))
(if (<= (pow B_m 2.0) 1e-82)
(/ 1.0 (/ t_0 (- (sqrt (* A (* -8.0 (* F (* C (* 2.0 A)))))))))
(if (<= (pow B_m 2.0) 1e+305)
(/
(* (sqrt (* F (+ A (- C (hypot B_m (- A C)))))) (- (sqrt (* 2.0 t_0))))
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(A, (C * -4.0), pow(B_m, 2.0));
double tmp;
if (pow(B_m, 2.0) <= 1e-82) {
tmp = 1.0 / (t_0 / -sqrt((A * (-8.0 * (F * (C * (2.0 * A)))))));
} else if (pow(B_m, 2.0) <= 1e+305) {
tmp = (sqrt((F * (A + (C - hypot(B_m, (A - C)))))) * -sqrt((2.0 * t_0))) / 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(A, Float64(C * -4.0), (B_m ^ 2.0)) tmp = 0.0 if ((B_m ^ 2.0) <= 1e-82) tmp = Float64(1.0 / Float64(t_0 / Float64(-sqrt(Float64(A * Float64(-8.0 * Float64(F * Float64(C * Float64(2.0 * A))))))))); elseif ((B_m ^ 2.0) <= 1e+305) tmp = Float64(Float64(sqrt(Float64(F * Float64(A + Float64(C - hypot(B_m, Float64(A - C)))))) * Float64(-sqrt(Float64(2.0 * t_0)))) / t_0); else tmp = Float64(Float64(sqrt(2.0) / B_m) * Float64(-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[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 1e-82], N[(1.0 / N[(t$95$0 / (-N[Sqrt[N[(A * N[(-8.0 * N[(F * N[(C * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Power[B$95$m, 2.0], $MachinePrecision], 1e+305], N[(N[(N[Sqrt[N[(F * N[(A + N[(C - N[Sqrt[B$95$m ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(2.0 * t$95$0), $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(A, C \cdot -4, {B_m}^{2}\right)\\
\mathbf{if}\;{B_m}^{2} \leq 10^{-82}:\\
\;\;\;\;\frac{1}{\frac{t_0}{-\sqrt{A \cdot \left(-8 \cdot \left(F \cdot \left(C \cdot \left(2 \cdot A\right)\right)\right)\right)}}}\\
\mathbf{elif}\;{B_m}^{2} \leq 10^{+305}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(A + \left(C - \mathsf{hypot}\left(B_m, A - C\right)\right)\right)} \cdot \left(-\sqrt{2 \cdot t_0}\right)}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2}}{B_m} \cdot \left(-\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)}\right)\\
\end{array}
\end{array}
if (pow.f64 B 2) < 1e-82Initial program 22.6%
Simplified27.6%
Taylor expanded in C around inf 23.6%
associate-*r*23.6%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt23.6%
associate-*r*23.0%
*-commutative23.0%
sub-neg23.0%
mul-1-neg23.0%
remove-double-neg23.0%
Simplified23.0%
clear-num23.0%
inv-pow23.0%
associate-*l*23.0%
count-223.0%
Applied egg-rr23.0%
unpow-123.0%
associate-*l*25.6%
Simplified25.6%
if 1e-82 < (pow.f64 B 2) < 9.9999999999999994e304Initial program 25.6%
Simplified23.3%
pow1/223.4%
associate-*r*29.3%
unpow-prod-down46.8%
associate-+r-46.7%
pow1/246.7%
Applied egg-rr46.7%
unpow1/246.7%
associate-+r-46.8%
+-commutative46.8%
associate-+l-46.6%
Simplified46.6%
if 9.9999999999999994e304 < (pow.f64 B 2) Initial program 0.1%
Simplified0.1%
Taylor expanded in C around 0 3.1%
mul-1-neg3.1%
distribute-rgt-neg-in3.1%
+-commutative3.1%
unpow23.1%
unpow23.1%
hypot-def23.6%
Simplified23.6%
Final simplification31.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
(if (<= (pow B_m 2.0) 2e-89)
(/
1.0
(/
(fma A (* C -4.0) (pow B_m 2.0))
(- (sqrt (* A (* -8.0 (* F (* C (* 2.0 A)))))))))
(* (sqrt (* F (- A (hypot B_m A)))) (- (/ (sqrt 2.0) B_m)))))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) <= 2e-89) {
tmp = 1.0 / (fma(A, (C * -4.0), pow(B_m, 2.0)) / -sqrt((A * (-8.0 * (F * (C * (2.0 * A)))))));
} else {
tmp = sqrt((F * (A - hypot(B_m, A)))) * -(sqrt(2.0) / B_m);
}
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) <= 2e-89) tmp = Float64(1.0 / Float64(fma(A, Float64(C * -4.0), (B_m ^ 2.0)) / Float64(-sqrt(Float64(A * Float64(-8.0 * Float64(F * Float64(C * Float64(2.0 * A))))))))); else tmp = Float64(sqrt(Float64(F * Float64(A - hypot(B_m, A)))) * Float64(-Float64(sqrt(2.0) / B_m))); 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], 2e-89], N[(1.0 / N[(N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B$95$m, 2.0], $MachinePrecision]), $MachinePrecision] / (-N[Sqrt[N[(A * N[(-8.0 * N[(F * N[(C * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $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 2 \cdot 10^{-89}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{fma}\left(A, C \cdot -4, {B_m}^{2}\right)}{-\sqrt{A \cdot \left(-8 \cdot \left(F \cdot \left(C \cdot \left(2 \cdot A\right)\right)\right)\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)} \cdot \left(-\frac{\sqrt{2}}{B_m}\right)\\
\end{array}
\end{array}
if (pow.f64 B 2) < 2.00000000000000008e-89Initial program 23.2%
Simplified28.3%
Taylor expanded in C around inf 24.2%
associate-*r*24.2%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt24.2%
associate-*r*23.6%
*-commutative23.6%
sub-neg23.6%
mul-1-neg23.6%
remove-double-neg23.6%
Simplified23.6%
clear-num23.6%
inv-pow23.6%
associate-*l*23.6%
count-223.6%
Applied egg-rr23.6%
unpow-123.6%
associate-*l*26.2%
Simplified26.2%
if 2.00000000000000008e-89 < (pow.f64 B 2) Initial program 13.7%
Simplified12.5%
Taylor expanded in C around 0 14.2%
mul-1-neg14.2%
distribute-rgt-neg-in14.2%
+-commutative14.2%
unpow214.2%
unpow214.2%
hypot-def23.6%
Simplified23.6%
Final simplification24.7%
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) 2e-89)
(-
(/
(sqrt (* A (* -8.0 (* F (* C (* 2.0 A))))))
(fma A (* C -4.0) (pow B_m 2.0))))
(* (sqrt (* F (- A (hypot B_m A)))) (- (/ (sqrt 2.0) B_m)))))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) <= 2e-89) {
tmp = -(sqrt((A * (-8.0 * (F * (C * (2.0 * A)))))) / fma(A, (C * -4.0), pow(B_m, 2.0)));
} else {
tmp = sqrt((F * (A - hypot(B_m, A)))) * -(sqrt(2.0) / B_m);
}
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) <= 2e-89) tmp = Float64(-Float64(sqrt(Float64(A * Float64(-8.0 * Float64(F * Float64(C * Float64(2.0 * A)))))) / fma(A, Float64(C * -4.0), (B_m ^ 2.0)))); else tmp = Float64(sqrt(Float64(F * Float64(A - hypot(B_m, A)))) * Float64(-Float64(sqrt(2.0) / B_m))); 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], 2e-89], (-N[(N[Sqrt[N[(A * N[(-8.0 * N[(F * N[(C * N[(2.0 * 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[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $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 2 \cdot 10^{-89}:\\
\;\;\;\;-\frac{\sqrt{A \cdot \left(-8 \cdot \left(F \cdot \left(C \cdot \left(2 \cdot A\right)\right)\right)\right)}}{\mathsf{fma}\left(A, C \cdot -4, {B_m}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)} \cdot \left(-\frac{\sqrt{2}}{B_m}\right)\\
\end{array}
\end{array}
if (pow.f64 B 2) < 2.00000000000000008e-89Initial program 23.2%
Simplified28.3%
Taylor expanded in C around inf 24.2%
associate-*r*24.2%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt24.2%
associate-*r*23.6%
*-commutative23.6%
sub-neg23.6%
mul-1-neg23.6%
remove-double-neg23.6%
Simplified23.6%
expm1-log1p-u22.6%
expm1-udef13.9%
associate-*l*13.9%
count-213.9%
Applied egg-rr13.9%
expm1-def22.6%
expm1-log1p23.6%
associate-*l*26.2%
Simplified26.2%
if 2.00000000000000008e-89 < (pow.f64 B 2) Initial program 13.7%
Simplified12.5%
Taylor expanded in C around 0 14.2%
mul-1-neg14.2%
distribute-rgt-neg-in14.2%
+-commutative14.2%
unpow214.2%
unpow214.2%
hypot-def23.6%
Simplified23.6%
Final simplification24.7%
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 3e-37)
(/
(- (sqrt (* (* A -8.0) (* (+ A A) (* C F)))))
(+ (pow B_m 2.0) (* A (* C -4.0))))
(* (sqrt (* F (- C (hypot B_m C)))) (/ (- (sqrt 2.0)) B_m))))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 <= 3e-37) {
tmp = -sqrt(((A * -8.0) * ((A + A) * (C * F)))) / (pow(B_m, 2.0) + (A * (C * -4.0)));
} else {
tmp = sqrt((F * (C - hypot(B_m, C)))) * (-sqrt(2.0) / B_m);
}
return tmp;
}
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) {
double tmp;
if (B_m <= 3e-37) {
tmp = -Math.sqrt(((A * -8.0) * ((A + A) * (C * F)))) / (Math.pow(B_m, 2.0) + (A * (C * -4.0)));
} else {
tmp = Math.sqrt((F * (C - Math.hypot(B_m, C)))) * (-Math.sqrt(2.0) / B_m);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if B_m <= 3e-37: tmp = -math.sqrt(((A * -8.0) * ((A + A) * (C * F)))) / (math.pow(B_m, 2.0) + (A * (C * -4.0))) else: tmp = math.sqrt((F * (C - math.hypot(B_m, C)))) * (-math.sqrt(2.0) / B_m) 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 <= 3e-37) tmp = Float64(Float64(-sqrt(Float64(Float64(A * -8.0) * Float64(Float64(A + A) * Float64(C * F))))) / Float64((B_m ^ 2.0) + Float64(A * Float64(C * -4.0)))); else tmp = Float64(sqrt(Float64(F * Float64(C - hypot(B_m, C)))) * Float64(Float64(-sqrt(2.0)) / B_m)); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if (B_m <= 3e-37)
tmp = -sqrt(((A * -8.0) * ((A + A) * (C * F)))) / ((B_m ^ 2.0) + (A * (C * -4.0)));
else
tmp = sqrt((F * (C - hypot(B_m, C)))) * (-sqrt(2.0) / B_m);
end
tmp_2 = 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, 3e-37], N[((-N[Sqrt[N[(N[(A * -8.0), $MachinePrecision] * N[(N[(A + A), $MachinePrecision] * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(N[Power[B$95$m, 2.0], $MachinePrecision] + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(C - N[Sqrt[B$95$m ^ 2 + C ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B$95$m), $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 3 \cdot 10^{-37}:\\
\;\;\;\;\frac{-\sqrt{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(C \cdot F\right)\right)}}{{B_m}^{2} + A \cdot \left(C \cdot -4\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(C - \mathsf{hypot}\left(B_m, C\right)\right)} \cdot \frac{-\sqrt{2}}{B_m}\\
\end{array}
\end{array}
if B < 3e-37Initial program 17.1%
Simplified20.3%
Taylor expanded in C around inf 15.1%
associate-*r*15.1%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt15.1%
associate-*r*14.8%
*-commutative14.8%
sub-neg14.8%
mul-1-neg14.8%
remove-double-neg14.8%
Simplified14.8%
fma-udef14.8%
Applied egg-rr14.8%
if 3e-37 < B Initial program 19.4%
Simplified16.1%
Taylor expanded in A around 0 28.5%
mul-1-neg28.5%
*-commutative28.5%
distribute-rgt-neg-in28.5%
unpow228.5%
unpow228.5%
hypot-def48.8%
Simplified48.8%
Final simplification24.1%
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 2.4e-37)
(/
(- (sqrt (* (* A -8.0) (* (+ A A) (* C F)))))
(+ (pow B_m 2.0) (* A (* C -4.0))))
(* (sqrt (* F (- A (hypot B_m A)))) (- (/ (sqrt 2.0) B_m)))))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 <= 2.4e-37) {
tmp = -sqrt(((A * -8.0) * ((A + A) * (C * F)))) / (pow(B_m, 2.0) + (A * (C * -4.0)));
} else {
tmp = sqrt((F * (A - hypot(B_m, A)))) * -(sqrt(2.0) / B_m);
}
return tmp;
}
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) {
double tmp;
if (B_m <= 2.4e-37) {
tmp = -Math.sqrt(((A * -8.0) * ((A + A) * (C * F)))) / (Math.pow(B_m, 2.0) + (A * (C * -4.0)));
} else {
tmp = Math.sqrt((F * (A - Math.hypot(B_m, A)))) * -(Math.sqrt(2.0) / B_m);
}
return tmp;
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): tmp = 0 if B_m <= 2.4e-37: tmp = -math.sqrt(((A * -8.0) * ((A + A) * (C * F)))) / (math.pow(B_m, 2.0) + (A * (C * -4.0))) else: tmp = math.sqrt((F * (A - math.hypot(B_m, A)))) * -(math.sqrt(2.0) / B_m) 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.4e-37) tmp = Float64(Float64(-sqrt(Float64(Float64(A * -8.0) * Float64(Float64(A + A) * Float64(C * F))))) / Float64((B_m ^ 2.0) + Float64(A * Float64(C * -4.0)))); else tmp = Float64(sqrt(Float64(F * Float64(A - hypot(B_m, A)))) * Float64(-Float64(sqrt(2.0) / B_m))); end return tmp end
B_m = abs(B);
A, B_m, C, F = num2cell(sort([A, B_m, C, F])){:}
function tmp_2 = code(A, B_m, C, F)
tmp = 0.0;
if (B_m <= 2.4e-37)
tmp = -sqrt(((A * -8.0) * ((A + A) * (C * F)))) / ((B_m ^ 2.0) + (A * (C * -4.0)));
else
tmp = sqrt((F * (A - hypot(B_m, A)))) * -(sqrt(2.0) / B_m);
end
tmp_2 = 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, 2.4e-37], N[((-N[Sqrt[N[(N[(A * -8.0), $MachinePrecision] * N[(N[(A + A), $MachinePrecision] * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(N[Power[B$95$m, 2.0], $MachinePrecision] + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[(N[Sqrt[2.0], $MachinePrecision] / B$95$m), $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 2.4 \cdot 10^{-37}:\\
\;\;\;\;\frac{-\sqrt{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(C \cdot F\right)\right)}}{{B_m}^{2} + A \cdot \left(C \cdot -4\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B_m, A\right)\right)} \cdot \left(-\frac{\sqrt{2}}{B_m}\right)\\
\end{array}
\end{array}
if B < 2.39999999999999991e-37Initial program 17.1%
Simplified20.3%
Taylor expanded in C around inf 15.1%
associate-*r*15.1%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt15.1%
associate-*r*14.8%
*-commutative14.8%
sub-neg14.8%
mul-1-neg14.8%
remove-double-neg14.8%
Simplified14.8%
fma-udef14.8%
Applied egg-rr14.8%
if 2.39999999999999991e-37 < B Initial program 19.4%
Simplified16.1%
Taylor expanded in C around 0 28.5%
mul-1-neg28.5%
distribute-rgt-neg-in28.5%
+-commutative28.5%
unpow228.5%
unpow228.5%
hypot-def46.9%
Simplified46.9%
Final simplification23.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 (* (* A -8.0) (* (+ A A) (* C F))))) (* C (* A -4.0))))
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(((A * -8.0) * ((A + A) * (C * F)))) / (C * (A * -4.0));
}
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(((a * (-8.0d0)) * ((a + a) * (c * f)))) / (c * (a * (-4.0d0)))
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(((A * -8.0) * ((A + A) * (C * F)))) / (C * (A * -4.0));
}
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(((A * -8.0) * ((A + A) * (C * F)))) / (C * (A * -4.0))
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(Float64(Float64(A * -8.0) * Float64(Float64(A + A) * Float64(C * F))))) / Float64(C * Float64(A * -4.0))) 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(((A * -8.0) * ((A + A) * (C * F)))) / (C * (A * -4.0));
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[Sqrt[N[(N[(A * -8.0), $MachinePrecision] * N[(N[(A + A), $MachinePrecision] * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(C * N[(A * -4.0), $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{\left(A \cdot -8\right) \cdot \left(\left(A + A\right) \cdot \left(C \cdot F\right)\right)}}{C \cdot \left(A \cdot -4\right)}
\end{array}
Initial program 17.7%
Simplified19.2%
Taylor expanded in C around inf 12.0%
associate-*r*12.0%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt12.0%
associate-*r*11.8%
*-commutative11.8%
sub-neg11.8%
mul-1-neg11.8%
remove-double-neg11.8%
Simplified11.8%
Taylor expanded in A around inf 11.6%
associate-*r*11.6%
Simplified11.6%
Final simplification11.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 (* -2.0 (* (/ 1.0 B_m) (sqrt (* C F)))))
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 -2.0 * ((1.0 / B_m) * sqrt((C * F)));
}
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 = (-2.0d0) * ((1.0d0 / b_m) * sqrt((c * f)))
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 -2.0 * ((1.0 / B_m) * Math.sqrt((C * F)));
}
B_m = math.fabs(B) [A, B_m, C, F] = sort([A, B_m, C, F]) def code(A, B_m, C, F): return -2.0 * ((1.0 / B_m) * math.sqrt((C * F)))
B_m = abs(B) A, B_m, C, F = sort([A, B_m, C, F]) function code(A, B_m, C, F) return Float64(-2.0 * Float64(Float64(1.0 / B_m) * sqrt(Float64(C * F)))) 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 = -2.0 * ((1.0 / B_m) * sqrt((C * F)));
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[(-2.0 * N[(N[(1.0 / B$95$m), $MachinePrecision] * N[Sqrt[N[(C * F), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
[A, B_m, C, F] = \mathsf{sort}([A, B_m, C, F])\\
\\
-2 \cdot \left(\frac{1}{B_m} \cdot \sqrt{C \cdot F}\right)
\end{array}
Initial program 17.7%
Simplified19.2%
Taylor expanded in C around -inf 11.1%
Taylor expanded in A around 0 3.0%
Final simplification3.0%
herbie shell --seed 2023337
(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))))