
(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 9 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 (sin (- b)) (sin a) (* (cos a) (cos b)))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(sin(-b), sin(a), (cos(a) * cos(b)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(sin(Float64(-b)), sin(a), Float64(cos(a) * cos(b)))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[(-b)], $MachinePrecision] * N[Sin[a], $MachinePrecision] + N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\sin \left(-b\right), \sin a, \cos a \cdot \cos b\right)}
\end{array}
Initial program 78.2%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-sin.f64N/A
sin-negN/A
lower-sin.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.4
Applied rewrites99.4%
Taylor expanded in r around 0
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
neg-mul-1N/A
lower-sin.f64N/A
neg-mul-1N/A
lower-neg.f6499.4
Applied rewrites99.4%
Applied rewrites99.4%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (/ (sin b) (cos (+ b a)))))
(if (<= t_0 -0.04)
(/ (* r (sin b)) (cos b))
(if (<= t_0 2e-20) (* b (/ r (cos a))) (* (sin b) (/ r (cos b)))))))
double code(double r, double a, double b) {
double t_0 = sin(b) / cos((b + a));
double tmp;
if (t_0 <= -0.04) {
tmp = (r * sin(b)) / cos(b);
} else if (t_0 <= 2e-20) {
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) :: t_0
real(8) :: tmp
t_0 = sin(b) / cos((b + a))
if (t_0 <= (-0.04d0)) then
tmp = (r * sin(b)) / cos(b)
else if (t_0 <= 2d-20) 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 t_0 = Math.sin(b) / Math.cos((b + a));
double tmp;
if (t_0 <= -0.04) {
tmp = (r * Math.sin(b)) / Math.cos(b);
} else if (t_0 <= 2e-20) {
tmp = b * (r / Math.cos(a));
} else {
tmp = Math.sin(b) * (r / Math.cos(b));
}
return tmp;
}
def code(r, a, b): t_0 = math.sin(b) / math.cos((b + a)) tmp = 0 if t_0 <= -0.04: tmp = (r * math.sin(b)) / math.cos(b) elif t_0 <= 2e-20: tmp = b * (r / math.cos(a)) else: tmp = math.sin(b) * (r / math.cos(b)) return tmp
function code(r, a, b) t_0 = Float64(sin(b) / cos(Float64(b + a))) tmp = 0.0 if (t_0 <= -0.04) tmp = Float64(Float64(r * sin(b)) / cos(b)); elseif (t_0 <= 2e-20) 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) t_0 = sin(b) / cos((b + a)); tmp = 0.0; if (t_0 <= -0.04) tmp = (r * sin(b)) / cos(b); elseif (t_0 <= 2e-20) tmp = b * (r / cos(a)); else tmp = sin(b) * (r / cos(b)); 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]}, If[LessEqual[t$95$0, -0.04], N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-20], 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}
t_0 := \frac{\sin b}{\cos \left(b + a\right)}\\
\mathbf{if}\;t\_0 \leq -0.04:\\
\;\;\;\;\frac{r \cdot \sin b}{\cos b}\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-20}:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;\sin b \cdot \frac{r}{\cos b}\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -0.0400000000000000008Initial program 59.1%
Taylor expanded in a around 0
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6458.8
Applied rewrites58.8%
if -0.0400000000000000008 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 1.99999999999999989e-20Initial program 99.7%
Taylor expanded in b around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
if 1.99999999999999989e-20 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 62.3%
Taylor expanded in a around 0
lower-cos.f6463.7
Applied rewrites63.7%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
lift-/.f64N/A
times-fracN/A
lift-/.f64N/A
remove-double-divN/A
lower-*.f64N/A
lower-/.f6463.8
Applied rewrites63.8%
Final simplification78.5%
(FPCore (r a b) :precision binary64 (let* ((t_0 (/ (sin b) (cos (+ b a)))) (t_1 (/ (* r (sin b)) (cos b)))) (if (<= t_0 -0.04) t_1 (if (<= t_0 2e-20) (* 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 * sin(b)) / cos(b);
double tmp;
if (t_0 <= -0.04) {
tmp = t_1;
} else if (t_0 <= 2e-20) {
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 * sin(b)) / cos(b)
if (t_0 <= (-0.04d0)) then
tmp = t_1
else if (t_0 <= 2d-20) 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.sin(b)) / Math.cos(b);
double tmp;
if (t_0 <= -0.04) {
tmp = t_1;
} else if (t_0 <= 2e-20) {
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.sin(b)) / math.cos(b) tmp = 0 if t_0 <= -0.04: tmp = t_1 elif t_0 <= 2e-20: 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(Float64(r * sin(b)) / cos(b)) tmp = 0.0 if (t_0 <= -0.04) tmp = t_1; elseif (t_0 <= 2e-20) 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 * sin(b)) / cos(b); tmp = 0.0; if (t_0 <= -0.04) tmp = t_1; elseif (t_0 <= 2e-20) 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[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.04], t$95$1, If[LessEqual[t$95$0, 2e-20], 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 := \frac{r \cdot \sin b}{\cos b}\\
\mathbf{if}\;t\_0 \leq -0.04:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-20}:\\
\;\;\;\;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 1.99999999999999989e-20 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 60.6%
Taylor expanded in a around 0
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6461.2
Applied rewrites61.2%
if -0.0400000000000000008 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 1.99999999999999989e-20Initial program 99.7%
Taylor expanded in b around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.8
Applied rewrites99.8%
Final simplification78.5%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (fma (cos a) (cos b) (* (sin (- b)) (sin a)))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(cos(a), cos(b), (sin(-b) * sin(a)));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(cos(a), cos(b), Float64(sin(Float64(-b)) * sin(a)))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision] + N[(N[Sin[(-b)], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos a, \cos b, \sin \left(-b\right) \cdot \sin a\right)}
\end{array}
Initial program 78.2%
lift-cos.f64N/A
lift-+.f64N/A
cos-sumN/A
sub-negN/A
+-commutativeN/A
lift-sin.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-sin.f64N/A
sin-negN/A
lower-sin.f64N/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f6499.4
Applied rewrites99.4%
Taylor expanded in r around 0
lower-/.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
neg-mul-1N/A
lower-sin.f64N/A
neg-mul-1N/A
lower-neg.f6499.4
Applied rewrites99.4%
Final simplification99.4%
(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 78.2%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*l/N/A
*-lft-identityN/A
lower-/.f6478.3
lift-+.f64N/A
+-commutativeN/A
lower-+.f6478.3
Applied rewrites78.3%
Final simplification78.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 78.2%
Final simplification78.2%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (* (sin b) (/ r 1.0))))
(if (<= b -6.8e+20)
t_0
(if (<= b 5800000000000.0) (* b (/ r (cos a))) t_0))))
double code(double r, double a, double b) {
double t_0 = sin(b) * (r / 1.0);
double tmp;
if (b <= -6.8e+20) {
tmp = t_0;
} else if (b <= 5800000000000.0) {
tmp = b * (r / cos(a));
} 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) * (r / 1.0d0)
if (b <= (-6.8d+20)) then
tmp = t_0
else if (b <= 5800000000000.0d0) then
tmp = b * (r / cos(a))
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) * (r / 1.0);
double tmp;
if (b <= -6.8e+20) {
tmp = t_0;
} else if (b <= 5800000000000.0) {
tmp = b * (r / Math.cos(a));
} else {
tmp = t_0;
}
return tmp;
}
def code(r, a, b): t_0 = math.sin(b) * (r / 1.0) tmp = 0 if b <= -6.8e+20: tmp = t_0 elif b <= 5800000000000.0: tmp = b * (r / math.cos(a)) else: tmp = t_0 return tmp
function code(r, a, b) t_0 = Float64(sin(b) * Float64(r / 1.0)) tmp = 0.0 if (b <= -6.8e+20) tmp = t_0; elseif (b <= 5800000000000.0) tmp = Float64(b * Float64(r / cos(a))); else tmp = t_0; end return tmp end
function tmp_2 = code(r, a, b) t_0 = sin(b) * (r / 1.0); tmp = 0.0; if (b <= -6.8e+20) tmp = t_0; elseif (b <= 5800000000000.0) tmp = b * (r / cos(a)); else tmp = t_0; end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] * N[(r / 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -6.8e+20], t$95$0, If[LessEqual[b, 5800000000000.0], N[(b * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin b \cdot \frac{r}{1}\\
\mathbf{if}\;b \leq -6.8 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 5800000000000:\\
\;\;\;\;b \cdot \frac{r}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -6.8e20 or 5.8e12 < b Initial program 58.6%
Taylor expanded in a around 0
lower-cos.f6459.1
Applied rewrites59.1%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
associate-*r/N/A
div-invN/A
lift-/.f64N/A
times-fracN/A
lift-/.f64N/A
remove-double-divN/A
lower-*.f64N/A
lower-/.f6459.2
Applied rewrites59.2%
Taylor expanded in b around 0
Applied rewrites11.0%
if -6.8e20 < b < 5.8e12Initial program 99.7%
Taylor expanded in b around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6496.9
Applied rewrites96.9%
Final simplification51.9%
(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 78.2%
Taylor expanded in b around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6447.9
Applied rewrites47.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 78.2%
Taylor expanded in b around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6447.9
Applied rewrites47.9%
Taylor expanded in a around 0
Applied rewrites34.4%
herbie shell --seed 2024233
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))