
(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 3 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 (fma (/ F (sqrt (fma 2.0 x (fma F F 2.0)))) (/ 1.0 (sin B)) (/ (- x) (tan B))))
double code(double F, double B, double x) {
return fma((F / sqrt(fma(2.0, x, fma(F, F, 2.0)))), (1.0 / sin(B)), (-x / tan(B)));
}
function code(F, B, x) return fma(Float64(F / sqrt(fma(2.0, x, fma(F, F, 2.0)))), Float64(1.0 / sin(B)), Float64(Float64(-x) / tan(B))) end
code[F_, B_, x_] := N[(N[(F / N[Sqrt[N[(2.0 * x + N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sin[B], $MachinePrecision]), $MachinePrecision] + N[((-x) / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{F}{\sqrt{\mathsf{fma}\left(2, x, \mathsf{fma}\left(F, F, 2\right)\right)}}, \frac{1}{\sin B}, \frac{-x}{\tan B}\right)
\end{array}
Initial program 76.6%
+-commutativeN/A
*-commutativeN/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
accelerator-lowering-fma.f64N/A
Applied egg-rr86.9%
clear-numN/A
associate-*l/N/A
div-invN/A
times-fracN/A
accelerator-lowering-fma.f64N/A
Applied egg-rr86.9%
associate-*l/N/A
div-invN/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
*-lft-identityN/A
/-lowering-/.f64N/A
unpow1/2N/A
sqrt-lowering-sqrt.f64N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f64N/A
neg-lowering-neg.f64N/A
/-lowering-/.f64N/A
tan-lowering-tan.f6486.9
Applied egg-rr86.9%
Final simplification86.9%
(FPCore (F B x) :precision binary64 (/ (- (/ F (sqrt (fma 2.0 x (fma F F 2.0)))) (* x (cos B))) (sin B)))
double code(double F, double B, double x) {
return ((F / sqrt(fma(2.0, x, fma(F, F, 2.0)))) - (x * cos(B))) / sin(B);
}
function code(F, B, x) return Float64(Float64(Float64(F / sqrt(fma(2.0, x, fma(F, F, 2.0)))) - Float64(x * cos(B))) / sin(B)) end
code[F_, B_, x_] := N[(N[(N[(F / N[Sqrt[N[(2.0 * x + N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(x * N[Cos[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sin[B], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{F}{\sqrt{\mathsf{fma}\left(2, x, \mathsf{fma}\left(F, F, 2\right)\right)}} - x \cdot \cos B}{\sin B}
\end{array}
Initial program 76.6%
+-commutativeN/A
*-commutativeN/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
accelerator-lowering-fma.f64N/A
Applied egg-rr86.9%
clear-numN/A
associate-*l/N/A
div-invN/A
times-fracN/A
accelerator-lowering-fma.f64N/A
Applied egg-rr86.9%
unsub-negN/A
associate-*l/N/A
tan-quotN/A
associate-/r/N/A
associate-*l/N/A
sub-divN/A
Applied egg-rr86.9%
(FPCore (F B x) :precision binary64 (- (/ F (* (sqrt (fma 2.0 x (fma F F 2.0))) (sin B))) (/ x (tan B))))
double code(double F, double B, double x) {
return (F / (sqrt(fma(2.0, x, fma(F, F, 2.0))) * sin(B))) - (x / tan(B));
}
function code(F, B, x) return Float64(Float64(F / Float64(sqrt(fma(2.0, x, fma(F, F, 2.0))) * sin(B))) - Float64(x / tan(B))) end
code[F_, B_, x_] := N[(N[(F / N[(N[Sqrt[N[(2.0 * x + N[(F * F + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x / N[Tan[B], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{F}{\sqrt{\mathsf{fma}\left(2, x, \mathsf{fma}\left(F, F, 2\right)\right)} \cdot \sin B} - \frac{x}{\tan B}
\end{array}
Initial program 76.6%
+-commutativeN/A
*-commutativeN/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
div-invN/A
accelerator-lowering-fma.f64N/A
Applied egg-rr86.9%
clear-numN/A
associate-*l/N/A
div-invN/A
times-fracN/A
accelerator-lowering-fma.f64N/A
Applied egg-rr86.9%
unsub-negN/A
frac-timesN/A
div-invN/A
*-lft-identityN/A
inv-powN/A
unpow-prod-downN/A
metadata-evalN/A
pow-flipN/A
unpow-prod-downN/A
div-invN/A
inv-powN/A
clear-numN/A
Applied egg-rr86.9%
herbie shell --seed 2024208
(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))))))