
(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
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (fma B B (* A (* C -4.0))))
(t_1 (fma B B (* C (* A -4.0))))
(t_2 (hypot B (- A C)))
(t_3 (- (pow B 2.0) (* 4.0 (* A C))))
(t_4 (- (pow B 2.0) (* (* 4.0 A) C)))
(t_5
(/
(-
(sqrt
(*
(* 2.0 (* t_4 F))
(+ (+ A C) (sqrt (+ (pow B 2.0) (pow (- A C) 2.0)))))))
t_4)))
(if (<= t_5 -5e-210)
(/ (* (sqrt (* 2.0 t_0)) (- (sqrt (* F (+ (+ A C) t_2))))) t_3)
(if (<= t_5 2e-130)
(/
(-
(sqrt
(* (* t_1 (* 2.0 F)) (+ (* -0.5 (* B (* B (/ 1.0 C)))) (* 2.0 A)))))
t_1)
(if (<= t_5 INFINITY)
(/ (* (sqrt (* 2.0 (* F t_0))) (- (sqrt (+ C (+ A t_2))))) t_3)
(* (sqrt (* F (+ B C))) (/ (- (sqrt 2.0)) B)))))))B = abs(B);
double code(double A, double B, double C, double F) {
double t_0 = fma(B, B, (A * (C * -4.0)));
double t_1 = fma(B, B, (C * (A * -4.0)));
double t_2 = hypot(B, (A - C));
double t_3 = pow(B, 2.0) - (4.0 * (A * C));
double t_4 = pow(B, 2.0) - ((4.0 * A) * C);
double t_5 = -sqrt(((2.0 * (t_4 * F)) * ((A + C) + sqrt((pow(B, 2.0) + pow((A - C), 2.0)))))) / t_4;
double tmp;
if (t_5 <= -5e-210) {
tmp = (sqrt((2.0 * t_0)) * -sqrt((F * ((A + C) + t_2)))) / t_3;
} else if (t_5 <= 2e-130) {
tmp = -sqrt(((t_1 * (2.0 * F)) * ((-0.5 * (B * (B * (1.0 / C)))) + (2.0 * A)))) / t_1;
} else if (t_5 <= ((double) INFINITY)) {
tmp = (sqrt((2.0 * (F * t_0))) * -sqrt((C + (A + t_2)))) / t_3;
} else {
tmp = sqrt((F * (B + C))) * (-sqrt(2.0) / B);
}
return tmp;
}
B = abs(B) function code(A, B, C, F) t_0 = fma(B, B, Float64(A * Float64(C * -4.0))) t_1 = fma(B, B, Float64(C * Float64(A * -4.0))) t_2 = hypot(B, Float64(A - C)) t_3 = Float64((B ^ 2.0) - Float64(4.0 * Float64(A * C))) t_4 = Float64((B ^ 2.0) - Float64(Float64(4.0 * A) * C)) t_5 = Float64(Float64(-sqrt(Float64(Float64(2.0 * Float64(t_4 * F)) * Float64(Float64(A + C) + sqrt(Float64((B ^ 2.0) + (Float64(A - C) ^ 2.0))))))) / t_4) tmp = 0.0 if (t_5 <= -5e-210) tmp = Float64(Float64(sqrt(Float64(2.0 * t_0)) * Float64(-sqrt(Float64(F * Float64(Float64(A + C) + t_2))))) / t_3); elseif (t_5 <= 2e-130) tmp = Float64(Float64(-sqrt(Float64(Float64(t_1 * Float64(2.0 * F)) * Float64(Float64(-0.5 * Float64(B * Float64(B * Float64(1.0 / C)))) + Float64(2.0 * A))))) / t_1); elseif (t_5 <= Inf) tmp = Float64(Float64(sqrt(Float64(2.0 * Float64(F * t_0))) * Float64(-sqrt(Float64(C + Float64(A + t_2))))) / t_3); else tmp = Float64(sqrt(Float64(F * Float64(B + C))) * Float64(Float64(-sqrt(2.0)) / B)); end return tmp end
NOTE: B should be positive 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[(B * B + N[(C * N[(A * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Power[B, 2.0], $MachinePrecision] - N[(N[(4.0 * A), $MachinePrecision] * C), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[((-N[Sqrt[N[(N[(2.0 * N[(t$95$4 * 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$4), $MachinePrecision]}, If[LessEqual[t$95$5, -5e-210], N[(N[(N[Sqrt[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(F * N[(N[(A + C), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$3), $MachinePrecision], If[LessEqual[t$95$5, 2e-130], N[((-N[Sqrt[N[(N[(t$95$1 * N[(2.0 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(-0.5 * N[(B * N[(B * N[(1.0 / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$1), $MachinePrecision], If[LessEqual[t$95$5, Infinity], N[(N[(N[Sqrt[N[(2.0 * N[(F * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(C + N[(A + t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / t$95$3), $MachinePrecision], N[(N[Sqrt[N[(F * N[(B + C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
B = |B|\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)\\
t_1 := \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\\
t_2 := \mathsf{hypot}\left(B, A - C\right)\\
t_3 := {B}^{2} - 4 \cdot \left(A \cdot C\right)\\
t_4 := {B}^{2} - \left(4 \cdot A\right) \cdot C\\
t_5 := \frac{-\sqrt{\left(2 \cdot \left(t_4 \cdot F\right)\right) \cdot \left(\left(A + C\right) + \sqrt{{B}^{2} + {\left(A - C\right)}^{2}}\right)}}{t_4}\\
\mathbf{if}\;t_5 \leq -5 \cdot 10^{-210}:\\
\;\;\;\;\frac{\sqrt{2 \cdot t_0} \cdot \left(-\sqrt{F \cdot \left(\left(A + C\right) + t_2\right)}\right)}{t_3}\\
\mathbf{elif}\;t_5 \leq 2 \cdot 10^{-130}:\\
\;\;\;\;\frac{-\sqrt{\left(t_1 \cdot \left(2 \cdot F\right)\right) \cdot \left(-0.5 \cdot \left(B \cdot \left(B \cdot \frac{1}{C}\right)\right) + 2 \cdot A\right)}}{t_1}\\
\mathbf{elif}\;t_5 \leq \infty:\\
\;\;\;\;\frac{\sqrt{2 \cdot \left(F \cdot t_0\right)} \cdot \left(-\sqrt{C + \left(A + t_2\right)}\right)}{t_3}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(B + C\right)} \cdot \frac{-\sqrt{2}}{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))) < -5.0000000000000002e-210Initial program 43.1%
Simplified43.1%
Applied egg-rr68.2%
if -5.0000000000000002e-210 < (/.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))) < 2.0000000000000002e-130Initial program 6.0%
Simplified12.1%
Taylor expanded in C around -inf 44.0%
div-inv44.0%
unpow244.0%
associate-*l*44.0%
Applied egg-rr44.0%
if 2.0000000000000002e-130 < (/.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 30.4%
Simplified30.4%
unpow230.4%
unpow230.4%
hypot-udef57.3%
add-sqr-sqrt57.3%
Applied egg-rr57.3%
sqrt-prod73.0%
*-commutative73.0%
+-commutative73.0%
rem-square-sqrt72.9%
associate-+l+72.9%
associate-*l*72.9%
*-commutative72.9%
cancel-sign-sub-inv72.9%
metadata-eval72.9%
*-commutative72.9%
*-commutative72.9%
associate-*r*72.9%
Applied egg-rr72.9%
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%
Simplified1.5%
Taylor expanded in B around inf 0.5%
+-commutative0.5%
Simplified0.5%
Taylor expanded in A around 0 19.2%
+-commutative19.2%
Simplified19.2%
Final simplification40.4%
NOTE: B should be positive before calling this function
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (fma B B (* A (* C -4.0)))))
(if (<= (pow B 2.0) 2e-208)
(/
(- (sqrt (* t_0 (* F (* 2.0 (fma -0.5 (/ (pow B 2.0) C) (* 2.0 A)))))))
t_0)
(if (<= (pow B 2.0) 1e+292)
(/
(* (sqrt (* 2.0 t_0)) (- (sqrt (* F (+ (+ A C) (hypot B (- A C)))))))
(- (pow B 2.0) (* 4.0 (* A C))))
(* (sqrt (* F (+ B C))) (/ (- (sqrt 2.0)) B))))))B = abs(B);
double code(double A, double B, double C, double F) {
double t_0 = fma(B, B, (A * (C * -4.0)));
double tmp;
if (pow(B, 2.0) <= 2e-208) {
tmp = -sqrt((t_0 * (F * (2.0 * fma(-0.5, (pow(B, 2.0) / C), (2.0 * A)))))) / t_0;
} else if (pow(B, 2.0) <= 1e+292) {
tmp = (sqrt((2.0 * t_0)) * -sqrt((F * ((A + C) + hypot(B, (A - C)))))) / (pow(B, 2.0) - (4.0 * (A * C)));
} else {
tmp = sqrt((F * (B + C))) * (-sqrt(2.0) / B);
}
return tmp;
}
B = abs(B) function code(A, B, C, F) t_0 = fma(B, B, Float64(A * Float64(C * -4.0))) tmp = 0.0 if ((B ^ 2.0) <= 2e-208) tmp = Float64(Float64(-sqrt(Float64(t_0 * Float64(F * Float64(2.0 * fma(-0.5, Float64((B ^ 2.0) / C), Float64(2.0 * A))))))) / t_0); elseif ((B ^ 2.0) <= 1e+292) tmp = Float64(Float64(sqrt(Float64(2.0 * t_0)) * Float64(-sqrt(Float64(F * Float64(Float64(A + C) + hypot(B, Float64(A - C))))))) / Float64((B ^ 2.0) - Float64(4.0 * Float64(A * C)))); else tmp = Float64(sqrt(Float64(F * Float64(B + C))) * Float64(Float64(-sqrt(2.0)) / B)); end return tmp end
NOTE: B should be positive 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[N[Power[B, 2.0], $MachinePrecision], 2e-208], N[((-N[Sqrt[N[(t$95$0 * N[(F * N[(2.0 * N[(-0.5 * N[(N[Power[B, 2.0], $MachinePrecision] / C), $MachinePrecision] + N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], If[LessEqual[N[Power[B, 2.0], $MachinePrecision], 1e+292], N[(N[(N[Sqrt[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[N[(F * N[(N[(A + C), $MachinePrecision] + N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision] / N[(N[Power[B, 2.0], $MachinePrecision] - N[(4.0 * N[(A * C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F * N[(B + C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
B = |B|\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)\\
\mathbf{if}\;{B}^{2} \leq 2 \cdot 10^{-208}:\\
\;\;\;\;\frac{-\sqrt{t_0 \cdot \left(F \cdot \left(2 \cdot \mathsf{fma}\left(-0.5, \frac{{B}^{2}}{C}, 2 \cdot A\right)\right)\right)}}{t_0}\\
\mathbf{elif}\;{B}^{2} \leq 10^{+292}:\\
\;\;\;\;\frac{\sqrt{2 \cdot t_0} \cdot \left(-\sqrt{F \cdot \left(\left(A + C\right) + \mathsf{hypot}\left(B, A - C\right)\right)}\right)}{{B}^{2} - 4 \cdot \left(A \cdot C\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(B + C\right)} \cdot \frac{-\sqrt{2}}{B}\\
\end{array}
\end{array}
if (pow.f64 B 2) < 2.0000000000000002e-208Initial program 19.4%
Simplified28.5%
Taylor expanded in C around -inf 30.0%
distribute-frac-neg30.0%
associate-*r*30.0%
associate-*l*30.0%
associate-*r*30.0%
*-commutative30.0%
associate-*l*30.0%
fma-def30.0%
associate-*r*30.0%
*-commutative30.0%
associate-*l*30.0%
Applied egg-rr30.0%
associate-*l*30.1%
Simplified30.1%
if 2.0000000000000002e-208 < (pow.f64 B 2) < 1e292Initial program 26.1%
Simplified26.8%
Applied egg-rr45.5%
if 1e292 < (pow.f64 B 2) Initial program 1.2%
Simplified1.2%
Taylor expanded in B around inf 0.0%
+-commutative0.0%
Simplified0.0%
Taylor expanded in A around 0 29.0%
+-commutative29.0%
Simplified29.0%
Final simplification36.0%
NOTE: B should be positive before calling this function
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (sqrt 2.0))) (t_1 (fma B B (* A (* C -4.0)))))
(if (<= F 3.3e-307)
(/ (- (sqrt (* (* 2.0 t_1) (* F (+ C (+ A (hypot B (- A C)))))))) t_1)
(if (<= F 44000000000.0)
(* (sqrt (* F (+ B C))) (/ t_0 B))
(* (sqrt (/ F B)) t_0)))))B = abs(B);
double code(double A, double B, double C, double F) {
double t_0 = -sqrt(2.0);
double t_1 = fma(B, B, (A * (C * -4.0)));
double tmp;
if (F <= 3.3e-307) {
tmp = -sqrt(((2.0 * t_1) * (F * (C + (A + hypot(B, (A - C))))))) / t_1;
} else if (F <= 44000000000.0) {
tmp = sqrt((F * (B + C))) * (t_0 / B);
} else {
tmp = sqrt((F / B)) * t_0;
}
return tmp;
}
B = abs(B) function code(A, B, C, F) t_0 = Float64(-sqrt(2.0)) t_1 = fma(B, B, Float64(A * Float64(C * -4.0))) tmp = 0.0 if (F <= 3.3e-307) tmp = Float64(Float64(-sqrt(Float64(Float64(2.0 * t_1) * Float64(F * Float64(C + Float64(A + hypot(B, Float64(A - C)))))))) / t_1); elseif (F <= 44000000000.0) tmp = Float64(sqrt(Float64(F * Float64(B + C))) * Float64(t_0 / B)); else tmp = Float64(sqrt(Float64(F / B)) * t_0); end return tmp end
NOTE: B should be positive before calling this function
code[A_, B_, C_, F_] := Block[{t$95$0 = (-N[Sqrt[2.0], $MachinePrecision])}, Block[{t$95$1 = N[(B * B + N[(A * N[(C * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[F, 3.3e-307], N[((-N[Sqrt[N[(N[(2.0 * t$95$1), $MachinePrecision] * N[(F * N[(C + N[(A + N[Sqrt[B ^ 2 + N[(A - C), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$1), $MachinePrecision], If[LessEqual[F, 44000000000.0], N[(N[Sqrt[N[(F * N[(B + C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 / B), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
B = |B|\\
\\
\begin{array}{l}
t_0 := -\sqrt{2}\\
t_1 := \mathsf{fma}\left(B, B, A \cdot \left(C \cdot -4\right)\right)\\
\mathbf{if}\;F \leq 3.3 \cdot 10^{-307}:\\
\;\;\;\;\frac{-\sqrt{\left(2 \cdot t_1\right) \cdot \left(F \cdot \left(C + \left(A + \mathsf{hypot}\left(B, A - C\right)\right)\right)\right)}}{t_1}\\
\mathbf{elif}\;F \leq 44000000000:\\
\;\;\;\;\sqrt{F \cdot \left(B + C\right)} \cdot \frac{t_0}{B}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{F}{B}} \cdot t_0\\
\end{array}
\end{array}
if F < 3.3e-307Initial program 17.8%
Simplified17.8%
unpow217.8%
unpow217.8%
hypot-udef36.6%
add-sqr-sqrt36.7%
Applied egg-rr36.7%
Applied egg-rr37.1%
if 3.3e-307 < F < 4.4e10Initial program 15.2%
Simplified20.0%
Taylor expanded in B around inf 4.4%
+-commutative4.4%
Simplified4.4%
Taylor expanded in A around 0 20.4%
+-commutative20.4%
Simplified20.4%
if 4.4e10 < F Initial program 16.0%
Simplified16.9%
Taylor expanded in C around 0 8.7%
Taylor expanded in A around 0 20.2%
Final simplification22.3%
NOTE: B should be positive before calling this function
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (fma B B (* C (* A -4.0)))))
(if (<= B 1.55e-48)
(/
(-
(sqrt
(* (* t_0 (* 2.0 F)) (+ (* -0.5 (* B (* B (/ 1.0 C)))) (* 2.0 A)))))
t_0)
(* (sqrt (* F (+ B C))) (/ (- (sqrt 2.0)) B)))))B = abs(B);
double code(double A, double B, double C, double F) {
double t_0 = fma(B, B, (C * (A * -4.0)));
double tmp;
if (B <= 1.55e-48) {
tmp = -sqrt(((t_0 * (2.0 * F)) * ((-0.5 * (B * (B * (1.0 / C)))) + (2.0 * A)))) / t_0;
} else {
tmp = sqrt((F * (B + C))) * (-sqrt(2.0) / B);
}
return tmp;
}
B = abs(B) function code(A, B, C, F) t_0 = fma(B, B, Float64(C * Float64(A * -4.0))) tmp = 0.0 if (B <= 1.55e-48) tmp = Float64(Float64(-sqrt(Float64(Float64(t_0 * Float64(2.0 * F)) * Float64(Float64(-0.5 * Float64(B * Float64(B * Float64(1.0 / C)))) + Float64(2.0 * A))))) / t_0); else tmp = Float64(sqrt(Float64(F * Float64(B + C))) * Float64(Float64(-sqrt(2.0)) / B)); end return tmp end
NOTE: B should be positive before calling this function
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(B * B + N[(C * N[(A * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[B, 1.55e-48], N[((-N[Sqrt[N[(N[(t$95$0 * N[(2.0 * F), $MachinePrecision]), $MachinePrecision] * N[(N[(-0.5 * N[(B * N[(B * N[(1.0 / C), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * A), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], N[(N[Sqrt[N[(F * N[(B + C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
B = |B|\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\\
\mathbf{if}\;B \leq 1.55 \cdot 10^{-48}:\\
\;\;\;\;\frac{-\sqrt{\left(t_0 \cdot \left(2 \cdot F\right)\right) \cdot \left(-0.5 \cdot \left(B \cdot \left(B \cdot \frac{1}{C}\right)\right) + 2 \cdot A\right)}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{F \cdot \left(B + C\right)} \cdot \frac{-\sqrt{2}}{B}\\
\end{array}
\end{array}
if B < 1.55000000000000008e-48Initial program 18.3%
Simplified22.7%
Taylor expanded in C around -inf 18.8%
div-inv18.8%
unpow218.8%
associate-*l*18.8%
Applied egg-rr18.8%
if 1.55000000000000008e-48 < B Initial program 10.6%
Simplified18.2%
Taylor expanded in B around inf 11.9%
+-commutative11.9%
Simplified11.9%
Taylor expanded in A around 0 46.5%
+-commutative46.5%
Simplified46.5%
Final simplification27.5%
NOTE: B should be positive before calling this function
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (fma B B (* C (* A -4.0)))) (t_1 (- (sqrt 2.0))))
(if (<= F -5e-310)
(/ (- (sqrt (* (* t_0 (* 2.0 F)) (* 2.0 A)))) t_0)
(if (<= F 340000000.0)
(* (sqrt (* F (+ B C))) (/ t_1 B))
(* (sqrt (/ F B)) t_1)))))B = abs(B);
double code(double A, double B, double C, double F) {
double t_0 = fma(B, B, (C * (A * -4.0)));
double t_1 = -sqrt(2.0);
double tmp;
if (F <= -5e-310) {
tmp = -sqrt(((t_0 * (2.0 * F)) * (2.0 * A))) / t_0;
} else if (F <= 340000000.0) {
tmp = sqrt((F * (B + C))) * (t_1 / B);
} else {
tmp = sqrt((F / B)) * t_1;
}
return tmp;
}
B = abs(B) function code(A, B, C, F) t_0 = fma(B, B, Float64(C * Float64(A * -4.0))) t_1 = Float64(-sqrt(2.0)) tmp = 0.0 if (F <= -5e-310) tmp = Float64(Float64(-sqrt(Float64(Float64(t_0 * Float64(2.0 * F)) * Float64(2.0 * A)))) / t_0); elseif (F <= 340000000.0) tmp = Float64(sqrt(Float64(F * Float64(B + C))) * Float64(t_1 / B)); else tmp = Float64(sqrt(Float64(F / B)) * t_1); end return tmp end
NOTE: B should be positive before calling this function
code[A_, B_, C_, F_] := Block[{t$95$0 = N[(B * B + N[(C * N[(A * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[Sqrt[2.0], $MachinePrecision])}, If[LessEqual[F, -5e-310], N[((-N[Sqrt[N[(N[(t$95$0 * N[(2.0 * F), $MachinePrecision]), $MachinePrecision] * N[(2.0 * A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / t$95$0), $MachinePrecision], If[LessEqual[F, 340000000.0], N[(N[Sqrt[N[(F * N[(B + C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(t$95$1 / B), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision]]]]]
\begin{array}{l}
B = |B|\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(B, B, C \cdot \left(A \cdot -4\right)\right)\\
t_1 := -\sqrt{2}\\
\mathbf{if}\;F \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-\sqrt{\left(t_0 \cdot \left(2 \cdot F\right)\right) \cdot \left(2 \cdot A\right)}}{t_0}\\
\mathbf{elif}\;F \leq 340000000:\\
\;\;\;\;\sqrt{F \cdot \left(B + C\right)} \cdot \frac{t_1}{B}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{F}{B}} \cdot t_1\\
\end{array}
\end{array}
if F < -4.999999999999985e-310Initial program 18.9%
Simplified35.5%
Taylor expanded in A around inf 22.8%
*-commutative22.8%
Simplified22.8%
if -4.999999999999985e-310 < F < 3.4e8Initial program 15.0%
Simplified20.6%
Taylor expanded in B around inf 4.5%
+-commutative4.5%
Simplified4.5%
Taylor expanded in A around 0 20.2%
+-commutative20.2%
Simplified20.2%
if 3.4e8 < F Initial program 16.0%
Simplified16.9%
Taylor expanded in C around 0 8.7%
Taylor expanded in A around 0 20.2%
Final simplification20.5%
NOTE: B should be positive before calling this function
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (sqrt 2.0))))
(if (<= F 4.6e-29)
(* (sqrt (* F (+ B A))) (/ t_0 B))
(* (sqrt (/ F B)) t_0))))B = abs(B);
double code(double A, double B, double C, double F) {
double t_0 = -sqrt(2.0);
double tmp;
if (F <= 4.6e-29) {
tmp = sqrt((F * (B + A))) * (t_0 / B);
} else {
tmp = sqrt((F / B)) * t_0;
}
return tmp;
}
NOTE: B should be positive 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 = -sqrt(2.0d0)
if (f <= 4.6d-29) then
tmp = sqrt((f * (b + a))) * (t_0 / b)
else
tmp = sqrt((f / b)) * t_0
end if
code = tmp
end function
B = Math.abs(B);
public static double code(double A, double B, double C, double F) {
double t_0 = -Math.sqrt(2.0);
double tmp;
if (F <= 4.6e-29) {
tmp = Math.sqrt((F * (B + A))) * (t_0 / B);
} else {
tmp = Math.sqrt((F / B)) * t_0;
}
return tmp;
}
B = abs(B) def code(A, B, C, F): t_0 = -math.sqrt(2.0) tmp = 0 if F <= 4.6e-29: tmp = math.sqrt((F * (B + A))) * (t_0 / B) else: tmp = math.sqrt((F / B)) * t_0 return tmp
B = abs(B) function code(A, B, C, F) t_0 = Float64(-sqrt(2.0)) tmp = 0.0 if (F <= 4.6e-29) tmp = Float64(sqrt(Float64(F * Float64(B + A))) * Float64(t_0 / B)); else tmp = Float64(sqrt(Float64(F / B)) * t_0); end return tmp end
B = abs(B) function tmp_2 = code(A, B, C, F) t_0 = -sqrt(2.0); tmp = 0.0; if (F <= 4.6e-29) tmp = sqrt((F * (B + A))) * (t_0 / B); else tmp = sqrt((F / B)) * t_0; end tmp_2 = tmp; end
NOTE: B should be positive before calling this function
code[A_, B_, C_, F_] := Block[{t$95$0 = (-N[Sqrt[2.0], $MachinePrecision])}, If[LessEqual[F, 4.6e-29], N[(N[Sqrt[N[(F * N[(B + A), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 / B), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}
B = |B|\\
\\
\begin{array}{l}
t_0 := -\sqrt{2}\\
\mathbf{if}\;F \leq 4.6 \cdot 10^{-29}:\\
\;\;\;\;\sqrt{F \cdot \left(B + A\right)} \cdot \frac{t_0}{B}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{F}{B}} \cdot t_0\\
\end{array}
\end{array}
if F < 4.59999999999999982e-29Initial program 15.4%
Simplified23.4%
Taylor expanded in B around inf 4.9%
+-commutative4.9%
Simplified4.9%
Taylor expanded in C around 0 15.2%
+-commutative15.2%
Simplified15.2%
if 4.59999999999999982e-29 < F Initial program 16.4%
Simplified17.1%
Taylor expanded in C around 0 9.1%
Taylor expanded in A around 0 20.5%
Final simplification17.8%
NOTE: B should be positive before calling this function
(FPCore (A B C F)
:precision binary64
(let* ((t_0 (- (sqrt 2.0))))
(if (<= F 320000000.0)
(* (sqrt (* F (+ B C))) (/ t_0 B))
(* (sqrt (/ F B)) t_0))))B = abs(B);
double code(double A, double B, double C, double F) {
double t_0 = -sqrt(2.0);
double tmp;
if (F <= 320000000.0) {
tmp = sqrt((F * (B + C))) * (t_0 / B);
} else {
tmp = sqrt((F / B)) * t_0;
}
return tmp;
}
NOTE: B should be positive 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 = -sqrt(2.0d0)
if (f <= 320000000.0d0) then
tmp = sqrt((f * (b + c))) * (t_0 / b)
else
tmp = sqrt((f / b)) * t_0
end if
code = tmp
end function
B = Math.abs(B);
public static double code(double A, double B, double C, double F) {
double t_0 = -Math.sqrt(2.0);
double tmp;
if (F <= 320000000.0) {
tmp = Math.sqrt((F * (B + C))) * (t_0 / B);
} else {
tmp = Math.sqrt((F / B)) * t_0;
}
return tmp;
}
B = abs(B) def code(A, B, C, F): t_0 = -math.sqrt(2.0) tmp = 0 if F <= 320000000.0: tmp = math.sqrt((F * (B + C))) * (t_0 / B) else: tmp = math.sqrt((F / B)) * t_0 return tmp
B = abs(B) function code(A, B, C, F) t_0 = Float64(-sqrt(2.0)) tmp = 0.0 if (F <= 320000000.0) tmp = Float64(sqrt(Float64(F * Float64(B + C))) * Float64(t_0 / B)); else tmp = Float64(sqrt(Float64(F / B)) * t_0); end return tmp end
B = abs(B) function tmp_2 = code(A, B, C, F) t_0 = -sqrt(2.0); tmp = 0.0; if (F <= 320000000.0) tmp = sqrt((F * (B + C))) * (t_0 / B); else tmp = sqrt((F / B)) * t_0; end tmp_2 = tmp; end
NOTE: B should be positive before calling this function
code[A_, B_, C_, F_] := Block[{t$95$0 = (-N[Sqrt[2.0], $MachinePrecision])}, If[LessEqual[F, 320000000.0], N[(N[Sqrt[N[(F * N[(B + C), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 / B), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}
B = |B|\\
\\
\begin{array}{l}
t_0 := -\sqrt{2}\\
\mathbf{if}\;F \leq 320000000:\\
\;\;\;\;\sqrt{F \cdot \left(B + C\right)} \cdot \frac{t_0}{B}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{F}{B}} \cdot t_0\\
\end{array}
\end{array}
if F < 3.2e8Initial program 15.7%
Simplified23.5%
Taylor expanded in B around inf 5.2%
+-commutative5.2%
Simplified5.2%
Taylor expanded in A around 0 16.5%
+-commutative16.5%
Simplified16.5%
if 3.2e8 < F Initial program 16.0%
Simplified16.9%
Taylor expanded in C around 0 8.7%
Taylor expanded in A around 0 20.2%
Final simplification18.1%
NOTE: B should be positive before calling this function (FPCore (A B C F) :precision binary64 (* (sqrt (/ F B)) (- (sqrt 2.0))))
B = abs(B);
double code(double A, double B, double C, double F) {
return sqrt((F / B)) * -sqrt(2.0);
}
NOTE: B should be positive 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((f / b)) * -sqrt(2.0d0)
end function
B = Math.abs(B);
public static double code(double A, double B, double C, double F) {
return Math.sqrt((F / B)) * -Math.sqrt(2.0);
}
B = abs(B) def code(A, B, C, F): return math.sqrt((F / B)) * -math.sqrt(2.0)
B = abs(B) function code(A, B, C, F) return Float64(sqrt(Float64(F / B)) * Float64(-sqrt(2.0))) end
B = abs(B) function tmp = code(A, B, C, F) tmp = sqrt((F / B)) * -sqrt(2.0); end
NOTE: B should be positive before calling this function code[A_, B_, C_, F_] := N[(N[Sqrt[N[(F / B), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[2.0], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
B = |B|\\
\\
\sqrt{\frac{F}{B}} \cdot \left(-\sqrt{2}\right)
\end{array}
Initial program 15.9%
Simplified16.5%
Taylor expanded in C around 0 6.8%
Taylor expanded in A around 0 13.8%
Final simplification13.8%
herbie shell --seed 2023305
(FPCore (A B C F)
:name "ABCF->ab-angle a"
: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))))