
(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 (fma (sin a) -1.0 (* (pow (tan b) -1.0) (cos a)))))
double code(double r, double a, double b) {
return r / fma(sin(a), -1.0, (pow(tan(b), -1.0) * cos(a)));
}
function code(r, a, b) return Float64(r / fma(sin(a), -1.0, Float64((tan(b) ^ -1.0) * cos(a)))) end
code[r_, a_, b_] := N[(r / N[(N[Sin[a], $MachinePrecision] * -1.0 + N[(N[Power[N[Tan[b], $MachinePrecision], -1.0], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\mathsf{fma}\left(\sin a, -1, {\tan b}^{-1} \cdot \cos a\right)}
\end{array}
Initial program 77.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6477.7
Applied rewrites77.7%
lift-/.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
lift-cos.f64N/A
lift-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lower-*.f6499.4
Applied rewrites99.4%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-inversesN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-fma.f6499.5
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.5%
(FPCore (r a b)
:precision binary64
(/
r
(*
(-
(*
(fma
(fma -0.00205026455026455 (* b b) -0.019444444444444445)
(* b b)
-0.16666666666666666)
b)
(pow b -1.0))
(/ (cos (+ a b)) -1.0))))
double code(double r, double a, double b) {
return r / (((fma(fma(-0.00205026455026455, (b * b), -0.019444444444444445), (b * b), -0.16666666666666666) * b) - pow(b, -1.0)) * (cos((a + b)) / -1.0));
}
function code(r, a, b) return Float64(r / Float64(Float64(Float64(fma(fma(-0.00205026455026455, Float64(b * b), -0.019444444444444445), Float64(b * b), -0.16666666666666666) * b) - (b ^ -1.0)) * Float64(cos(Float64(a + b)) / -1.0))) end
code[r_, a_, b_] := N[(r / N[(N[(N[(N[(N[(-0.00205026455026455 * N[(b * b), $MachinePrecision] + -0.019444444444444445), $MachinePrecision] * N[(b * b), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * b), $MachinePrecision] - N[Power[b, -1.0], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision] / -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.00205026455026455, b \cdot b, -0.019444444444444445\right), b \cdot b, -0.16666666666666666\right) \cdot b - {b}^{-1}\right) \cdot \frac{\cos \left(a + b\right)}{-1}}
\end{array}
Initial program 77.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6477.7
Applied rewrites77.7%
lift-/.f64N/A
frac-2negN/A
neg-mul-1N/A
neg-mul-1N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6477.7
Applied rewrites77.7%
Taylor expanded in b around 0
div-subN/A
*-commutativeN/A
associate-/l*N/A
*-lft-identityN/A
associate-*l/N/A
unpow2N/A
associate-*r*N/A
lft-mult-inverseN/A
*-lft-identityN/A
lower--.f64N/A
Applied rewrites52.4%
Final simplification52.4%
(FPCore (r a b) :precision binary64 (/ r (* (- (* -0.16666666666666666 b) (pow b -1.0)) (/ (cos (+ a b)) -1.0))))
double code(double r, double a, double b) {
return r / (((-0.16666666666666666 * b) - pow(b, -1.0)) * (cos((a + b)) / -1.0));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r / ((((-0.16666666666666666d0) * b) - (b ** (-1.0d0))) * (cos((a + b)) / (-1.0d0)))
end function
public static double code(double r, double a, double b) {
return r / (((-0.16666666666666666 * b) - Math.pow(b, -1.0)) * (Math.cos((a + b)) / -1.0));
}
def code(r, a, b): return r / (((-0.16666666666666666 * b) - math.pow(b, -1.0)) * (math.cos((a + b)) / -1.0))
function code(r, a, b) return Float64(r / Float64(Float64(Float64(-0.16666666666666666 * b) - (b ^ -1.0)) * Float64(cos(Float64(a + b)) / -1.0))) end
function tmp = code(r, a, b) tmp = r / (((-0.16666666666666666 * b) - (b ^ -1.0)) * (cos((a + b)) / -1.0)); end
code[r_, a_, b_] := N[(r / N[(N[(N[(-0.16666666666666666 * b), $MachinePrecision] - N[Power[b, -1.0], $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision] / -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\left(-0.16666666666666666 \cdot b - {b}^{-1}\right) \cdot \frac{\cos \left(a + b\right)}{-1}}
\end{array}
Initial program 77.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6477.7
Applied rewrites77.7%
lift-/.f64N/A
frac-2negN/A
neg-mul-1N/A
neg-mul-1N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6477.7
Applied rewrites77.7%
Taylor expanded in b around 0
div-subN/A
associate-/l*N/A
*-lft-identityN/A
associate-*l/N/A
unpow2N/A
associate-*r*N/A
lft-mult-inverseN/A
*-lft-identityN/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f6452.4
Applied rewrites52.4%
Final simplification52.4%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (* r (sin b))))
(if (or (<= a -11000000000.0) (not (<= a 0.0019)))
(/ t_0 (cos a))
(/ t_0 (cos b)))))
double code(double r, double a, double b) {
double t_0 = r * sin(b);
double tmp;
if ((a <= -11000000000.0) || !(a <= 0.0019)) {
tmp = t_0 / cos(a);
} else {
tmp = t_0 / cos(b);
}
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) :: t_0
real(8) :: tmp
t_0 = r * sin(b)
if ((a <= (-11000000000.0d0)) .or. (.not. (a <= 0.0019d0))) then
tmp = t_0 / cos(a)
else
tmp = t_0 / cos(b)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = r * Math.sin(b);
double tmp;
if ((a <= -11000000000.0) || !(a <= 0.0019)) {
tmp = t_0 / Math.cos(a);
} else {
tmp = t_0 / Math.cos(b);
}
return tmp;
}
def code(r, a, b): t_0 = r * math.sin(b) tmp = 0 if (a <= -11000000000.0) or not (a <= 0.0019): tmp = t_0 / math.cos(a) else: tmp = t_0 / math.cos(b) return tmp
function code(r, a, b) t_0 = Float64(r * sin(b)) tmp = 0.0 if ((a <= -11000000000.0) || !(a <= 0.0019)) tmp = Float64(t_0 / cos(a)); else tmp = Float64(t_0 / cos(b)); end return tmp end
function tmp_2 = code(r, a, b) t_0 = r * sin(b); tmp = 0.0; if ((a <= -11000000000.0) || ~((a <= 0.0019))) tmp = t_0 / cos(a); else tmp = t_0 / cos(b); end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[a, -11000000000.0], N[Not[LessEqual[a, 0.0019]], $MachinePrecision]], N[(t$95$0 / N[Cos[a], $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Cos[b], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := r \cdot \sin b\\
\mathbf{if}\;a \leq -11000000000 \lor \neg \left(a \leq 0.0019\right):\\
\;\;\;\;\frac{t\_0}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\cos b}\\
\end{array}
\end{array}
if a < -1.1e10 or 0.0019 < a Initial program 58.1%
Taylor expanded in b around 0
lower-cos.f6458.6
Applied rewrites58.6%
if -1.1e10 < a < 0.0019Initial program 97.3%
Taylor expanded in a around 0
lower-cos.f6497.3
Applied rewrites97.3%
Final simplification78.1%
(FPCore (r a b) :precision binary64 (if (or (<= a -11000000000.0) (not (<= a 0.0019))) (/ (* r (sin b)) (cos a)) (* (/ r (cos b)) (sin b))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -11000000000.0) || !(a <= 0.0019)) {
tmp = (r * sin(b)) / cos(a);
} else {
tmp = (r / cos(b)) * sin(b);
}
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 <= (-11000000000.0d0)) .or. (.not. (a <= 0.0019d0))) then
tmp = (r * sin(b)) / cos(a)
else
tmp = (r / cos(b)) * sin(b)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -11000000000.0) || !(a <= 0.0019)) {
tmp = (r * Math.sin(b)) / Math.cos(a);
} else {
tmp = (r / Math.cos(b)) * Math.sin(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -11000000000.0) or not (a <= 0.0019): tmp = (r * math.sin(b)) / math.cos(a) else: tmp = (r / math.cos(b)) * math.sin(b) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -11000000000.0) || !(a <= 0.0019)) tmp = Float64(Float64(r * sin(b)) / cos(a)); else tmp = Float64(Float64(r / cos(b)) * sin(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -11000000000.0) || ~((a <= 0.0019))) tmp = (r * sin(b)) / cos(a); else tmp = (r / cos(b)) * sin(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -11000000000.0], N[Not[LessEqual[a, 0.0019]], $MachinePrecision]], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision], N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -11000000000 \lor \neg \left(a \leq 0.0019\right):\\
\;\;\;\;\frac{r \cdot \sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\cos b} \cdot \sin b\\
\end{array}
\end{array}
if a < -1.1e10 or 0.0019 < a Initial program 58.1%
Taylor expanded in b around 0
lower-cos.f6458.6
Applied rewrites58.6%
if -1.1e10 < a < 0.0019Initial program 97.3%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-sin.f6497.3
Applied rewrites97.3%
Final simplification78.1%
(FPCore (r a b) :precision binary64 (if (or (<= b -1.9e-5) (not (<= b 0.21))) (* (/ r (cos b)) (sin b)) (* (/ b (cos a)) r)))
double code(double r, double a, double b) {
double tmp;
if ((b <= -1.9e-5) || !(b <= 0.21)) {
tmp = (r / cos(b)) * sin(b);
} 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 <= (-1.9d-5)) .or. (.not. (b <= 0.21d0))) then
tmp = (r / cos(b)) * sin(b)
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 <= -1.9e-5) || !(b <= 0.21)) {
tmp = (r / Math.cos(b)) * Math.sin(b);
} else {
tmp = (b / Math.cos(a)) * r;
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -1.9e-5) or not (b <= 0.21): tmp = (r / math.cos(b)) * math.sin(b) else: tmp = (b / math.cos(a)) * r return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -1.9e-5) || !(b <= 0.21)) tmp = Float64(Float64(r / cos(b)) * sin(b)); else tmp = Float64(Float64(b / cos(a)) * r); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -1.9e-5) || ~((b <= 0.21))) tmp = (r / cos(b)) * sin(b); else tmp = (b / cos(a)) * r; end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -1.9e-5], N[Not[LessEqual[b, 0.21]], $MachinePrecision]], N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{-5} \lor \neg \left(b \leq 0.21\right):\\
\;\;\;\;\frac{r}{\cos b} \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\cos a} \cdot r\\
\end{array}
\end{array}
if b < -1.9000000000000001e-5 or 0.209999999999999992 < b Initial program 56.6%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-sin.f6455.5
Applied rewrites55.5%
if -1.9000000000000001e-5 < b < 0.209999999999999992Initial program 98.7%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6498.8
Applied rewrites98.8%
Applied rewrites98.8%
Final simplification77.3%
(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.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.9
Applied rewrites77.9%
(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.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.8
Applied rewrites77.8%
(FPCore (r a b) :precision binary64 (* (/ b (cos a)) r))
double code(double r, double a, double b) {
return (b / cos(a)) * 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 / cos(a)) * r
end function
public static double code(double r, double a, double b) {
return (b / Math.cos(a)) * r;
}
def code(r, a, b): return (b / math.cos(a)) * r
function code(r, a, b) return Float64(Float64(b / cos(a)) * r) end
function tmp = code(r, a, b) tmp = (b / cos(a)) * r; end
code[r_, a_, b_] := N[(N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{\cos a} \cdot r
\end{array}
Initial program 77.8%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6452.1
Applied rewrites52.1%
Applied rewrites52.1%
(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.8%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6452.1
Applied rewrites52.1%
Taylor expanded in a around 0
Applied rewrites35.4%
herbie shell --seed 2024302
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))