
(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 10 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 (- A (hypot B A)))
(t_1 (fma A (* C -4.0) (pow B 2.0)))
(t_2 (fma B B (* A (* C -4.0))))
(t_3 (sqrt (* F t_0))))
(if (<= B 0.0146)
(/ (- (sqrt (* 2.0 (* t_2 (* F (+ A A)))))) t_2)
(if (<= B 5.6e+62)
(/
(*
(sqrt (* 2.0 t_2))
(-
(*
0.5
(*
C
(*
(sqrt (/ F t_0))
(- -1.0 (* A (sqrt (/ 1.0 (fma A A (pow B 2.0)))))))))
t_3))
t_2)
(if (<= B 1.5e+84)
(/
(-
(sqrt (* 2.0 (* (* F t_1) (+ A (+ A (* -0.5 (/ (pow B 2.0) C))))))))
t_1)
(/ (* t_3 (- (sqrt 2.0))) B))))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = A - hypot(B, A);
double t_1 = fma(A, (C * -4.0), pow(B, 2.0));
double t_2 = fma(B, B, (A * (C * -4.0)));
double t_3 = sqrt((F * t_0));
double tmp;
if (B <= 0.0146) {
tmp = -sqrt((2.0 * (t_2 * (F * (A + A))))) / t_2;
} else if (B <= 5.6e+62) {
tmp = (sqrt((2.0 * t_2)) * ((0.5 * (C * (sqrt((F / t_0)) * (-1.0 - (A * sqrt((1.0 / fma(A, A, pow(B, 2.0))))))))) - t_3)) / t_2;
} else if (B <= 1.5e+84) {
tmp = -sqrt((2.0 * ((F * t_1) * (A + (A + (-0.5 * (pow(B, 2.0) / C))))))) / t_1;
} else {
tmp = (t_3 * -sqrt(2.0)) / B;
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(A - hypot(B, A)) t_1 = fma(A, Float64(C * -4.0), (B ^ 2.0)) t_2 = fma(B, B, Float64(A * Float64(C * -4.0))) t_3 = sqrt(Float64(F * t_0)) tmp = 0.0 if (B <= 0.0146) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(t_2 * Float64(F * Float64(A + A)))))) / t_2); elseif (B <= 5.6e+62) tmp = Float64(Float64(sqrt(Float64(2.0 * t_2)) * Float64(Float64(0.5 * Float64(C * Float64(sqrt(Float64(F / t_0)) * Float64(-1.0 - Float64(A * sqrt(Float64(1.0 / fma(A, A, (B ^ 2.0))))))))) - t_3)) / t_2); elseif (B <= 1.5e+84) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(F * t_1) * Float64(A + Float64(A + Float64(-0.5 * Float64((B ^ 2.0) / C)))))))) / t_1); else tmp = Float64(Float64(t_3 * 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[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(F * t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[B, 0.0146], N[((-N[Sqrt[N[(2.0 * N[(t$95$2 * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$2), $MachinePrecision], If[LessEqual[B, 5.6e+62], N[(N[(N[Sqrt[N[(2.0 * t$95$2), $MachinePrecision]], $MachinePrecision] * N[(N[(0.5 * N[(C * N[(N[Sqrt[N[(F / t$95$0), $MachinePrecision]], $MachinePrecision] * N[(-1.0 - N[(A * N[Sqrt[N[(1.0 / N[(A * A + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$3), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], If[LessEqual[B, 1.5e+84], N[((-N[Sqrt[N[(2.0 * N[(N[(F * t$95$1), $MachinePrecision] * N[(A + N[(A + N[(-0.5 * N[(N[Power[B, 2.0], $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$1), $MachinePrecision], N[(N[(t$95$3 * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision] / B), $MachinePrecision]]]]]]]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := A - \mathsf{hypot}\left(B, A\right)\\
t_1 := \mathsf{fma}\left(A, C \cdot -4, {B}^{2}\right)\\
t_2 := \mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)\\
t_3 := \sqrt{F \cdot t_0}\\
\mathbf{if}\;B \leq 0.0146:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(t_2 \cdot \left(F \cdot \left(A + A\right)\right)\right)}}{t_2}\\
\mathbf{elif}\;B \leq 5.6 \cdot 10^{+62}:\\
\;\;\;\;\frac{\sqrt{2 \cdot t_2} \cdot \left(0.5 \cdot \left(C \cdot \left(\sqrt{\frac{F}{t_0}} \cdot \left(-1 - A \cdot \sqrt{\frac{1}{\mathsf{fma}\left(A, A, {B}^{2}\right)}}\right)\right)\right) - t_3\right)}{t_2}\\
\mathbf{elif}\;B \leq 1.5 \cdot 10^{+84}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(F \cdot t_1\right) \cdot \left(A + \left(A + -0.5 \cdot \frac{{B}^{2}}{C}\right)\right)\right)}}{t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_3 \cdot \left(-\sqrt{2}\right)}{B}\\
\end{array}
\end{array}
if B < 0.0146000000000000001Initial program 14.4%
Simplified19.5%
associate--l+21.0%
Applied egg-rr21.0%
Taylor expanded in C around inf 15.0%
if 0.0146000000000000001 < B < 5.60000000000000029e62Initial program 29.2%
Simplified30.0%
associate-*r*30.0%
sqrt-prod37.6%
associate--l+39.0%
Applied egg-rr39.0%
Taylor expanded in C around 0 36.8%
+-commutative36.8%
Simplified36.8%
if 5.60000000000000029e62 < B < 1.49999999999999998e84Initial program 3.9%
Simplified3.9%
Taylor expanded in C around inf 0.0%
sub-neg0.0%
associate--l+0.0%
mul-1-neg0.0%
mul-1-neg0.0%
remove-double-neg0.0%
Simplified0.0%
Taylor expanded in A around 0 0.0%
if 1.49999999999999998e84 < B Initial program 6.3%
Simplified8.2%
Taylor expanded in C around 0 13.6%
mul-1-neg13.6%
distribute-rgt-neg-in13.6%
+-commutative13.6%
unpow213.6%
unpow213.6%
hypot-def59.3%
Simplified59.3%
associate-*l/59.4%
Applied egg-rr59.4%
Final simplification24.9%
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 B B (* A (* C -4.0)))) (t_1 (fma A (* C -4.0) (pow B 2.0))))
(if (<= B 0.012)
(/ (- (sqrt (* 2.0 (* t_0 (* F (+ A A)))))) t_0)
(if (<= B 3.8e+65)
(/
(* (sqrt (* F (+ A (- C (hypot B (- A C)))))) (- (sqrt (* 2.0 t_0))))
t_0)
(if (<= B 1.55e+84)
(/
(-
(sqrt (* 2.0 (* (* F t_1) (+ A (+ A (* -0.5 (/ (pow B 2.0) C))))))))
t_1)
(/ (* (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(B, B, (A * (C * -4.0)));
double t_1 = fma(A, (C * -4.0), pow(B, 2.0));
double tmp;
if (B <= 0.012) {
tmp = -sqrt((2.0 * (t_0 * (F * (A + A))))) / t_0;
} else if (B <= 3.8e+65) {
tmp = (sqrt((F * (A + (C - hypot(B, (A - C)))))) * -sqrt((2.0 * t_0))) / t_0;
} else if (B <= 1.55e+84) {
tmp = -sqrt((2.0 * ((F * t_1) * (A + (A + (-0.5 * (pow(B, 2.0) / C))))))) / t_1;
} 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(B, B, Float64(A * Float64(C * -4.0))) t_1 = fma(A, Float64(C * -4.0), (B ^ 2.0)) tmp = 0.0 if (B <= 0.012) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(t_0 * Float64(F * Float64(A + A)))))) / t_0); elseif (B <= 3.8e+65) tmp = Float64(Float64(sqrt(Float64(F * Float64(A + Float64(C - hypot(B, Float64(A - C)))))) * Float64(-sqrt(Float64(2.0 * t_0)))) / t_0); elseif (B <= 1.55e+84) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(F * t_1) * Float64(A + Float64(A + Float64(-0.5 * Float64((B ^ 2.0) / C)))))))) / t_1); else tmp = Float64(Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * 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[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(A * N[(C * -4.0), $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 0.012], N[((-N[Sqrt[N[(2.0 * N[(t$95$0 * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], If[LessEqual[B, 3.8e+65], N[(N[(N[Sqrt[N[(F * N[(A + N[(C - N[Sqrt[B ^ 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], If[LessEqual[B, 1.55e+84], N[((-N[Sqrt[N[(2.0 * N[(N[(F * t$95$1), $MachinePrecision] * N[(A + N[(A + N[(-0.5 * N[(N[Power[B, 2.0], $MachinePrecision] / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$1), $MachinePrecision], N[(N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision] / B), $MachinePrecision]]]]]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)\\
t_1 := \mathsf{fma}\left(A, C \cdot -4, {B}^{2}\right)\\
\mathbf{if}\;B \leq 0.012:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(t_0 \cdot \left(F \cdot \left(A + A\right)\right)\right)}}{t_0}\\
\mathbf{elif}\;B \leq 3.8 \cdot 10^{+65}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(A + \left(C - \mathsf{hypot}\left(B, A - C\right)\right)\right)} \cdot \left(-\sqrt{2 \cdot t_0}\right)}{t_0}\\
\mathbf{elif}\;B \leq 1.55 \cdot 10^{+84}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(F \cdot t_1\right) \cdot \left(A + \left(A + -0.5 \cdot \frac{{B}^{2}}{C}\right)\right)\right)}}{t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \left(-\sqrt{2}\right)}{B}\\
\end{array}
\end{array}
if B < 0.012Initial program 14.4%
Simplified19.5%
associate--l+21.0%
Applied egg-rr21.0%
Taylor expanded in C around inf 15.0%
if 0.012 < B < 3.80000000000000011e65Initial program 29.2%
Simplified30.0%
associate-*r*30.0%
sqrt-prod37.6%
associate--l+39.0%
Applied egg-rr39.0%
if 3.80000000000000011e65 < B < 1.55000000000000001e84Initial program 3.9%
Simplified3.9%
Taylor expanded in C around inf 0.0%
sub-neg0.0%
associate--l+0.0%
mul-1-neg0.0%
mul-1-neg0.0%
remove-double-neg0.0%
Simplified0.0%
Taylor expanded in A around 0 0.0%
if 1.55000000000000001e84 < B Initial program 6.3%
Simplified8.2%
Taylor expanded in C around 0 13.6%
mul-1-neg13.6%
distribute-rgt-neg-in13.6%
+-commutative13.6%
unpow213.6%
unpow213.6%
hypot-def59.3%
Simplified59.3%
associate-*l/59.4%
Applied egg-rr59.4%
Final simplification25.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
(let* ((t_0 (fma B B (* A (* C -4.0)))))
(if (<= B 0.0125)
(/ (- (sqrt (* 2.0 (* t_0 (* F (+ A A)))))) 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(B, B, (A * (C * -4.0)));
double tmp;
if (B <= 0.0125) {
tmp = -sqrt((2.0 * (t_0 * (F * (A + A))))) / 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(B, B, Float64(A * Float64(C * -4.0))) tmp = 0.0 if (B <= 0.0125) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(t_0 * Float64(F * Float64(A + A)))))) / t_0); else tmp = Float64(Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * 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[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 0.0125], N[((-N[Sqrt[N[(2.0 * N[(t$95$0 * N[(F * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[(N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision] / B), $MachinePrecision]]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)\\
\mathbf{if}\;B \leq 0.0125:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(t_0 \cdot \left(F \cdot \left(A + A\right)\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \left(-\sqrt{2}\right)}{B}\\
\end{array}
\end{array}
if B < 0.012500000000000001Initial program 14.4%
Simplified19.5%
associate--l+21.0%
Applied egg-rr21.0%
Taylor expanded in C around inf 15.0%
if 0.012500000000000001 < B Initial program 10.2%
Simplified11.9%
Taylor expanded in C around 0 16.3%
mul-1-neg16.3%
distribute-rgt-neg-in16.3%
+-commutative16.3%
unpow216.3%
unpow216.3%
hypot-def53.6%
Simplified53.6%
associate-*l/53.6%
Applied egg-rr53.6%
Final simplification24.6%
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 (- (sqrt 2.0))))
(if (<= B 9e-11)
(/
(* (sqrt (* (* -4.0 (* A C)) (* F (* 2.0 A)))) t_0)
(fma B B (* A (* C -4.0))))
(/ (* (sqrt (* F (- A (hypot B A)))) t_0) B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = -sqrt(2.0);
double tmp;
if (B <= 9e-11) {
tmp = (sqrt(((-4.0 * (A * C)) * (F * (2.0 * A)))) * t_0) / fma(B, B, (A * (C * -4.0)));
} else {
tmp = (sqrt((F * (A - hypot(B, A)))) * t_0) / B;
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(-sqrt(2.0)) tmp = 0.0 if (B <= 9e-11) tmp = Float64(Float64(sqrt(Float64(Float64(-4.0 * Float64(A * C)) * Float64(F * Float64(2.0 * A)))) * t_0) / fma(B, B, Float64(A * Float64(C * -4.0)))); else tmp = Float64(Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * t_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[Sqrt[2.0], $MachinePrecision])}, If[LessEqual[B, 9e-11], N[(N[(N[Sqrt[N[(N[(-4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision] * N[(F * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] / N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] / B), $MachinePrecision]]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := -\sqrt{2}\\
\mathbf{if}\;B \leq 9 \cdot 10^{-11}:\\
\;\;\;\;\frac{\sqrt{\left(-4 \cdot \left(A \cdot C\right)\right) \cdot \left(F \cdot \left(2 \cdot A\right)\right)} \cdot t_0}{\mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot t_0}{B}\\
\end{array}
\end{array}
if B < 8.9999999999999999e-11Initial program 14.5%
Simplified19.6%
Taylor expanded in C around inf 14.0%
sub-neg14.0%
mul-1-neg14.0%
remove-double-neg14.0%
Simplified14.0%
sqrt-prod14.0%
associate-*r*14.4%
count-214.4%
Applied egg-rr14.4%
associate-*r*14.4%
*-commutative14.4%
Simplified14.4%
if 8.9999999999999999e-11 < B Initial program 10.1%
Simplified11.8%
Taylor expanded in C around 0 16.2%
mul-1-neg16.2%
distribute-rgt-neg-in16.2%
+-commutative16.2%
unpow216.2%
unpow216.2%
hypot-def52.9%
Simplified52.9%
associate-*l/52.9%
Applied egg-rr52.9%
Final simplification24.1%
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 (<= B 8.2e-11)
(/
(- (sqrt (* -8.0 (* (* A C) (* F (* 2.0 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 (B <= 8.2e-11) {
tmp = -sqrt((-8.0 * ((A * C) * (F * (2.0 * 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 <= 8.2e-11) tmp = Float64(Float64(-sqrt(Float64(-8.0 * Float64(Float64(A * C) * Float64(F * Float64(2.0 * 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[B, 8.2e-11], N[((-N[Sqrt[N[(-8.0 * N[(N[(A * C), $MachinePrecision] * N[(F * N[(2.0 * A), $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 \leq 8.2 \cdot 10^{-11}:\\
\;\;\;\;\frac{-\sqrt{-8 \cdot \left(\left(A \cdot C\right) \cdot \left(F \cdot \left(2 \cdot A\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 B < 8.2000000000000001e-11Initial program 14.5%
Simplified19.6%
Taylor expanded in C around inf 14.0%
sub-neg14.0%
mul-1-neg14.0%
remove-double-neg14.0%
Simplified14.0%
distribute-frac-neg14.0%
associate-*r*14.0%
metadata-eval14.0%
associate-*r*14.4%
count-214.4%
*-commutative14.4%
Applied egg-rr14.4%
if 8.2000000000000001e-11 < B Initial program 10.1%
Simplified11.8%
Taylor expanded in C around 0 16.2%
mul-1-neg16.2%
distribute-rgt-neg-in16.2%
+-commutative16.2%
unpow216.2%
unpow216.2%
hypot-def52.9%
Simplified52.9%
Final simplification24.2%
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 (<= B 1.02e-10)
(/
(- (sqrt (* -8.0 (* (* A C) (* F (* 2.0 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 (B <= 1.02e-10) {
tmp = -sqrt((-8.0 * ((A * C) * (F * (2.0 * 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 <= 1.02e-10) tmp = Float64(Float64(-sqrt(Float64(-8.0 * Float64(Float64(A * C) * Float64(F * Float64(2.0 * A)))))) / fma(B, B, Float64(A * Float64(C * -4.0)))); else tmp = Float64(Float64(sqrt(Float64(F * Float64(A - hypot(B, A)))) * 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[B, 1.02e-10], N[((-N[Sqrt[N[(-8.0 * N[(N[(A * C), $MachinePrecision] * N[(F * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision] / B), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;B \leq 1.02 \cdot 10^{-10}:\\
\;\;\;\;\frac{-\sqrt{-8 \cdot \left(\left(A \cdot C\right) \cdot \left(F \cdot \left(2 \cdot A\right)\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)} \cdot \left(-\sqrt{2}\right)}{B}\\
\end{array}
\end{array}
if B < 1.01999999999999997e-10Initial program 14.5%
Simplified19.6%
Taylor expanded in C around inf 14.0%
sub-neg14.0%
mul-1-neg14.0%
remove-double-neg14.0%
Simplified14.0%
distribute-frac-neg14.0%
associate-*r*14.0%
metadata-eval14.0%
associate-*r*14.4%
count-214.4%
*-commutative14.4%
Applied egg-rr14.4%
if 1.01999999999999997e-10 < B Initial program 10.1%
Simplified11.8%
Taylor expanded in C around 0 16.2%
mul-1-neg16.2%
distribute-rgt-neg-in16.2%
+-commutative16.2%
unpow216.2%
unpow216.2%
hypot-def52.9%
Simplified52.9%
associate-*l/52.9%
Applied egg-rr52.9%
Final simplification24.2%
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 (<= B 2.6e-10)
(/
(- (sqrt (* -8.0 (* (* A C) (* F (* 2.0 A))))))
(fma B B (* A (* C -4.0))))
(* (/ (sqrt 2.0) B) (- (sqrt (- (* A F) (* B F)))))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double tmp;
if (B <= 2.6e-10) {
tmp = -sqrt((-8.0 * ((A * C) * (F * (2.0 * A))))) / fma(B, B, (A * (C * -4.0)));
} else {
tmp = (sqrt(2.0) / B) * -sqrt(((A * F) - (B * F)));
}
return tmp;
}
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) tmp = 0.0 if (B <= 2.6e-10) tmp = Float64(Float64(-sqrt(Float64(-8.0 * Float64(Float64(A * C) * Float64(F * Float64(2.0 * A)))))) / fma(B, B, Float64(A * Float64(C * -4.0)))); else tmp = Float64(Float64(sqrt(2.0) / B) * Float64(-sqrt(Float64(Float64(A * F) - Float64(B * F))))); 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[B, 2.6e-10], N[((-N[Sqrt[N[(-8.0 * N[(N[(A * C), $MachinePrecision] * N[(F * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision] * (-N[Sqrt[N[(N[(A * F), $MachinePrecision] - N[(B * F), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;B \leq 2.6 \cdot 10^{-10}:\\
\;\;\;\;\frac{-\sqrt{-8 \cdot \left(\left(A \cdot C\right) \cdot \left(F \cdot \left(2 \cdot A\right)\right)\right)}}{\mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{2}}{B} \cdot \left(-\sqrt{A \cdot F - B \cdot F}\right)\\
\end{array}
\end{array}
if B < 2.59999999999999981e-10Initial program 14.5%
Simplified19.6%
Taylor expanded in C around inf 14.0%
sub-neg14.0%
mul-1-neg14.0%
remove-double-neg14.0%
Simplified14.0%
distribute-frac-neg14.0%
associate-*r*14.0%
metadata-eval14.0%
associate-*r*14.4%
count-214.4%
*-commutative14.4%
Applied egg-rr14.4%
if 2.59999999999999981e-10 < B Initial program 10.1%
Simplified11.8%
Taylor expanded in C around 0 16.2%
mul-1-neg16.2%
distribute-rgt-neg-in16.2%
+-commutative16.2%
unpow216.2%
unpow216.2%
hypot-def52.9%
Simplified52.9%
Taylor expanded in A around 0 47.2%
Final simplification22.7%
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 (* (/ (sqrt 2.0) B) (- (sqrt (* B (- F))))))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return (sqrt(2.0) / B) * -sqrt((B * -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 = (sqrt(2.0d0) / b) * -sqrt((b * -f))
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return (Math.sqrt(2.0) / B) * -Math.sqrt((B * -F));
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return (math.sqrt(2.0) / B) * -math.sqrt((B * -F))
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(sqrt(2.0) / B) * Float64(-sqrt(Float64(B * Float64(-F))))) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = (sqrt(2.0) / B) * -sqrt((B * -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[(N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision] * (-N[Sqrt[N[(B * (-F)), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\frac{\sqrt{2}}{B} \cdot \left(-\sqrt{B \cdot \left(-F\right)}\right)
\end{array}
Initial program 13.3%
Simplified17.6%
Taylor expanded in C around 0 6.6%
mul-1-neg6.6%
distribute-rgt-neg-in6.6%
+-commutative6.6%
unpow26.6%
unpow26.6%
hypot-def17.1%
Simplified17.1%
Taylor expanded in A around 0 14.5%
associate-*r*14.5%
mul-1-neg14.5%
Simplified14.5%
Final simplification14.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 (- (* (/ (sqrt 2.0) B) (sqrt (* B F)))))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -((sqrt(2.0) / B) * sqrt((B * 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 = -((sqrt(2.0d0) / b) * sqrt((b * f)))
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return -((Math.sqrt(2.0) / B) * Math.sqrt((B * F)));
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -((math.sqrt(2.0) / B) * math.sqrt((B * F)))
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(-Float64(Float64(sqrt(2.0) / B) * sqrt(Float64(B * F)))) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -((sqrt(2.0) / B) * sqrt((B * 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[(N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision] * N[Sqrt[N[(B * F), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
-\frac{\sqrt{2}}{B} \cdot \sqrt{B \cdot F}
\end{array}
Initial program 13.3%
Simplified17.6%
Taylor expanded in C around 0 6.6%
mul-1-neg6.6%
distribute-rgt-neg-in6.6%
+-commutative6.6%
unpow26.6%
unpow26.6%
hypot-def17.1%
Simplified17.1%
Taylor expanded in B around -inf 1.7%
Final simplification1.7%
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 (* (* -0.25 (sqrt (/ F C))) (sqrt -16.0)))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return (-0.25 * sqrt((F / C))) * sqrt(-16.0);
}
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 = ((-0.25d0) * sqrt((f / c))) * sqrt((-16.0d0))
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return (-0.25 * Math.sqrt((F / C))) * Math.sqrt(-16.0);
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return (-0.25 * math.sqrt((F / C))) * math.sqrt(-16.0)
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(-0.25 * sqrt(Float64(F / C))) * sqrt(-16.0)) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = (-0.25 * sqrt((F / C))) * sqrt(-16.0);
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[(-0.25 * N[Sqrt[N[(F / C), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[-16.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\left(-0.25 \cdot \sqrt{\frac{F}{C}}\right) \cdot \sqrt{-16}
\end{array}
Initial program 13.3%
Simplified17.6%
Taylor expanded in C around inf 11.5%
sub-neg11.5%
mul-1-neg11.5%
remove-double-neg11.5%
Simplified11.5%
Taylor expanded in A around -inf 0.0%
associate-*r*0.0%
Simplified0.0%
Final simplification0.0%
herbie shell --seed 2024024
(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))))