
(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 11 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)
(fma (sin a) (sin (- b)) (fma (- (sin a)) (sin b) (* (sin b) (sin a))))))))
double code(double r, double a, double b) {
return r * (sin(b) / fma(cos(b), cos(a), fma(sin(a), sin(-b), fma(-sin(a), sin(b), (sin(b) * sin(a))))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / fma(cos(b), cos(a), fma(sin(a), sin(Float64(-b)), fma(Float64(-sin(a)), sin(b), Float64(sin(b) * sin(a))))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * N[Sin[(-b)], $MachinePrecision] + N[((-N[Sin[a], $MachinePrecision]) * N[Sin[b], $MachinePrecision] + N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \mathsf{fma}\left(\sin a, \sin \left(-b\right), \mathsf{fma}\left(-\sin a, \sin b, \sin b \cdot \sin a\right)\right)\right)}
\end{array}
Initial program 76.0%
associate-/l*76.1%
remove-double-neg76.1%
remove-double-neg76.1%
+-commutative76.1%
Simplified76.1%
cos-sum99.5%
Applied egg-rr99.5%
prod-diff99.5%
*-commutative99.5%
fma-define99.5%
associate-+l+99.5%
*-commutative99.5%
distribute-rgt-neg-in99.5%
*-commutative99.5%
Applied egg-rr99.5%
fma-define99.5%
fma-define99.5%
sin-neg99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (- (* (cos b) (cos a)) (log1p (expm1 (* (sin b) (sin a))))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(b) * cos(a)) - log1p(expm1((sin(b) * sin(a))))));
}
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - Math.log1p(Math.expm1((Math.sin(b) * Math.sin(a))))));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) - math.log1p(math.expm1((math.sin(b) * math.sin(a))))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - log1p(expm1(Float64(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[Log[1 + N[(Exp[N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a - \mathsf{log1p}\left(\mathsf{expm1}\left(\sin b \cdot \sin a\right)\right)}
\end{array}
Initial program 76.0%
associate-/l*76.1%
remove-double-neg76.1%
remove-double-neg76.1%
+-commutative76.1%
Simplified76.1%
cos-sum99.5%
Applied egg-rr99.5%
log1p-expm1-u99.5%
Applied egg-rr99.5%
Final simplification99.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 76.0%
associate-/l*76.1%
remove-double-neg76.1%
remove-double-neg76.1%
+-commutative76.1%
Simplified76.1%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (* (cos b) (cos a)))))
double code(double r, double a, double b) {
return r * (sin(b) / (cos(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(b) * cos(a)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / (Math.cos(b) * Math.cos(a)));
}
def code(r, a, b): return r * (math.sin(b) / (math.cos(b) * math.cos(a)))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(cos(b) * cos(a)))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / (cos(b) * cos(a))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a}
\end{array}
Initial program 76.0%
associate-/l*76.1%
remove-double-neg76.1%
remove-double-neg76.1%
+-commutative76.1%
Simplified76.1%
cos-sum99.5%
Applied egg-rr99.5%
*-commutative99.5%
sin-mult76.7%
+-commutative76.7%
div-sub76.7%
cos-sum77.4%
*-commutative77.4%
cancel-sign-sub-inv77.4%
add-sqr-sqrt37.6%
sqrt-unprod76.6%
sqr-neg76.6%
sqrt-unprod39.0%
add-sqr-sqrt75.9%
*-commutative75.9%
cos-diff76.5%
Applied egg-rr76.5%
+-inverses76.5%
Simplified76.5%
Final simplification76.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -0.00034) (not (<= a 9.8e-5))) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -0.00034) || !(a <= 9.8e-5)) {
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 <= (-0.00034d0)) .or. (.not. (a <= 9.8d-5))) 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 <= -0.00034) || !(a <= 9.8e-5)) {
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 <= -0.00034) or not (a <= 9.8e-5): 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 <= -0.00034) || !(a <= 9.8e-5)) 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 <= -0.00034) || ~((a <= 9.8e-5))) 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, -0.00034], N[Not[LessEqual[a, 9.8e-5]], $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 -0.00034 \lor \neg \left(a \leq 9.8 \cdot 10^{-5}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if a < -3.4e-4 or 9.8e-5 < a Initial program 53.1%
associate-/l*53.2%
remove-double-neg53.2%
remove-double-neg53.2%
+-commutative53.2%
Simplified53.2%
Taylor expanded in b around 0 52.4%
if -3.4e-4 < a < 9.8e-5Initial program 99.2%
associate-/l*99.3%
remove-double-neg99.3%
remove-double-neg99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in a around 0 99.0%
Final simplification75.5%
(FPCore (r a b) :precision binary64 (if (<= a -0.00014) (* (sin b) (/ r (cos a))) (if (<= a 0.00014) (* r (/ (sin b) (cos b))) (* r (/ (sin b) (cos a))))))
double code(double r, double a, double b) {
double tmp;
if (a <= -0.00014) {
tmp = sin(b) * (r / cos(a));
} else if (a <= 0.00014) {
tmp = r * (sin(b) / 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 <= (-0.00014d0)) then
tmp = sin(b) * (r / cos(a))
else if (a <= 0.00014d0) then
tmp = r * (sin(b) / 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 <= -0.00014) {
tmp = Math.sin(b) * (r / Math.cos(a));
} else if (a <= 0.00014) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else {
tmp = r * (Math.sin(b) / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if a <= -0.00014: tmp = math.sin(b) * (r / math.cos(a)) elif a <= 0.00014: tmp = r * (math.sin(b) / math.cos(b)) else: tmp = r * (math.sin(b) / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if (a <= -0.00014) tmp = Float64(sin(b) * Float64(r / cos(a))); elseif (a <= 0.00014) tmp = Float64(r * Float64(sin(b) / cos(b))); else tmp = Float64(r * Float64(sin(b) / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (a <= -0.00014) tmp = sin(b) * (r / cos(a)); elseif (a <= 0.00014) tmp = r * (sin(b) / cos(b)); else tmp = r * (sin(b) / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[a, -0.00014], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.00014], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.00014:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos a}\\
\mathbf{elif}\;a \leq 0.00014:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\end{array}
\end{array}
if a < -1.3999999999999999e-4Initial program 51.1%
+-commutative51.1%
Simplified51.1%
add-log-exp51.1%
Applied egg-rr51.1%
Taylor expanded in b around 0 50.0%
rem-log-exp50.1%
log1p-expm1-u50.0%
Applied egg-rr50.0%
Taylor expanded in r around 0 50.1%
*-commutative50.1%
associate-*r/50.1%
Simplified50.1%
if -1.3999999999999999e-4 < a < 1.3999999999999999e-4Initial program 99.2%
associate-/l*99.3%
remove-double-neg99.3%
remove-double-neg99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in a around 0 99.0%
if 1.3999999999999999e-4 < a Initial program 55.2%
associate-/l*55.3%
remove-double-neg55.3%
remove-double-neg55.3%
+-commutative55.3%
Simplified55.3%
Taylor expanded in b around 0 54.8%
Final simplification75.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(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 76.0%
associate-/l*76.1%
remove-double-neg76.1%
remove-double-neg76.1%
+-commutative76.1%
Simplified76.1%
Final simplification76.1%
(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 76.0%
associate-/l*76.1%
remove-double-neg76.1%
remove-double-neg76.1%
+-commutative76.1%
Simplified76.1%
Taylor expanded in b around 0 52.0%
Final simplification52.0%
(FPCore (r a b) :precision binary64 (if (or (<= b -1.32) (not (<= b 42000000.0))) (* r (sin b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -1.32) || !(b <= 42000000.0)) {
tmp = r * sin(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 <= (-1.32d0)) .or. (.not. (b <= 42000000.0d0))) then
tmp = r * sin(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 <= -1.32) || !(b <= 42000000.0)) {
tmp = r * Math.sin(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -1.32) or not (b <= 42000000.0): tmp = r * math.sin(b) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -1.32) || !(b <= 42000000.0)) tmp = Float64(r * sin(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 <= -1.32) || ~((b <= 42000000.0))) tmp = r * sin(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -1.32], N[Not[LessEqual[b, 42000000.0]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.32 \lor \neg \left(b \leq 42000000\right):\\
\;\;\;\;r \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -1.32000000000000006 or 4.2e7 < b Initial program 55.8%
+-commutative55.8%
Simplified55.8%
add-log-exp55.4%
Applied egg-rr55.4%
Taylor expanded in b around 0 11.2%
Taylor expanded in a around 0 11.3%
if -1.32000000000000006 < b < 4.2e7Initial program 98.9%
associate-/l*99.0%
remove-double-neg99.0%
remove-double-neg99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in b around 0 98.3%
associate-/l*98.4%
Simplified98.4%
Final simplification52.1%
(FPCore (r a b) :precision binary64 (* r (sin b)))
double code(double r, double a, double b) {
return r * 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)
end function
public static double code(double r, double a, double b) {
return r * Math.sin(b);
}
def code(r, a, b): return r * math.sin(b)
function code(r, a, b) return Float64(r * sin(b)) end
function tmp = code(r, a, b) tmp = r * sin(b); end
code[r_, a_, b_] := N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \sin b
\end{array}
Initial program 76.0%
+-commutative76.0%
Simplified76.0%
add-log-exp75.7%
Applied egg-rr75.7%
Taylor expanded in b around 0 51.8%
Taylor expanded in a around 0 37.7%
Final simplification37.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 76.0%
associate-/l*76.1%
remove-double-neg76.1%
remove-double-neg76.1%
+-commutative76.1%
Simplified76.1%
Taylor expanded in b around 0 48.1%
associate-/l*48.1%
Simplified48.1%
Taylor expanded in a around 0 33.9%
Final simplification33.9%
herbie shell --seed 2024041
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))