
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((a + b))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(a + b)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((a + b))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (fma (cos a) (cos b) (* (sin a) (sin (- b))))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(cos(a), cos(b), (sin(a) * sin(-b)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(a), cos(b), Float64(sin(a) * sin(Float64(-b))))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * N[Sin[(-b)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos a, \cos b, \sin a \cdot \sin \left(-b\right)\right)}
\end{array}
Initial program 78.0%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-sin.f64N/A
sin-negN/A
lower-sin.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.6
Applied rewrites99.6%
Taylor expanded in r around 0
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
neg-mul-1N/A
lower-sin.f64N/A
neg-mul-1N/A
lower-neg.f6499.6
Applied rewrites99.6%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (/ (- a b) (/ (- b a) (+ b a)))))))
double code(double r, double a, double b) {
return r * (sin(b) / cos(((a - b) / ((b - a) / (b + a)))));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos(((a - b) / ((b - a) / (b + a)))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos(((a - b) / ((b - a) / (b + a)))));
}
def code(r, a, b): return r * (math.sin(b) / math.cos(((a - b) / ((b - a) / (b + a)))))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(Float64(a - b) / Float64(Float64(b - a) / Float64(b + a)))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos(((a - b) / ((b - a) / (b + a))))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(N[(a - b), $MachinePrecision] / N[(N[(b - a), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(\frac{a - b}{\frac{b - a}{b + a}}\right)}
\end{array}
Initial program 76.3%
lift-cos.f64N/A
lift-+.f64N/A
flip-+N/A
frac-2negN/A
distribute-frac-negN/A
cos-negN/A
lower-cos.f64N/A
lower-/.f64N/A
difference-of-squaresN/A
lift-+.f64N/A
lower-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f64N/A
lower-neg.f64N/A
lower--.f6448.7
Applied rewrites48.7%
lift-/.f64N/A
frac-2negN/A
Applied rewrites39.9%
Applied rewrites76.3%
herbie shell --seed 2024227
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))