
(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) (- (* (cos a) (cos b)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(a) * cos(b)) - (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(a) * cos(b)) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / ((Math.cos(a) * Math.cos(b)) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(a) * math.cos(b)) - (math.sin(b) * math.sin(a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(a) * cos(b)) - Float64(sin(b) * sin(a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((cos(a) * cos(b)) - (sin(b) * sin(a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a}
\end{array}
Initial program 73.4%
+-commutative73.4%
Simplified73.4%
cos-sum99.4%
cancel-sign-sub-inv99.4%
fma-define99.4%
Applied egg-rr99.4%
Taylor expanded in r around 0 99.4%
associate-/l*99.4%
+-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
neg-mul-199.4%
cancel-sign-sub-inv99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (* (cos a) (cos b))))
double code(double r, double a, double b) {
return (r * sin(b)) / (cos(a) * cos(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) * cos(b))
end function
public static double code(double r, double a, double b) {
return (r * Math.sin(b)) / (Math.cos(a) * Math.cos(b));
}
def code(r, a, b): return (r * math.sin(b)) / (math.cos(a) * math.cos(b))
function code(r, a, b) return Float64(Float64(r * sin(b)) / Float64(cos(a) * cos(b))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / (cos(a) * cos(b)); end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos a \cdot \cos b}
\end{array}
Initial program 73.4%
+-commutative73.4%
Simplified73.4%
cos-sum99.4%
cancel-sign-sub-inv99.4%
fma-define99.4%
Applied egg-rr99.4%
add-sqr-sqrt50.8%
sqrt-unprod88.1%
sqr-neg88.1%
sqrt-unprod37.4%
add-sqr-sqrt73.6%
sin-mult74.8%
cos-diff73.9%
add-sqr-sqrt37.4%
sqrt-unprod75.0%
sqr-neg75.0%
sqrt-unprod37.5%
add-sqr-sqrt75.8%
cancel-sign-sub-inv75.8%
cos-sum74.7%
Applied egg-rr74.7%
+-inverses74.7%
metadata-eval74.7%
Simplified74.7%
Taylor expanded in r around 0 74.7%
*-commutative74.7%
Simplified74.7%
Final simplification74.7%
(FPCore (r a b) :precision binary64 (if (or (<= a -5400000000000.0) (not (<= a 3.1e-8))) (* r (/ (sin b) (cos a))) (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) {
tmp = r * (sin(b) / cos(a));
} else {
tmp = sin(b) * (r / 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) :: tmp
if ((a <= (-5400000000000.0d0)) .or. (.not. (a <= 3.1d-8))) then
tmp = r * (sin(b) / cos(a))
else
tmp = sin(b) * (r / cos(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -5400000000000.0) or not (a <= 3.1e-8): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(sin(b) * Float64(r / cos(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -5400000000000.0) || ~((a <= 3.1e-8))) tmp = r * (sin(b) / cos(a)); else tmp = sin(b) * (r / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -5400000000000.0], N[Not[LessEqual[a, 3.1e-8]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5400000000000 \lor \neg \left(a \leq 3.1 \cdot 10^{-8}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if a < -5.4e12 or 3.1e-8 < a Initial program 47.4%
+-commutative47.4%
Simplified47.4%
cos-sum99.1%
cancel-sign-sub-inv99.1%
fma-define99.1%
Applied egg-rr99.1%
Taylor expanded in r around 0 99.1%
associate-/l*99.2%
+-commutative99.2%
*-commutative99.2%
associate-*r*99.2%
neg-mul-199.2%
cancel-sign-sub-inv99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in b around 0 48.2%
if -5.4e12 < a < 3.1e-8Initial program 98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in a around 0 98.1%
*-commutative98.1%
associate-/l*98.2%
Simplified98.2%
Final simplification73.8%
(FPCore (r a b) :precision binary64 (if (or (<= a -5400000000000.0) (not (<= a 3.1e-8))) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) {
tmp = r * (sin(b) / cos(a));
} else {
tmp = r * (sin(b) / 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) :: tmp
if ((a <= (-5400000000000.0d0)) .or. (.not. (a <= 3.1d-8))) then
tmp = r * (sin(b) / cos(a))
else
tmp = r * (sin(b) / cos(b))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = r * (Math.sin(b) / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -5400000000000.0) or not (a <= 3.1e-8): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = r * (math.sin(b) / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -5400000000000.0) || !(a <= 3.1e-8)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(r * Float64(sin(b) / cos(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -5400000000000.0) || ~((a <= 3.1e-8))) tmp = r * (sin(b) / cos(a)); else tmp = r * (sin(b) / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -5400000000000.0], N[Not[LessEqual[a, 3.1e-8]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5400000000000 \lor \neg \left(a \leq 3.1 \cdot 10^{-8}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if a < -5.4e12 or 3.1e-8 < a Initial program 47.4%
+-commutative47.4%
Simplified47.4%
cos-sum99.1%
cancel-sign-sub-inv99.1%
fma-define99.1%
Applied egg-rr99.1%
Taylor expanded in r around 0 99.1%
associate-/l*99.2%
+-commutative99.2%
*-commutative99.2%
associate-*r*99.2%
neg-mul-199.2%
cancel-sign-sub-inv99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in b around 0 48.2%
if -5.4e12 < a < 3.1e-8Initial program 98.1%
+-commutative98.1%
Simplified98.1%
cos-sum99.7%
cancel-sign-sub-inv99.7%
fma-define99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 98.1%
associate-/l*98.1%
Simplified98.1%
Final simplification73.7%
(FPCore (r a b) :precision binary64 (if (<= a -5400000000000.0) (* r (/ (sin b) (cos a))) (if (<= a 3.1e-8) (* (sin b) (/ r (cos b))) (/ (* r (sin b)) (cos a)))))
double code(double r, double a, double b) {
double tmp;
if (a <= -5400000000000.0) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 3.1e-8) {
tmp = sin(b) * (r / cos(b));
} else {
tmp = (r * sin(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 (a <= (-5400000000000.0d0)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 3.1d-8) then
tmp = sin(b) * (r / cos(b))
else
tmp = (r * sin(b)) / cos(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (a <= -5400000000000.0) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 3.1e-8) {
tmp = Math.sin(b) * (r / Math.cos(b));
} else {
tmp = (r * Math.sin(b)) / Math.cos(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if a <= -5400000000000.0: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 3.1e-8: tmp = math.sin(b) * (r / math.cos(b)) else: tmp = (r * math.sin(b)) / math.cos(a) return tmp
function code(r, a, b) tmp = 0.0 if (a <= -5400000000000.0) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 3.1e-8) tmp = Float64(sin(b) * Float64(r / cos(b))); else tmp = Float64(Float64(r * sin(b)) / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (a <= -5400000000000.0) tmp = r * (sin(b) / cos(a)); elseif (a <= 3.1e-8) tmp = sin(b) * (r / cos(b)); else tmp = (r * sin(b)) / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[a, -5400000000000.0], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 3.1e-8], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5400000000000:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 3.1 \cdot 10^{-8}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos a}\\
\end{array}
\end{array}
if a < -5.4e12Initial program 45.1%
+-commutative45.1%
Simplified45.1%
cos-sum99.0%
cancel-sign-sub-inv99.0%
fma-define99.0%
Applied egg-rr99.0%
Taylor expanded in r around 0 99.0%
associate-/l*99.2%
+-commutative99.2%
*-commutative99.2%
associate-*r*99.2%
neg-mul-199.2%
cancel-sign-sub-inv99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in b around 0 46.0%
if -5.4e12 < a < 3.1e-8Initial program 98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in a around 0 98.1%
*-commutative98.1%
associate-/l*98.2%
Simplified98.2%
if 3.1e-8 < a Initial program 49.8%
+-commutative49.8%
Simplified49.8%
Taylor expanded in b around 0 50.5%
(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.4%
+-commutative73.4%
Simplified73.4%
cos-sum99.4%
cancel-sign-sub-inv99.4%
fma-define99.4%
Applied egg-rr99.4%
fma-undefine99.4%
add-sqr-sqrt50.8%
sqrt-unprod88.1%
sqr-neg88.1%
sqrt-unprod37.4%
add-sqr-sqrt73.6%
cos-diff73.5%
Applied egg-rr73.5%
(FPCore (r a b) :precision binary64 (* (sin b) (/ r (cos (+ b a)))))
double code(double r, double a, double b) {
return sin(b) * (r / 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 = sin(b) * (r / cos((b + a)))
end function
public static double code(double r, double a, double b) {
return Math.sin(b) * (r / Math.cos((b + a)));
}
def code(r, a, b): return math.sin(b) * (r / math.cos((b + a)))
function code(r, a, b) return Float64(sin(b) * Float64(r / cos(Float64(b + a)))) end
function tmp = code(r, a, b) tmp = sin(b) * (r / cos((b + a))); end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin b \cdot \frac{r}{\cos \left(b + a\right)}
\end{array}
Initial program 73.4%
+-commutative73.4%
Simplified73.4%
*-commutative73.4%
associate-/l*73.4%
Applied egg-rr73.4%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos a))))
double code(double r, double a, double b) {
return r * (sin(b) / cos(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))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos(a));
}
def code(r, a, b): return r * (math.sin(b) / math.cos(a))
function code(r, a, b) return Float64(r * Float64(sin(b) / cos(a))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / cos(a)); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos a}
\end{array}
Initial program 73.4%
+-commutative73.4%
Simplified73.4%
cos-sum99.4%
cancel-sign-sub-inv99.4%
fma-define99.4%
Applied egg-rr99.4%
Taylor expanded in r around 0 99.4%
associate-/l*99.4%
+-commutative99.4%
*-commutative99.4%
associate-*r*99.4%
neg-mul-199.4%
cancel-sign-sub-inv99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in b around 0 51.7%
(FPCore (r a b) :precision binary64 (* b (/ r (cos a))))
double code(double r, double a, double b) {
return b * (r / cos(a));
}
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 / cos(a))
end function
public static double code(double r, double a, double b) {
return b * (r / Math.cos(a));
}
def code(r, a, b): return b * (r / math.cos(a))
function code(r, a, b) return Float64(b * Float64(r / cos(a))) end
function tmp = code(r, a, b) tmp = b * (r / cos(a)); end
code[r_, a_, b_] := N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b \cdot \frac{r}{\cos a}
\end{array}
Initial program 73.4%
+-commutative73.4%
Simplified73.4%
Taylor expanded in b around 0 47.7%
associate-/l*47.7%
Simplified47.7%
(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.4%
+-commutative73.4%
Simplified73.4%
Taylor expanded in b around 0 47.7%
associate-/l*47.7%
Simplified47.7%
Taylor expanded in a around 0 33.5%
Final simplification33.5%
herbie shell --seed 2024096
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))