
(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 (- (* B B) (* 4.0 (* A C)))))
(if (<= (pow B 2.0) 1e+51)
(/ (- (sqrt (* (* 2.0 (* t_0 F)) (+ A A)))) t_0)
(* (- (/ (sqrt 2.0) B)) (sqrt (* F (- A (hypot B A))))))))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 (pow(B, 2.0) <= 1e+51) {
tmp = -sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0;
} else {
tmp = -(sqrt(2.0) / B) * sqrt((F * (A - hypot(B, A))));
}
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 (Math.pow(B, 2.0) <= 1e+51) {
tmp = -Math.sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0;
} else {
tmp = -(Math.sqrt(2.0) / B) * Math.sqrt((F * (A - Math.hypot(B, A))));
}
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 math.pow(B, 2.0) <= 1e+51: tmp = -math.sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0 else: tmp = -(math.sqrt(2.0) / B) * math.sqrt((F * (A - math.hypot(B, A)))) 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 ^ 2.0) <= 1e+51) tmp = Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(A + A)))) / t_0); else tmp = Float64(Float64(-Float64(sqrt(2.0) / B)) * sqrt(Float64(F * Float64(A - hypot(B, A))))); 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 ^ 2.0) <= 1e+51)
tmp = -sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0;
else
tmp = -(sqrt(2.0) / B) * sqrt((F * (A - hypot(B, A))));
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[N[Power[B, 2.0], $MachinePrecision], 1e+51], N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[((-N[(N[Sqrt[2.0], $MachinePrecision] / B), $MachinePrecision]) * N[Sqrt[N[(F * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $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}^{2} \leq 10^{+51}:\\
\;\;\;\;\frac{-\sqrt{\left(2 \cdot \left(t_0 \cdot F\right)\right) \cdot \left(A + A\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\left(-\frac{\sqrt{2}}{B}\right) \cdot \sqrt{F \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 1e51Initial program 23.6%
Simplified23.6%
Taylor expanded in C around inf 21.1%
sub-neg21.1%
mul-1-neg21.1%
remove-double-neg21.1%
Simplified21.1%
if 1e51 < (pow.f64 B 2) Initial program 11.8%
Simplified11.8%
Taylor expanded in C around 0 9.5%
associate-*r*9.5%
mul-1-neg9.5%
+-commutative9.5%
unpow29.5%
unpow29.5%
hypot-def22.7%
Simplified22.7%
Final simplification21.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 (- (* B B) (* 4.0 (* A C)))) (t_1 (* 2.0 (* t_0 F))))
(if (<= C 2e+26)
(/ (- (sqrt (* t_1 (- A (hypot B A))))) t_0)
(/
(-
(sqrt (* t_1 (+ A (fma -0.5 (/ (- (+ (* B B) (* A A)) (* A A)) C) 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));
double t_1 = 2.0 * (t_0 * F);
double tmp;
if (C <= 2e+26) {
tmp = -sqrt((t_1 * (A - hypot(B, A)))) / t_0;
} else {
tmp = -sqrt((t_1 * (A + fma(-0.5, ((((B * B) + (A * A)) - (A * A)) / C), A)))) / 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(2.0 * Float64(t_0 * F)) tmp = 0.0 if (C <= 2e+26) tmp = Float64(Float64(-sqrt(Float64(t_1 * Float64(A - hypot(B, A))))) / t_0); else tmp = Float64(Float64(-sqrt(Float64(t_1 * Float64(A + fma(-0.5, Float64(Float64(Float64(Float64(B * B) + Float64(A * A)) - Float64(A * A)) / C), A))))) / t_0); 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[(N[(B * B), $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[C, 2e+26], N[((-N[Sqrt[N[(t$95$1 * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[((-N[Sqrt[N[(t$95$1 * N[(A + N[(-0.5 * N[(N[(N[(N[(B * B), $MachinePrecision] + N[(A * A), $MachinePrecision]), $MachinePrecision] - N[(A * A), $MachinePrecision]), $MachinePrecision] / C), $MachinePrecision] + 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)\\
t_1 := 2 \cdot \left(t_0 \cdot F\right)\\
\mathbf{if}\;C \leq 2 \cdot 10^{+26}:\\
\;\;\;\;\frac{-\sqrt{t_1 \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{t_1 \cdot \left(A + \mathsf{fma}\left(-0.5, \frac{\left(B \cdot B + A \cdot A\right) - A \cdot A}{C}, A\right)\right)}}{t_0}\\
\end{array}
\end{array}
if C < 2.0000000000000001e26Initial program 21.9%
Simplified21.9%
Taylor expanded in C around 0 16.6%
+-commutative16.6%
unpow216.6%
unpow216.6%
hypot-def20.1%
Simplified20.1%
if 2.0000000000000001e26 < C Initial program 3.3%
Simplified3.3%
Taylor expanded in C around inf 27.3%
associate--l+27.3%
fma-neg27.3%
+-commutative27.3%
unpow227.3%
unpow227.3%
unpow227.3%
mul-1-neg27.3%
mul-1-neg27.3%
sqr-neg27.3%
mul-1-neg27.3%
remove-double-neg27.3%
Simplified27.3%
Final simplification21.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 (- (* B B) (* 4.0 (* A C)))) (t_1 (* 2.0 (* t_0 F))))
(if (<= C 5.2e+18)
(/ (- (sqrt (* t_1 (- A (hypot B A))))) t_0)
(/ (- (sqrt (* t_1 (+ 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));
double t_1 = 2.0 * (t_0 * F);
double tmp;
if (C <= 5.2e+18) {
tmp = -sqrt((t_1 * (A - hypot(B, A)))) / t_0;
} else {
tmp = -sqrt((t_1 * (A + A))) / t_0;
}
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 t_1 = 2.0 * (t_0 * F);
double tmp;
if (C <= 5.2e+18) {
tmp = -Math.sqrt((t_1 * (A - Math.hypot(B, A)))) / t_0;
} else {
tmp = -Math.sqrt((t_1 * (A + A))) / 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 = 2.0 * (t_0 * F) tmp = 0 if C <= 5.2e+18: tmp = -math.sqrt((t_1 * (A - math.hypot(B, A)))) / t_0 else: tmp = -math.sqrt((t_1 * (A + A))) / 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(2.0 * Float64(t_0 * F)) tmp = 0.0 if (C <= 5.2e+18) tmp = Float64(Float64(-sqrt(Float64(t_1 * Float64(A - hypot(B, A))))) / t_0); else tmp = Float64(Float64(-sqrt(Float64(t_1 * Float64(A + A)))) / 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 = 2.0 * (t_0 * F);
tmp = 0.0;
if (C <= 5.2e+18)
tmp = -sqrt((t_1 * (A - hypot(B, A)))) / t_0;
else
tmp = -sqrt((t_1 * (A + A))) / 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[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[C, 5.2e+18], N[((-N[Sqrt[N[(t$95$1 * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[((-N[Sqrt[N[(t$95$1 * N[(A + A), $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 := 2 \cdot \left(t_0 \cdot F\right)\\
\mathbf{if}\;C \leq 5.2 \cdot 10^{+18}:\\
\;\;\;\;\frac{-\sqrt{t_1 \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{t_1 \cdot \left(A + A\right)}}{t_0}\\
\end{array}
\end{array}
if C < 5.2e18Initial program 21.4%
Simplified21.4%
Taylor expanded in C around 0 16.3%
+-commutative16.3%
unpow216.3%
unpow216.3%
hypot-def19.4%
Simplified19.4%
if 5.2e18 < C Initial program 6.2%
Simplified6.2%
Taylor expanded in C around inf 20.6%
sub-neg20.6%
mul-1-neg20.6%
remove-double-neg20.6%
Simplified20.6%
Final simplification19.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
(let* ((t_0 (- (* B B) (* 4.0 (* A C)))) (t_1 (* 2.0 (* t_0 F))))
(if (<= B 3.8e+45)
(/ (- (sqrt (* t_1 (+ A A)))) t_0)
(if (<= B 1.3e+129) (/ (- (sqrt (* t_1 (+ A (- C B))))) t_0) -1.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 = 2.0 * (t_0 * F);
double tmp;
if (B <= 3.8e+45) {
tmp = -sqrt((t_1 * (A + A))) / t_0;
} else if (B <= 1.3e+129) {
tmp = -sqrt((t_1 * (A + (C - B)))) / t_0;
} else {
tmp = -1.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 = 2.0d0 * (t_0 * f)
if (b <= 3.8d+45) then
tmp = -sqrt((t_1 * (a + a))) / t_0
else if (b <= 1.3d+129) then
tmp = -sqrt((t_1 * (a + (c - b)))) / t_0
else
tmp = -1.0d0
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 = 2.0 * (t_0 * F);
double tmp;
if (B <= 3.8e+45) {
tmp = -Math.sqrt((t_1 * (A + A))) / t_0;
} else if (B <= 1.3e+129) {
tmp = -Math.sqrt((t_1 * (A + (C - B)))) / t_0;
} else {
tmp = -1.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 = 2.0 * (t_0 * F) tmp = 0 if B <= 3.8e+45: tmp = -math.sqrt((t_1 * (A + A))) / t_0 elif B <= 1.3e+129: tmp = -math.sqrt((t_1 * (A + (C - B)))) / t_0 else: tmp = -1.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(2.0 * Float64(t_0 * F)) tmp = 0.0 if (B <= 3.8e+45) tmp = Float64(Float64(-sqrt(Float64(t_1 * Float64(A + A)))) / t_0); elseif (B <= 1.3e+129) tmp = Float64(Float64(-sqrt(Float64(t_1 * Float64(A + Float64(C - B))))) / t_0); else tmp = -1.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 = 2.0 * (t_0 * F);
tmp = 0.0;
if (B <= 3.8e+45)
tmp = -sqrt((t_1 * (A + A))) / t_0;
elseif (B <= 1.3e+129)
tmp = -sqrt((t_1 * (A + (C - B)))) / t_0;
else
tmp = -1.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[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 3.8e+45], N[((-N[Sqrt[N[(t$95$1 * N[(A + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], If[LessEqual[B, 1.3e+129], N[((-N[Sqrt[N[(t$95$1 * N[(A + N[(C - B), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], -1.0]]]]
\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 := 2 \cdot \left(t_0 \cdot F\right)\\
\mathbf{if}\;B \leq 3.8 \cdot 10^{+45}:\\
\;\;\;\;\frac{-\sqrt{t_1 \cdot \left(A + A\right)}}{t_0}\\
\mathbf{elif}\;B \leq 1.3 \cdot 10^{+129}:\\
\;\;\;\;\frac{-\sqrt{t_1 \cdot \left(A + \left(C - B\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if B < 3.8000000000000002e45Initial program 18.8%
Simplified18.8%
Taylor expanded in C around inf 15.8%
sub-neg15.8%
mul-1-neg15.8%
remove-double-neg15.8%
Simplified15.8%
if 3.8000000000000002e45 < B < 1.30000000000000006e129Initial program 38.0%
Simplified38.0%
Taylor expanded in B around inf 34.8%
mul-1-neg34.8%
unsub-neg34.8%
Simplified34.8%
if 1.30000000000000006e129 < B Initial program 0.4%
Simplified0.4%
frac-2neg0.4%
remove-double-neg0.4%
div-inv0.4%
fma-neg0.4%
distribute-lft-neg-in0.4%
metadata-eval0.4%
*-commutative0.4%
associate-*r*0.4%
Applied egg-rr0.4%
Applied egg-rr6.3%
Final simplification16.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 8.4e+77) (/ (- (sqrt (* (* 2.0 (* t_0 F)) (+ A A)))) t_0) -1.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 tmp;
if (B <= 8.4e+77) {
tmp = -sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0;
} else {
tmp = -1.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) :: tmp
t_0 = (b * b) - (4.0d0 * (a * c))
if (b <= 8.4d+77) then
tmp = -sqrt(((2.0d0 * (t_0 * f)) * (a + a))) / t_0
else
tmp = -1.0d0
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.4e+77) {
tmp = -Math.sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0;
} else {
tmp = -1.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)) tmp = 0 if B <= 8.4e+77: tmp = -math.sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0 else: tmp = -1.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))) tmp = 0.0 if (B <= 8.4e+77) tmp = Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(A + A)))) / t_0); else tmp = -1.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));
tmp = 0.0;
if (B <= 8.4e+77)
tmp = -sqrt(((2.0 * (t_0 * F)) * (A + A))) / t_0;
else
tmp = -1.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]}, If[LessEqual[B, 8.4e+77], N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], -1.0]]
\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.4 \cdot 10^{+77}:\\
\;\;\;\;\frac{-\sqrt{\left(2 \cdot \left(t_0 \cdot F\right)\right) \cdot \left(A + A\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if B < 8.3999999999999995e77Initial program 20.5%
Simplified20.5%
Taylor expanded in C around inf 15.8%
sub-neg15.8%
mul-1-neg15.8%
remove-double-neg15.8%
Simplified15.8%
if 8.3999999999999995e77 < B Initial program 5.3%
Simplified5.3%
frac-2neg5.3%
remove-double-neg5.3%
div-inv5.3%
fma-neg5.3%
distribute-lft-neg-in5.3%
metadata-eval5.3%
*-commutative5.3%
associate-*r*5.3%
Applied egg-rr5.3%
Applied egg-rr6.2%
Final simplification14.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 -64.0)
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -64.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 = -64.0d0
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return -64.0;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -64.0
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return -64.0 end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -64.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_] := -64.0
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
-64
\end{array}
Initial program 18.0%
Simplified18.0%
frac-2neg18.0%
remove-double-neg18.0%
div-inv18.0%
fma-neg18.0%
distribute-lft-neg-in18.0%
metadata-eval18.0%
*-commutative18.0%
associate-*r*18.0%
Applied egg-rr24.5%
Applied egg-rr4.9%
Final simplification4.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 -1.0)
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -1.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 = -1.0d0
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return -1.0;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -1.0
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return -1.0 end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -1.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_] := -1.0
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
-1
\end{array}
Initial program 18.0%
Simplified18.0%
frac-2neg18.0%
remove-double-neg18.0%
div-inv18.0%
fma-neg18.0%
distribute-lft-neg-in18.0%
metadata-eval18.0%
*-commutative18.0%
associate-*r*18.0%
Applied egg-rr24.5%
Applied egg-rr5.0%
Final simplification5.0%
herbie shell --seed 2023297
(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))))