
(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 8 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 78.0%
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
lower-neg.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6499.5
Applied rewrites99.5%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (cos (+ b a))) (t_1 (/ (sin b) t_0)) (t_2 (* r (tan b))))
(if (<= t_1 -0.04)
t_2
(if (<= t_1 0.0002)
(* (/ r t_0) (fma b (* -0.16666666666666666 (* b b)) b))
t_2))))
double code(double r, double a, double b) {
double t_0 = cos((b + a));
double t_1 = sin(b) / t_0;
double t_2 = r * tan(b);
double tmp;
if (t_1 <= -0.04) {
tmp = t_2;
} else if (t_1 <= 0.0002) {
tmp = (r / t_0) * fma(b, (-0.16666666666666666 * (b * b)), b);
} else {
tmp = t_2;
}
return tmp;
}
function code(r, a, b) t_0 = cos(Float64(b + a)) t_1 = Float64(sin(b) / t_0) t_2 = Float64(r * tan(b)) tmp = 0.0 if (t_1 <= -0.04) tmp = t_2; elseif (t_1 <= 0.0002) tmp = Float64(Float64(r / t_0) * fma(b, Float64(-0.16666666666666666 * Float64(b * b)), b)); else tmp = t_2; end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[b], $MachinePrecision] / t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.04], t$95$2, If[LessEqual[t$95$1, 0.0002], N[(N[(r / t$95$0), $MachinePrecision] * N[(b * N[(-0.16666666666666666 * N[(b * b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(b + a\right)\\
t_1 := \frac{\sin b}{t\_0}\\
t_2 := r \cdot \tan b\\
\mathbf{if}\;t\_1 \leq -0.04:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 0.0002:\\
\;\;\;\;\frac{r}{t\_0} \cdot \mathsf{fma}\left(b, -0.16666666666666666 \cdot \left(b \cdot b\right), b\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -0.0400000000000000008 or 2.0000000000000001e-4 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 60.9%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
times-fracN/A
*-lft-identityN/A
associate-*l/N/A
lower-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-/.f6460.8
Applied rewrites60.8%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6460.7
Applied rewrites60.7%
Applied rewrites60.7%
if -0.0400000000000000008 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 2.0000000000000001e-4Initial program 97.4%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
times-fracN/A
*-lft-identityN/A
associate-*l/N/A
lower-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-/.f6497.3
Applied rewrites97.3%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6497.4
Applied rewrites97.4%
Final simplification77.9%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (cos (+ b a))) (t_1 (/ (sin b) t_0)) (t_2 (* r (tan b))))
(if (<= t_1 -0.04)
t_2
(if (<= t_1 0.0002)
(* r (/ (fma b (* b (* b -0.16666666666666666)) b) t_0))
t_2))))
double code(double r, double a, double b) {
double t_0 = cos((b + a));
double t_1 = sin(b) / t_0;
double t_2 = r * tan(b);
double tmp;
if (t_1 <= -0.04) {
tmp = t_2;
} else if (t_1 <= 0.0002) {
tmp = r * (fma(b, (b * (b * -0.16666666666666666)), b) / t_0);
} else {
tmp = t_2;
}
return tmp;
}
function code(r, a, b) t_0 = cos(Float64(b + a)) t_1 = Float64(sin(b) / t_0) t_2 = Float64(r * tan(b)) tmp = 0.0 if (t_1 <= -0.04) tmp = t_2; elseif (t_1 <= 0.0002) tmp = Float64(r * Float64(fma(b, Float64(b * Float64(b * -0.16666666666666666)), b) / t_0)); else tmp = t_2; end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[b], $MachinePrecision] / t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.04], t$95$2, If[LessEqual[t$95$1, 0.0002], N[(r * N[(N[(b * N[(b * N[(b * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(b + a\right)\\
t_1 := \frac{\sin b}{t\_0}\\
t_2 := r \cdot \tan b\\
\mathbf{if}\;t\_1 \leq -0.04:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 0.0002:\\
\;\;\;\;r \cdot \frac{\mathsf{fma}\left(b, b \cdot \left(b \cdot -0.16666666666666666\right), b\right)}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -0.0400000000000000008 or 2.0000000000000001e-4 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 60.9%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
times-fracN/A
*-lft-identityN/A
associate-*l/N/A
lower-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-/.f6460.8
Applied rewrites60.8%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6460.7
Applied rewrites60.7%
Applied rewrites60.7%
if -0.0400000000000000008 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 2.0000000000000001e-4Initial program 97.4%
Taylor expanded in b around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.4
Applied rewrites97.4%
Final simplification77.9%
(FPCore (r a b) :precision binary64 (let* ((t_0 (/ (sin b) (cos (+ b a)))) (t_1 (* r (tan b)))) (if (<= t_0 -0.04) t_1 (if (<= t_0 0.0002) (* b (/ r (cos a))) t_1))))
double code(double r, double a, double b) {
double t_0 = sin(b) / cos((b + a));
double t_1 = r * tan(b);
double tmp;
if (t_0 <= -0.04) {
tmp = t_1;
} else if (t_0 <= 0.0002) {
tmp = b * (r / cos(a));
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = sin(b) / cos((b + a))
t_1 = r * tan(b)
if (t_0 <= (-0.04d0)) then
tmp = t_1
else if (t_0 <= 0.0002d0) then
tmp = b * (r / cos(a))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double r, double a, double b) {
double t_0 = Math.sin(b) / Math.cos((b + a));
double t_1 = r * Math.tan(b);
double tmp;
if (t_0 <= -0.04) {
tmp = t_1;
} else if (t_0 <= 0.0002) {
tmp = b * (r / Math.cos(a));
} else {
tmp = t_1;
}
return tmp;
}
def code(r, a, b): t_0 = math.sin(b) / math.cos((b + a)) t_1 = r * math.tan(b) tmp = 0 if t_0 <= -0.04: tmp = t_1 elif t_0 <= 0.0002: tmp = b * (r / math.cos(a)) else: tmp = t_1 return tmp
function code(r, a, b) t_0 = Float64(sin(b) / cos(Float64(b + a))) t_1 = Float64(r * tan(b)) tmp = 0.0 if (t_0 <= -0.04) tmp = t_1; elseif (t_0 <= 0.0002) tmp = Float64(b * Float64(r / cos(a))); else tmp = t_1; end return tmp end
function tmp_2 = code(r, a, b) t_0 = sin(b) / cos((b + a)); t_1 = r * tan(b); tmp = 0.0; if (t_0 <= -0.04) tmp = t_1; elseif (t_0 <= 0.0002) tmp = b * (r / cos(a)); else tmp = t_1; end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.04], t$95$1, If[LessEqual[t$95$0, 0.0002], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sin b}{\cos \left(b + a\right)}\\
t_1 := r \cdot \tan b\\
\mathbf{if}\;t\_0 \leq -0.04:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 0.0002:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -0.0400000000000000008 or 2.0000000000000001e-4 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 60.9%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
times-fracN/A
*-lft-identityN/A
associate-*l/N/A
lower-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-/.f6460.8
Applied rewrites60.8%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6460.7
Applied rewrites60.7%
Applied rewrites60.7%
if -0.0400000000000000008 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 2.0000000000000001e-4Initial program 97.4%
Taylor expanded in b around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6497.3
Applied rewrites97.3%
Final simplification77.9%
(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 78.0%
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
lower-neg.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6499.5
Applied rewrites99.5%
Taylor expanded in r around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-sin.f6499.4
Applied rewrites99.4%
Final simplification99.4%
(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 78.0%
Final simplification78.0%
(FPCore (r a b) :precision binary64 (* r (tan b)))
double code(double r, double a, double b) {
return r * tan(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 * tan(b)
end function
public static double code(double r, double a, double b) {
return r * Math.tan(b);
}
def code(r, a, b): return r * math.tan(b)
function code(r, a, b) return Float64(r * tan(b)) end
function tmp = code(r, a, b) tmp = r * tan(b); end
code[r_, a_, b_] := N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \tan b
\end{array}
Initial program 78.0%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
times-fracN/A
*-lft-identityN/A
associate-*l/N/A
lower-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lower-/.f6477.9
Applied rewrites77.9%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6464.1
Applied rewrites64.1%
Applied rewrites64.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 78.0%
Taylor expanded in b around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6447.8
Applied rewrites47.8%
Taylor expanded in a around 0
Applied rewrites34.0%
Final simplification34.0%
herbie shell --seed 2024232
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))