
(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 (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 73.9%
+-commutative73.9%
Simplified73.9%
cos-sum99.5%
cancel-sign-sub-inv99.5%
fma-define99.5%
Applied egg-rr99.5%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (- (* (cos b) (cos a)) (* (sin b) (sin a)))))
double code(double r, double a, double b) {
return (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(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(b) * cos(a)) - (sin(b) * sin(a)))
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(b) * Math.sin(a)));
}
def code(r, a, b): return (r * math.sin(b)) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a)))
function code(r, a, b) return Float64(Float64(r * sin(b)) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a)))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(a))); 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[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 73.9%
+-commutative73.9%
Simplified73.9%
cos-sum99.5%
Applied egg-rr99.5%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(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(b) * cos(a)) - (sin(b) * sin(a))))
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(b) * Math.sin(a))));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 73.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
cos-sum99.5%
Applied egg-rr99.5%
(FPCore (r a b) :precision binary64 (/ 1.0 (- (* (/ (cos a) r) (/ (cos b) (sin b))) (/ (sin a) r))))
double code(double r, double a, double b) {
return 1.0 / (((cos(a) / r) * (cos(b) / sin(b))) - (sin(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 = 1.0d0 / (((cos(a) / r) * (cos(b) / sin(b))) - (sin(a) / r))
end function
public static double code(double r, double a, double b) {
return 1.0 / (((Math.cos(a) / r) * (Math.cos(b) / Math.sin(b))) - (Math.sin(a) / r));
}
def code(r, a, b): return 1.0 / (((math.cos(a) / r) * (math.cos(b) / math.sin(b))) - (math.sin(a) / r))
function code(r, a, b) return Float64(1.0 / Float64(Float64(Float64(cos(a) / r) * Float64(cos(b) / sin(b))) - Float64(sin(a) / r))) end
function tmp = code(r, a, b) tmp = 1.0 / (((cos(a) / r) * (cos(b) / sin(b))) - (sin(a) / r)); end
code[r_, a_, b_] := N[(1.0 / N[(N[(N[(N[Cos[a], $MachinePrecision] / r), $MachinePrecision] * N[(N[Cos[b], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[a], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\cos a}{r} \cdot \frac{\cos b}{\sin b} - \frac{\sin a}{r}}
\end{array}
Initial program 73.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
associate-*r/73.9%
clear-num73.8%
Applied egg-rr73.8%
add-sqr-sqrt30.1%
pow230.1%
Applied egg-rr30.1%
unpow230.1%
add-sqr-sqrt73.8%
cos-sum99.4%
div-sub89.3%
*-commutative89.3%
*-commutative89.3%
Applied egg-rr89.3%
*-commutative89.3%
*-commutative89.3%
times-frac89.1%
times-frac99.2%
*-inverses99.2%
*-lft-identity99.2%
Simplified99.2%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (cos (+ b a))))
double code(double r, double a, double b) {
return (r * sin(b)) / cos((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((b + a))
end function
public static double code(double r, double a, double b) {
return (r * Math.sin(b)) / Math.cos((b + a));
}
def code(r, a, b): return (r * math.sin(b)) / math.cos((b + a))
function code(r, a, b) return Float64(Float64(r * sin(b)) / cos(Float64(b + a))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / cos((b + a)); end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos \left(b + a\right)}
\end{array}
Initial program 73.9%
Final simplification73.9%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ b a)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((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((b + a)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((b + a)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((b + a)))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(Float64(b + a)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos((b + a))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(b + a\right)}
\end{array}
Initial program 73.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.00042) (not (<= b 1.45e-5))) (* r (tan b)) (/ (* r b) (cos a))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.00042) || !(b <= 1.45e-5)) {
tmp = r * tan(b);
} else {
tmp = (r * b) / cos(a);
}
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 <= (-0.00042d0)) .or. (.not. (b <= 1.45d-5))) then
tmp = r * tan(b)
else
tmp = (r * b) / cos(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -0.00042) || !(b <= 1.45e-5)) {
tmp = r * Math.tan(b);
} else {
tmp = (r * b) / Math.cos(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.00042) or not (b <= 1.45e-5): tmp = r * math.tan(b) else: tmp = (r * b) / math.cos(a) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.00042) || !(b <= 1.45e-5)) tmp = Float64(r * tan(b)); else tmp = Float64(Float64(r * b) / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -0.00042) || ~((b <= 1.45e-5))) tmp = r * tan(b); else tmp = (r * b) / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.00042], N[Not[LessEqual[b, 1.45e-5]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(N[(r * b), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.00042 \lor \neg \left(b \leq 1.45 \cdot 10^{-5}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot b}{\cos a}\\
\end{array}
\end{array}
if b < -4.2000000000000002e-4 or 1.45e-5 < b Initial program 49.5%
associate-/l*49.6%
remove-double-neg49.6%
remove-double-neg49.6%
+-commutative49.6%
Simplified49.6%
add-cube-cbrt49.0%
pow349.0%
Applied egg-rr49.0%
Taylor expanded in a around 0 48.8%
rem-cube-cbrt49.4%
*-un-lft-identity49.4%
quot-tan49.5%
Applied egg-rr49.5%
*-lft-identity49.5%
Simplified49.5%
if -4.2000000000000002e-4 < b < 1.45e-5Initial program 99.0%
associate-/l*98.9%
remove-double-neg98.9%
remove-double-neg98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in b around 0 99.0%
Final simplification73.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -9.2e-5) (not (<= b 8.5e-6))) (* r (tan b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -9.2e-5) || !(b <= 8.5e-6)) {
tmp = r * tan(b);
} else {
tmp = b * (r / cos(a));
}
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 <= (-9.2d-5)) .or. (.not. (b <= 8.5d-6))) then
tmp = r * tan(b)
else
tmp = b * (r / cos(a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -9.2e-5) || !(b <= 8.5e-6)) {
tmp = r * Math.tan(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -9.2e-5) or not (b <= 8.5e-6): tmp = r * math.tan(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -9.2e-5) || !(b <= 8.5e-6)) tmp = Float64(r * tan(b)); else tmp = Float64(b * Float64(r / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -9.2e-5) || ~((b <= 8.5e-6))) tmp = r * tan(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -9.2e-5], N[Not[LessEqual[b, 8.5e-6]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.2 \cdot 10^{-5} \lor \neg \left(b \leq 8.5 \cdot 10^{-6}\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -9.20000000000000001e-5 or 8.4999999999999999e-6 < b Initial program 49.5%
associate-/l*49.6%
remove-double-neg49.6%
remove-double-neg49.6%
+-commutative49.6%
Simplified49.6%
add-cube-cbrt49.0%
pow349.0%
Applied egg-rr49.0%
Taylor expanded in a around 0 48.8%
rem-cube-cbrt49.4%
*-un-lft-identity49.4%
quot-tan49.5%
Applied egg-rr49.5%
*-lft-identity49.5%
Simplified49.5%
if -9.20000000000000001e-5 < b < 8.4999999999999999e-6Initial program 99.0%
associate-/l*98.9%
remove-double-neg98.9%
remove-double-neg98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in b around 0 99.0%
associate-/l*99.0%
Simplified99.0%
Final simplification73.8%
(FPCore (r a b) :precision binary64 (* r (tan b)))
double code(double r, double a, double b) {
return r * tan(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 * tan(b)
end function
public static double code(double r, double a, double b) {
return r * Math.tan(b);
}
def code(r, a, b): return r * math.tan(b)
function code(r, a, b) return Float64(r * tan(b)) end
function tmp = code(r, a, b) tmp = r * tan(b); end
code[r_, a_, b_] := N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \tan b
\end{array}
Initial program 73.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
add-cube-cbrt72.8%
pow372.8%
Applied egg-rr72.8%
Taylor expanded in a around 0 58.1%
rem-cube-cbrt58.9%
*-un-lft-identity58.9%
quot-tan59.0%
Applied egg-rr59.0%
*-lft-identity59.0%
Simplified59.0%
(FPCore (r a b) :precision binary64 (* r b))
double code(double r, double a, double b) {
return r * 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 * b
end function
public static double code(double r, double a, double b) {
return r * b;
}
def code(r, a, b): return r * b
function code(r, a, b) return Float64(r * b) end
function tmp = code(r, a, b) tmp = r * b; end
code[r_, a_, b_] := N[(r * b), $MachinePrecision]
\begin{array}{l}
\\
r \cdot b
\end{array}
Initial program 73.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
Taylor expanded in b around 0 50.8%
associate-/l*50.8%
Simplified50.8%
Taylor expanded in a around 0 36.1%
*-commutative36.1%
Simplified36.1%
herbie shell --seed 2024114
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))