
(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}
B_m = (fabs.f64 B) (FPCore (A B_m C F) :precision binary64 (* (* (sqrt (+ A (hypot B_m A))) (sqrt F)) (/ -1.0 (/ B_m (sqrt 2.0)))))
B_m = fabs(B);
double code(double A, double B_m, double C, double F) {
return (sqrt((A + hypot(B_m, A))) * sqrt(F)) * (-1.0 / (B_m / sqrt(2.0)));
}
B_m = Math.abs(B);
public static double code(double A, double B_m, double C, double F) {
return (Math.sqrt((A + Math.hypot(B_m, A))) * Math.sqrt(F)) * (-1.0 / (B_m / Math.sqrt(2.0)));
}
B_m = math.fabs(B) def code(A, B_m, C, F): return (math.sqrt((A + math.hypot(B_m, A))) * math.sqrt(F)) * (-1.0 / (B_m / math.sqrt(2.0)))
B_m = abs(B) function code(A, B_m, C, F) return Float64(Float64(sqrt(Float64(A + hypot(B_m, A))) * sqrt(F)) * Float64(-1.0 / Float64(B_m / sqrt(2.0)))) end
B_m = abs(B); function tmp = code(A, B_m, C, F) tmp = (sqrt((A + hypot(B_m, A))) * sqrt(F)) * (-1.0 / (B_m / sqrt(2.0))); end
B_m = N[Abs[B], $MachinePrecision] code[A_, B$95$m_, C_, F_] := N[(N[(N[Sqrt[N[(A + N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[F], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(B$95$m / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
\left(\sqrt{A + \mathsf{hypot}\left(B\_m, A\right)} \cdot \sqrt{F}\right) \cdot \frac{-1}{\frac{B\_m}{\sqrt{2}}}
\end{array}
Initial program 19.3%
Simplified19.9%
Taylor expanded in C around 0 12.4%
mul-1-neg12.4%
distribute-rgt-neg-in12.4%
unpow212.4%
unpow212.4%
hypot-def17.6%
Simplified17.6%
pow1/217.6%
*-commutative17.6%
unpow-prod-down23.6%
pow1/223.6%
pow1/223.6%
Applied egg-rr23.6%
hypot-def12.8%
unpow212.8%
unpow212.8%
+-commutative12.8%
unpow212.8%
unpow212.8%
hypot-def23.6%
Simplified23.6%
clear-num23.6%
inv-pow23.6%
Applied egg-rr23.6%
unpow-123.6%
Simplified23.6%
Final simplification23.6%
B_m = (fabs.f64 B) (FPCore (A B_m C F) :precision binary64 (* (* (sqrt (+ A (hypot B_m A))) (sqrt F)) (* (sqrt 2.0) (/ -1.0 B_m))))
B_m = fabs(B);
double code(double A, double B_m, double C, double F) {
return (sqrt((A + hypot(B_m, A))) * sqrt(F)) * (sqrt(2.0) * (-1.0 / B_m));
}
B_m = Math.abs(B);
public static double code(double A, double B_m, double C, double F) {
return (Math.sqrt((A + Math.hypot(B_m, A))) * Math.sqrt(F)) * (Math.sqrt(2.0) * (-1.0 / B_m));
}
B_m = math.fabs(B) def code(A, B_m, C, F): return (math.sqrt((A + math.hypot(B_m, A))) * math.sqrt(F)) * (math.sqrt(2.0) * (-1.0 / B_m))
B_m = abs(B) function code(A, B_m, C, F) return Float64(Float64(sqrt(Float64(A + hypot(B_m, A))) * sqrt(F)) * Float64(sqrt(2.0) * Float64(-1.0 / B_m))) end
B_m = abs(B); function tmp = code(A, B_m, C, F) tmp = (sqrt((A + hypot(B_m, A))) * sqrt(F)) * (sqrt(2.0) * (-1.0 / B_m)); end
B_m = N[Abs[B], $MachinePrecision] code[A_, B$95$m_, C_, F_] := N[(N[(N[Sqrt[N[(A + N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[F], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[2.0], $MachinePrecision] * N[(-1.0 / B$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
\left(\sqrt{A + \mathsf{hypot}\left(B\_m, A\right)} \cdot \sqrt{F}\right) \cdot \left(\sqrt{2} \cdot \frac{-1}{B\_m}\right)
\end{array}
Initial program 19.3%
Simplified19.9%
Taylor expanded in C around 0 12.4%
mul-1-neg12.4%
distribute-rgt-neg-in12.4%
unpow212.4%
unpow212.4%
hypot-def17.6%
Simplified17.6%
pow1/217.6%
*-commutative17.6%
unpow-prod-down23.6%
pow1/223.6%
pow1/223.6%
Applied egg-rr23.6%
hypot-def12.8%
unpow212.8%
unpow212.8%
+-commutative12.8%
unpow212.8%
unpow212.8%
hypot-def23.6%
Simplified23.6%
div-inv23.6%
Applied egg-rr23.6%
Final simplification23.6%
B_m = (fabs.f64 B) (FPCore (A B_m C F) :precision binary64 (* (* (sqrt (+ A (hypot B_m A))) (sqrt F)) (/ (- (sqrt 2.0)) B_m)))
B_m = fabs(B);
double code(double A, double B_m, double C, double F) {
return (sqrt((A + hypot(B_m, A))) * sqrt(F)) * (-sqrt(2.0) / B_m);
}
B_m = Math.abs(B);
public static double code(double A, double B_m, double C, double F) {
return (Math.sqrt((A + Math.hypot(B_m, A))) * Math.sqrt(F)) * (-Math.sqrt(2.0) / B_m);
}
B_m = math.fabs(B) def code(A, B_m, C, F): return (math.sqrt((A + math.hypot(B_m, A))) * math.sqrt(F)) * (-math.sqrt(2.0) / B_m)
B_m = abs(B) function code(A, B_m, C, F) return Float64(Float64(sqrt(Float64(A + hypot(B_m, A))) * sqrt(F)) * Float64(Float64(-sqrt(2.0)) / B_m)) end
B_m = abs(B); function tmp = code(A, B_m, C, F) tmp = (sqrt((A + hypot(B_m, A))) * sqrt(F)) * (-sqrt(2.0) / B_m); end
B_m = N[Abs[B], $MachinePrecision] code[A_, B$95$m_, C_, F_] := N[(N[(N[Sqrt[N[(A + N[Sqrt[B$95$m ^ 2 + A ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[F], $MachinePrecision]), $MachinePrecision] * N[((-N[Sqrt[2.0], $MachinePrecision]) / B$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
\left(\sqrt{A + \mathsf{hypot}\left(B\_m, A\right)} \cdot \sqrt{F}\right) \cdot \frac{-\sqrt{2}}{B\_m}
\end{array}
Initial program 19.3%
Simplified19.9%
Taylor expanded in C around 0 12.4%
mul-1-neg12.4%
distribute-rgt-neg-in12.4%
unpow212.4%
unpow212.4%
hypot-def17.6%
Simplified17.6%
pow1/217.6%
*-commutative17.6%
unpow-prod-down23.6%
pow1/223.6%
pow1/223.6%
Applied egg-rr23.6%
hypot-def12.8%
unpow212.8%
unpow212.8%
+-commutative12.8%
unpow212.8%
unpow212.8%
hypot-def23.6%
Simplified23.6%
Final simplification23.6%
B_m = (fabs.f64 B) (FPCore (A B_m C F) :precision binary64 (* (sqrt 2.0) (* (sqrt (/ 1.0 B_m)) (- (sqrt F)))))
B_m = fabs(B);
double code(double A, double B_m, double C, double F) {
return sqrt(2.0) * (sqrt((1.0 / B_m)) * -sqrt(F));
}
B_m = abs(B)
real(8) function code(a, b_m, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
code = sqrt(2.0d0) * (sqrt((1.0d0 / b_m)) * -sqrt(f))
end function
B_m = Math.abs(B);
public static double code(double A, double B_m, double C, double F) {
return Math.sqrt(2.0) * (Math.sqrt((1.0 / B_m)) * -Math.sqrt(F));
}
B_m = math.fabs(B) def code(A, B_m, C, F): return math.sqrt(2.0) * (math.sqrt((1.0 / B_m)) * -math.sqrt(F))
B_m = abs(B) function code(A, B_m, C, F) return Float64(sqrt(2.0) * Float64(sqrt(Float64(1.0 / B_m)) * Float64(-sqrt(F)))) end
B_m = abs(B); function tmp = code(A, B_m, C, F) tmp = sqrt(2.0) * (sqrt((1.0 / B_m)) * -sqrt(F)); end
B_m = N[Abs[B], $MachinePrecision] code[A_, B$95$m_, C_, F_] := N[(N[Sqrt[2.0], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / B$95$m), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[F], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
\sqrt{2} \cdot \left(\sqrt{\frac{1}{B\_m}} \cdot \left(-\sqrt{F}\right)\right)
\end{array}
Initial program 19.3%
Simplified19.9%
Taylor expanded in A around 0 11.6%
mul-1-neg11.6%
distribute-rgt-neg-in11.6%
+-commutative11.6%
unpow211.6%
unpow211.6%
hypot-def17.1%
Simplified17.1%
Taylor expanded in C around 0 16.8%
mul-1-neg16.8%
Simplified16.8%
pow1/217.0%
div-inv17.0%
unpow-prod-down19.8%
pow1/219.8%
Applied egg-rr19.8%
unpow1/219.8%
*-commutative19.8%
Simplified19.8%
Final simplification19.8%
B_m = (fabs.f64 B) (FPCore (A B_m C F) :precision binary64 (* (sqrt 2.0) (- (/ (sqrt F) (sqrt B_m)))))
B_m = fabs(B);
double code(double A, double B_m, double C, double F) {
return sqrt(2.0) * -(sqrt(F) / sqrt(B_m));
}
B_m = abs(B)
real(8) function code(a, b_m, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
code = sqrt(2.0d0) * -(sqrt(f) / sqrt(b_m))
end function
B_m = Math.abs(B);
public static double code(double A, double B_m, double C, double F) {
return Math.sqrt(2.0) * -(Math.sqrt(F) / Math.sqrt(B_m));
}
B_m = math.fabs(B) def code(A, B_m, C, F): return math.sqrt(2.0) * -(math.sqrt(F) / math.sqrt(B_m))
B_m = abs(B) function code(A, B_m, C, F) return Float64(sqrt(2.0) * Float64(-Float64(sqrt(F) / sqrt(B_m)))) end
B_m = abs(B); function tmp = code(A, B_m, C, F) tmp = sqrt(2.0) * -(sqrt(F) / sqrt(B_m)); end
B_m = N[Abs[B], $MachinePrecision] code[A_, B$95$m_, C_, F_] := N[(N[Sqrt[2.0], $MachinePrecision] * (-N[(N[Sqrt[F], $MachinePrecision] / N[Sqrt[B$95$m], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
B_m = \left|B\right|
\\
\sqrt{2} \cdot \left(-\frac{\sqrt{F}}{\sqrt{B\_m}}\right)
\end{array}
Initial program 19.3%
Simplified19.9%
Taylor expanded in A around 0 11.6%
mul-1-neg11.6%
distribute-rgt-neg-in11.6%
+-commutative11.6%
unpow211.6%
unpow211.6%
hypot-def17.1%
Simplified17.1%
Taylor expanded in C around 0 16.8%
mul-1-neg16.8%
Simplified16.8%
sqrt-div19.8%
Applied egg-rr19.8%
Final simplification19.8%
B_m = (fabs.f64 B) (FPCore (A B_m C F) :precision binary64 (- (pow (* 2.0 (/ F B_m)) 0.5)))
B_m = fabs(B);
double code(double A, double B_m, double C, double F) {
return -pow((2.0 * (F / B_m)), 0.5);
}
B_m = abs(B)
real(8) function code(a, b_m, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
code = -((2.0d0 * (f / b_m)) ** 0.5d0)
end function
B_m = Math.abs(B);
public static double code(double A, double B_m, double C, double F) {
return -Math.pow((2.0 * (F / B_m)), 0.5);
}
B_m = math.fabs(B) def code(A, B_m, C, F): return -math.pow((2.0 * (F / B_m)), 0.5)
B_m = abs(B) function code(A, B_m, C, F) return Float64(-(Float64(2.0 * Float64(F / B_m)) ^ 0.5)) end
B_m = abs(B); function tmp = code(A, B_m, C, F) tmp = -((2.0 * (F / B_m)) ^ 0.5); end
B_m = N[Abs[B], $MachinePrecision] code[A_, B$95$m_, C_, F_] := (-N[Power[N[(2.0 * N[(F / B$95$m), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision])
\begin{array}{l}
B_m = \left|B\right|
\\
-{\left(2 \cdot \frac{F}{B\_m}\right)}^{0.5}
\end{array}
Initial program 19.3%
Simplified19.9%
Taylor expanded in A around 0 11.6%
mul-1-neg11.6%
distribute-rgt-neg-in11.6%
+-commutative11.6%
unpow211.6%
unpow211.6%
hypot-def17.1%
Simplified17.1%
Taylor expanded in C around 0 16.8%
mul-1-neg16.8%
Simplified16.8%
sqrt-unprod16.9%
pow1/217.0%
Applied egg-rr17.0%
Final simplification17.0%
B_m = (fabs.f64 B) (FPCore (A B_m C F) :precision binary64 (- (sqrt (* 2.0 (/ F B_m)))))
B_m = fabs(B);
double code(double A, double B_m, double C, double F) {
return -sqrt((2.0 * (F / B_m)));
}
B_m = abs(B)
real(8) function code(a, b_m, c, f)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
real(8), intent (in) :: c
real(8), intent (in) :: f
code = -sqrt((2.0d0 * (f / b_m)))
end function
B_m = Math.abs(B);
public static double code(double A, double B_m, double C, double F) {
return -Math.sqrt((2.0 * (F / B_m)));
}
B_m = math.fabs(B) def code(A, B_m, C, F): return -math.sqrt((2.0 * (F / B_m)))
B_m = abs(B) function code(A, B_m, C, F) return Float64(-sqrt(Float64(2.0 * Float64(F / B_m)))) end
B_m = abs(B); function tmp = code(A, B_m, C, F) tmp = -sqrt((2.0 * (F / B_m))); end
B_m = N[Abs[B], $MachinePrecision] code[A_, B$95$m_, C_, F_] := (-N[Sqrt[N[(2.0 * N[(F / B$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}
B_m = \left|B\right|
\\
-\sqrt{2 \cdot \frac{F}{B\_m}}
\end{array}
Initial program 19.3%
Simplified19.9%
Taylor expanded in A around 0 11.6%
mul-1-neg11.6%
distribute-rgt-neg-in11.6%
+-commutative11.6%
unpow211.6%
unpow211.6%
hypot-def17.1%
Simplified17.1%
Taylor expanded in C around 0 16.8%
mul-1-neg16.8%
Simplified16.8%
sqrt-unprod16.9%
Applied egg-rr16.9%
Final simplification16.9%
herbie shell --seed 2024033
(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))))