
(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 13 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 (sin b) (- (sin a)) (* (cos a) (cos b)))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(sin(b), -sin(a), (cos(a) * cos(b)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(sin(b), Float64(-sin(a)), Float64(cos(a) * cos(b)))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision]) + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\sin b, -\sin a, \cos a \cdot \cos b\right)}
\end{array}
Initial program 73.9%
+-commutative73.9%
Simplified73.9%
cos-sum99.5%
sub-neg99.5%
Applied egg-rr99.5%
+-commutative99.5%
distribute-rgt-neg-in99.5%
fma-define99.6%
*-commutative99.6%
Simplified99.6%
(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.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (fma (cos b) (cos a) 0.0)))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(cos(b), cos(a), 0.0);
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(b), cos(a), 0.0)) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, 0\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%
add-sqr-sqrt49.3%
sqrt-unprod87.9%
sqr-neg87.9%
sqrt-unprod38.5%
add-sqr-sqrt74.2%
sin-mult75.5%
cos-diff74.5%
add-sqr-sqrt38.6%
sqrt-unprod75.2%
sqr-neg75.2%
sqrt-unprod36.6%
add-sqr-sqrt75.9%
distribute-lft-neg-out75.9%
unsub-neg75.9%
cos-sum75.6%
Applied egg-rr75.6%
+-inverses75.6%
metadata-eval75.6%
Simplified75.6%
(FPCore (r a b)
:precision binary64
(if (<= a -4.2)
(* r (/ (sin b) (cos a)))
(if (<= a 1.28e-5)
(/ (* r (sin b)) (cos b))
(* r (/ 1.0 (/ (cos a) (sin b)))))))
double code(double r, double a, double b) {
double tmp;
if (a <= -4.2) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 1.28e-5) {
tmp = (r * sin(b)) / cos(b);
} else {
tmp = r * (1.0 / (cos(a) / 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 <= (-4.2d0)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 1.28d-5) then
tmp = (r * sin(b)) / cos(b)
else
tmp = r * (1.0d0 / (cos(a) / sin(b)))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (a <= -4.2) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 1.28e-5) {
tmp = (r * Math.sin(b)) / Math.cos(b);
} else {
tmp = r * (1.0 / (Math.cos(a) / Math.sin(b)));
}
return tmp;
}
def code(r, a, b): tmp = 0 if a <= -4.2: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 1.28e-5: tmp = (r * math.sin(b)) / math.cos(b) else: tmp = r * (1.0 / (math.cos(a) / math.sin(b))) return tmp
function code(r, a, b) tmp = 0.0 if (a <= -4.2) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 1.28e-5) tmp = Float64(Float64(r * sin(b)) / cos(b)); else tmp = Float64(r * Float64(1.0 / Float64(cos(a) / sin(b)))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (a <= -4.2) tmp = r * (sin(b) / cos(a)); elseif (a <= 1.28e-5) tmp = (r * sin(b)) / cos(b); else tmp = r * (1.0 / (cos(a) / sin(b))); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[a, -4.2], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.28e-5], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(1.0 / N[(N[Cos[a], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.2:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 1.28 \cdot 10^{-5}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{1}{\frac{\cos a}{\sin b}}\\
\end{array}
\end{array}
if a < -4.20000000000000018Initial program 48.8%
associate-/l*48.8%
remove-double-neg48.8%
remove-double-neg48.8%
+-commutative48.8%
Simplified48.8%
Taylor expanded in b around 0 50.5%
if -4.20000000000000018 < a < 1.2799999999999999e-5Initial program 98.0%
associate-/l*98.0%
remove-double-neg98.0%
remove-double-neg98.0%
+-commutative98.0%
Simplified98.0%
Taylor expanded in a around 0 98.0%
if 1.2799999999999999e-5 < a Initial program 50.7%
associate-/l*50.7%
remove-double-neg50.7%
remove-double-neg50.7%
+-commutative50.7%
Simplified50.7%
log1p-expm1-u50.7%
Applied egg-rr50.7%
Taylor expanded in b around 0 51.0%
log1p-expm1-u51.0%
clear-num51.1%
Applied egg-rr51.1%
(FPCore (r a b) :precision binary64 (if (or (<= a -4.2) (not (<= a 0.00029))) (* r (/ (sin b) (cos a))) (/ (* r (sin b)) (cos b))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -4.2) || !(a <= 0.00029)) {
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 <= (-4.2d0)) .or. (.not. (a <= 0.00029d0))) 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 <= -4.2) || !(a <= 0.00029)) {
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 <= -4.2) or not (a <= 0.00029): 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 <= -4.2) || !(a <= 0.00029)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(Float64(r * sin(b)) / cos(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -4.2) || ~((a <= 0.00029))) 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, -4.2], N[Not[LessEqual[a, 0.00029]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.2 \lor \neg \left(a \leq 0.00029\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\
\end{array}
\end{array}
if a < -4.20000000000000018 or 2.9e-4 < a Initial program 49.8%
associate-/l*49.8%
remove-double-neg49.8%
remove-double-neg49.8%
+-commutative49.8%
Simplified49.8%
Taylor expanded in b around 0 50.8%
if -4.20000000000000018 < a < 2.9e-4Initial program 98.0%
associate-/l*98.0%
remove-double-neg98.0%
remove-double-neg98.0%
+-commutative98.0%
Simplified98.0%
Taylor expanded in a around 0 98.0%
Final simplification74.4%
(FPCore (r a b) :precision binary64 (if (or (<= a -4.2) (not (<= a 1.32e-5))) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -4.2) || !(a <= 1.32e-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 <= (-4.2d0)) .or. (.not. (a <= 1.32d-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 <= -4.2) || !(a <= 1.32e-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 <= -4.2) or not (a <= 1.32e-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 <= -4.2) || !(a <= 1.32e-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 <= -4.2) || ~((a <= 1.32e-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, -4.2], N[Not[LessEqual[a, 1.32e-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 -4.2 \lor \neg \left(a \leq 1.32 \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 < -4.20000000000000018 or 1.32000000000000007e-5 < a Initial program 49.8%
associate-/l*49.8%
remove-double-neg49.8%
remove-double-neg49.8%
+-commutative49.8%
Simplified49.8%
Taylor expanded in b around 0 50.8%
if -4.20000000000000018 < a < 1.32000000000000007e-5Initial program 98.0%
associate-/l*98.0%
remove-double-neg98.0%
remove-double-neg98.0%
+-commutative98.0%
Simplified98.0%
Taylor expanded in a around 0 98.0%
associate-/l*98.0%
Simplified98.0%
Final simplification74.4%
(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 (* 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.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
Taylor expanded in b around 0 52.3%
(FPCore (r a b) :precision binary64 (if (or (<= b -2.3e+37) (not (<= b 1.85e+38))) (* r (sin b)) (* r (/ b (cos (+ b a))))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -2.3e+37) || !(b <= 1.85e+38)) {
tmp = r * sin(b);
} else {
tmp = r * (b / cos((b + 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 <= (-2.3d+37)) .or. (.not. (b <= 1.85d+38))) then
tmp = r * sin(b)
else
tmp = r * (b / cos((b + a)))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -2.3e+37) || !(b <= 1.85e+38)) {
tmp = r * Math.sin(b);
} else {
tmp = r * (b / Math.cos((b + a)));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -2.3e+37) or not (b <= 1.85e+38): tmp = r * math.sin(b) else: tmp = r * (b / math.cos((b + a))) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -2.3e+37) || !(b <= 1.85e+38)) tmp = Float64(r * sin(b)); else tmp = Float64(r * Float64(b / cos(Float64(b + a)))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -2.3e+37) || ~((b <= 1.85e+38))) tmp = r * sin(b); else tmp = r * (b / cos((b + a))); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -2.3e+37], N[Not[LessEqual[b, 1.85e+38]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.3 \cdot 10^{+37} \lor \neg \left(b \leq 1.85 \cdot 10^{+38}\right):\\
\;\;\;\;r \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\
\end{array}
\end{array}
if b < -2.30000000000000002e37 or 1.8500000000000001e38 < b Initial program 53.7%
associate-/l*53.7%
remove-double-neg53.7%
remove-double-neg53.7%
+-commutative53.7%
Simplified53.7%
log1p-expm1-u53.4%
Applied egg-rr53.4%
Taylor expanded in b around 0 13.2%
Taylor expanded in a around 0 12.4%
if -2.30000000000000002e37 < b < 1.8500000000000001e38Initial program 91.7%
associate-/l*91.8%
remove-double-neg91.8%
remove-double-neg91.8%
+-commutative91.8%
Simplified91.8%
Taylor expanded in b around 0 86.7%
Final simplification51.9%
(FPCore (r a b) :precision binary64 (if (or (<= b -650.0) (not (<= b 14.6))) (* r (sin b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -650.0) || !(b <= 14.6)) {
tmp = r * sin(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 <= (-650.0d0)) .or. (.not. (b <= 14.6d0))) then
tmp = r * sin(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 <= -650.0) || !(b <= 14.6)) {
tmp = r * Math.sin(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -650.0) or not (b <= 14.6): tmp = r * math.sin(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -650.0) || !(b <= 14.6)) tmp = Float64(r * sin(b)); else tmp = Float64(r * Float64(b / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -650.0) || ~((b <= 14.6))) tmp = r * sin(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -650.0], N[Not[LessEqual[b, 14.6]], $MachinePrecision]], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -650 \lor \neg \left(b \leq 14.6\right):\\
\;\;\;\;r \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -650 or 14.5999999999999996 < b Initial program 53.2%
associate-/l*53.1%
remove-double-neg53.1%
remove-double-neg53.1%
+-commutative53.1%
Simplified53.1%
log1p-expm1-u52.9%
Applied egg-rr52.9%
Taylor expanded in b around 0 12.6%
Taylor expanded in a around 0 11.8%
if -650 < b < 14.5999999999999996Initial program 97.4%
associate-/l*97.5%
remove-double-neg97.5%
remove-double-neg97.5%
+-commutative97.5%
Simplified97.5%
Taylor expanded in b around 0 97.2%
*-commutative97.2%
associate-/l*97.3%
Simplified97.3%
Final simplification51.8%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.58) (not (<= b 14.0))) (* r (sin b)) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.58) || !(b <= 14.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 <= (-0.58d0)) .or. (.not. (b <= 14.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 <= -0.58) || !(b <= 14.0)) {
tmp = r * Math.sin(b);
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.58) or not (b <= 14.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 <= -0.58) || !(b <= 14.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 <= -0.58) || ~((b <= 14.0))) tmp = r * sin(b); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.58], N[Not[LessEqual[b, 14.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 -0.58 \lor \neg \left(b \leq 14\right):\\
\;\;\;\;r \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -0.57999999999999996 or 14 < b Initial program 53.2%
associate-/l*53.1%
remove-double-neg53.1%
remove-double-neg53.1%
+-commutative53.1%
Simplified53.1%
log1p-expm1-u52.9%
Applied egg-rr52.9%
Taylor expanded in b around 0 12.6%
Taylor expanded in a around 0 11.8%
if -0.57999999999999996 < b < 14Initial program 97.4%
associate-/l*97.5%
remove-double-neg97.5%
remove-double-neg97.5%
+-commutative97.5%
Simplified97.5%
Taylor expanded in b around 0 97.2%
associate-/l*97.2%
Simplified97.2%
Final simplification51.8%
(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 73.9%
associate-/l*73.9%
remove-double-neg73.9%
remove-double-neg73.9%
+-commutative73.9%
Simplified73.9%
log1p-expm1-u73.8%
Applied egg-rr73.8%
Taylor expanded in b around 0 52.3%
Taylor expanded in a around 0 37.2%
(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 47.5%
associate-/l*47.5%
Simplified47.5%
Taylor expanded in a around 0 33.0%
*-commutative33.0%
Simplified33.0%
herbie shell --seed 2024136
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))