
(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 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(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 (* (/ (sin b) (fma (sin b) (- (sin a)) (* (cos a) (cos b)))) r))
double code(double r, double a, double b) {
return (sin(b) / fma(sin(b), -sin(a), (cos(a) * cos(b)))) * r;
}
function code(r, a, b) return Float64(Float64(sin(b) / fma(sin(b), Float64(-sin(a)), Float64(cos(a) * cos(b)))) * r) end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * (-N[Sin[a], $MachinePrecision]) + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b}{\mathsf{fma}\left(\sin b, -\sin a, \cos a \cdot \cos b\right)} \cdot r
\end{array}
Initial program 77.4%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (cos (+ a b)))
(t_1 (/ (sin b) t_0))
(t_2 (* (/ r (cos b)) (sin b))))
(if (<= t_1 -1e-7)
t_2
(if (<= t_1 0.071)
(/ (* (* (fma (* b b) -0.16666666666666666 1.0) r) b) t_0)
t_2))))
double code(double r, double a, double b) {
double t_0 = cos((a + b));
double t_1 = sin(b) / t_0;
double t_2 = (r / cos(b)) * sin(b);
double tmp;
if (t_1 <= -1e-7) {
tmp = t_2;
} else if (t_1 <= 0.071) {
tmp = ((fma((b * b), -0.16666666666666666, 1.0) * r) * b) / t_0;
} else {
tmp = t_2;
}
return tmp;
}
function code(r, a, b) t_0 = cos(Float64(a + b)) t_1 = Float64(sin(b) / t_0) t_2 = Float64(Float64(r / cos(b)) * sin(b)) tmp = 0.0 if (t_1 <= -1e-7) tmp = t_2; elseif (t_1 <= 0.071) tmp = Float64(Float64(Float64(fma(Float64(b * b), -0.16666666666666666, 1.0) * r) * b) / t_0); else tmp = t_2; end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[b], $MachinePrecision] / t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-7], t$95$2, If[LessEqual[t$95$1, 0.071], N[(N[(N[(N[(N[(b * b), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * r), $MachinePrecision] * b), $MachinePrecision] / t$95$0), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(a + b\right)\\
t_1 := \frac{\sin b}{t\_0}\\
t_2 := \frac{r}{\cos b} \cdot \sin b\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-7}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 0.071:\\
\;\;\;\;\frac{\left(\mathsf{fma}\left(b \cdot b, -0.16666666666666666, 1\right) \cdot r\right) \cdot b}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -9.9999999999999995e-8 or 0.0709999999999999937 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 55.2%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-sin.f6454.8
Applied rewrites54.8%
if -9.9999999999999995e-8 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 0.0709999999999999937Initial program 97.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6497.6
Applied rewrites97.6%
Taylor expanded in b around 0
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6497.4
Applied rewrites97.4%
(FPCore (r a b) :precision binary64 (* (/ (sin b) (- (* (cos a) (cos b)) (* (sin a) (sin b)))) r))
double code(double r, double a, double b) {
return (sin(b) / ((cos(a) * cos(b)) - (sin(a) * sin(b)))) * r;
}
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) / ((cos(a) * cos(b)) - (sin(a) * sin(b)))) * r
end function
public static double code(double r, double a, double b) {
return (Math.sin(b) / ((Math.cos(a) * Math.cos(b)) - (Math.sin(a) * Math.sin(b)))) * r;
}
def code(r, a, b): return (math.sin(b) / ((math.cos(a) * math.cos(b)) - (math.sin(a) * math.sin(b)))) * r
function code(r, a, b) return Float64(Float64(sin(b) / Float64(Float64(cos(a) * cos(b)) - Float64(sin(a) * sin(b)))) * r) end
function tmp = code(r, a, b) tmp = (sin(b) / ((cos(a) * cos(b)) - (sin(a) * sin(b)))) * r; end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[a], $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b}{\cos a \cdot \cos b - \sin a \cdot \sin b} \cdot r
\end{array}
Initial program 77.4%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lift-sin.f64N/A
lower-*.f64N/A
lower-sin.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (r a b) :precision binary64 (/ (* (sin b) r) (fma (- (sin a)) (sin b) (* (cos a) (cos b)))))
double code(double r, double a, double b) {
return (sin(b) * r) / fma(-sin(a), sin(b), (cos(a) * cos(b)));
}
function code(r, a, b) return Float64(Float64(sin(b) * r) / fma(Float64(-sin(a)), sin(b), Float64(cos(a) * cos(b)))) end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] * r), $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{\sin b \cdot r}{\mathsf{fma}\left(-\sin a, \sin b, \cos a \cdot \cos b\right)}
\end{array}
Initial program 77.4%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.6
Applied rewrites99.6%
Taylor expanded in r around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.6
Applied rewrites99.6%
Final simplification99.6%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (- (sin a))) (t_1 (/ r (/ (fma t_0 b (cos a)) b))))
(if (<= a -0.48)
t_1
(if (<= a 0.42)
(*
(/
(sin b)
(fma
(sin b)
t_0
(*
(fma
(fma
(fma -0.001388888888888889 (* a a) 0.041666666666666664)
(* a a)
-0.5)
(* a a)
1.0)
(cos b))))
r)
t_1))))
double code(double r, double a, double b) {
double t_0 = -sin(a);
double t_1 = r / (fma(t_0, b, cos(a)) / b);
double tmp;
if (a <= -0.48) {
tmp = t_1;
} else if (a <= 0.42) {
tmp = (sin(b) / fma(sin(b), t_0, (fma(fma(fma(-0.001388888888888889, (a * a), 0.041666666666666664), (a * a), -0.5), (a * a), 1.0) * cos(b)))) * r;
} else {
tmp = t_1;
}
return tmp;
}
function code(r, a, b) t_0 = Float64(-sin(a)) t_1 = Float64(r / Float64(fma(t_0, b, cos(a)) / b)) tmp = 0.0 if (a <= -0.48) tmp = t_1; elseif (a <= 0.42) tmp = Float64(Float64(sin(b) / fma(sin(b), t_0, Float64(fma(fma(fma(-0.001388888888888889, Float64(a * a), 0.041666666666666664), Float64(a * a), -0.5), Float64(a * a), 1.0) * cos(b)))) * r); else tmp = t_1; end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = (-N[Sin[a], $MachinePrecision])}, Block[{t$95$1 = N[(r / N[(N[(t$95$0 * b + N[Cos[a], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.48], t$95$1, If[LessEqual[a, 0.42], N[(N[(N[Sin[b], $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * t$95$0 + N[(N[(N[(N[(-0.001388888888888889 * N[(a * a), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(a * a), $MachinePrecision] + -0.5), $MachinePrecision] * N[(a * a), $MachinePrecision] + 1.0), $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin a\\
t_1 := \frac{r}{\frac{\mathsf{fma}\left(t\_0, b, \cos a\right)}{b}}\\
\mathbf{if}\;a \leq -0.48:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \leq 0.42:\\
\;\;\;\;\frac{\sin b}{\mathsf{fma}\left(\sin b, t\_0, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, a \cdot a, 0.041666666666666664\right), a \cdot a, -0.5\right), a \cdot a, 1\right) \cdot \cos b\right)} \cdot r\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if a < -0.47999999999999998 or 0.419999999999999984 < a Initial program 55.8%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6454.6
Applied rewrites54.6%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6454.5
Applied rewrites54.5%
Taylor expanded in b around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6460.9
Applied rewrites60.9%
if -0.47999999999999998 < a < 0.419999999999999984Initial program 97.7%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.7
Applied rewrites99.7%
Final simplification80.9%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (- (sin a))) (t_1 (/ r (/ (fma t_0 b (cos a)) b))))
(if (<= a -0.24)
t_1
(if (<= a 0.28)
(*
(/
(sin b)
(fma
(sin b)
t_0
(*
(fma (fma 0.041666666666666664 (* a a) -0.5) (* a a) 1.0)
(cos b))))
r)
t_1))))
double code(double r, double a, double b) {
double t_0 = -sin(a);
double t_1 = r / (fma(t_0, b, cos(a)) / b);
double tmp;
if (a <= -0.24) {
tmp = t_1;
} else if (a <= 0.28) {
tmp = (sin(b) / fma(sin(b), t_0, (fma(fma(0.041666666666666664, (a * a), -0.5), (a * a), 1.0) * cos(b)))) * r;
} else {
tmp = t_1;
}
return tmp;
}
function code(r, a, b) t_0 = Float64(-sin(a)) t_1 = Float64(r / Float64(fma(t_0, b, cos(a)) / b)) tmp = 0.0 if (a <= -0.24) tmp = t_1; elseif (a <= 0.28) tmp = Float64(Float64(sin(b) / fma(sin(b), t_0, Float64(fma(fma(0.041666666666666664, Float64(a * a), -0.5), Float64(a * a), 1.0) * cos(b)))) * r); else tmp = t_1; end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = (-N[Sin[a], $MachinePrecision])}, Block[{t$95$1 = N[(r / N[(N[(t$95$0 * b + N[Cos[a], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.24], t$95$1, If[LessEqual[a, 0.28], N[(N[(N[Sin[b], $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * t$95$0 + N[(N[(N[(0.041666666666666664 * N[(a * a), $MachinePrecision] + -0.5), $MachinePrecision] * N[(a * a), $MachinePrecision] + 1.0), $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin a\\
t_1 := \frac{r}{\frac{\mathsf{fma}\left(t\_0, b, \cos a\right)}{b}}\\
\mathbf{if}\;a \leq -0.24:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \leq 0.28:\\
\;\;\;\;\frac{\sin b}{\mathsf{fma}\left(\sin b, t\_0, \mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, a \cdot a, -0.5\right), a \cdot a, 1\right) \cdot \cos b\right)} \cdot r\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if a < -0.23999999999999999 or 0.28000000000000003 < a Initial program 55.8%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6454.6
Applied rewrites54.6%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6454.5
Applied rewrites54.5%
Taylor expanded in b around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6460.9
Applied rewrites60.9%
if -0.23999999999999999 < a < 0.28000000000000003Initial program 97.7%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.7
Applied rewrites99.7%
Final simplification80.9%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (/ r (/ (fma (- (sin a)) b (cos a)) b))))
(if (<= a -3.3)
t_0
(if (<= a 3.6)
(*
(/
(sin b)
(fma
(cos b)
(cos a)
(* (* (fma (* 0.16666666666666666 a) a -1.0) (sin b)) a)))
r)
t_0))))
double code(double r, double a, double b) {
double t_0 = r / (fma(-sin(a), b, cos(a)) / b);
double tmp;
if (a <= -3.3) {
tmp = t_0;
} else if (a <= 3.6) {
tmp = (sin(b) / fma(cos(b), cos(a), ((fma((0.16666666666666666 * a), a, -1.0) * sin(b)) * a))) * r;
} else {
tmp = t_0;
}
return tmp;
}
function code(r, a, b) t_0 = Float64(r / Float64(fma(Float64(-sin(a)), b, cos(a)) / b)) tmp = 0.0 if (a <= -3.3) tmp = t_0; elseif (a <= 3.6) tmp = Float64(Float64(sin(b) / fma(cos(b), cos(a), Float64(Float64(fma(Float64(0.16666666666666666 * a), a, -1.0) * sin(b)) * a))) * r); else tmp = t_0; end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = N[(r / N[(N[((-N[Sin[a], $MachinePrecision]) * b + N[Cos[a], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -3.3], t$95$0, If[LessEqual[a, 3.6], N[(N[(N[Sin[b], $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[(N[(N[(0.16666666666666666 * a), $MachinePrecision] * a + -1.0), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{r}{\frac{\mathsf{fma}\left(-\sin a, b, \cos a\right)}{b}}\\
\mathbf{if}\;a \leq -3.3:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 3.6:\\
\;\;\;\;\frac{\sin b}{\mathsf{fma}\left(\cos b, \cos a, \left(\mathsf{fma}\left(0.16666666666666666 \cdot a, a, -1\right) \cdot \sin b\right) \cdot a\right)} \cdot r\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -3.2999999999999998 or 3.60000000000000009 < a Initial program 55.8%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6454.6
Applied rewrites54.6%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6454.5
Applied rewrites54.5%
Taylor expanded in b around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6460.9
Applied rewrites60.9%
if -3.2999999999999998 < a < 3.60000000000000009Initial program 97.7%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lift-sin.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6499.7
Applied rewrites99.7%
Taylor expanded in a around 0
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-sin.f64N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.5
Applied rewrites99.5%
Final simplification80.8%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (- (sin a))) (t_1 (/ r (/ (fma t_0 b (cos a)) b))))
(if (<= a -0.00088)
t_1
(if (<= a 0.11)
(* (/ (sin b) (fma (sin b) t_0 (* (fma (* a a) -0.5 1.0) (cos b)))) r)
t_1))))
double code(double r, double a, double b) {
double t_0 = -sin(a);
double t_1 = r / (fma(t_0, b, cos(a)) / b);
double tmp;
if (a <= -0.00088) {
tmp = t_1;
} else if (a <= 0.11) {
tmp = (sin(b) / fma(sin(b), t_0, (fma((a * a), -0.5, 1.0) * cos(b)))) * r;
} else {
tmp = t_1;
}
return tmp;
}
function code(r, a, b) t_0 = Float64(-sin(a)) t_1 = Float64(r / Float64(fma(t_0, b, cos(a)) / b)) tmp = 0.0 if (a <= -0.00088) tmp = t_1; elseif (a <= 0.11) tmp = Float64(Float64(sin(b) / fma(sin(b), t_0, Float64(fma(Float64(a * a), -0.5, 1.0) * cos(b)))) * r); else tmp = t_1; end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = (-N[Sin[a], $MachinePrecision])}, Block[{t$95$1 = N[(r / N[(N[(t$95$0 * b + N[Cos[a], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.00088], t$95$1, If[LessEqual[a, 0.11], N[(N[(N[Sin[b], $MachinePrecision] / N[(N[Sin[b], $MachinePrecision] * t$95$0 + N[(N[(N[(a * a), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin a\\
t_1 := \frac{r}{\frac{\mathsf{fma}\left(t\_0, b, \cos a\right)}{b}}\\
\mathbf{if}\;a \leq -0.00088:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \leq 0.11:\\
\;\;\;\;\frac{\sin b}{\mathsf{fma}\left(\sin b, t\_0, \mathsf{fma}\left(a \cdot a, -0.5, 1\right) \cdot \cos b\right)} \cdot r\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if a < -8.80000000000000031e-4 or 0.110000000000000001 < a Initial program 56.5%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6455.3
Applied rewrites55.3%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6455.3
Applied rewrites55.3%
Taylor expanded in b around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6461.5
Applied rewrites61.5%
if -8.80000000000000031e-4 < a < 0.110000000000000001Initial program 97.7%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.7
Applied rewrites99.7%
Taylor expanded in a around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.2
Applied rewrites99.2%
Final simplification80.7%
(FPCore (r a b) :precision binary64 (if (<= a 34000000000.0) (* (/ (sin b) (cos (+ a b))) r) (/ r (/ (fma (- (sin a)) b (cos a)) b))))
double code(double r, double a, double b) {
double tmp;
if (a <= 34000000000.0) {
tmp = (sin(b) / cos((a + b))) * r;
} else {
tmp = r / (fma(-sin(a), b, cos(a)) / b);
}
return tmp;
}
function code(r, a, b) tmp = 0.0 if (a <= 34000000000.0) tmp = Float64(Float64(sin(b) / cos(Float64(a + b))) * r); else tmp = Float64(r / Float64(fma(Float64(-sin(a)), b, cos(a)) / b)); end return tmp end
code[r_, a_, b_] := If[LessEqual[a, 34000000000.0], N[(N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision], N[(r / N[(N[((-N[Sin[a], $MachinePrecision]) * b + N[Cos[a], $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 34000000000:\\
\;\;\;\;\frac{\sin b}{\cos \left(a + b\right)} \cdot r\\
\mathbf{else}:\\
\;\;\;\;\frac{r}{\frac{\mathsf{fma}\left(-\sin a, b, \cos a\right)}{b}}\\
\end{array}
\end{array}
if a < 3.4e10Initial program 83.7%
if 3.4e10 < a Initial program 62.4%
Taylor expanded in b around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6462.5
Applied rewrites62.5%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6462.4
Applied rewrites62.4%
Taylor expanded in b around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-cos.f6468.0
Applied rewrites68.0%
Final simplification79.0%
(FPCore (r a b) :precision binary64 (let* ((t_0 (* (/ (sin b) (cos a)) r))) (if (<= a -0.00041) t_0 (if (<= a 0.0085) (* (/ (sin b) (cos b)) r) t_0))))
double code(double r, double a, double b) {
double t_0 = (sin(b) / cos(a)) * r;
double tmp;
if (a <= -0.00041) {
tmp = t_0;
} else if (a <= 0.0085) {
tmp = (sin(b) / cos(b)) * r;
} else {
tmp = t_0;
}
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 = (sin(b) / cos(a)) * r
if (a <= (-0.00041d0)) then
tmp = t_0
else if (a <= 0.0085d0) then
tmp = (sin(b) / cos(b)) * r
else
tmp = t_0
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = (Math.sin(b) / Math.cos(a)) * r;
double tmp;
if (a <= -0.00041) {
tmp = t_0;
} else if (a <= 0.0085) {
tmp = (Math.sin(b) / Math.cos(b)) * r;
} else {
tmp = t_0;
}
return tmp;
}
def code(r, a, b): t_0 = (math.sin(b) / math.cos(a)) * r tmp = 0 if a <= -0.00041: tmp = t_0 elif a <= 0.0085: tmp = (math.sin(b) / math.cos(b)) * r else: tmp = t_0 return tmp
function code(r, a, b) t_0 = Float64(Float64(sin(b) / cos(a)) * r) tmp = 0.0 if (a <= -0.00041) tmp = t_0; elseif (a <= 0.0085) tmp = Float64(Float64(sin(b) / cos(b)) * r); else tmp = t_0; end return tmp end
function tmp_2 = code(r, a, b) t_0 = (sin(b) / cos(a)) * r; tmp = 0.0; if (a <= -0.00041) tmp = t_0; elseif (a <= 0.0085) tmp = (sin(b) / cos(b)) * r; else tmp = t_0; end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]}, If[LessEqual[a, -0.00041], t$95$0, If[LessEqual[a, 0.0085], N[(N[(N[Sin[b], $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin b}{\cos a} \cdot r\\
\mathbf{if}\;a \leq -0.00041:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 0.0085:\\
\;\;\;\;\frac{\sin b}{\cos b} \cdot r\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -4.0999999999999999e-4 or 0.0085000000000000006 < a Initial program 56.5%
Taylor expanded in b around 0
lower-cos.f6456.9
Applied rewrites56.9%
if -4.0999999999999999e-4 < a < 0.0085000000000000006Initial program 97.7%
Taylor expanded in a around 0
lower-cos.f6497.6
Applied rewrites97.6%
Final simplification77.6%
(FPCore (r a b) :precision binary64 (let* ((t_0 (* (/ (sin b) (cos a)) r))) (if (<= a -0.00041) t_0 (if (<= a 0.0085) (* (/ r (cos b)) (sin b)) t_0))))
double code(double r, double a, double b) {
double t_0 = (sin(b) / cos(a)) * r;
double tmp;
if (a <= -0.00041) {
tmp = t_0;
} else if (a <= 0.0085) {
tmp = (r / cos(b)) * sin(b);
} else {
tmp = t_0;
}
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 = (sin(b) / cos(a)) * r
if (a <= (-0.00041d0)) then
tmp = t_0
else if (a <= 0.0085d0) then
tmp = (r / cos(b)) * sin(b)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = (Math.sin(b) / Math.cos(a)) * r;
double tmp;
if (a <= -0.00041) {
tmp = t_0;
} else if (a <= 0.0085) {
tmp = (r / Math.cos(b)) * Math.sin(b);
} else {
tmp = t_0;
}
return tmp;
}
def code(r, a, b): t_0 = (math.sin(b) / math.cos(a)) * r tmp = 0 if a <= -0.00041: tmp = t_0 elif a <= 0.0085: tmp = (r / math.cos(b)) * math.sin(b) else: tmp = t_0 return tmp
function code(r, a, b) t_0 = Float64(Float64(sin(b) / cos(a)) * r) tmp = 0.0 if (a <= -0.00041) tmp = t_0; elseif (a <= 0.0085) tmp = Float64(Float64(r / cos(b)) * sin(b)); else tmp = t_0; end return tmp end
function tmp_2 = code(r, a, b) t_0 = (sin(b) / cos(a)) * r; tmp = 0.0; if (a <= -0.00041) tmp = t_0; elseif (a <= 0.0085) tmp = (r / cos(b)) * sin(b); else tmp = t_0; end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[(N[Sin[b], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]}, If[LessEqual[a, -0.00041], t$95$0, If[LessEqual[a, 0.0085], N[(N[(r / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin b}{\cos a} \cdot r\\
\mathbf{if}\;a \leq -0.00041:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 0.0085:\\
\;\;\;\;\frac{r}{\cos b} \cdot \sin b\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -4.0999999999999999e-4 or 0.0085000000000000006 < a Initial program 56.5%
Taylor expanded in b around 0
lower-cos.f6456.9
Applied rewrites56.9%
if -4.0999999999999999e-4 < a < 0.0085000000000000006Initial program 97.7%
Taylor expanded in a around 0
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
lower-sin.f6497.6
Applied rewrites97.6%
Final simplification77.6%
(FPCore (r a b) :precision binary64 (* (/ (sin b) (cos (+ a b))) r))
double code(double r, double a, double b) {
return (sin(b) / cos((a + b))) * r;
}
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) / cos((a + b))) * r
end function
public static double code(double r, double a, double b) {
return (Math.sin(b) / Math.cos((a + b))) * r;
}
def code(r, a, b): return (math.sin(b) / math.cos((a + b))) * r
function code(r, a, b) return Float64(Float64(sin(b) / cos(Float64(a + b))) * r) end
function tmp = code(r, a, b) tmp = (sin(b) / cos((a + b))) * r; end
code[r_, a_, b_] := N[(N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin b}{\cos \left(a + b\right)} \cdot r
\end{array}
Initial program 77.4%
Final simplification77.4%
(FPCore (r a b) :precision binary64 (* (/ b (cos a)) r))
double code(double r, double a, double b) {
return (b / cos(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 = (b / cos(a)) * r
end function
public static double code(double r, double a, double b) {
return (b / Math.cos(a)) * r;
}
def code(r, a, b): return (b / math.cos(a)) * r
function code(r, a, b) return Float64(Float64(b / cos(a)) * r) end
function tmp = code(r, a, b) tmp = (b / cos(a)) * r; end
code[r_, a_, b_] := N[(N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{\cos a} \cdot r
\end{array}
Initial program 77.4%
Taylor expanded in b around 0
lower-/.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
Final simplification53.2%
(FPCore (r a b) :precision binary64 (* (/ r (cos a)) b))
double code(double r, double a, double b) {
return (r / 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 / cos(a)) * b
end function
public static double code(double r, double a, double b) {
return (r / Math.cos(a)) * b;
}
def code(r, a, b): return (r / math.cos(a)) * b
function code(r, a, b) return Float64(Float64(r / cos(a)) * b) end
function tmp = code(r, a, b) tmp = (r / cos(a)) * b; end
code[r_, a_, b_] := N[(N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]
\begin{array}{l}
\\
\frac{r}{\cos a} \cdot b
\end{array}
Initial program 77.4%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.6
Applied rewrites99.6%
Taylor expanded in b around 0
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
(FPCore (r a b) :precision binary64 (* (/ b 1.0) r))
double code(double r, double a, double b) {
return (b / 1.0) * r;
}
real(8) function code(r, a, b)
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (b / 1.0d0) * r
end function
public static double code(double r, double a, double b) {
return (b / 1.0) * r;
}
def code(r, a, b): return (b / 1.0) * r
function code(r, a, b) return Float64(Float64(b / 1.0) * r) end
function tmp = code(r, a, b) tmp = (b / 1.0) * r; end
code[r_, a_, b_] := N[(N[(b / 1.0), $MachinePrecision] * r), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{1} \cdot r
\end{array}
Initial program 77.4%
Taylor expanded in b around 0
lower-/.f64N/A
lower-cos.f6453.2
Applied rewrites53.2%
Taylor expanded in a around 0
Applied rewrites36.2%
Final simplification36.2%
herbie shell --seed 2024284
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))