
(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 15 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 a) (- (sin b)) (* (cos a) (cos b)))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(sin(a), -sin(b), (cos(a) * cos(b)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(sin(a), Float64(-sin(b)), Float64(cos(a) * cos(b)))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[a], $MachinePrecision] * (-N[Sin[b], $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 a, -\sin b, \cos a \cdot \cos b\right)}
\end{array}
Initial program 77.8%
+-commutative77.8%
Simplified77.8%
cos-sum99.4%
sub-neg99.4%
Applied egg-rr99.4%
+-commutative99.4%
distribute-lft-neg-in99.4%
*-commutative99.4%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(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(sin(b) * Float64(-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, \sin b \cdot \left(-\sin a\right)\right)}
\end{array}
Initial program 77.8%
+-commutative77.8%
Simplified77.8%
cos-sum99.4%
fma-neg99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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 77.8%
associate-/l*77.8%
remove-double-neg77.8%
sin-neg77.8%
neg-mul-177.8%
associate-/r*77.8%
associate-/l*77.8%
*-commutative77.8%
associate-*l/77.8%
associate-/l*77.8%
sin-neg77.8%
distribute-lft-neg-in77.8%
distribute-rgt-neg-in77.8%
associate-/l*77.8%
metadata-eval77.8%
/-rgt-identity77.8%
+-commutative77.8%
Simplified77.8%
cos-sum99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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 77.8%
associate-/l*77.8%
+-commutative77.8%
Simplified77.8%
cos-sum99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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(Float64(r * 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[(N[(r * N[Sin[b], $MachinePrecision]), $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{r \cdot \sin b}{\cos a \cdot \cos b - \sin b \cdot \sin a}
\end{array}
Initial program 77.8%
+-commutative77.8%
Simplified77.8%
cos-sum99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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 77.8%
+-commutative77.8%
Simplified77.8%
cos-sum99.4%
fma-neg99.4%
Applied egg-rr99.4%
sin-mult78.7%
cos-sum79.6%
fma-neg79.6%
div-sub79.6%
fma-udef79.6%
add-sqr-sqrt41.4%
sqrt-unprod78.6%
sqr-neg78.6%
sqrt-unprod47.8%
add-sqr-sqrt78.0%
cos-diff78.6%
Applied egg-rr78.6%
+-inverses78.6%
Simplified78.6%
Final simplification78.6%
(FPCore (r a b) :precision binary64 (if (or (<= a -2.15e+24) (not (<= a 22.0))) (* r (/ (sin b) (cos a))) (/ r (- (/ 1.0 (tan b)) a))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -2.15e+24) || !(a <= 22.0)) {
tmp = r * (sin(b) / cos(a));
} else {
tmp = r / ((1.0 / tan(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 ((a <= (-2.15d+24)) .or. (.not. (a <= 22.0d0))) then
tmp = r * (sin(b) / cos(a))
else
tmp = r / ((1.0d0 / tan(b)) - a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -2.15e+24) || !(a <= 22.0)) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else {
tmp = r / ((1.0 / Math.tan(b)) - a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -2.15e+24) or not (a <= 22.0): tmp = r * (math.sin(b) / math.cos(a)) else: tmp = r / ((1.0 / math.tan(b)) - a) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -2.15e+24) || !(a <= 22.0)) tmp = Float64(r * Float64(sin(b) / cos(a))); else tmp = Float64(r / Float64(Float64(1.0 / tan(b)) - a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -2.15e+24) || ~((a <= 22.0))) tmp = r * (sin(b) / cos(a)); else tmp = r / ((1.0 / tan(b)) - a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -2.15e+24], N[Not[LessEqual[a, 22.0]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / N[(N[(1.0 / N[Tan[b], $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.15 \cdot 10^{+24} \lor \neg \left(a \leq 22\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\frac{1}{\tan b} - a}\\
\end{array}
\end{array}
if a < -2.14999999999999994e24 or 22 < a Initial program 55.5%
associate-/l*55.6%
remove-double-neg55.6%
sin-neg55.6%
neg-mul-155.6%
associate-/r*55.6%
associate-/l*55.5%
*-commutative55.5%
associate-*l/55.6%
associate-/l*55.6%
sin-neg55.6%
distribute-lft-neg-in55.6%
distribute-rgt-neg-in55.6%
associate-/l*55.6%
metadata-eval55.6%
/-rgt-identity55.6%
+-commutative55.6%
Simplified55.6%
Taylor expanded in b around 0 55.8%
if -2.14999999999999994e24 < a < 22Initial program 97.7%
associate-/l*97.6%
+-commutative97.6%
Simplified97.6%
Taylor expanded in a around 0 97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
expm1-log1p-u75.8%
expm1-udef35.5%
clear-num35.5%
quot-tan35.5%
Applied egg-rr35.5%
expm1-def75.9%
expm1-log1p97.5%
Simplified97.5%
Final simplification77.8%
(FPCore (r a b) :precision binary64 (if (or (<= a -2.15e+24) (not (<= a 22.0))) (/ r (/ (cos a) (sin b))) (/ r (- (/ 1.0 (tan b)) a))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -2.15e+24) || !(a <= 22.0)) {
tmp = r / (cos(a) / sin(b));
} else {
tmp = r / ((1.0 / tan(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 ((a <= (-2.15d+24)) .or. (.not. (a <= 22.0d0))) then
tmp = r / (cos(a) / sin(b))
else
tmp = r / ((1.0d0 / tan(b)) - a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((a <= -2.15e+24) || !(a <= 22.0)) {
tmp = r / (Math.cos(a) / Math.sin(b));
} else {
tmp = r / ((1.0 / Math.tan(b)) - a);
}
return tmp;
}
def code(r, a, b): tmp = 0 if (a <= -2.15e+24) or not (a <= 22.0): tmp = r / (math.cos(a) / math.sin(b)) else: tmp = r / ((1.0 / math.tan(b)) - a) return tmp
function code(r, a, b) tmp = 0.0 if ((a <= -2.15e+24) || !(a <= 22.0)) tmp = Float64(r / Float64(cos(a) / sin(b))); else tmp = Float64(r / Float64(Float64(1.0 / tan(b)) - a)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((a <= -2.15e+24) || ~((a <= 22.0))) tmp = r / (cos(a) / sin(b)); else tmp = r / ((1.0 / tan(b)) - a); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[a, -2.15e+24], N[Not[LessEqual[a, 22.0]], $MachinePrecision]], N[(r / N[(N[Cos[a], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r / N[(N[(1.0 / N[Tan[b], $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.15 \cdot 10^{+24} \lor \neg \left(a \leq 22\right):\\
\;\;\;\;\frac{r}{\frac{\cos a}{\sin b}}\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\frac{1}{\tan b} - a}\\
\end{array}
\end{array}
if a < -2.14999999999999994e24 or 22 < a Initial program 55.5%
associate-/l*55.6%
+-commutative55.6%
Simplified55.6%
Taylor expanded in b around 0 55.8%
if -2.14999999999999994e24 < a < 22Initial program 97.7%
associate-/l*97.6%
+-commutative97.6%
Simplified97.6%
Taylor expanded in a around 0 97.5%
+-commutative97.5%
mul-1-neg97.5%
unsub-neg97.5%
Simplified97.5%
expm1-log1p-u75.8%
expm1-udef35.5%
clear-num35.5%
quot-tan35.5%
Applied egg-rr35.5%
expm1-def75.9%
expm1-log1p97.5%
Simplified97.5%
Final simplification77.8%
(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 77.8%
associate-/l*77.8%
+-commutative77.8%
Simplified77.8%
associate-/r/77.8%
Applied egg-rr77.8%
Final simplification77.8%
(FPCore (r a b) :precision binary64 (if (or (<= b -9.6e-5) (not (<= b 0.0016))) (* r (tan b)) (* r (* b (/ 1.0 (cos a))))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -9.6e-5) || !(b <= 0.0016)) {
tmp = r * tan(b);
} else {
tmp = r * (b * (1.0 / 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.6d-5)) .or. (.not. (b <= 0.0016d0))) then
tmp = r * tan(b)
else
tmp = r * (b * (1.0d0 / cos(a)))
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if ((b <= -9.6e-5) || !(b <= 0.0016)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b * (1.0 / Math.cos(a)));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -9.6e-5) or not (b <= 0.0016): tmp = r * math.tan(b) else: tmp = r * (b * (1.0 / math.cos(a))) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -9.6e-5) || !(b <= 0.0016)) tmp = Float64(r * tan(b)); else tmp = Float64(r * Float64(b * Float64(1.0 / cos(a)))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -9.6e-5) || ~((b <= 0.0016))) tmp = r * tan(b); else tmp = r * (b * (1.0 / cos(a))); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -9.6e-5], N[Not[LessEqual[b, 0.0016]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b * N[(1.0 / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.6 \cdot 10^{-5} \lor \neg \left(b \leq 0.0016\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \left(b \cdot \frac{1}{\cos a}\right)\\
\end{array}
\end{array}
if b < -9.6000000000000002e-5 or 0.00160000000000000008 < b Initial program 59.2%
associate-/l*59.2%
remove-double-neg59.2%
sin-neg59.2%
neg-mul-159.2%
associate-/r*59.2%
associate-/l*59.2%
*-commutative59.2%
associate-*l/59.1%
associate-/l*59.1%
sin-neg59.1%
distribute-lft-neg-in59.1%
distribute-rgt-neg-in59.1%
associate-/l*59.1%
metadata-eval59.1%
/-rgt-identity59.1%
+-commutative59.1%
Simplified59.1%
Taylor expanded in a around 0 58.8%
tan-quot58.9%
expm1-log1p-u50.0%
expm1-udef49.5%
Applied egg-rr49.5%
expm1-def50.0%
expm1-log1p58.9%
Simplified58.9%
if -9.6000000000000002e-5 < b < 0.00160000000000000008Initial program 98.2%
associate-/l*98.2%
remove-double-neg98.2%
sin-neg98.2%
neg-mul-198.2%
associate-/r*98.2%
associate-/l*98.2%
*-commutative98.2%
associate-*l/98.2%
associate-/l*98.2%
sin-neg98.2%
distribute-lft-neg-in98.2%
distribute-rgt-neg-in98.2%
associate-/l*98.2%
metadata-eval98.2%
/-rgt-identity98.2%
+-commutative98.2%
Simplified98.2%
Taylor expanded in b around 0 98.2%
div-inv98.3%
Applied egg-rr98.3%
Final simplification77.6%
(FPCore (r a b) :precision binary64 (if (or (<= b -7.8e-5) (not (<= b 0.0015))) (* r (tan b)) (* r (/ b (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -7.8e-5) || !(b <= 0.0015)) {
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 <= (-7.8d-5)) .or. (.not. (b <= 0.0015d0))) 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 <= -7.8e-5) || !(b <= 0.0015)) {
tmp = r * Math.tan(b);
} else {
tmp = r * (b / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -7.8e-5) or not (b <= 0.0015): tmp = r * math.tan(b) else: tmp = r * (b / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -7.8e-5) || !(b <= 0.0015)) tmp = Float64(r * tan(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 <= -7.8e-5) || ~((b <= 0.0015))) tmp = r * tan(b); else tmp = r * (b / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -7.8e-5], N[Not[LessEqual[b, 0.0015]], $MachinePrecision]], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.8 \cdot 10^{-5} \lor \neg \left(b \leq 0.0015\right):\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\end{array}
\end{array}
if b < -7.7999999999999999e-5 or 0.0015 < b Initial program 59.2%
associate-/l*59.2%
remove-double-neg59.2%
sin-neg59.2%
neg-mul-159.2%
associate-/r*59.2%
associate-/l*59.2%
*-commutative59.2%
associate-*l/59.1%
associate-/l*59.1%
sin-neg59.1%
distribute-lft-neg-in59.1%
distribute-rgt-neg-in59.1%
associate-/l*59.1%
metadata-eval59.1%
/-rgt-identity59.1%
+-commutative59.1%
Simplified59.1%
Taylor expanded in a around 0 58.8%
tan-quot58.9%
expm1-log1p-u50.0%
expm1-udef49.5%
Applied egg-rr49.5%
expm1-def50.0%
expm1-log1p58.9%
Simplified58.9%
if -7.7999999999999999e-5 < b < 0.0015Initial program 98.2%
associate-/l*98.2%
remove-double-neg98.2%
sin-neg98.2%
neg-mul-198.2%
associate-/r*98.2%
associate-/l*98.2%
*-commutative98.2%
associate-*l/98.2%
associate-/l*98.2%
sin-neg98.2%
distribute-lft-neg-in98.2%
distribute-rgt-neg-in98.2%
associate-/l*98.2%
metadata-eval98.2%
/-rgt-identity98.2%
+-commutative98.2%
Simplified98.2%
Taylor expanded in b around 0 98.2%
Final simplification77.6%
(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 77.8%
associate-/l*77.8%
remove-double-neg77.8%
sin-neg77.8%
neg-mul-177.8%
associate-/r*77.8%
associate-/l*77.8%
*-commutative77.8%
associate-*l/77.8%
associate-/l*77.8%
sin-neg77.8%
distribute-lft-neg-in77.8%
distribute-rgt-neg-in77.8%
associate-/l*77.8%
metadata-eval77.8%
/-rgt-identity77.8%
+-commutative77.8%
Simplified77.8%
Taylor expanded in b around 0 53.7%
Taylor expanded in a around 0 37.3%
Final simplification37.3%
(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 77.8%
associate-/l*77.8%
remove-double-neg77.8%
sin-neg77.8%
neg-mul-177.8%
associate-/r*77.8%
associate-/l*77.8%
*-commutative77.8%
associate-*l/77.8%
associate-/l*77.8%
sin-neg77.8%
distribute-lft-neg-in77.8%
distribute-rgt-neg-in77.8%
associate-/l*77.8%
metadata-eval77.8%
/-rgt-identity77.8%
+-commutative77.8%
Simplified77.8%
Taylor expanded in a around 0 61.3%
tan-quot61.3%
expm1-log1p-u56.7%
expm1-udef41.4%
Applied egg-rr41.4%
expm1-def56.7%
expm1-log1p61.3%
Simplified61.3%
Final simplification61.3%
(FPCore (r a b) :precision binary64 (/ r (+ (* b -0.3333333333333333) (/ 1.0 b))))
double code(double r, double a, double b) {
return r / ((b * -0.3333333333333333) + (1.0 / 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 * (-0.3333333333333333d0)) + (1.0d0 / b))
end function
public static double code(double r, double a, double b) {
return r / ((b * -0.3333333333333333) + (1.0 / b));
}
def code(r, a, b): return r / ((b * -0.3333333333333333) + (1.0 / b))
function code(r, a, b) return Float64(r / Float64(Float64(b * -0.3333333333333333) + Float64(1.0 / b))) end
function tmp = code(r, a, b) tmp = r / ((b * -0.3333333333333333) + (1.0 / b)); end
code[r_, a_, b_] := N[(r / N[(N[(b * -0.3333333333333333), $MachinePrecision] + N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{b \cdot -0.3333333333333333 + \frac{1}{b}}
\end{array}
Initial program 77.8%
associate-/l*77.8%
+-commutative77.8%
Simplified77.8%
Taylor expanded in b around 0 50.3%
+-commutative50.3%
neg-mul-150.3%
unsub-neg50.3%
fma-def50.3%
distribute-rgt-out--50.3%
metadata-eval50.3%
Simplified50.3%
Taylor expanded in a around 0 33.3%
Final simplification33.3%
(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 77.8%
associate-/l*77.8%
remove-double-neg77.8%
sin-neg77.8%
neg-mul-177.8%
associate-/r*77.8%
associate-/l*77.8%
*-commutative77.8%
associate-*l/77.8%
associate-/l*77.8%
sin-neg77.8%
distribute-lft-neg-in77.8%
distribute-rgt-neg-in77.8%
associate-/l*77.8%
metadata-eval77.8%
/-rgt-identity77.8%
+-commutative77.8%
Simplified77.8%
Taylor expanded in b around 0 48.9%
Taylor expanded in a around 0 32.5%
*-commutative32.5%
Simplified32.5%
Final simplification32.5%
herbie shell --seed 2023322
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))