
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
(/
(-
(sqrt
(*
(* 2.0 (* t_0 F))
(- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
t_0)))
double code(double A, double B, double C, double F) {
double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
return -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_0;
}
real(8) function code(a, b, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: t_0
t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) - sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F): t_0 = math.pow(B, 2.0) - ((4.0 * A) * C) return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F) t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0) end
function tmp = code(A, B, C, F) t_0 = (B ^ 2.0) - ((4.0 * A) * C); tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0; end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (pow B 2.0) (* (* 4.0 A) C))))
(/
(-
(sqrt
(*
(* 2.0 (* t_0 F))
(- (+ A C) (sqrt (+ (pow (- A C) 2.0) (pow B 2.0)))))))
t_0)))
double code(double A, double B, double C, double F) {
double t_0 = pow(B, 2.0) - ((4.0 * A) * C);
return -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((pow((A - C), 2.0) + pow(B, 2.0)))))) / t_0;
}
real(8) function code(a, b, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: f
real(8) :: t_0
t_0 = (b ** 2.0d0) - ((4.0d0 * a) * c)
code = -sqrt(((2.0d0 * (t_0 * f)) * ((a + c) - sqrt((((a - c) ** 2.0d0) + (b ** 2.0d0)))))) / t_0
end function
public static double code(double A, double B, double C, double F) {
double t_0 = Math.pow(B, 2.0) - ((4.0 * A) * C);
return -Math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - Math.sqrt((Math.pow((A - C), 2.0) + Math.pow(B, 2.0)))))) / t_0;
}
def code(A, B, C, F): t_0 = math.pow(B, 2.0) - ((4.0 * A) * C) return -math.sqrt(((2.0 * (t_0 * F)) * ((A + C) - math.sqrt((math.pow((A - C), 2.0) + math.pow(B, 2.0)))))) / t_0
function code(A, B, C, F) t_0 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) return Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_0 * F)) * Float64(Float64(A + C) - sqrt(Float64((Float64(A - C) ^ 2.0) + (B ^ 2.0))))))) / t_0) end
function tmp = code(A, B, C, F) t_0 = (B ^ 2.0) - ((4.0 * A) * C); tmp = -sqrt(((2.0 * (t_0 * F)) * ((A + C) - sqrt((((A - C) ^ 2.0) + (B ^ 2.0)))))) / t_0; end
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$0 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[B, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
\frac{-\sqrt{\left(2 \cdot \left(t_0 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{\left(A - C\right)}^{2} + {B}^{2}}\right)}}{t_0}
\end{array}
\end{array}
NOTE: B should be positive before calling this function
NOTE: A and C should be sorted in increasing order before calling this function.
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (fma B B (* A (* C -4.0))))
(t_1 (- (pow B 2.0) (* (* 4.0 A) C)))
(t_2
(/
(-
(sqrt
(*
(* 2.0 (* t_1 F))
(- (+ A C) (sqrt (+ (pow B 2.0) (pow (- A C) 2.0)))))))
t_1)))
(if (<= t_2 -2e-188)
(/
(* (pow (* 2.0 t_0) 0.5) (- (sqrt (* F (+ A (- C (hypot B (- A C))))))))
t_0)
(if (<= t_2 INFINITY)
(* 0.25 (/ (sqrt (* A (* (* F (* A (* 2.0 C))) -8.0))) (* A C)))
(/ (- (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 = fma(B, B, (A * (C * -4.0)));
double t_1 = pow(B, 2.0) - ((4.0 * A) * C);
double t_2 = -sqrt(((2.0 * (t_1 * F)) * ((A + C) - sqrt((pow(B, 2.0) + pow((A - C), 2.0)))))) / t_1;
double tmp;
if (t_2 <= -2e-188) {
tmp = (pow((2.0 * t_0), 0.5) * -sqrt((F * (A + (C - hypot(B, (A - C))))))) / t_0;
} else if (t_2 <= ((double) INFINITY)) {
tmp = 0.25 * (sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C));
} else {
tmp = -sqrt(((2.0 * F) * (A - hypot(B, A)))) / 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 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) t_2 = Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_1 * F)) * Float64(Float64(A + C) - sqrt(Float64((B ^ 2.0) + (Float64(A - C) ^ 2.0))))))) / t_1) tmp = 0.0 if (t_2 <= -2e-188) tmp = Float64(Float64((Float64(2.0 * t_0) ^ 0.5) * Float64(-sqrt(Float64(F * Float64(A + Float64(C - hypot(B, Float64(A - C)))))))) / t_0); elseif (t_2 <= Inf) tmp = Float64(0.25 * Float64(sqrt(Float64(A * Float64(Float64(F * Float64(A * Float64(2.0 * C))) * -8.0))) / Float64(A * C))); else tmp = Float64(Float64(-sqrt(Float64(Float64(2.0 * F) * Float64(A - hypot(B, A))))) / 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[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$1 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(A + C), $MachinePrecision] - N[Sqrt[N[(N[Power[B, 2.0], $MachinePrecision] + N[Power[N[(A - C), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -2e-188], N[(N[(N[Power[N[(2.0 * t$95$0), $MachinePrecision], 0.5], $MachinePrecision] * (-N[Sqrt[N[(F * N[(A + N[(C - N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[(0.25 * N[(N[Sqrt[N[(A * N[(N[(F * N[(A * N[(2.0 * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -8.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[Sqrt[N[(N[(2.0 * F), $MachinePrecision] * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $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 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
t_2 := \frac{-\sqrt{\left(2 \cdot \left(t_1 \cdot F\right)\right) \cdot \left(\left(A + C\right) - \sqrt{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{t_1}\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{-188}:\\
\;\;\;\;\frac{{\left(2 \cdot t_0\right)}^{0.5} \cdot \left(-\sqrt{F \cdot \left(A + \left(C - \mathsf{hypot}\left(B, A - C\right)\right)\right)}\right)}{t_0}\\
\mathbf{elif}\;t_2 \leq \infty:\\
\;\;\;\;0.25 \cdot \frac{\sqrt{A \cdot \left(\left(F \cdot \left(A \cdot \left(2 \cdot C\right)\right)\right) \cdot -8\right)}}{A \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{\left(2 \cdot F\right) \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)}}{B}\\
\end{array}
\end{array}
if (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < -1.9999999999999999e-188Initial program 46.8%
Simplified51.1%
pow1/251.1%
associate-*r*51.1%
unpow-prod-down67.0%
pow1/267.0%
associate--l+67.7%
Applied egg-rr67.7%
if -1.9999999999999999e-188 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) < +inf.0Initial program 17.0%
Simplified19.0%
Taylor expanded in C around inf 27.6%
associate-*r*27.6%
*-commutative27.6%
cancel-sign-sub-inv27.6%
metadata-eval27.6%
*-lft-identity27.6%
Simplified27.6%
Taylor expanded in B around 0 29.2%
expm1-log1p-u26.7%
expm1-udef12.6%
Applied egg-rr12.7%
expm1-def26.7%
expm1-log1p29.2%
distribute-neg-frac29.2%
neg-mul-129.2%
associate-*r*29.2%
*-commutative29.2%
associate-*r*29.2%
times-frac29.2%
metadata-eval29.2%
associate-*l*29.2%
associate-*r*25.4%
*-commutative25.4%
Simplified25.4%
expm1-log1p-u24.6%
expm1-udef10.6%
associate-*l*12.5%
Applied egg-rr12.5%
expm1-def28.3%
expm1-log1p31.0%
associate-*r*31.0%
Simplified31.0%
if +inf.0 < (/.f64 (neg.f64 (sqrt.f64 (*.f64 (*.f64 2 (*.f64 (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C)) F)) (-.f64 (+.f64 A C) (sqrt.f64 (+.f64 (pow.f64 (-.f64 A C) 2) (pow.f64 B 2))))))) (-.f64 (pow.f64 B 2) (*.f64 (*.f64 4 A) C))) Initial program 0.0%
Simplified0.5%
Taylor expanded in C around 0 1.8%
mul-1-neg1.8%
distribute-rgt-neg-in1.8%
+-commutative1.8%
unpow21.8%
unpow21.8%
hypot-def12.9%
Simplified12.9%
associate-*l/12.9%
Applied egg-rr12.9%
expm1-log1p-u3.8%
expm1-udef2.0%
distribute-rgt-neg-out2.0%
pow1/22.0%
pow1/22.0%
pow-prod-down2.0%
Applied egg-rr2.0%
expm1-def3.8%
expm1-log1p13.0%
unpow1/213.0%
associate-*r*13.0%
Simplified13.0%
Final simplification37.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
(let* ((t_0 (fma B B (* A (* C -4.0)))) (t_1 (- (pow B 2.0) (* 4.0 (* A C)))))
(if (<= (pow B 2.0) 2e-69)
(/ (- (sqrt (* (* F (* 2.0 t_1)) (+ A A)))) t_1)
(if (<= (pow B 2.0) 2e+87)
(/ (- (sqrt (* 2.0 (* t_0 (* F (+ A (- C (hypot B (- A C))))))))) 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 = fma(B, B, (A * (C * -4.0)));
double t_1 = pow(B, 2.0) - (4.0 * (A * C));
double tmp;
if (pow(B, 2.0) <= 2e-69) {
tmp = -sqrt(((F * (2.0 * t_1)) * (A + A))) / t_1;
} else if (pow(B, 2.0) <= 2e+87) {
tmp = -sqrt((2.0 * (t_0 * (F * (A + (C - hypot(B, (A - C)))))))) / t_0;
} else {
tmp = -sqrt(((2.0 * F) * (A - hypot(B, A)))) / 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 = Float64((B ^ 2.0) - Float64(4.0 * Float64(A * C))) tmp = 0.0 if ((B ^ 2.0) <= 2e-69) tmp = Float64(Float64(-sqrt(Float64(Float64(F * Float64(2.0 * t_1)) * Float64(A + A)))) / t_1); elseif ((B ^ 2.0) <= 2e+87) tmp = Float64(Float64(-sqrt(Float64(2.0 * Float64(t_0 * Float64(F * Float64(A + Float64(C - hypot(B, Float64(A - C))))))))) / t_0); else tmp = Float64(Float64(-sqrt(Float64(Float64(2.0 * F) * Float64(A - hypot(B, A))))) / 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[(N[Power[B, 2.0], $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 2e-69], N[((-N[Sqrt[N[(N[(F * N[(2.0 * t$95$1), $MachinePrecision]), $MachinePrecision] * N[(A + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$1), $MachinePrecision], If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 2e+87], N[((-N[Sqrt[N[(2.0 * N[(t$95$0 * N[(F * N[(A + N[(C - N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[((-N[Sqrt[N[(N[(2.0 * F), $MachinePrecision] * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $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 := {B}^{2} - 4 \cdot \left(A \cdot C\right)\\
\mathbf{if}\;{B}^{2} \leq 2 \cdot 10^{-69}:\\
\;\;\;\;\frac{-\sqrt{\left(F \cdot \left(2 \cdot t_1\right)\right) \cdot \left(A + A\right)}}{t_1}\\
\mathbf{elif}\;{B}^{2} \leq 2 \cdot 10^{+87}:\\
\;\;\;\;\frac{-\sqrt{2 \cdot \left(t_0 \cdot \left(F \cdot \left(A + \left(C - \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{\left(2 \cdot F\right) \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)}}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 1.9999999999999999e-69Initial program 26.1%
Simplified26.1%
unpow226.1%
unpow226.1%
hypot-udef31.0%
expm1-log1p-u29.4%
Applied egg-rr29.4%
Taylor expanded in C around inf 29.0%
mul-1-neg29.0%
Simplified29.0%
if 1.9999999999999999e-69 < (pow.f64 B 2) < 1.9999999999999999e87Initial program 35.9%
Simplified41.5%
associate--l+41.9%
Applied egg-rr41.9%
if 1.9999999999999999e87 < (pow.f64 B 2) Initial program 10.8%
Simplified10.9%
Taylor expanded in C around 0 8.1%
mul-1-neg8.1%
distribute-rgt-neg-in8.1%
+-commutative8.1%
unpow28.1%
unpow28.1%
hypot-def18.9%
Simplified18.9%
associate-*l/18.9%
Applied egg-rr18.9%
expm1-log1p-u6.6%
expm1-udef1.5%
distribute-rgt-neg-out1.5%
pow1/21.5%
pow1/21.5%
pow-prod-down1.5%
Applied egg-rr1.5%
expm1-def6.6%
expm1-log1p19.0%
unpow1/219.0%
associate-*r*19.0%
Simplified19.0%
Final simplification26.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 (if (<= (pow B 2.0) 2e+87) (* 0.25 (/ (sqrt (* A (* (* F (* A (* 2.0 C))) -8.0))) (* A C))) (/ (- (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 tmp;
if (pow(B, 2.0) <= 2e+87) {
tmp = 0.25 * (sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C));
} 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 tmp;
if (Math.pow(B, 2.0) <= 2e+87) {
tmp = 0.25 * (Math.sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C));
} 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): tmp = 0 if math.pow(B, 2.0) <= 2e+87: tmp = 0.25 * (math.sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C)) 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) tmp = 0.0 if ((B ^ 2.0) <= 2e+87) tmp = Float64(0.25 * Float64(sqrt(Float64(A * Float64(Float64(F * Float64(A * Float64(2.0 * C))) * -8.0))) / Float64(A * C))); else tmp = Float64(Float64(-sqrt(Float64(Float64(2.0 * 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)
tmp = 0.0;
if ((B ^ 2.0) <= 2e+87)
tmp = 0.25 * (sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C));
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_] := If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 2e+87], N[(0.25 * N[(N[Sqrt[N[(A * N[(N[(F * N[(A * N[(2.0 * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -8.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[Sqrt[N[(N[(2.0 * F), $MachinePrecision] * N[(A - N[Sqrt[B ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / B), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;{B}^{2} \leq 2 \cdot 10^{+87}:\\
\;\;\;\;0.25 \cdot \frac{\sqrt{A \cdot \left(\left(F \cdot \left(A \cdot \left(2 \cdot C\right)\right)\right) \cdot -8\right)}}{A \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{\left(2 \cdot F\right) \cdot \left(A - \mathsf{hypot}\left(B, A\right)\right)}}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 1.9999999999999999e87Initial program 28.6%
Simplified32.5%
Taylor expanded in C around inf 23.1%
associate-*r*23.0%
*-commutative23.0%
cancel-sign-sub-inv23.0%
metadata-eval23.0%
*-lft-identity23.0%
Simplified23.0%
Taylor expanded in B around 0 24.1%
expm1-log1p-u18.8%
expm1-udef6.2%
Applied egg-rr6.3%
expm1-def18.9%
expm1-log1p24.1%
distribute-neg-frac24.1%
neg-mul-124.1%
associate-*r*24.1%
*-commutative24.1%
associate-*r*24.1%
times-frac24.1%
metadata-eval24.1%
associate-*l*24.1%
associate-*r*20.8%
*-commutative20.8%
Simplified20.8%
expm1-log1p-u18.8%
expm1-udef9.0%
associate-*l*10.3%
Applied egg-rr10.3%
expm1-def21.3%
expm1-log1p25.3%
associate-*r*25.3%
Simplified25.3%
if 1.9999999999999999e87 < (pow.f64 B 2) Initial program 10.8%
Simplified10.9%
Taylor expanded in C around 0 8.1%
mul-1-neg8.1%
distribute-rgt-neg-in8.1%
+-commutative8.1%
unpow28.1%
unpow28.1%
hypot-def18.9%
Simplified18.9%
associate-*l/18.9%
Applied egg-rr18.9%
expm1-log1p-u6.6%
expm1-udef1.5%
distribute-rgt-neg-out1.5%
pow1/21.5%
pow1/21.5%
pow-prod-down1.5%
Applied egg-rr1.5%
expm1-def6.6%
expm1-log1p19.0%
unpow1/219.0%
associate-*r*19.0%
Simplified19.0%
Final simplification22.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 (* 2.0 (* A F))))
(if (<= B 3.25e+44)
(* 0.25 (/ (sqrt (* -8.0 (* A (* C t_0)))) (* A C)))
(/ (- (sqrt (+ (* -2.0 (* B F)) t_0))) B))))B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double t_0 = 2.0 * (A * F);
double tmp;
if (B <= 3.25e+44) {
tmp = 0.25 * (sqrt((-8.0 * (A * (C * t_0)))) / (A * C));
} else {
tmp = -sqrt(((-2.0 * (B * F)) + t_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 = 2.0d0 * (a * f)
if (b <= 3.25d+44) then
tmp = 0.25d0 * (sqrt(((-8.0d0) * (a * (c * t_0)))) / (a * c))
else
tmp = -sqrt((((-2.0d0) * (b * f)) + t_0)) / 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 = 2.0 * (A * F);
double tmp;
if (B <= 3.25e+44) {
tmp = 0.25 * (Math.sqrt((-8.0 * (A * (C * t_0)))) / (A * C));
} else {
tmp = -Math.sqrt(((-2.0 * (B * F)) + t_0)) / B;
}
return tmp;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): t_0 = 2.0 * (A * F) tmp = 0 if B <= 3.25e+44: tmp = 0.25 * (math.sqrt((-8.0 * (A * (C * t_0)))) / (A * C)) else: tmp = -math.sqrt(((-2.0 * (B * F)) + t_0)) / B return tmp
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) t_0 = Float64(2.0 * Float64(A * F)) tmp = 0.0 if (B <= 3.25e+44) tmp = Float64(0.25 * Float64(sqrt(Float64(-8.0 * Float64(A * Float64(C * t_0)))) / Float64(A * C))); else tmp = Float64(Float64(-sqrt(Float64(Float64(-2.0 * Float64(B * F)) + t_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 = 2.0 * (A * F);
tmp = 0.0;
if (B <= 3.25e+44)
tmp = 0.25 * (sqrt((-8.0 * (A * (C * t_0)))) / (A * C));
else
tmp = -sqrt(((-2.0 * (B * F)) + t_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[(2.0 * N[(A * F), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 3.25e+44], N[(0.25 * N[(N[Sqrt[N[(-8.0 * N[(A * N[(C * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[Sqrt[N[(N[(-2.0 * N[(B * F), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]) / B), $MachinePrecision]]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
t_0 := 2 \cdot \left(A \cdot F\right)\\
\mathbf{if}\;B \leq 3.25 \cdot 10^{+44}:\\
\;\;\;\;0.25 \cdot \frac{\sqrt{-8 \cdot \left(A \cdot \left(C \cdot t_0\right)\right)}}{A \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{-2 \cdot \left(B \cdot F\right) + t_0}}{B}\\
\end{array}
\end{array}
if B < 3.25000000000000009e44Initial program 22.9%
Simplified25.6%
Taylor expanded in C around inf 16.8%
associate-*r*16.8%
*-commutative16.8%
cancel-sign-sub-inv16.8%
metadata-eval16.8%
*-lft-identity16.8%
Simplified16.8%
Taylor expanded in B around 0 17.3%
add-cbrt-cube15.3%
pow1/314.3%
Applied egg-rr13.7%
expm1-log1p-u10.6%
expm1-udef3.5%
Applied egg-rr4.8%
expm1-def13.5%
expm1-log1p17.3%
distribute-neg-frac17.3%
neg-mul-117.3%
associate-*l*17.3%
times-frac17.3%
metadata-eval17.3%
associate-*l*17.3%
*-commutative17.3%
associate-*r*17.3%
*-commutative17.3%
Simplified17.3%
if 3.25000000000000009e44 < B Initial program 11.9%
Simplified12.0%
Taylor expanded in C around 0 18.3%
mul-1-neg18.3%
distribute-rgt-neg-in18.3%
+-commutative18.3%
unpow218.3%
unpow218.3%
hypot-def43.1%
Simplified43.1%
associate-*l/43.2%
Applied egg-rr43.2%
expm1-log1p-u14.7%
expm1-udef1.8%
distribute-rgt-neg-out1.8%
pow1/21.8%
pow1/21.8%
pow-prod-down1.8%
Applied egg-rr1.8%
expm1-def14.8%
expm1-log1p43.4%
unpow1/243.4%
associate-*r*43.4%
Simplified43.4%
Taylor expanded in A around 0 41.6%
Final simplification21.5%
NOTE: B should be positive before calling this function NOTE: A and C should be sorted in increasing order before calling this function. (FPCore (A B C F) :precision binary64 (if (<= B 4.1e+43) (* 0.25 (/ (sqrt (* A (* (* F (* A (* 2.0 C))) -8.0))) (* A C))) (/ (- (sqrt (+ (* -2.0 (* B F)) (* 2.0 (* A F))))) B)))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
double tmp;
if (B <= 4.1e+43) {
tmp = 0.25 * (sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C));
} else {
tmp = -sqrt(((-2.0 * (B * F)) + (2.0 * (A * F)))) / 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) :: tmp
if (b <= 4.1d+43) then
tmp = 0.25d0 * (sqrt((a * ((f * (a * (2.0d0 * c))) * (-8.0d0)))) / (a * c))
else
tmp = -sqrt((((-2.0d0) * (b * f)) + (2.0d0 * (a * f)))) / 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 tmp;
if (B <= 4.1e+43) {
tmp = 0.25 * (Math.sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C));
} else {
tmp = -Math.sqrt(((-2.0 * (B * F)) + (2.0 * (A * F)))) / B;
}
return tmp;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): tmp = 0 if B <= 4.1e+43: tmp = 0.25 * (math.sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C)) else: tmp = -math.sqrt(((-2.0 * (B * F)) + (2.0 * (A * F)))) / B return tmp
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) tmp = 0.0 if (B <= 4.1e+43) tmp = Float64(0.25 * Float64(sqrt(Float64(A * Float64(Float64(F * Float64(A * Float64(2.0 * C))) * -8.0))) / Float64(A * C))); else tmp = Float64(Float64(-sqrt(Float64(Float64(-2.0 * Float64(B * F)) + Float64(2.0 * Float64(A * F))))) / B); end return tmp end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp_2 = code(A, B, C, F)
tmp = 0.0;
if (B <= 4.1e+43)
tmp = 0.25 * (sqrt((A * ((F * (A * (2.0 * C))) * -8.0))) / (A * C));
else
tmp = -sqrt(((-2.0 * (B * F)) + (2.0 * (A * F)))) / 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_] := If[LessEqual[B, 4.1e+43], N[(0.25 * N[(N[Sqrt[N[(A * N[(N[(F * N[(A * N[(2.0 * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -8.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-N[Sqrt[N[(N[(-2.0 * N[(B * F), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(A * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / B), $MachinePrecision]]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\begin{array}{l}
\mathbf{if}\;B \leq 4.1 \cdot 10^{+43}:\\
\;\;\;\;0.25 \cdot \frac{\sqrt{A \cdot \left(\left(F \cdot \left(A \cdot \left(2 \cdot C\right)\right)\right) \cdot -8\right)}}{A \cdot C}\\
\mathbf{else}:\\
\;\;\;\;\frac{-\sqrt{-2 \cdot \left(B \cdot F\right) + 2 \cdot \left(A \cdot F\right)}}{B}\\
\end{array}
\end{array}
if B < 4.1e43Initial program 22.9%
Simplified25.6%
Taylor expanded in C around inf 16.8%
associate-*r*16.8%
*-commutative16.8%
cancel-sign-sub-inv16.8%
metadata-eval16.8%
*-lft-identity16.8%
Simplified16.8%
Taylor expanded in B around 0 17.3%
expm1-log1p-u13.5%
expm1-udef4.8%
Applied egg-rr4.9%
expm1-def13.6%
expm1-log1p17.3%
distribute-neg-frac17.3%
neg-mul-117.3%
associate-*r*17.3%
*-commutative17.3%
associate-*r*17.3%
times-frac17.3%
metadata-eval17.3%
associate-*l*17.3%
associate-*r*15.1%
*-commutative15.1%
Simplified15.1%
expm1-log1p-u13.7%
expm1-udef7.0%
associate-*l*7.9%
Applied egg-rr7.9%
expm1-def15.3%
expm1-log1p18.2%
associate-*r*18.2%
Simplified18.2%
if 4.1e43 < B Initial program 11.9%
Simplified12.0%
Taylor expanded in C around 0 18.3%
mul-1-neg18.3%
distribute-rgt-neg-in18.3%
+-commutative18.3%
unpow218.3%
unpow218.3%
hypot-def43.1%
Simplified43.1%
associate-*l/43.2%
Applied egg-rr43.2%
expm1-log1p-u14.7%
expm1-udef1.8%
distribute-rgt-neg-out1.8%
pow1/21.8%
pow1/21.8%
pow-prod-down1.8%
Applied egg-rr1.8%
expm1-def14.8%
expm1-log1p43.4%
unpow1/243.4%
associate-*r*43.4%
Simplified43.4%
Taylor expanded in A around 0 41.6%
Final simplification22.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 (* B (* 2.0 F)))) B))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -sqrt((B * (2.0 * 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 = -sqrt((b * (2.0d0 * f))) / b
end function
B = Math.abs(B);
assert A < C;
public static double code(double A, double B, double C, double F) {
return -Math.sqrt((B * (2.0 * F))) / B;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -math.sqrt((B * (2.0 * F))) / B
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(-sqrt(Float64(B * Float64(2.0 * F)))) / B) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -sqrt((B * (2.0 * 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[((-N[Sqrt[N[(B * N[(2.0 * F), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / B), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\frac{-\sqrt{B \cdot \left(2 \cdot F\right)}}{B}
\end{array}
Initial program 21.0%
Simplified23.3%
Taylor expanded in C around 0 6.7%
mul-1-neg6.7%
distribute-rgt-neg-in6.7%
+-commutative6.7%
unpow26.7%
unpow26.7%
hypot-def11.6%
Simplified11.6%
associate-*l/11.6%
Applied egg-rr11.6%
expm1-log1p-u4.8%
expm1-udef1.9%
distribute-rgt-neg-out1.9%
pow1/21.9%
pow1/21.9%
pow-prod-down1.9%
Applied egg-rr1.9%
expm1-def4.8%
expm1-log1p11.7%
unpow1/211.7%
associate-*r*11.7%
Simplified11.7%
Taylor expanded in B around -inf 1.6%
Final simplification1.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 (/ (- (sqrt (* -2.0 (* B F)))) B))
B = abs(B);
assert(A < C);
double code(double A, double B, double C, double F) {
return -sqrt((-2.0 * (B * 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 = -sqrt(((-2.0d0) * (b * f))) / b
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 * F))) / B;
}
B = abs(B) [A, C] = sort([A, C]) def code(A, B, C, F): return -math.sqrt((-2.0 * (B * F))) / B
B = abs(B) A, C = sort([A, C]) function code(A, B, C, F) return Float64(Float64(-sqrt(Float64(-2.0 * Float64(B * F)))) / B) end
B = abs(B)
A, C = num2cell(sort([A, C])){:}
function tmp = code(A, B, C, F)
tmp = -sqrt((-2.0 * (B * 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[((-N[Sqrt[N[(-2.0 * N[(B * F), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / B), $MachinePrecision]
\begin{array}{l}
B = |B|\\
[A, C] = \mathsf{sort}([A, C])\\
\\
\frac{-\sqrt{-2 \cdot \left(B \cdot F\right)}}{B}
\end{array}
Initial program 21.0%
Simplified23.3%
Taylor expanded in C around 0 6.7%
mul-1-neg6.7%
distribute-rgt-neg-in6.7%
+-commutative6.7%
unpow26.7%
unpow26.7%
hypot-def11.6%
Simplified11.6%
associate-*l/11.6%
Applied egg-rr11.6%
expm1-log1p-u4.8%
expm1-udef1.9%
distribute-rgt-neg-out1.9%
pow1/21.9%
pow1/21.9%
pow-prod-down1.9%
Applied egg-rr1.9%
expm1-def4.8%
expm1-log1p11.7%
unpow1/211.7%
associate-*r*11.7%
Simplified11.7%
Taylor expanded in A around 0 10.4%
*-commutative10.4%
Simplified10.4%
Final simplification10.4%
herbie shell --seed 2023314
(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))))