
(FPCore (F B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))
double code(double F, double B, double x) {
return -(x * (1.0 / tan(B))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
real(8) function code(f, b, x)
real(8), intent (in) :: f
real(8), intent (in) :: b
real(8), intent (in) :: x
code = -(x * (1.0d0 / tan(b))) + ((f / sin(b)) * ((((f * f) + 2.0d0) + (2.0d0 * x)) ** -(1.0d0 / 2.0d0)))
end function
public static double code(double F, double B, double x) {
return -(x * (1.0 / Math.tan(B))) + ((F / Math.sin(B)) * Math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
def code(F, B, x): return -(x * (1.0 / math.tan(B))) + ((F / math.sin(B)) * math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)))
function code(F, B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-Float64(1.0 / 2.0))))) end
function tmp = code(F, B, x) tmp = -(x * (1.0 / tan(B))) + ((F / sin(B)) * ((((F * F) + 2.0) + (2.0 * x)) ^ -(1.0 / 2.0))); end
code[F_, B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], (-N[(1.0 / 2.0), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 22 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (F B x) :precision binary64 (+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))
double code(double F, double B, double x) {
return -(x * (1.0 / tan(B))) + ((F / sin(B)) * pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
real(8) function code(f, b, x)
real(8), intent (in) :: f
real(8), intent (in) :: b
real(8), intent (in) :: x
code = -(x * (1.0d0 / tan(b))) + ((f / sin(b)) * ((((f * f) + 2.0d0) + (2.0d0 * x)) ** -(1.0d0 / 2.0d0)))
end function
public static double code(double F, double B, double x) {
return -(x * (1.0 / Math.tan(B))) + ((F / Math.sin(B)) * Math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)));
}
def code(F, B, x): return -(x * (1.0 / math.tan(B))) + ((F / math.sin(B)) * math.pow((((F * F) + 2.0) + (2.0 * x)), -(1.0 / 2.0)))
function code(F, B, x) return Float64(Float64(-Float64(x * Float64(1.0 / tan(B)))) + Float64(Float64(F / sin(B)) * (Float64(Float64(Float64(F * F) + 2.0) + Float64(2.0 * x)) ^ Float64(-Float64(1.0 / 2.0))))) end
function tmp = code(F, B, x) tmp = -(x * (1.0 / tan(B))) + ((F / sin(B)) * ((((F * F) + 2.0) + (2.0 * x)) ^ -(1.0 / 2.0))); end
code[F_, B_, x_] := N[((-N[(x * N[(1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]) + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(N[(F * F), $MachinePrecision] + 2.0), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision], (-N[(1.0 / 2.0), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-x \cdot \frac{1}{\tan B}\right) + \frac{F}{\sin B} \cdot {\left(\left(F \cdot F + 2\right) + 2 \cdot x\right)}^{\left(-\frac{1}{2}\right)}
\end{array}
(FPCore (F B x)
:precision binary64
(let* ((t_0 (/ -1.0 (tan B))))
(if (<= F -2e+21)
(fma t_0 x (/ -1.0 (sin B)))
(if (<= F 125000000.0)
(fma
(/ (pow (fma 2.0 x (fma F F 2.0)) -0.5) (sin B))
F
(- (/ x (tan B))))
(fma t_0 x (/ 1.0 (sin B)))))))
double code(double F, double B, double x) {
double t_0 = -1.0 / tan(B);
double tmp;
if (F <= -2e+21) {
tmp = fma(t_0, x, (-1.0 / sin(B)));
} else if (F <= 125000000.0) {
tmp = fma((pow(fma(2.0, x, fma(F, F, 2.0)), -0.5) / sin(B)), F, -(x / tan(B)));
} else {
tmp = fma(t_0, x, (1.0 / sin(B)));
}
return tmp;
}
function code(F, B, x) t_0 = Float64(-1.0 / tan(B)) tmp = 0.0 if (F <= -2e+21) tmp = fma(t_0, x, Float64(-1.0 / sin(B))); elseif (F <= 125000000.0) tmp = fma(Float64((fma(2.0, x, fma(F, F, 2.0)) ^ -0.5) / sin(B)), F, Float64(-Float64(x / tan(B)))); else tmp = fma(t_0, x, Float64(1.0 / sin(B))); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[F, -2e+21], N[(t$95$0 * x + N[(-1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 125000000.0], N[(N[(N[Power[N[(2.0 * x + N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision] * F + (-N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision])), $MachinePrecision], N[(t$95$0 * x + N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1}{\tan B}\\
\mathbf{if}\;F \leq -2 \cdot 10^{+21}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, x, \frac{-1}{\sin B}\right)\\
\mathbf{elif}\;F \leq 125000000:\\
\;\;\;\;\mathsf{fma}\left(\frac{{\left(\mathsf{fma}\left(2, x, \mathsf{fma}\left(F, F, 2\right)\right)\right)}^{-0.5}}{\sin B}, F, -\frac{x}{\tan B}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, x, \frac{1}{\sin B}\right)\\
\end{array}
\end{array}
if F < -2e21Initial program 45.6%
lift-+.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6445.6
Applied rewrites45.6%
Taylor expanded in F around -inf
lower-/.f64N/A
lower-sin.f6499.7
Applied rewrites99.7%
if -2e21 < F < 1.25e8Initial program 99.4%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
lower-fma.f64N/A
Applied rewrites99.7%
if 1.25e8 < F Initial program 70.5%
lift-+.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6470.5
Applied rewrites70.5%
Taylor expanded in F around inf
lower-/.f64N/A
lower-sin.f6499.7
Applied rewrites99.7%
Final simplification99.7%
(FPCore (F B x)
:precision binary64
(let* ((t_0 (* x (/ -1.0 (tan B))))
(t_1
(+
t_0
(* (/ F (sin B)) (pow (+ (+ 2.0 (* F F)) (* x 2.0)) (/ -1.0 2.0)))))
(t_2 (sqrt (/ 1.0 (fma F F 2.0))))
(t_3
(fma
(/
t_2
(fma
(* B (* B B))
(fma (* B B) 0.008333333333333333 -0.16666666666666666)
B))
F
(- (/ x (tan B))))))
(if (<= t_1 -1000.0)
t_3
(if (<= t_1 -2e-26)
(* t_2 (* F (/ 1.0 (sin B))))
(if (<= t_1 5e-42)
(+ t_0 (* (sqrt (/ 1.0 (fma x 2.0 (fma F F 2.0)))) (/ F B)))
(if (<= t_1 20.0)
(/ F (* (sin B) (sqrt (fma F F 2.0))))
(if (<= t_1 INFINITY)
t_3
(/ (/ (- 1.0 (* x x)) (+ -1.0 x)) B))))))))
double code(double F, double B, double x) {
double t_0 = x * (-1.0 / tan(B));
double t_1 = t_0 + ((F / sin(B)) * pow(((2.0 + (F * F)) + (x * 2.0)), (-1.0 / 2.0)));
double t_2 = sqrt((1.0 / fma(F, F, 2.0)));
double t_3 = fma((t_2 / fma((B * (B * B)), fma((B * B), 0.008333333333333333, -0.16666666666666666), B)), F, -(x / tan(B)));
double tmp;
if (t_1 <= -1000.0) {
tmp = t_3;
} else if (t_1 <= -2e-26) {
tmp = t_2 * (F * (1.0 / sin(B)));
} else if (t_1 <= 5e-42) {
tmp = t_0 + (sqrt((1.0 / fma(x, 2.0, fma(F, F, 2.0)))) * (F / B));
} else if (t_1 <= 20.0) {
tmp = F / (sin(B) * sqrt(fma(F, F, 2.0)));
} else if (t_1 <= ((double) INFINITY)) {
tmp = t_3;
} else {
tmp = ((1.0 - (x * x)) / (-1.0 + x)) / B;
}
return tmp;
}
function code(F, B, x) t_0 = Float64(x * Float64(-1.0 / tan(B))) t_1 = Float64(t_0 + Float64(Float64(F / sin(B)) * (Float64(Float64(2.0 + Float64(F * F)) + Float64(x * 2.0)) ^ Float64(-1.0 / 2.0)))) t_2 = sqrt(Float64(1.0 / fma(F, F, 2.0))) t_3 = fma(Float64(t_2 / fma(Float64(B * Float64(B * B)), fma(Float64(B * B), 0.008333333333333333, -0.16666666666666666), B)), F, Float64(-Float64(x / tan(B)))) tmp = 0.0 if (t_1 <= -1000.0) tmp = t_3; elseif (t_1 <= -2e-26) tmp = Float64(t_2 * Float64(F * Float64(1.0 / sin(B)))); elseif (t_1 <= 5e-42) tmp = Float64(t_0 + Float64(sqrt(Float64(1.0 / fma(x, 2.0, fma(F, F, 2.0)))) * Float64(F / B))); elseif (t_1 <= 20.0) tmp = Float64(F / Float64(sin(B) * sqrt(fma(F, F, 2.0)))); elseif (t_1 <= Inf) tmp = t_3; else tmp = Float64(Float64(Float64(1.0 - Float64(x * x)) / Float64(-1.0 + x)) / B); end return tmp end
code[F_, B_, x_] := Block[{t$95$0 = N[(x * N[(-1.0 / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(N[(F / N[Sin[B], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(2.0 + N[(F * F), $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision], N[(-1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(1.0 / N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(t$95$2 / N[(N[(B * N[(B * B), $MachinePrecision]), $MachinePrecision] * N[(N[(B * B), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] + B), $MachinePrecision]), $MachinePrecision] * F + (-N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]}, If[LessEqual[t$95$1, -1000.0], t$95$3, If[LessEqual[t$95$1, -2e-26], N[(t$95$2 * N[(F * N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e-42], N[(t$95$0 + N[(N[Sqrt[N[(1.0 / N[(x * 2.0 + N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(F / B), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 20.0], N[(F / N[(N[Sin[B], $MachinePrecision] * N[Sqrt[N[(F * F + 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], t$95$3, N[(N[(N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] / B), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{-1}{\tan B}\\
t_1 := t\_0 + \frac{F}{\sin B} \cdot {\left(\left(2 + F \cdot F\right) + x \cdot 2\right)}^{\left(\frac{-1}{2}\right)}\\
t_2 := \sqrt{\frac{1}{\mathsf{fma}\left(F, F, 2\right)}}\\
t_3 := \mathsf{fma}\left(\frac{t\_2}{\mathsf{fma}\left(B \cdot \left(B \cdot B\right), \mathsf{fma}\left(B \cdot B, 0.008333333333333333, -0.16666666666666666\right), B\right)}, F, -\frac{x}{\tan B}\right)\\
\mathbf{if}\;t\_1 \leq -1000:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_1 \leq -2 \cdot 10^{-26}:\\
\;\;\;\;t\_2 \cdot \left(F \cdot \frac{1}{\sin B}\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-42}:\\
\;\;\;\;t\_0 + \sqrt{\frac{1}{\mathsf{fma}\left(x, 2, \mathsf{fma}\left(F, F, 2\right)\right)}} \cdot \frac{F}{B}\\
\mathbf{elif}\;t\_1 \leq 20:\\
\;\;\;\;\frac{F}{\sin B \cdot \sqrt{\mathsf{fma}\left(F, F, 2\right)}}\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - x \cdot x}{-1 + x}}{B}\\
\end{array}
\end{array}
if (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (*.f64 (/.f64 F (sin.f64 B)) (pow.f64 (+.f64 (+.f64 (*.f64 F F) #s(literal 2 binary64)) (*.f64 #s(literal 2 binary64) x)) (neg.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))))) < -1e3 or 20 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (*.f64 (/.f64 F (sin.f64 B)) (pow.f64 (+.f64 (+.f64 (*.f64 F F) #s(literal 2 binary64)) (*.f64 #s(literal 2 binary64) x)) (neg.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))))) < +inf.0Initial program 95.2%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
lower-fma.f64N/A
Applied rewrites98.7%
Taylor expanded in x around 0
lower-sqrt.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f6498.6
Applied rewrites98.6%
Taylor expanded in B around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6498.3
Applied rewrites98.3%
if -1e3 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (*.f64 (/.f64 F (sin.f64 B)) (pow.f64 (+.f64 (+.f64 (*.f64 F F) #s(literal 2 binary64)) (*.f64 #s(literal 2 binary64) x)) (neg.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))))) < -2.0000000000000001e-26Initial program 94.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
lower-fma.f64N/A
Applied rewrites94.7%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f6475.4
Applied rewrites75.4%
Applied rewrites75.4%
if -2.0000000000000001e-26 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (*.f64 (/.f64 F (sin.f64 B)) (pow.f64 (+.f64 (+.f64 (*.f64 F F) #s(literal 2 binary64)) (*.f64 #s(literal 2 binary64) x)) (neg.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))))) < 5.00000000000000003e-42Initial program 65.4%
Taylor expanded in B around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
lower-/.f6439.9
Applied rewrites39.9%
if 5.00000000000000003e-42 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (*.f64 (/.f64 F (sin.f64 B)) (pow.f64 (+.f64 (+.f64 (*.f64 F F) #s(literal 2 binary64)) (*.f64 #s(literal 2 binary64) x)) (neg.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))))) < 20Initial program 90.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
lower-fma.f64N/A
Applied rewrites91.0%
Taylor expanded in x around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f6469.2
Applied rewrites69.2%
Applied rewrites69.3%
if +inf.0 < (+.f64 (neg.f64 (*.f64 x (/.f64 #s(literal 1 binary64) (tan.f64 B)))) (*.f64 (/.f64 F (sin.f64 B)) (pow.f64 (+.f64 (+.f64 (*.f64 F F) #s(literal 2 binary64)) (*.f64 #s(literal 2 binary64) x)) (neg.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))))) Initial program 0.0%
Taylor expanded in B around 0
lower-/.f64N/A
sub-negN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
lower-neg.f6450.3
Applied rewrites50.3%
Taylor expanded in F around -inf
Applied rewrites73.7%
Applied rewrites71.9%
Final simplification78.3%
herbie shell --seed 2024227
(FPCore (F B x)
:name "VandenBroeck and Keller, Equation (23)"
:precision binary64
(+ (- (* x (/ 1.0 (tan B)))) (* (/ F (sin B)) (pow (+ (+ (* F F) 2.0) (* 2.0 x)) (- (/ 1.0 2.0))))))