
(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 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(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)
(+ (- (* (cos a) (cos b)) t_0) (fma (- (sin b)) (sin a) t_0))))))
double code(double r, double a, double b) {
double t_0 = sin(b) * sin(a);
return r * (sin(b) / (((cos(a) * cos(b)) - t_0) + fma(-sin(b), sin(a), t_0)));
}
function code(r, a, b) t_0 = Float64(sin(b) * sin(a)) return Float64(r * Float64(sin(b) / Float64(Float64(Float64(cos(a) * cos(b)) - t_0) + fma(Float64(-sin(b)), sin(a), t_0)))) end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]}, N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] + N[((-N[Sin[b], $MachinePrecision]) * N[Sin[a], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin b \cdot \sin a\\
r \cdot \frac{\sin b}{\left(\cos a \cdot \cos b - t\_0\right) + \mathsf{fma}\left(-\sin b, \sin a, t\_0\right)}
\end{array}
\end{array}
Initial program 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
cos-sum99.5%
*-un-lft-identity99.5%
prod-diff99.5%
Applied egg-rr99.5%
fma-undefine99.5%
distribute-lft-neg-in99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
*-rgt-identity99.5%
*-commutative99.5%
fma-undefine99.5%
*-rgt-identity99.5%
distribute-lft-neg-in99.5%
*-rgt-identity99.5%
fma-undefine99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.5%
(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 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (if (or (<= a -2.95e-5) (not (<= a 0.0145))) (* r (/ (sin b) (cos a))) (* r (/ (sin b) (cos b)))))
double code(double r, double a, double b) {
double tmp;
if ((a <= -2.95e-5) || !(a <= 0.0145)) {
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 <= (-2.95d-5)) .or. (.not. (a <= 0.0145d0))) 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 <= -2.95e-5) || !(a <= 0.0145)) {
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 <= -2.95e-5) or not (a <= 0.0145): 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 <= -2.95e-5) || !(a <= 0.0145)) 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 <= -2.95e-5) || ~((a <= 0.0145))) 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, -2.95e-5], N[Not[LessEqual[a, 0.0145]], $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 -2.95 \cdot 10^{-5} \lor \neg \left(a \leq 0.0145\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\end{array}
\end{array}
if a < -2.9499999999999999e-5 or 0.0145000000000000007 < a Initial program 62.0%
associate-/l*62.0%
+-commutative62.0%
Simplified62.0%
Taylor expanded in b around 0 61.3%
if -2.9499999999999999e-5 < a < 0.0145000000000000007Initial program 98.0%
associate-/l*98.0%
+-commutative98.0%
Simplified98.0%
Taylor expanded in a around 0 98.0%
Final simplification81.5%
(FPCore (r a b) :precision binary64 (if (<= a -5.4e-5) (* r (/ (sin b) (cos a))) (if (<= a 0.0145) (* 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 <= 0.0145) {
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 <= 0.0145d0) 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 <= 0.0145) {
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 <= 0.0145: 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 <= 0.0145) 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 <= 0.0145) 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, 0.0145], 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 0.0145:\\
\;\;\;\;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 64.0%
associate-/l*64.1%
+-commutative64.1%
Simplified64.1%
Taylor expanded in b around 0 63.9%
if -5.3999999999999998e-5 < a < 0.0145000000000000007Initial program 98.0%
associate-/l*98.0%
+-commutative98.0%
Simplified98.0%
Taylor expanded in a around 0 98.0%
if 0.0145000000000000007 < a Initial program 60.1%
+-commutative60.1%
Simplified60.1%
Taylor expanded in b around 0 59.0%
Final simplification81.5%
(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 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
Final simplification81.8%
(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 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in b around 0 59.2%
Final simplification59.2%
(FPCore (r a b) :precision binary64 (/ (* r b) (cos (+ b a))))
double code(double r, double a, double b) {
return (r * 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 * b) / cos((b + a))
end function
public static double code(double r, double a, double b) {
return (r * b) / Math.cos((b + a));
}
def code(r, a, b): return (r * b) / math.cos((b + a))
function code(r, a, b) return Float64(Float64(r * b) / cos(Float64(b + a))) end
function tmp = code(r, a, b) tmp = (r * b) / cos((b + a)); end
code[r_, a_, b_] := N[(N[(r * b), $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot b}{\cos \left(b + a\right)}
\end{array}
Initial program 81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in b around 0 55.3%
Final simplification55.3%
(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 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
cos-sum99.5%
*-un-lft-identity99.5%
prod-diff99.5%
Applied egg-rr99.5%
fma-undefine99.5%
distribute-lft-neg-in99.5%
cancel-sign-sub-inv99.5%
*-commutative99.5%
*-rgt-identity99.5%
*-commutative99.5%
fma-undefine99.5%
*-rgt-identity99.5%
distribute-lft-neg-in99.5%
*-rgt-identity99.5%
fma-undefine99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in b around 0 55.2%
associate-/l*55.2%
Simplified55.2%
Final simplification55.2%
(FPCore (r a b) :precision binary64 (* r (/ b (cos a))))
double code(double r, double a, double b) {
return r * (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 * (b / cos(a))
end function
public static double code(double r, double a, double b) {
return r * (b / Math.cos(a));
}
def code(r, a, b): return r * (b / math.cos(a))
function code(r, a, b) return Float64(r * Float64(b / cos(a))) end
function tmp = code(r, a, b) tmp = r * (b / cos(a)); end
code[r_, a_, b_] := N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{b}{\cos a}
\end{array}
Initial program 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in b around 0 55.2%
Final simplification55.2%
(FPCore (r a b) :precision binary64 (/ (* r b) (cos a)))
double code(double r, double a, double b) {
return (r * 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 * b) / cos(a)
end function
public static double code(double r, double a, double b) {
return (r * b) / Math.cos(a);
}
def code(r, a, b): return (r * b) / math.cos(a)
function code(r, a, b) return Float64(Float64(r * b) / cos(a)) end
function tmp = code(r, a, b) tmp = (r * b) / cos(a); end
code[r_, a_, b_] := N[(N[(r * b), $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot b}{\cos a}
\end{array}
Initial program 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in b around 0 55.2%
Final simplification55.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 81.8%
associate-/l*81.8%
+-commutative81.8%
Simplified81.8%
Taylor expanded in b around 0 55.2%
Taylor expanded in a around 0 36.6%
Final simplification36.6%
herbie shell --seed 2024077
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))