
(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 12 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 (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) / (fma(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(fma(cos(a), cos(b), t_0) - fma(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[Cos[a], $MachinePrecision] * N[Cos[b], $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}{\mathsf{fma}\left(\cos a, \cos b, t\_0\right) - \mathsf{fma}\left(\sin b, \sin a, t\_0\right)}
\end{array}
\end{array}
Initial program 77.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
cos-sum99.5%
cancel-sign-sub-inv99.5%
fma-define99.6%
Applied egg-rr99.6%
distribute-lft-neg-out99.6%
fma-neg99.5%
add-sqr-sqrt50.1%
sqrt-unprod88.6%
sqr-neg88.6%
sqrt-unprod38.5%
add-sqr-sqrt77.5%
distribute-lft-neg-out77.5%
neg-mul-177.5%
add-sqr-sqrt39.0%
sqrt-unprod88.4%
sqr-neg88.4%
sqrt-unprod49.3%
add-sqr-sqrt99.5%
prod-diff99.6%
Applied egg-rr99.6%
+-commutative99.6%
fma-undefine99.6%
*-commutative99.6%
neg-mul-199.6%
*-commutative99.6%
neg-mul-199.6%
distribute-neg-out99.6%
fma-undefine99.6%
*-commutative99.6%
fma-undefine99.6%
*-commutative99.6%
fma-undefine99.6%
*-commutative99.6%
neg-mul-199.6%
Simplified99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (fma (cos b) (cos a) (* (sin a) (- (sin b)))))))
double code(double r, double a, double b) {
return r * (sin(b) / fma(cos(b), cos(a), (sin(a) * -sin(b))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / fma(cos(b), cos(a), Float64(sin(a) * Float64(-sin(b)))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * (-N[Sin[b], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin a \cdot \left(-\sin b\right)\right)}
\end{array}
Initial program 77.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
cos-sum99.5%
cancel-sign-sub-inv99.5%
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.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
cos-sum99.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (r a b) :precision binary64 (/ 1.0 (- (* (/ (cos a) r) (/ (cos b) (sin b))) (/ (sin a) r))))
double code(double r, double a, double b) {
return 1.0 / (((cos(a) / r) * (cos(b) / sin(b))) - (sin(a) / r));
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (((cos(a) / r) * (cos(b) / sin(b))) - (sin(a) / r))
end function
public static double code(double r, double a, double b) {
return 1.0 / (((Math.cos(a) / r) * (Math.cos(b) / Math.sin(b))) - (Math.sin(a) / r));
}
def code(r, a, b): return 1.0 / (((math.cos(a) / r) * (math.cos(b) / math.sin(b))) - (math.sin(a) / r))
function code(r, a, b) return Float64(1.0 / Float64(Float64(Float64(cos(a) / r) * Float64(cos(b) / sin(b))) - Float64(sin(a) / r))) end
function tmp = code(r, a, b) tmp = 1.0 / (((cos(a) / r) * (cos(b) / sin(b))) - (sin(a) / r)); end
code[r_, a_, b_] := N[(1.0 / N[(N[(N[(N[Cos[a], $MachinePrecision] / r), $MachinePrecision] * N[(N[Cos[b], $MachinePrecision] / N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Sin[a], $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\cos a}{r} \cdot \frac{\cos b}{\sin b} - \frac{\sin a}{r}}
\end{array}
Initial program 77.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
associate-*r/77.2%
clear-num76.4%
*-commutative76.4%
Applied egg-rr76.4%
*-commutative76.4%
cos-sum98.6%
div-sub91.3%
*-commutative91.3%
*-commutative91.3%
Applied egg-rr91.3%
*-commutative91.3%
*-commutative91.3%
times-frac91.1%
remove-double-neg91.1%
neg-mul-191.1%
*-commutative91.1%
distribute-rgt-neg-in91.1%
distribute-frac-neg91.1%
associate-*r*91.1%
*-commutative91.1%
neg-mul-191.1%
distribute-neg-frac91.1%
times-frac98.5%
*-inverses98.5%
distribute-lft-neg-in98.5%
metadata-eval98.5%
associate-*r/98.5%
Simplified98.5%
(FPCore (r a b) :precision binary64 (if (or (<= b -1.6e-6) (not (<= b 0.000135))) (* r (/ (sin b) (cos b))) (* b (/ r (cos a)))))
double code(double r, double a, double b) {
double tmp;
if ((b <= -1.6e-6) || !(b <= 0.000135)) {
tmp = r * (sin(b) / cos(b));
} 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 <= (-1.6d-6)) .or. (.not. (b <= 0.000135d0))) then
tmp = r * (sin(b) / cos(b))
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 <= -1.6e-6) || !(b <= 0.000135)) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else {
tmp = b * (r / Math.cos(a));
}
return tmp;
}
def code(r, a, b): tmp = 0 if (b <= -1.6e-6) or not (b <= 0.000135): tmp = r * (math.sin(b) / math.cos(b)) else: tmp = b * (r / math.cos(a)) return tmp
function code(r, a, b) tmp = 0.0 if ((b <= -1.6e-6) || !(b <= 0.000135)) tmp = Float64(r * Float64(sin(b) / cos(b))); else tmp = Float64(b * Float64(r / cos(a))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if ((b <= -1.6e-6) || ~((b <= 0.000135))) tmp = r * (sin(b) / cos(b)); else tmp = b * (r / cos(a)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[Or[LessEqual[b, -1.6e-6], N[Not[LessEqual[b, 0.000135]], $MachinePrecision]], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.6 \cdot 10^{-6} \lor \neg \left(b \leq 0.000135\right):\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\end{array}
\end{array}
if b < -1.5999999999999999e-6 or 1.35000000000000002e-4 < b Initial program 52.5%
associate-/l*52.6%
+-commutative52.6%
Simplified52.6%
Taylor expanded in a around 0 53.4%
if -1.5999999999999999e-6 < b < 1.35000000000000002e-4Initial program 98.7%
associate-/l*98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in b around 0 98.7%
clear-num98.6%
un-div-inv98.5%
Applied egg-rr98.5%
associate-/r/98.7%
Simplified98.7%
Final simplification77.7%
(FPCore (r a b) :precision binary64 (if (<= b -4.2e-6) (* r (/ (sin b) (cos b))) (if (<= b 0.00052) (* b (/ r (cos a))) (* (sin b) (/ r (cos b))))))
double code(double r, double a, double b) {
double tmp;
if (b <= -4.2e-6) {
tmp = r * (sin(b) / cos(b));
} else if (b <= 0.00052) {
tmp = b * (r / cos(a));
} 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 (b <= (-4.2d-6)) then
tmp = r * (sin(b) / cos(b))
else if (b <= 0.00052d0) then
tmp = b * (r / cos(a))
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 (b <= -4.2e-6) {
tmp = r * (Math.sin(b) / Math.cos(b));
} else if (b <= 0.00052) {
tmp = b * (r / Math.cos(a));
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): tmp = 0 if b <= -4.2e-6: tmp = r * (math.sin(b) / math.cos(b)) elif b <= 0.00052: tmp = b * (r / math.cos(a)) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) tmp = 0.0 if (b <= -4.2e-6) tmp = Float64(r * Float64(sin(b) / cos(b))); elseif (b <= 0.00052) tmp = Float64(b * Float64(r / cos(a))); else tmp = Float64(sin(b) * Float64(r / cos(b))); end return tmp end
function tmp_2 = code(r, a, b) tmp = 0.0; if (b <= -4.2e-6) tmp = r * (sin(b) / cos(b)); elseif (b <= 0.00052) tmp = b * (r / cos(a)); else tmp = sin(b) * (r / cos(b)); end tmp_2 = tmp; end
code[r_, a_, b_] := If[LessEqual[b, -4.2e-6], N[(r * N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 0.00052], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.2 \cdot 10^{-6}:\\
\;\;\;\;r \cdot \frac{\sin b}{\cos b}\\
\mathbf{elif}\;b \leq 0.00052:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if b < -4.1999999999999996e-6Initial program 51.8%
associate-/l*51.9%
+-commutative51.9%
Simplified51.9%
Taylor expanded in a around 0 52.0%
if -4.1999999999999996e-6 < b < 5.19999999999999954e-4Initial program 98.7%
associate-/l*98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in b around 0 98.7%
clear-num98.6%
un-div-inv98.5%
Applied egg-rr98.5%
associate-/r/98.7%
Simplified98.7%
if 5.19999999999999954e-4 < b Initial program 53.2%
associate-/l*53.3%
+-commutative53.3%
Simplified53.3%
Taylor expanded in a around 0 54.9%
*-commutative54.9%
associate-/l*55.0%
Simplified55.0%
Final simplification77.7%
(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.2%
+-commutative77.2%
Simplified77.2%
*-commutative77.2%
associate-/l*77.3%
Applied egg-rr77.3%
(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.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
(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.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
Taylor expanded in b around 0 58.7%
(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.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
Taylor expanded in b around 0 54.9%
clear-num54.9%
un-div-inv54.8%
Applied egg-rr54.8%
associate-/r/54.9%
Simplified54.9%
Final simplification54.9%
(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 77.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
Taylor expanded in b around 0 54.9%
(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.2%
associate-/l*77.2%
+-commutative77.2%
Simplified77.2%
Taylor expanded in b around 0 54.9%
Taylor expanded in a around 0 39.3%
herbie shell --seed 2024088
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))