
(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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(a + b\right)}
\end{array}
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (fma (sin b) (- (sin a)) (* (cos b) (cos a)))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(sin(b), -sin(a), (cos(b) * cos(a)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(sin(b), Float64(-sin(a)), Float64(cos(b) * cos(a)))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision]) + N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \cos b \cdot \cos a\right)}
\end{array}
Initial program 77.0%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.5
Applied rewrites99.5%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (fma (cos b) (cos a) (* (- (sin b)) (sin a)))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(cos(b), cos(a), (-sin(b) * sin(a)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(b), cos(a), Float64(Float64(-sin(b)) * sin(a)))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[((-N[Sin[b], $MachinePrecision]) * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin b\right) \cdot \sin a\right)}
\end{array}
Initial program 77.0%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lift-sin.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6499.5
Applied rewrites99.5%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (- (* (cos b) (cos a)) (* (sin a) (sin b)))))
double code(double r, double a, double b) {
return (r * sin(b)) / ((cos(b) * cos(a)) - (sin(a) * sin(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(b) * cos(a)) - (sin(a) * sin(b)))
end function
public static double code(double r, double a, double b) {
return (r * Math.sin(b)) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(a) * Math.sin(b)));
}
def code(r, a, b): return (r * math.sin(b)) / ((math.cos(b) * math.cos(a)) - (math.sin(a) * math.sin(b)))
function code(r, a, b) return Float64(Float64(r * sin(b)) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(a) * sin(b)))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(a) * sin(b))); end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[a], $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin a \cdot \sin b}
\end{array}
Initial program 77.0%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lower-sin.f6499.5
Applied rewrites99.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.000225) (not (<= a 3.4e-7))) (/ (* r (sin b)) (cos a)) (* (tan b) r)))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.000225) || !(a <= 3.4e-7)) {
tmp = (r * sin(b)) / cos(a);
} else {
tmp = tan(b) * r;
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((a <= (-0.000225d0)) .or. (.not. (a <= 3.4d-7))) then
tmp = (r * sin(b)) / cos(a)
else
tmp = tan(b) * r
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -0.000225) || !(a <= 3.4e-7)) {
tmp = (r * Math.sin(b)) / Math.cos(a);
} else {
tmp = Math.tan(b) * r;
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -0.000225) or not (a <= 3.4e-7): tmp = (r * math.sin(b)) / math.cos(a) else: tmp = math.tan(b) * r return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -0.000225) || !(a <= 3.4e-7)) tmp = Float64(Float64(r * sin(b)) / cos(a)); else tmp = Float64(tan(b) * r); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -0.000225) || ~((a <= 3.4e-7))) tmp = (r * sin(b)) / cos(a); else tmp = tan(b) * r; end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -0.000225], N[Not[LessEqual[a, 3.4e-7]], $MachinePrecision]], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision], N[(N[Tan[b], $MachinePrecision] * r), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.000225 \lor \neg \left(a \leq 3.4 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{r \cdot \sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\tan b \cdot r\\
\end{array}
\end{array}
if a < -2.2499999999999999e-4 or 3.39999999999999974e-7 < a Initial program 57.3%
Taylor expanded in b around 0
lower-cos.f6457.2
Applied rewrites57.2%
if -2.2499999999999999e-4 < a < 3.39999999999999974e-7Initial program 98.1%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6498.0
Applied rewrites98.0%
Applied rewrites98.2%
Final simplification77.1%
(FPCore (r a b) :precision binary64 (* (/ (sin b) (cos (+ a b))) r))
double code(double r, double a, double b) {
return (sin(b) / cos((a + b))) * r;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (sin(b) / cos((a + b))) * r
end function
public static double code(double r, double a, double b) {
return (Math.sin(b) / Math.cos((a + b))) * r;
}
def code(r, a, b): return (math.sin(b) / math.cos((a + b))) * r
function code(r, a, b) return Float64(Float64(sin(b) / cos(Float64(a + b))) * r) end
function tmp = code(r, a, b) tmp = (sin(b) / cos((a + b))) * r; end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b}{\cos \left(a + b\right)} \cdot r
\end{array}
Initial program 77.0%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
(FPCore (r a b) :precision binary64 (* (/ r (cos (+ a b))) (sin b)))
double code(double r, double a, double b) {
return (r / cos((a + b))) * sin(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 / cos((a + b))) * sin(b)
end function
public static double code(double r, double a, double b) {
return (r / Math.cos((a + b))) * Math.sin(b);
}
def code(r, a, b): return (r / math.cos((a + b))) * math.sin(b)
function code(r, a, b) return Float64(Float64(r / cos(Float64(a + b))) * sin(b)) end
function tmp = code(r, a, b) tmp = (r / cos((a + b))) * sin(b); end
code[r_, a_, b_] := N[(N[(r / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\cos \left(a + b\right)} \cdot \sin b
\end{array}
Initial program 77.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.0
Applied rewrites77.0%
(FPCore (r a b)
:precision binary64
(if (or (<= b -4100000000.0) (not (<= b 72000000.0)))
(* (tan b) r)
(/
(*
(*
r
(fma
(fma 0.008333333333333333 (* b b) -0.16666666666666666)
(* b b)
1.0))
b)
(cos (+ a b)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -4100000000.0) || !(b <= 72000000.0)) {
tmp = tan(b) * r;
} else {
tmp = ((r * fma(fma(0.008333333333333333, (b * b), -0.16666666666666666), (b * b), 1.0)) * b) / cos((a + b));
}
return tmp;
}
function code(r, a, b) tmp = 0.0 if ((b <= -4100000000.0) || !(b <= 72000000.0)) tmp = Float64(tan(b) * r); else tmp = Float64(Float64(Float64(r * fma(fma(0.008333333333333333, Float64(b * b), -0.16666666666666666), Float64(b * b), 1.0)) * b) / cos(Float64(a + b))); end return tmp end
code[r_, a_, b_] := If[Or[LessEqual[b, -4100000000.0], N[Not[LessEqual[b, 72000000.0]], $MachinePrecision]], N[(N[Tan[b], $MachinePrecision] * r), $MachinePrecision], N[(N[(N[(r * N[(N[(0.008333333333333333 * N[(b * b), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * N[(b * b), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4100000000 \lor \neg \left(b \leq 72000000\right):\\
\;\;\;\;\tan b \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(r \cdot \mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right), b \cdot b, 1\right)\right) \cdot b}{\cos \left(a + b\right)}\\
\end{array}
\end{array}
if b < -4.1e9 or 7.2e7 < b Initial program 56.2%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.3
Applied rewrites99.3%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6455.7
Applied rewrites55.7%
Applied rewrites55.9%
if -4.1e9 < b < 7.2e7Initial program 96.3%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites95.9%
Final simplification76.7%
(FPCore (r a b) :precision binary64 (if (or (<= b -4100000000.0) (not (<= b 7.5e-7))) (* (tan b) r) (* (/ b (cos a)) r)))
double code(double r, double a, double b) {
double tmp;
if ((b <= -4100000000.0) || !(b <= 7.5e-7)) {
tmp = tan(b) * r;
} else {
tmp = (b / cos(a)) * r;
}
return tmp;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b <= (-4100000000.0d0)) .or. (.not. (b <= 7.5d-7))) then
tmp = tan(b) * r
else
tmp = (b / cos(a)) * r
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -4100000000.0) || !(b <= 7.5e-7)) {
tmp = Math.tan(b) * r;
} else {
tmp = (b / Math.cos(a)) * r;
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -4100000000.0) or not (b <= 7.5e-7): tmp = math.tan(b) * r else: tmp = (b / math.cos(a)) * r return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -4100000000.0) || !(b <= 7.5e-7)) tmp = Float64(tan(b) * r); else tmp = Float64(Float64(b / cos(a)) * r); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -4100000000.0) || ~((b <= 7.5e-7))) tmp = tan(b) * r; else tmp = (b / cos(a)) * r; end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -4100000000.0], N[Not[LessEqual[b, 7.5e-7]], $MachinePrecision]], N[(N[Tan[b], $MachinePrecision] * r), $MachinePrecision], N[(N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4100000000 \lor \neg \left(b \leq 7.5 \cdot 10^{-7}\right):\\
\;\;\;\;\tan b \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\cos a} \cdot r\\
\end{array}
\end{array}
if b < -4.1e9 or 7.5000000000000002e-7 < b Initial program 55.1%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.3
Applied rewrites99.3%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6454.4
Applied rewrites54.4%
Applied rewrites54.6%
if -4.1e9 < b < 7.5000000000000002e-7Initial program 99.0%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6498.7
Applied rewrites98.7%
Applied rewrites98.7%
Final simplification76.6%
(FPCore (r a b) :precision binary64 (* (tan b) r))
double code(double r, double a, double b) {
return tan(b) * r;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = tan(b) * r
end function
public static double code(double r, double a, double b) {
return Math.tan(b) * r;
}
def code(r, a, b): return math.tan(b) * r
function code(r, a, b) return Float64(tan(b) * r) end
function tmp = code(r, a, b) tmp = tan(b) * r; end
code[r_, a_, b_] := N[(N[Tan[b], $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\tan b \cdot r
\end{array}
Initial program 77.0%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.5
Applied rewrites99.5%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6458.8
Applied rewrites58.8%
Applied rewrites58.9%
(FPCore (r a b) :precision binary64 (* b r))
double code(double r, double a, double b) {
return b * r;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = b * r
end function
public static double code(double r, double a, double b) {
return b * r;
}
def code(r, a, b): return b * r
function code(r, a, b) return Float64(b * r) end
function tmp = code(r, a, b) tmp = b * r; end
code[r_, a_, b_] := N[(b * r), $MachinePrecision]
\begin{array}{l}
\\
b \cdot r
\end{array}
Initial program 77.0%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6451.2
Applied rewrites51.2%
Taylor expanded in a around 0
Applied rewrites33.6%
herbie shell --seed 2024322
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))