
(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 9 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 (cos b) (cos a) (* (- (sin a)) (sin b)))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(cos(b), cos(a), (-sin(a) * sin(b)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(b), cos(a), Float64(Float64(-sin(a)) * sin(b)))) 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[a], $MachinePrecision]) * N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \left(-\sin a\right) \cdot \sin b\right)}
\end{array}
Initial program 77.4%
Applied rewrites99.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -3.05e-5) (not (<= a 6.8e-6))) (* (/ (sin b) (cos a)) r) (* (/ r (cos b)) (sin b))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -3.05e-5) || !(a <= 6.8e-6)) {
tmp = (sin(b) / cos(a)) * r;
} 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 <= (-3.05d-5)) .or. (.not. (a <= 6.8d-6))) then
tmp = (sin(b) / cos(a)) * r
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 <= -3.05e-5) || !(a <= 6.8e-6)) {
tmp = (Math.sin(b) / Math.cos(a)) * r;
} else {
tmp = (r / Math.cos(b)) * Math.sin(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -3.05e-5) or not (a <= 6.8e-6): tmp = (math.sin(b) / math.cos(a)) * r else: tmp = (r / math.cos(b)) * math.sin(b) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -3.05e-5) || !(a <= 6.8e-6)) tmp = Float64(Float64(sin(b) / cos(a)) * r); 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 <= -3.05e-5) || ~((a <= 6.8e-6))) tmp = (sin(b) / cos(a)) * r; else tmp = (r / cos(b)) * sin(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -3.05e-5], N[Not[LessEqual[a, 6.8e-6]], $MachinePrecision]], N[(N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision], N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.05 \cdot 10^{-5} \lor \neg \left(a \leq 6.8 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{\sin b}{\cos a} \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\cos b} \cdot \sin b\\
\end{array}
\end{array}
if a < -3.04999999999999994e-5 or 6.80000000000000012e-6 < a Initial program 53.3%
Taylor expanded in b around 0
lower-cos.f6452.9
Applied rewrites52.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6452.9
Applied rewrites52.9%
if -3.04999999999999994e-5 < a < 6.80000000000000012e-6Initial program 97.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.f6497.6
Applied rewrites97.6%
Final simplification77.2%
(FPCore (r a b) :precision binary64 (if (or (<= b -3e-6) (not (<= b 7e-7))) (* (/ r (cos b)) (sin b)) (* (/ r (cos a)) b)))
double code(double r, double a, double b) {
double tmp;
if ((b <= -3e-6) || !(b <= 7e-7)) {
tmp = (r / cos(b)) * sin(b);
} else {
tmp = (r / cos(a)) * 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 ((b <= (-3d-6)) .or. (.not. (b <= 7d-7))) then
tmp = (r / cos(b)) * sin(b)
else
tmp = (r / cos(a)) * b
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -3e-6) || !(b <= 7e-7)) {
tmp = (r / Math.cos(b)) * Math.sin(b);
} else {
tmp = (r / Math.cos(a)) * b;
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -3e-6) or not (b <= 7e-7): tmp = (r / math.cos(b)) * math.sin(b) else: tmp = (r / math.cos(a)) * b return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -3e-6) || !(b <= 7e-7)) tmp = Float64(Float64(r / cos(b)) * sin(b)); else tmp = Float64(Float64(r / cos(a)) * b); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -3e-6) || ~((b <= 7e-7))) tmp = (r / cos(b)) * sin(b); else tmp = (r / cos(a)) * b; end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -3e-6], N[Not[LessEqual[b, 7e-7]], $MachinePrecision]], N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-6} \lor \neg \left(b \leq 7 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{r}{\cos b} \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\cos a} \cdot b\\
\end{array}
\end{array}
if b < -3.0000000000000001e-6 or 6.99999999999999968e-7 < b Initial program 59.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.f6458.6
Applied rewrites58.6%
if -3.0000000000000001e-6 < b < 6.99999999999999968e-7Initial program 99.4%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.5
Applied rewrites99.5%
Final simplification76.9%
(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}
Initial program 77.4%
(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.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.3
Applied rewrites77.3%
(FPCore (r a b)
:precision binary64
(if (or (<= b -0.0064) (not (<= b 9.5)))
(/ (* r (sin b)) 1.0)
(/
(*
(fma
(* (fma 0.008333333333333333 (* b b) -0.16666666666666666) r)
(* b b)
r)
b)
(cos (+ a b)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.0064) || !(b <= 9.5)) {
tmp = (r * sin(b)) / 1.0;
} else {
tmp = (fma((fma(0.008333333333333333, (b * b), -0.16666666666666666) * r), (b * b), r) * b) / cos((a + b));
}
return tmp;
}
function code(r, a, b) tmp = 0.0 if ((b <= -0.0064) || !(b <= 9.5)) tmp = Float64(Float64(r * sin(b)) / 1.0); else tmp = Float64(Float64(fma(Float64(fma(0.008333333333333333, Float64(b * b), -0.16666666666666666) * r), Float64(b * b), r) * b) / cos(Float64(a + b))); end return tmp end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.0064], N[Not[LessEqual[b, 9.5]], $MachinePrecision]], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / 1.0), $MachinePrecision], N[(N[(N[(N[(N[(0.008333333333333333 * N[(b * b), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * r), $MachinePrecision] * N[(b * b), $MachinePrecision] + r), $MachinePrecision] * b), $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0064 \lor \neg \left(b \leq 9.5\right):\\
\;\;\;\;\frac{r \cdot \sin b}{1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, b \cdot b, -0.16666666666666666\right) \cdot r, b \cdot b, r\right) \cdot b}{\cos \left(a + b\right)}\\
\end{array}
\end{array}
if b < -0.00640000000000000031 or 9.5 < b Initial program 57.9%
Taylor expanded in b around 0
lower-cos.f6411.9
Applied rewrites11.9%
Taylor expanded in a around 0
Applied rewrites11.9%
if -0.00640000000000000031 < b < 9.5Initial program 99.4%
Taylor expanded in b around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.2
Applied rewrites99.2%
Final simplification52.8%
(FPCore (r a b) :precision binary64 (if (or (<= b -1.05e+14) (not (<= b 1320000000000.0))) (/ (* r (sin b)) 1.0) (* (/ r (cos a)) b)))
double code(double r, double a, double b) {
double tmp;
if ((b <= -1.05e+14) || !(b <= 1320000000000.0)) {
tmp = (r * sin(b)) / 1.0;
} else {
tmp = (r / cos(a)) * 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 ((b <= (-1.05d+14)) .or. (.not. (b <= 1320000000000.0d0))) then
tmp = (r * sin(b)) / 1.0d0
else
tmp = (r / cos(a)) * b
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -1.05e+14) || !(b <= 1320000000000.0)) {
tmp = (r * Math.sin(b)) / 1.0;
} else {
tmp = (r / Math.cos(a)) * b;
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -1.05e+14) or not (b <= 1320000000000.0): tmp = (r * math.sin(b)) / 1.0 else: tmp = (r / math.cos(a)) * b return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -1.05e+14) || !(b <= 1320000000000.0)) tmp = Float64(Float64(r * sin(b)) / 1.0); else tmp = Float64(Float64(r / cos(a)) * b); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -1.05e+14) || ~((b <= 1320000000000.0))) tmp = (r * sin(b)) / 1.0; else tmp = (r / cos(a)) * b; end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -1.05e+14], N[Not[LessEqual[b, 1320000000000.0]], $MachinePrecision]], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / 1.0), $MachinePrecision], N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05 \cdot 10^{+14} \lor \neg \left(b \leq 1320000000000\right):\\
\;\;\;\;\frac{r \cdot \sin b}{1}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\cos a} \cdot b\\
\end{array}
\end{array}
if b < -1.05e14 or 1.32e12 < b Initial program 58.5%
Taylor expanded in b around 0
lower-cos.f6412.0
Applied rewrites12.0%
Taylor expanded in a around 0
Applied rewrites12.3%
if -1.05e14 < b < 1.32e12Initial program 95.9%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6491.8
Applied rewrites91.8%
Final simplification52.4%
(FPCore (r a b) :precision binary64 (* (/ r (cos a)) b))
double code(double r, double a, double b) {
return (r / 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 / cos(a)) * b
end function
public static double code(double r, double a, double b) {
return (r / Math.cos(a)) * b;
}
def code(r, a, b): return (r / math.cos(a)) * b
function code(r, a, b) return Float64(Float64(r / cos(a)) * b) end
function tmp = code(r, a, b) tmp = (r / cos(a)) * b; end
code[r_, a_, b_] := N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\cos a} \cdot b
\end{array}
Initial program 77.4%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6448.0
Applied rewrites48.0%
(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.4%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6448.0
Applied rewrites48.0%
Taylor expanded in a around 0
Applied rewrites32.6%
herbie shell --seed 2024343
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))