
(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
(let* ((t_0 (* (sin b) (sin a))))
(/
(* r (sin b))
(+ (fma (- (sin b)) (sin a) t_0) (- (* (cos a) (cos b)) t_0)))))
double code(double r, double a, double b) {
double t_0 = sin(b) * sin(a);
return (r * sin(b)) / (fma(-sin(b), sin(a), t_0) + ((cos(a) * cos(b)) - t_0));
}
function code(r, a, b) t_0 = Float64(sin(b) * sin(a)) return Float64(Float64(r * sin(b)) / Float64(fma(Float64(-sin(b)), sin(a), t_0) + Float64(Float64(cos(a) * cos(b)) - t_0))) end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]}, N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[((-N[Sin[b], $MachinePrecision]) * N[Sin[a], $MachinePrecision] + t$95$0), $MachinePrecision] + N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin b \cdot \sin a\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(-\sin b, \sin a, t\_0\right) + \left(\cos a \cdot \cos b - t\_0\right)}
\end{array}
\end{array}
Initial program 77.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
*-un-lft-identity99.6%
prod-diff99.6%
Applied egg-rr99.6%
*-rgt-identity99.6%
fma-define99.6%
sub-neg99.6%
*-commutative99.6%
*-commutative99.6%
fma-undefine99.6%
*-rgt-identity99.6%
distribute-lft-neg-in99.6%
*-rgt-identity99.6%
fma-undefine99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.6%
(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(-Float64(sin(b) * 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 \sin a\right)}
\end{array}
Initial program 77.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
cancel-sign-sub-inv99.6%
fma-define99.6%
Applied egg-rr99.6%
Final simplification99.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 77.7%
associate-/l*77.7%
remove-double-neg77.7%
remove-double-neg77.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
Applied egg-rr99.6%
Final simplification99.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(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.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (- (* 0.5 (* 2.0 (cos (+ b a)))) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((0.5 * (2.0 * cos((b + 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) / ((0.5d0 * (2.0d0 * cos((b + a)))) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / ((0.5 * (2.0 * Math.cos((b + a)))) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b): return r * (math.sin(b) / ((0.5 * (2.0 * math.cos((b + a)))) - (math.sin(b) * math.sin(a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(0.5 * Float64(2.0 * cos(Float64(b + a)))) - Float64(sin(b) * sin(a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((0.5 * (2.0 * cos((b + a)))) - (sin(b) * sin(a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(0.5 * N[(2.0 * N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{0.5 \cdot \left(2 \cdot \cos \left(b + a\right)\right) - \sin b \cdot \sin a}
\end{array}
Initial program 77.7%
associate-/l*77.7%
remove-double-neg77.7%
remove-double-neg77.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
Applied egg-rr99.6%
cos-mult78.7%
clear-num78.7%
cos-diff78.4%
add-sqr-sqrt42.2%
sqrt-unprod78.4%
sqr-neg78.4%
sqrt-unprod36.3%
add-sqr-sqrt78.6%
cancel-sign-sub-inv78.6%
cos-sum78.5%
Applied egg-rr78.5%
associate-/r/78.6%
metadata-eval78.6%
count-278.6%
Simplified78.6%
Final simplification78.6%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (- (* 0.5 (* 2.0 (cos (+ b a)))) (* (sin b) (sin a)))))
double code(double r, double a, double b) {
return (r * sin(b)) / ((0.5 * (2.0 * cos((b + 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)) / ((0.5d0 * (2.0d0 * cos((b + a)))) - (sin(b) * sin(a)))
end function
public static double code(double r, double a, double b) {
return (r * Math.sin(b)) / ((0.5 * (2.0 * Math.cos((b + a)))) - (Math.sin(b) * Math.sin(a)));
}
def code(r, a, b): return (r * math.sin(b)) / ((0.5 * (2.0 * math.cos((b + a)))) - (math.sin(b) * math.sin(a)))
function code(r, a, b) return Float64(Float64(r * sin(b)) / Float64(Float64(0.5 * Float64(2.0 * cos(Float64(b + a)))) - Float64(sin(b) * sin(a)))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / ((0.5 * (2.0 * cos((b + a)))) - (sin(b) * sin(a))); end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[(0.5 * N[(2.0 * N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{0.5 \cdot \left(2 \cdot \cos \left(b + a\right)\right) - \sin b \cdot \sin a}
\end{array}
Initial program 77.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
Applied egg-rr99.6%
cos-mult78.7%
clear-num78.7%
cos-diff78.4%
add-sqr-sqrt42.2%
sqrt-unprod78.4%
sqr-neg78.4%
sqrt-unprod36.3%
add-sqr-sqrt78.6%
cancel-sign-sub-inv78.6%
cos-sum78.5%
Applied egg-rr78.5%
associate-/r/78.6%
metadata-eval78.6%
count-278.6%
Simplified78.6%
Final simplification78.6%
(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.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
cancel-sign-sub-inv99.6%
fma-define99.6%
Applied egg-rr99.6%
add-sqr-sqrt45.4%
sqrt-unprod87.2%
sqr-neg87.2%
sqrt-unprod41.7%
add-sqr-sqrt77.0%
sin-mult78.0%
div-sub78.0%
cos-diff77.3%
add-sqr-sqrt41.9%
sqrt-unprod77.9%
sqr-neg77.9%
sqrt-unprod36.0%
add-sqr-sqrt78.5%
cancel-sign-sub-inv78.5%
cos-sum78.0%
Applied egg-rr78.0%
+-inverses78.0%
Simplified78.0%
Final simplification78.0%
(FPCore (r a b) :precision binary64 (if (or (<= a -3.9e-6) (not (<= a 165000.0))) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -3.9e-6) || !(a <= 165000.0)) {
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 <= (-3.9d-6)) .or. (.not. (a <= 165000.0d0))) 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 <= -3.9e-6) || !(a <= 165000.0)) {
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 <= -3.9e-6) or not (a <= 165000.0): 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 <= -3.9e-6) || !(a <= 165000.0)) 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 <= -3.9e-6) || ~((a <= 165000.0))) 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, -3.9e-6], N[Not[LessEqual[a, 165000.0]], $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 -3.9 \cdot 10^{-6} \lor \neg \left(a \leq 165000\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if a < -3.8999999999999999e-6 or 165000 < a Initial program 53.0%
associate-/l*52.9%
remove-double-neg52.9%
remove-double-neg52.9%
+-commutative52.9%
Simplified52.9%
Taylor expanded in b around 0 51.7%
if -3.8999999999999999e-6 < a < 165000Initial program 98.9%
associate-/l*98.9%
remove-double-neg98.9%
remove-double-neg98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in a around 0 98.9%
Final simplification77.1%
(FPCore (r a b) :precision binary64 (if (<= a -2.7e-6) (* r (/ (sin b) (cos a))) (if (<= a 165000.0) (* r (/ (sin b) (cos b))) (/ (* r (sin b)) (cos a)))))
double code(double r, double a, double b) {
double tmp;
if (a <= -2.7e-6) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 165000.0) {
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 <= (-2.7d-6)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 165000.0d0) 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 <= -2.7e-6) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 165000.0) {
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 <= -2.7e-6: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 165000.0: 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 <= -2.7e-6) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 165000.0) tmp = Float64(r * Float64(sin(b) / 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 <= -2.7e-6) tmp = r * (sin(b) / cos(a)); elseif (a <= 165000.0) 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, -2.7e-6], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 165000.0], N[(r * N[(N[Sin[b], $MachinePrecision] / 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 -2.7 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 165000:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos a}\\
\end{array}
\end{array}
if a < -2.69999999999999998e-6Initial program 59.4%
associate-/l*59.4%
remove-double-neg59.4%
remove-double-neg59.4%
+-commutative59.4%
Simplified59.4%
Taylor expanded in b around 0 59.1%
if -2.69999999999999998e-6 < a < 165000Initial program 98.9%
associate-/l*98.9%
remove-double-neg98.9%
remove-double-neg98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in a around 0 98.9%
if 165000 < a Initial program 45.4%
+-commutative45.4%
Simplified45.4%
Taylor expanded in b around 0 43.0%
Final simplification77.1%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (* r (sin b))))
(if (<= a -3.9e-6)
(* r (/ (sin b) (cos a)))
(if (<= a 165000.0) (/ t_0 (cos b)) (/ t_0 (cos a))))))
double code(double r, double a, double b) {
double t_0 = r * sin(b);
double tmp;
if (a <= -3.9e-6) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 165000.0) {
tmp = t_0 / cos(b);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = r * sin(b)
if (a <= (-3.9d-6)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 165000.0d0) then
tmp = t_0 / cos(b)
else
tmp = t_0 / cos(a)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = r * Math.sin(b);
double tmp;
if (a <= -3.9e-6) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 165000.0) {
tmp = t_0 / Math.cos(b);
} else {
tmp = t_0 / Math.cos(a);
}
return tmp;
}
def code(r, a, b): t_0 = r * math.sin(b) tmp = 0 if a <= -3.9e-6: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 165000.0: tmp = t_0 / math.cos(b) else: tmp = t_0 / math.cos(a) return tmp
function code(r, a, b) t_0 = Float64(r * sin(b)) tmp = 0.0 if (a <= -3.9e-6) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 165000.0) tmp = Float64(t_0 / cos(b)); else tmp = Float64(t_0 / cos(a)); end return tmp end
function tmp_2 = code(r, a, b) t_0 = r * sin(b); tmp = 0.0; if (a <= -3.9e-6) tmp = r * (sin(b) / cos(a)); elseif (a <= 165000.0) tmp = t_0 / cos(b); else tmp = t_0 / cos(a); end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -3.9e-6], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 165000.0], N[(t$95$0 / N[Cos[b], $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Cos[a], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := r \cdot \sin b\\
\mathbf{if}\;a \leq -3.9 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 165000:\\
\;\;\;\;\frac{t\_0}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\cos a}\\
\end{array}
\end{array}
if a < -3.8999999999999999e-6Initial program 59.4%
associate-/l*59.4%
remove-double-neg59.4%
remove-double-neg59.4%
+-commutative59.4%
Simplified59.4%
Taylor expanded in b around 0 59.1%
if -3.8999999999999999e-6 < a < 165000Initial program 98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in a around 0 98.9%
if 165000 < a Initial program 45.4%
+-commutative45.4%
Simplified45.4%
Taylor expanded in b around 0 43.0%
Final simplification77.1%
(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 77.7%
associate-/l*77.7%
remove-double-neg77.7%
remove-double-neg77.7%
+-commutative77.7%
Simplified77.7%
Final simplification77.7%
(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 77.7%
Final simplification77.7%
(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 77.7%
associate-/l*77.7%
remove-double-neg77.7%
remove-double-neg77.7%
+-commutative77.7%
Simplified77.7%
Taylor expanded in b around 0 57.6%
Final simplification57.6%
(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 77.7%
+-commutative77.7%
Simplified77.7%
cos-sum99.6%
*-un-lft-identity99.6%
prod-diff99.6%
Applied egg-rr99.6%
*-rgt-identity99.6%
fma-define99.6%
sub-neg99.6%
*-commutative99.6%
*-commutative99.6%
fma-undefine99.6%
*-rgt-identity99.6%
distribute-lft-neg-in99.6%
*-rgt-identity99.6%
fma-undefine99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in b around 0 54.0%
Simplified54.0%
Final simplification54.0%
(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.7%
associate-/l*77.7%
remove-double-neg77.7%
remove-double-neg77.7%
+-commutative77.7%
Simplified77.7%
Taylor expanded in b around 0 54.0%
Taylor expanded in a around 0 39.6%
Final simplification39.6%
herbie shell --seed 2024081
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))