
(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 (/ (* (sin b) r) (fma (sin b) (- (sin a)) (* (cos a) (cos b)))))
double code(double r, double a, double b) {
return (sin(b) * r) / fma(sin(b), -sin(a), (cos(a) * cos(b)));
}
function code(r, a, b) return Float64(Float64(sin(b) * r) / fma(sin(b), Float64(-sin(a)), Float64(cos(a) * cos(b)))) end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] * r), $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{\sin b \cdot r}{\mathsf{fma}\left(\sin b, -\sin a, \cos a \cdot \cos b\right)}
\end{array}
Initial program 80.4%
+-commutative80.4%
Simplified80.4%
cos-sum99.5%
cancel-sign-sub-inv99.5%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in r around 0 99.5%
*-commutative99.5%
mul-1-neg99.5%
*-commutative99.5%
distribute-rgt-neg-in99.5%
*-commutative99.5%
fma-def99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (/ (* (sin b) r) (fma (cos b) (cos a) (* (sin b) (- (sin a))))))
double code(double r, double a, double b) {
return (sin(b) * r) / fma(cos(b), cos(a), (sin(b) * -sin(a)));
}
function code(r, a, b) return Float64(Float64(sin(b) * r) / fma(cos(b), cos(a), Float64(sin(b) * Float64(-sin(a))))) end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] * r), $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{\sin b \cdot r}{\mathsf{fma}\left(\cos b, \cos a, \sin b \cdot \left(-\sin a\right)\right)}
\end{array}
Initial program 80.4%
+-commutative80.4%
Simplified80.4%
cos-sum99.5%
cancel-sign-sub-inv99.5%
fma-def99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (/ r (/ (- (* (cos a) (cos b)) (* (sin b) (sin a))) (sin b))))
double code(double r, double a, double b) {
return r / (((cos(a) * cos(b)) - (sin(b) * sin(a))) / 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 / (((cos(a) * cos(b)) - (sin(b) * sin(a))) / sin(b))
end function
public static double code(double r, double a, double b) {
return r / (((Math.cos(a) * Math.cos(b)) - (Math.sin(b) * Math.sin(a))) / Math.sin(b));
}
def code(r, a, b): return r / (((math.cos(a) * math.cos(b)) - (math.sin(b) * math.sin(a))) / math.sin(b))
function code(r, a, b) return Float64(r / Float64(Float64(Float64(cos(a) * cos(b)) - Float64(sin(b) * sin(a))) / sin(b))) end
function tmp = code(r, a, b) tmp = r / (((cos(a) * cos(b)) - (sin(b) * sin(a))) / sin(b)); end
code[r_, a_, b_] := N[(r / N[(N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\frac{\cos a \cdot \cos b - \sin b \cdot \sin a}{\sin b}}
\end{array}
Initial program 80.4%
+-commutative80.4%
Simplified80.4%
cos-sum99.5%
cancel-sign-sub-inv99.5%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in r around 0 99.5%
associate-/l*99.5%
+-commutative99.5%
mul-1-neg99.5%
*-commutative99.5%
sub-neg99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (/ (* (sin b) r) (- (* (cos a) (cos b)) (* (sin b) (sin a)))))
double code(double r, double a, double b) {
return (sin(b) * r) / ((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 = (sin(b) * r) / ((cos(a) * cos(b)) - (sin(b) * sin(a)))
end function
public static double code(double r, double a, double b) {
return (Math.sin(b) * r) / ((Math.cos(a) * Math.cos(b)) - (Math.sin(b) * Math.sin(a)));
}
def code(r, a, b): return (math.sin(b) * r) / ((math.cos(a) * math.cos(b)) - (math.sin(b) * math.sin(a)))
function code(r, a, b) return Float64(Float64(sin(b) * r) / Float64(Float64(cos(a) * cos(b)) - Float64(sin(b) * sin(a)))) end
function tmp = code(r, a, b) tmp = (sin(b) * r) / ((cos(a) * cos(b)) - (sin(b) * sin(a))); end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision] / N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b \cdot r}{\cos a \cdot \cos b - \sin b \cdot \sin a}
\end{array}
Initial program 80.4%
+-commutative80.4%
Simplified80.4%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= b -0.0001) (not (<= b 0.086))) (* (sin b) (/ r (cos b))) (/ (* b r) (cos (+ b a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -0.0001) || !(b <= 0.086)) {
tmp = sin(b) * (r / cos(b));
} else {
tmp = (b * r) / 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 <= (-0.0001d0)) .or. (.not. (b <= 0.086d0))) then
tmp = sin(b) * (r / cos(b))
else
tmp = (b * r) / cos((b + a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -0.0001) || !(b <= 0.086)) {
tmp = Math.sin(b) * (r / Math.cos(b));
} else {
tmp = (b * r) / Math.cos((b + a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -0.0001) or not (b <= 0.086): tmp = math.sin(b) * (r / math.cos(b)) else: tmp = (b * r) / math.cos((b + a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -0.0001) || !(b <= 0.086)) tmp = Float64(sin(b) * Float64(r / cos(b))); else tmp = Float64(Float64(b * r) / cos(Float64(b + a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -0.0001) || ~((b <= 0.086))) tmp = sin(b) * (r / cos(b)); else tmp = (b * r) / cos((b + a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -0.0001], N[Not[LessEqual[b, 0.086]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * r), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0001 \lor \neg \left(b \leq 0.086\right):\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\
\end{array}
\end{array}
if b < -1.00000000000000005e-4 or 0.085999999999999993 < b Initial program 61.4%
*-commutative61.4%
associate-/l*61.3%
+-commutative61.3%
Simplified61.3%
Taylor expanded in a around 0 61.2%
associate-/l*61.3%
associate-/r/61.3%
Simplified61.3%
if -1.00000000000000005e-4 < b < 0.085999999999999993Initial program 98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in b around 0 98.3%
Final simplification80.4%
(FPCore (r a b) :precision binary64 (if (or (<= a -22000000.0) (not (<= a 0.0023))) (/ r (/ (cos a) (sin b))) (* (sin b) (/ r (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -22000000.0) || !(a <= 0.0023)) {
tmp = r / (cos(a) / sin(b));
} 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 <= (-22000000.0d0)) .or. (.not. (a <= 0.0023d0))) then
tmp = r / (cos(a) / sin(b))
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 <= -22000000.0) || !(a <= 0.0023)) {
tmp = r / (Math.cos(a) / Math.sin(b));
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -22000000.0) or not (a <= 0.0023): tmp = r / (math.cos(a) / math.sin(b)) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -22000000.0) || !(a <= 0.0023)) tmp = Float64(r / Float64(cos(a) / sin(b))); 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 <= -22000000.0) || ~((a <= 0.0023))) tmp = r / (cos(a) / sin(b)); else tmp = sin(b) * (r / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -22000000.0], N[Not[LessEqual[a, 0.0023]], $MachinePrecision]], N[(r / N[(N[Cos[a], $MachinePrecision] / N[Sin[b], $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 -22000000 \lor \neg \left(a \leq 0.0023\right):\\
\;\;\;\;\frac{r}{\frac{\cos a}{\sin b}}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if a < -2.2e7 or 0.0023 < a Initial program 63.7%
+-commutative63.7%
Simplified63.7%
log1p-expm1-u48.2%
log1p-udef15.3%
*-commutative15.3%
Applied egg-rr15.3%
Taylor expanded in b around 0 15.5%
Taylor expanded in b around inf 64.1%
associate-/l*64.1%
Simplified64.1%
if -2.2e7 < a < 0.0023Initial program 95.9%
*-commutative95.9%
associate-/l*95.8%
+-commutative95.8%
Simplified95.8%
Taylor expanded in a around 0 95.8%
associate-/l*95.7%
associate-/r/95.9%
Simplified95.9%
Final simplification80.6%
(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 80.4%
*-commutative80.4%
associate-/l*80.3%
+-commutative80.3%
Simplified80.3%
clear-num79.7%
associate-/r/80.2%
clear-num80.4%
Applied egg-rr80.4%
Final simplification80.4%
(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(Float64(sin(b) * 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[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b \cdot r}{\cos \left(b + a\right)}
\end{array}
Initial program 80.4%
Final simplification80.4%
(FPCore (r a b) :precision binary64 (if (or (<= b -980000.0) (not (<= b 105.0))) (* (sin b) r) (/ (* b r) (cos (+ b a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -980000.0) || !(b <= 105.0)) {
tmp = sin(b) * r;
} else {
tmp = (b * r) / 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 <= (-980000.0d0)) .or. (.not. (b <= 105.0d0))) then
tmp = sin(b) * r
else
tmp = (b * r) / cos((b + a))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -980000.0) || !(b <= 105.0)) {
tmp = Math.sin(b) * r;
} else {
tmp = (b * r) / Math.cos((b + a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -980000.0) or not (b <= 105.0): tmp = math.sin(b) * r else: tmp = (b * r) / math.cos((b + a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -980000.0) || !(b <= 105.0)) tmp = Float64(sin(b) * r); else tmp = Float64(Float64(b * r) / cos(Float64(b + a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -980000.0) || ~((b <= 105.0))) tmp = sin(b) * r; else tmp = (b * r) / cos((b + a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -980000.0], N[Not[LessEqual[b, 105.0]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(N[(b * r), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -980000 \lor \neg \left(b \leq 105\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot r}{\cos \left(b + a\right)}\\
\end{array}
\end{array}
if b < -9.8e5 or 105 < b Initial program 61.1%
+-commutative61.1%
Simplified61.1%
log1p-expm1-u34.8%
log1p-udef4.9%
*-commutative4.9%
Applied egg-rr4.9%
Taylor expanded in b around 0 4.5%
Taylor expanded in a around 0 13.0%
if -9.8e5 < b < 105Initial program 97.7%
+-commutative97.7%
Simplified97.7%
Taylor expanded in b around 0 96.6%
Final simplification57.1%
(FPCore (r a b) :precision binary64 (if (or (<= b -105.0) (not (<= b 1.86))) (* (sin b) r) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -105.0) || !(b <= 1.86)) {
tmp = sin(b) * r;
} 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 <= (-105.0d0)) .or. (.not. (b <= 1.86d0))) then
tmp = sin(b) * r
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 <= -105.0) || !(b <= 1.86)) {
tmp = Math.sin(b) * r;
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -105.0) or not (b <= 1.86): tmp = math.sin(b) * r else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -105.0) || !(b <= 1.86)) tmp = Float64(sin(b) * r); else tmp = Float64(r * Float64(b / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -105.0) || ~((b <= 1.86))) tmp = sin(b) * r; else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -105.0], N[Not[LessEqual[b, 1.86]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -105 \lor \neg \left(b \leq 1.86\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -105 or 1.8600000000000001 < b Initial program 61.4%
+-commutative61.4%
Simplified61.4%
log1p-expm1-u35.4%
log1p-udef4.9%
*-commutative4.9%
Applied egg-rr4.9%
Taylor expanded in b around 0 4.4%
Taylor expanded in a around 0 12.9%
if -105 < b < 1.8600000000000001Initial program 97.7%
*-commutative97.7%
associate-/l*97.5%
+-commutative97.5%
Simplified97.5%
Taylor expanded in b around 0 97.2%
associate-/l*97.0%
associate-/r/97.1%
Simplified97.1%
Final simplification57.0%
(FPCore (r a b) :precision binary64 (if (or (<= b -118.0) (not (<= b 0.74))) (* (sin b) r) (/ (* b r) (cos a))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -118.0) || !(b <= 0.74)) {
tmp = sin(b) * r;
} 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 <= (-118.0d0)) .or. (.not. (b <= 0.74d0))) then
tmp = sin(b) * r
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 <= -118.0) || !(b <= 0.74)) {
tmp = Math.sin(b) * r;
} else {
tmp = (b * r) / Math.cos(a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -118.0) or not (b <= 0.74): tmp = math.sin(b) * r else: tmp = (b * r) / math.cos(a) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -118.0) || !(b <= 0.74)) tmp = Float64(sin(b) * r); else tmp = Float64(Float64(b * r) / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -118.0) || ~((b <= 0.74))) tmp = sin(b) * r; else tmp = (b * r) / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -118.0], N[Not[LessEqual[b, 0.74]], $MachinePrecision]], N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision], N[(N[(b * r), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -118 \lor \neg \left(b \leq 0.74\right):\\
\;\;\;\;\sin b \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot r}{\cos a}\\
\end{array}
\end{array}
if b < -118 or 0.73999999999999999 < b Initial program 61.4%
+-commutative61.4%
Simplified61.4%
log1p-expm1-u35.4%
log1p-udef4.9%
*-commutative4.9%
Applied egg-rr4.9%
Taylor expanded in b around 0 4.4%
Taylor expanded in a around 0 12.9%
if -118 < b < 0.73999999999999999Initial program 97.7%
*-commutative97.7%
associate-/l*97.5%
+-commutative97.5%
Simplified97.5%
Taylor expanded in b around 0 97.2%
Final simplification57.0%
(FPCore (r a b) :precision binary64 (* (sin b) r))
double code(double r, double a, double b) {
return sin(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) * r
end function
public static double code(double r, double a, double b) {
return Math.sin(b) * r;
}
def code(r, a, b): return math.sin(b) * r
function code(r, a, b) return Float64(sin(b) * r) end
function tmp = code(r, a, b) tmp = sin(b) * r; end
code[r_, a_, b_] := N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\sin b \cdot r
\end{array}
Initial program 80.4%
+-commutative80.4%
Simplified80.4%
log1p-expm1-u55.3%
log1p-udef16.3%
*-commutative16.3%
Applied egg-rr16.3%
Taylor expanded in b around 0 16.1%
Taylor expanded in a around 0 36.0%
Final simplification36.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 80.4%
*-commutative80.4%
associate-/l*80.3%
+-commutative80.3%
Simplified80.3%
Taylor expanded in b around 0 52.6%
associate-/l*52.4%
associate-/r/52.5%
Simplified52.5%
Taylor expanded in a around 0 31.6%
Final simplification31.6%
herbie shell --seed 2023287
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))