
(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 8 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 (- (* B B) (* 4.0 (* A C)))))
(if (<= B 3.6e+27)
(/ (- (sqrt (* 2.0 (* (* t_0 F) (+ A A))))) t_0)
(- (/ (sqrt (* 2.0 (* F (- A (hypot B A))))) B)))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double tmp;
if (B <= 3.6e+27) {
tmp = -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
} else {
tmp = -(sqrt((2.0 * (F * (A - hypot(B, A))))) / B);
}
return tmp;
}
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double tmp;
if (B <= 3.6e+27) {
tmp = -Math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
} else {
tmp = -(Math.sqrt((2.0 * (F * (A - Math.hypot(B, A))))) / B);
}
return tmp;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): t_0 = (B * B) - (4.0 * (A * C)) tmp = 0 if B <= 3.6e+27: tmp = -math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0 else: tmp = -(math.sqrt((2.0 * (F * (A - math.hypot(B, A))))) / B) return tmp
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(Float64(B * B) - Float64(4.0 * Float64(A * C))) tmp = 0.0 if (B <= 3.6e+27) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(t_0 * F) * Float64(A + A))))) / t_0); else tmp = Float64(-Float64(sqrt(Float64(2.0 * Float64(F * Float64(A - hypot(B, A))))) / B)); end return tmp end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (B * B) - (4.0 * (A * C));
tmp = 0.0;
if (B <= 3.6e+27)
tmp = -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
else
tmp = -(sqrt((2.0 * (F * (A - hypot(B, A))))) / B);
end
tmp_2 = 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[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 3.6e+27], N[((-N[Sqrt[N[(2.0 * N[(N[(t$95$0 * F), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], (-N[(N[Sqrt[N[(2.0 * N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / B), $MachinePrecision])]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := B \cdot B - 4 \cdot \left(A \cdot C\right)\\
\mathbf{if}\;B \leq 3.6 \cdot 10^{+27}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(t_0 \cdot F\right) \cdot \left(A + A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\sqrt{2 \cdot \left(F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)\right)}}{B}\\
\end{array}
\end{array}
if B < 3.59999999999999983e27Initial program 19.9%
Simplified19.9%
Taylor expanded in C around inf 16.7%
cancel-sign-sub-inv16.7%
metadata-eval16.7%
*-lft-identity16.7%
Simplified16.7%
if 3.59999999999999983e27 < B Initial program 13.0%
Simplified13.0%
Taylor expanded in C around 0 27.8%
mul-1-neg27.8%
associate-*l/27.8%
distribute-neg-frac27.8%
unpow227.8%
unpow227.8%
hypot-def57.2%
Simplified57.2%
div-inv57.2%
sqrt-unprod57.3%
*-commutative57.3%
Applied egg-rr57.3%
associate-*r/57.3%
Simplified57.3%
Final simplification25.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
(let* ((t_0 (- (* B B) (* 4.0 (* A C)))))
(if (<= B 8.8e+36)
(/ (- (sqrt (* 2.0 (* (* t_0 F) (+ A A))))) t_0)
(/ (* (sqrt (* F (- A B))) (- (sqrt 2.0))) B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double tmp;
if (B <= 8.8e+36) {
tmp = -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
} else {
tmp = (sqrt((F * (A - B))) * -sqrt(2.0)) / B;
}
return tmp;
}
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
real(8) :: t_0
real(8) :: tmp
t_0 = (b * b) - (4.0d0 * (a * c))
if (b <= 8.8d+36) then
tmp = -sqrt((2.0d0 * ((t_0 * f) * (a + a)))) / t_0
else
tmp = (sqrt((f * (a - b))) * -sqrt(2.0d0)) / b
end if
code = tmp
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double tmp;
if (B <= 8.8e+36) {
tmp = -Math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
} else {
tmp = (Math.sqrt((F * (A - B))) * -Math.sqrt(2.0)) / B;
}
return tmp;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): t_0 = (B * B) - (4.0 * (A * C)) tmp = 0 if B <= 8.8e+36: tmp = -math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0 else: tmp = (math.sqrt((F * (A - B))) * -math.sqrt(2.0)) / B return tmp
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(Float64(B * B) - Float64(4.0 * Float64(A * C))) tmp = 0.0 if (B <= 8.8e+36) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(t_0 * F) * Float64(A + A))))) / t_0); else tmp = Float64(Float64(sqrt(Float64(F * Float64(A - B))) * Float64(-sqrt(2.0))) / B); end return tmp end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (B * B) - (4.0 * (A * C));
tmp = 0.0;
if (B <= 8.8e+36)
tmp = -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
else
tmp = (sqrt((F * (A - B))) * -sqrt(2.0)) / B;
end
tmp_2 = 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[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 8.8e+36], N[((-N[Sqrt[N[(2.0 * N[(N[(t$95$0 * F), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[(N[(N[Sqrt[N[(F * N[(A - B), $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 := B \cdot B - 4 \cdot \left(A \cdot C\right)\\
\mathbf{if}\;B \leq 8.8 \cdot 10^{+36}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(t_0 \cdot F\right) \cdot \left(A + A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{F \cdot \left(A - B\right)} \cdot \left(-\sqrt{2}\right)}{B}\\
\end{array}
\end{array}
if B < 8.80000000000000002e36Initial program 20.2%
Simplified20.2%
Taylor expanded in C around inf 16.6%
cancel-sign-sub-inv16.6%
metadata-eval16.6%
*-lft-identity16.6%
Simplified16.6%
if 8.80000000000000002e36 < B Initial program 11.6%
Simplified11.6%
Taylor expanded in C around 0 28.6%
mul-1-neg28.6%
associate-*l/28.6%
distribute-neg-frac28.6%
unpow228.6%
unpow228.6%
hypot-def59.1%
Simplified59.1%
Taylor expanded in A around 0 51.7%
mul-1-neg51.7%
unsub-neg51.7%
Simplified51.7%
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
(let* ((t_0 (- (* B B) (* 4.0 (* A C)))))
(if (<= B 7e+36)
(/ (- (sqrt (* 2.0 (* (* t_0 F) (+ A A))))) t_0)
(/ (* (sqrt (* B (- F))) (- (sqrt 2.0))) B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double tmp;
if (B <= 7e+36) {
tmp = -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
} else {
tmp = (sqrt((B * -F)) * -sqrt(2.0)) / B;
}
return tmp;
}
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
real(8) :: t_0
real(8) :: tmp
t_0 = (b * b) - (4.0d0 * (a * c))
if (b <= 7d+36) then
tmp = -sqrt((2.0d0 * ((t_0 * f) * (a + a)))) / t_0
else
tmp = (sqrt((b * -f)) * -sqrt(2.0d0)) / b
end if
code = tmp
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double tmp;
if (B <= 7e+36) {
tmp = -Math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
} else {
tmp = (Math.sqrt((B * -F)) * -Math.sqrt(2.0)) / B;
}
return tmp;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): t_0 = (B * B) - (4.0 * (A * C)) tmp = 0 if B <= 7e+36: tmp = -math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0 else: tmp = (math.sqrt((B * -F)) * -math.sqrt(2.0)) / B return tmp
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(Float64(B * B) - Float64(4.0 * Float64(A * C))) tmp = 0.0 if (B <= 7e+36) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(t_0 * F) * Float64(A + A))))) / t_0); else tmp = Float64(Float64(sqrt(Float64(B * Float64(-F))) * Float64(-sqrt(2.0))) / B); end return tmp end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (B * B) - (4.0 * (A * C));
tmp = 0.0;
if (B <= 7e+36)
tmp = -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
else
tmp = (sqrt((B * -F)) * -sqrt(2.0)) / B;
end
tmp_2 = 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[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 7e+36], N[((-N[Sqrt[N[(2.0 * N[(N[(t$95$0 * F), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[(N[(N[Sqrt[N[(B * (-F)), $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 := B \cdot B - 4 \cdot \left(A \cdot C\right)\\
\mathbf{if}\;B \leq 7 \cdot 10^{+36}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(\left(t_0 \cdot F\right) \cdot \left(A + A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{B \cdot \left(-F\right)} \cdot \left(-\sqrt{2}\right)}{B}\\
\end{array}
\end{array}
if B < 6.9999999999999996e36Initial program 20.2%
Simplified20.2%
Taylor expanded in C around inf 16.6%
cancel-sign-sub-inv16.6%
metadata-eval16.6%
*-lft-identity16.6%
Simplified16.6%
if 6.9999999999999996e36 < B Initial program 11.6%
Simplified11.6%
Taylor expanded in C around 0 28.6%
mul-1-neg28.6%
associate-*l/28.6%
distribute-neg-frac28.6%
unpow228.6%
unpow228.6%
hypot-def59.1%
Simplified59.1%
Taylor expanded in A around 0 51.3%
mul-1-neg51.3%
Simplified51.3%
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
(let* ((t_0 (- (* B B) (* 4.0 (* A C)))) (t_1 (* t_0 F)))
(if (<= B 1.1e+37)
(/ (- (sqrt (* 2.0 (* t_1 (+ A A))))) t_0)
(/ (- (sqrt (* 2.0 (* t_1 (+ A (- C B)))))) t_0))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double t_1 = t_0 * F;
double tmp;
if (B <= 1.1e+37) {
tmp = -sqrt((2.0 * (t_1 * (A + A)))) / t_0;
} else {
tmp = -sqrt((2.0 * (t_1 * (A + (C - B))))) / t_0;
}
return tmp;
}
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
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (b * b) - (4.0d0 * (a * c))
t_1 = t_0 * f
if (b <= 1.1d+37) then
tmp = -sqrt((2.0d0 * (t_1 * (a + a)))) / t_0
else
tmp = -sqrt((2.0d0 * (t_1 * (a + (c - b))))) / t_0
end if
code = tmp
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
double t_1 = t_0 * F;
double tmp;
if (B <= 1.1e+37) {
tmp = -Math.sqrt((2.0 * (t_1 * (A + A)))) / t_0;
} else {
tmp = -Math.sqrt((2.0 * (t_1 * (A + (C - B))))) / t_0;
}
return tmp;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): t_0 = (B * B) - (4.0 * (A * C)) t_1 = t_0 * F tmp = 0 if B <= 1.1e+37: tmp = -math.sqrt((2.0 * (t_1 * (A + A)))) / t_0 else: tmp = -math.sqrt((2.0 * (t_1 * (A + (C - B))))) / t_0 return tmp
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(Float64(B * B) - Float64(4.0 * Float64(A * C))) t_1 = Float64(t_0 * F) tmp = 0.0 if (B <= 1.1e+37) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(t_1 * Float64(A + A))))) / t_0); else tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(t_1 * Float64(A + Float64(C - B)))))) / t_0); end return tmp end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp_2 = code(A, B, C, F)
t_0 = (B * B) - (4.0 * (A * C));
t_1 = t_0 * F;
tmp = 0.0;
if (B <= 1.1e+37)
tmp = -sqrt((2.0 * (t_1 * (A + A)))) / t_0;
else
tmp = -sqrt((2.0 * (t_1 * (A + (C - B))))) / t_0;
end
tmp_2 = 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[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * F), $MachinePrecision]}, If[LessEqual[B, 1.1e+37], N[((-N[Sqrt[N[(2.0 * N[(t$95$1 * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[((-N[Sqrt[N[(2.0 * N[(t$95$1 * N[(A + N[(C - B), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision]]]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := B \cdot B - 4 \cdot \left(A \cdot C\right)\\
t_1 := t_0 \cdot F\\
\mathbf{if}\;B \leq 1.1 \cdot 10^{+37}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(t_1 \cdot \left(A + A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(t_1 \cdot \left(A + \left(C - B\right)\right)\right)}}{t_0}\\
\end{array}
\end{array}
if B < 1.1e37Initial program 20.2%
Simplified20.2%
Taylor expanded in C around inf 16.6%
cancel-sign-sub-inv16.6%
metadata-eval16.6%
*-lft-identity16.6%
Simplified16.6%
if 1.1e37 < B Initial program 11.6%
Simplified11.6%
Taylor expanded in B around inf 10.1%
mul-1-neg10.1%
unsub-neg10.1%
Simplified10.1%
Final simplification15.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 (let* ((t_0 (- (* B B) (* 4.0 (* A C))))) (/ (- (sqrt (* 2.0 (* (* t_0 F) (+ A A))))) t_0)))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
return -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_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
real(8) :: t_0
t_0 = (b * b) - (4.0d0 * (a * c))
code = -sqrt((2.0d0 * ((t_0 * f) * (a + a)))) / t_0
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
double t_0 = (B * B) - (4.0 * (A * C));
return -Math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): t_0 = (B * B) - (4.0 * (A * C)) return -math.sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_0
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(Float64(B * B) - Float64(4.0 * Float64(A * C))) return Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(t_0 * F) * Float64(A + A))))) / t_0) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
t_0 = (B * B) - (4.0 * (A * C));
tmp = -sqrt((2.0 * ((t_0 * F) * (A + A)))) / t_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_] := Block[{t$95$0 = N[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(2.0 * N[(N[(t$95$0 * F), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := B \cdot B - 4 \cdot \left(A \cdot C\right)\\
\frac{-\sqrt{2 \cdot \left(\left(t_0 \cdot F\right) \cdot \left(A + A\right)\right)}}{t_0}
\end{array}
\end{array}
Initial program 18.4%
Simplified18.4%
Taylor expanded in C around inf 13.2%
cancel-sign-sub-inv13.2%
metadata-eval13.2%
*-lft-identity13.2%
Simplified13.2%
Final simplification13.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 (/ (- (sqrt (* 2.0 (* (* -4.0 (* A (* C F))) (+ C C))))) (- (* B B) (* 4.0 (* A C)))))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -sqrt((2.0 * ((-4.0 * (A * (C * F))) * (C + C)))) / ((B * B) - (4.0 * (A * C)));
}
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 * (((-4.0d0) * (a * (c * f))) * (c + c)))) / ((b * b) - (4.0d0 * (a * c)))
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 * ((-4.0 * (A * (C * F))) * (C + C)))) / ((B * B) - (4.0 * (A * C)));
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -math.sqrt((2.0 * ((-4.0 * (A * (C * F))) * (C + C)))) / ((B * B) - (4.0 * (A * C)))
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(-4.0 * Float64(A * Float64(C * F))) * Float64(C + C))))) / Float64(Float64(B * B) - Float64(4.0 * Float64(A * C)))) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -sqrt((2.0 * ((-4.0 * (A * (C * F))) * (C + C)))) / ((B * B) - (4.0 * (A * C)));
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[Sqrt[N[(2.0 * N[(N[(-4.0 * N[(A * N[(C * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(C + C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\frac{-\sqrt{2 \cdot \left(\left(-4 \cdot \left(A \cdot \left(C \cdot F\right)\right)\right) \cdot \left(C + C\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\end{array}
Initial program 18.4%
Simplified18.4%
Taylor expanded in A around inf 17.2%
cancel-sign-sub-inv17.2%
metadata-eval17.2%
*-lft-identity17.2%
Simplified17.2%
Taylor expanded in B around 0 14.3%
Final simplification14.3%
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 (* (+ C C) (* (* B B) F))))) (- (* B B) (* 4.0 (* A C)))))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -sqrt((2.0 * ((C + C) * ((B * B) * F)))) / ((B * B) - (4.0 * (A * C)));
}
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 * ((c + c) * ((b * b) * f)))) / ((b * b) - (4.0d0 * (a * c)))
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 * ((C + C) * ((B * B) * F)))) / ((B * B) - (4.0 * (A * C)));
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -math.sqrt((2.0 * ((C + C) * ((B * B) * F)))) / ((B * B) - (4.0 * (A * C)))
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(-sqrt(Float64(2.0 * Float64(Float64(C + C) * Float64(Float64(B * B) * F))))) / Float64(Float64(B * B) - Float64(4.0 * Float64(A * C)))) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -sqrt((2.0 * ((C + C) * ((B * B) * F)))) / ((B * B) - (4.0 * (A * C)));
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[Sqrt[N[(2.0 * N[(N[(C + C), $MachinePrecision] * N[(N[(B * B), $MachinePrecision] * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\frac{-\sqrt{2 \cdot \left(\left(C + C\right) \cdot \left(\left(B \cdot B\right) \cdot F\right)\right)}}{B \cdot B - 4 \cdot \left(A \cdot C\right)}
\end{array}
Initial program 18.4%
Simplified18.4%
Taylor expanded in A around inf 17.2%
cancel-sign-sub-inv17.2%
metadata-eval17.2%
*-lft-identity17.2%
Simplified17.2%
Taylor expanded in B around inf 4.0%
unpow24.0%
Simplified4.0%
Final simplification4.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 (/ (sqrt (* C F)) B)))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -2.0 * (sqrt((C * F)) / 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) * (sqrt((c * f)) / 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.sqrt((C * F)) / B);
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -2.0 * (math.sqrt((C * F)) / B)
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(-2.0 * Float64(sqrt(Float64(C * F)) / B)) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -2.0 * (sqrt((C * F)) / 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[(-2.0 * N[(N[Sqrt[N[(C * F), $MachinePrecision]], $MachinePrecision] / B), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
-2 \cdot \frac{\sqrt{C \cdot F}}{B}
\end{array}
Initial program 18.4%
Simplified18.4%
Taylor expanded in A around inf 17.2%
cancel-sign-sub-inv17.2%
metadata-eval17.2%
*-lft-identity17.2%
Simplified17.2%
Taylor expanded in B around inf 4.1%
associate-*l/4.1%
*-lft-identity4.1%
*-commutative4.1%
Simplified4.1%
Final simplification4.1%
herbie shell --seed 2023283
(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))))