
(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(r * Float64(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[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (cos (+ a b)))))
double code(double r, double a, double b) {
return r * (sin(b) / cos((a + b)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / cos((a + b)))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / Math.cos((a + b)));
}
def code(r, a, b): return r * (math.sin(b) / math.cos((a + b)))
function code(r, a, b) return Float64(r * Float64(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[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos \left(a + b\right)}
\end{array}
(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(r * Float64(sin(b) / fma(cos(b), cos(a), Float64(-Float64(sin(b) * sin(a)))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + (-N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, -\sin b \cdot \sin a\right)}
\end{array}
Initial program 80.7%
remove-double-neg80.7%
remove-double-neg80.7%
+-commutative80.7%
Simplified80.7%
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 (/ (sin b) (- (* (cos b) (cos a)) (* (sin b) (sin a))))))
double code(double r, double a, double b) {
return r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a))))
end function
public static double code(double r, double a, double b) {
return r * (Math.sin(b) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a))));
}
def code(r, a, b): return r * (math.sin(b) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a))))
function code(r, a, b) return Float64(r * Float64(sin(b) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a))))) end
function tmp = code(r, a, b) tmp = r * (sin(b) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))); end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 80.7%
remove-double-neg80.7%
remove-double-neg80.7%
+-commutative80.7%
Simplified80.7%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (- (* (cos b) (cos a)) (* (sin b) (sin a)))))
double code(double r, double a, double b) {
return (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(a)));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(a)))
end function
public static double code(double r, double a, double b) {
return (r * Math.sin(b)) / ((Math.cos(b) * Math.cos(a)) - (Math.sin(b) * Math.sin(a)));
}
def code(r, a, b): return (r * math.sin(b)) / ((math.cos(b) * math.cos(a)) - (math.sin(b) * math.sin(a)))
function code(r, a, b) return Float64(Float64(r * sin(b)) / Float64(Float64(cos(b) * cos(a)) - Float64(sin(b) * sin(a)))) end
function tmp = code(r, a, b) tmp = (r * sin(b)) / ((cos(b) * cos(a)) - (sin(b) * sin(a))); end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 80.7%
associate-*r/80.7%
+-commutative80.7%
Simplified80.7%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -4.8e-5) (not (<= a 1.9e-6))) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -4.8e-5) || !(a <= 1.9e-6)) {
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.8d-5)) .or. (.not. (a <= 1.9d-6))) 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.8e-5) || !(a <= 1.9e-6)) {
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.8e-5) or not (a <= 1.9e-6): 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.8e-5) || !(a <= 1.9e-6)) 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.8e-5) || ~((a <= 1.9e-6))) 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.8e-5], N[Not[LessEqual[a, 1.9e-6]], $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.8 \cdot 10^{-5} \lor \neg \left(a \leq 1.9 \cdot 10^{-6}\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if a < -4.8000000000000001e-5 or 1.9e-6 < a Initial program 56.5%
remove-double-neg56.5%
remove-double-neg56.5%
+-commutative56.5%
Simplified56.5%
Taylor expanded in b around 0 56.1%
if -4.8000000000000001e-5 < a < 1.9e-6Initial program 98.4%
remove-double-neg98.4%
remove-double-neg98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in a around 0 98.4%
Final simplification80.6%
(FPCore (r a b) :precision binary64 (if (<= a -5.4e-5) (* r (/ (sin b) (cos a))) (if (<= a 5.8e-6) (* r (/ (sin b) (cos b))) (/ (* r (sin b)) (cos a)))))
double code(double r, double a, double b) {
double tmp;
if (a <= -5.4e-5) {
tmp = r * (sin(b) / cos(a));
} else if (a <= 5.8e-6) {
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 <= (-5.4d-5)) then
tmp = r * (sin(b) / cos(a))
else if (a <= 5.8d-6) 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 <= -5.4e-5) {
tmp = r * (Math.sin(b) / Math.cos(a));
} else if (a <= 5.8e-6) {
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 <= -5.4e-5: tmp = r * (math.sin(b) / math.cos(a)) elif a <= 5.8e-6: 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 <= -5.4e-5) tmp = Float64(r * Float64(sin(b) / cos(a))); elseif (a <= 5.8e-6) 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 <= -5.4e-5) tmp = r * (sin(b) / cos(a)); elseif (a <= 5.8e-6) 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, -5.4e-5], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 5.8e-6], 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 -5.4 \cdot 10^{-5}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{elif}\;a \leq 5.8 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos a}\\
\end{array}
\end{array}
if a < -5.3999999999999998e-5Initial program 60.8%
remove-double-neg60.8%
remove-double-neg60.8%
+-commutative60.8%
Simplified60.8%
Taylor expanded in b around 0 59.9%
if -5.3999999999999998e-5 < a < 5.8000000000000004e-6Initial program 98.4%
remove-double-neg98.4%
remove-double-neg98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in a around 0 98.4%
if 5.8000000000000004e-6 < a Initial program 52.6%
associate-*r/52.6%
+-commutative52.6%
Simplified52.6%
Taylor expanded in b around 0 52.7%
Final simplification80.6%
(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 80.7%
Final simplification80.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 80.7%
remove-double-neg80.7%
remove-double-neg80.7%
+-commutative80.7%
Simplified80.7%
Taylor expanded in b around 0 60.3%
Final simplification60.3%
(FPCore (r a b) :precision binary64 (if (<= b 4.4) (* r (/ b (cos (+ b a)))) (* r (sin b))))
double code(double r, double a, double b) {
double tmp;
if (b <= 4.4) {
tmp = r * (b / cos((b + a)));
} else {
tmp = r * 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 (b <= 4.4d0) then
tmp = r * (b / cos((b + a)))
else
tmp = r * sin(b)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= 4.4) {
tmp = r * (b / Math.cos((b + a)));
} else {
tmp = r * Math.sin(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= 4.4: tmp = r * (b / math.cos((b + a))) else: tmp = r * math.sin(b) return tmp
function code(r, a, b) tmp = 0.0 if (b <= 4.4) tmp = Float64(r * Float64(b / cos(Float64(b + a)))); else tmp = Float64(r * sin(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= 4.4) tmp = r * (b / cos((b + a))); else tmp = r * sin(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, 4.4], N[(r * N[(b / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.4:\\
\;\;\;\;r \cdot \frac{b}{\cos \left(b + a\right)}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \sin b\\
\end{array}
\end{array}
if b < 4.4000000000000004Initial program 90.1%
remove-double-neg90.1%
remove-double-neg90.1%
+-commutative90.1%
Simplified90.1%
Taylor expanded in b around 0 75.3%
if 4.4000000000000004 < b Initial program 54.7%
associate-*r/54.6%
+-commutative54.6%
Simplified54.6%
Taylor expanded in b around 0 7.8%
mul-1-neg7.8%
unsub-neg7.8%
Simplified7.8%
Taylor expanded in a around 0 14.8%
*-commutative14.8%
Simplified14.8%
Final simplification59.2%
(FPCore (r a b) :precision binary64 (if (<= b 1.55e+18) (* r (/ b (cos a))) (* r (sin b))))
double code(double r, double a, double b) {
double tmp;
if (b <= 1.55e+18) {
tmp = r * (b / cos(a));
} else {
tmp = r * 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 (b <= 1.55d+18) then
tmp = r * (b / cos(a))
else
tmp = r * sin(b)
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double tmp;
if (b <= 1.55e+18) {
tmp = r * (b / Math.cos(a));
} else {
tmp = r * Math.sin(b);
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= 1.55e+18: tmp = r * (b / math.cos(a)) else: tmp = r * math.sin(b) return tmp
function code(r, a, b) tmp = 0.0 if (b <= 1.55e+18) tmp = Float64(r * Float64(b / cos(a))); else tmp = Float64(r * sin(b)); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= 1.55e+18) tmp = r * (b / cos(a)); else tmp = r * sin(b); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, 1.55e+18], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.55 \cdot 10^{+18}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \sin b\\
\end{array}
\end{array}
if b < 1.55e18Initial program 89.4%
remove-double-neg89.4%
remove-double-neg89.4%
+-commutative89.4%
Simplified89.4%
Taylor expanded in b around 0 74.1%
if 1.55e18 < b Initial program 55.3%
associate-*r/55.2%
+-commutative55.2%
Simplified55.2%
Taylor expanded in b around 0 7.7%
mul-1-neg7.7%
unsub-neg7.7%
Simplified7.7%
Taylor expanded in a around 0 15.1%
*-commutative15.1%
Simplified15.1%
Final simplification59.1%
(FPCore (r a b) :precision binary64 (* r (sin b)))
double code(double r, double a, double b) {
return r * sin(b);
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = r * sin(b)
end function
public static double code(double r, double a, double b) {
return r * Math.sin(b);
}
def code(r, a, b): return r * math.sin(b)
function code(r, a, b) return Float64(r * sin(b)) end
function tmp = code(r, a, b) tmp = r * sin(b); end
code[r_, a_, b_] := N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \sin b
\end{array}
Initial program 80.7%
associate-*r/80.7%
+-commutative80.7%
Simplified80.7%
Taylor expanded in b around 0 58.1%
mul-1-neg58.1%
unsub-neg58.1%
Simplified58.1%
Taylor expanded in a around 0 46.4%
*-commutative46.4%
Simplified46.4%
Final simplification46.4%
(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 80.7%
remove-double-neg80.7%
remove-double-neg80.7%
+-commutative80.7%
Simplified80.7%
Taylor expanded in b around 0 56.1%
Taylor expanded in a around 0 42.1%
Final simplification42.1%
herbie shell --seed 2024039
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))