
(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 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(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 (/ (* 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(Float64(r * sin(b)) / fma(cos(b), cos(a), Float64(sin(a) * Float64(-sin(b))))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * (-N[Sin[b], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\cos b, \cos a, \sin a \cdot \left(-\sin b\right)\right)}
\end{array}
Initial program 77.2%
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.4
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (r a b) :precision binary64 (* r (/ (sin b) (fma (sin (- b)) (sin a) (* (cos b) (cos a))))))
double code(double r, double a, double b) {
return r * (sin(b) / fma(sin(-b), sin(a), (cos(b) * cos(a))));
}
function code(r, a, b) return Float64(r * Float64(sin(b) / fma(sin(Float64(-b)), sin(a), Float64(cos(b) * cos(a))))) end
code[r_, a_, b_] := N[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[Sin[(-b)], $MachinePrecision] * N[Sin[a], $MachinePrecision] + N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\mathsf{fma}\left(\sin \left(-b\right), \sin a, \cos b \cdot \cos a\right)}
\end{array}
Initial program 77.2%
lift-sin.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-cos.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6477.1
Applied egg-rr77.1%
+-commutativeN/A
cos-sumN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
unsub-negN/A
lift-neg.f64N/A
+-commutativeN/A
lift-neg.f64N/A
lift-*.f64N/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-*.f6499.4
Applied egg-rr99.4%
Final simplification99.4%
(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%
lift-sin.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-cos.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6477.1
Applied egg-rr77.1%
+-commutativeN/A
cos-sumN/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
unsub-negN/A
lift-neg.f64N/A
lift-fma.f6499.4
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (r a b) :precision binary64 (let* ((t_0 (* (sin b) (/ r (cos a))))) (if (<= a -0.00245) t_0 (if (<= a 0.0012) (* r (tan b)) t_0))))
double code(double r, double a, double b) {
double t_0 = sin(b) * (r / cos(a));
double tmp;
if (a <= -0.00245) {
tmp = t_0;
} else if (a <= 0.0012) {
tmp = r * tan(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) * (r / cos(a))
if (a <= (-0.00245d0)) then
tmp = t_0
else if (a <= 0.0012d0) then
tmp = r * tan(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) * (r / Math.cos(a));
double tmp;
if (a <= -0.00245) {
tmp = t_0;
} else if (a <= 0.0012) {
tmp = r * Math.tan(b);
} else {
tmp = t_0;
}
return tmp;
}
def code(r, a, b): t_0 = math.sin(b) * (r / math.cos(a)) tmp = 0 if a <= -0.00245: tmp = t_0 elif a <= 0.0012: tmp = r * math.tan(b) else: tmp = t_0 return tmp
function code(r, a, b) t_0 = Float64(sin(b) * Float64(r / cos(a))) tmp = 0.0 if (a <= -0.00245) tmp = t_0; elseif (a <= 0.0012) tmp = Float64(r * tan(b)); else tmp = t_0; end return tmp end
function tmp_2 = code(r, a, b) t_0 = sin(b) * (r / cos(a)); tmp = 0.0; if (a <= -0.00245) tmp = t_0; elseif (a <= 0.0012) tmp = r * tan(b); else tmp = t_0; end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Sin[b], $MachinePrecision] * N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.00245], t$95$0, If[LessEqual[a, 0.0012], N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin b \cdot \frac{r}{\cos a}\\
\mathbf{if}\;a \leq -0.00245:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;a \leq 0.0012:\\
\;\;\;\;r \cdot \tan b\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < -0.0024499999999999999 or 0.00119999999999999989 < a Initial program 53.7%
Taylor expanded in b around 0
lower-cos.f6453.5
Simplified53.5%
lift-sin.f64N/A
*-commutativeN/A
lift-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6453.5
Applied egg-rr53.5%
if -0.0024499999999999999 < a < 0.00119999999999999989Initial program 98.2%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6498.0
Simplified98.0%
lift-sin.f64N/A
*-commutativeN/A
lift-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6498.2
Applied egg-rr98.2%
(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%
lift-sin.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-cos.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.2
Applied egg-rr77.2%
Final simplification77.2%
(FPCore (r a b) :precision binary64 (let* ((t_0 (* r (tan b)))) (if (<= b -6.5e-7) t_0 (if (<= b 8e-20) (* b (* r (/ 1.0 (cos a)))) t_0))))
double code(double r, double a, double b) {
double t_0 = r * tan(b);
double tmp;
if (b <= -6.5e-7) {
tmp = t_0;
} else if (b <= 8e-20) {
tmp = b * (r * (1.0 / 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 = r * tan(b)
if (b <= (-6.5d-7)) then
tmp = t_0
else if (b <= 8d-20) then
tmp = b * (r * (1.0d0 / 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 = r * Math.tan(b);
double tmp;
if (b <= -6.5e-7) {
tmp = t_0;
} else if (b <= 8e-20) {
tmp = b * (r * (1.0 / Math.cos(a)));
} else {
tmp = t_0;
}
return tmp;
}
def code(r, a, b): t_0 = r * math.tan(b) tmp = 0 if b <= -6.5e-7: tmp = t_0 elif b <= 8e-20: tmp = b * (r * (1.0 / math.cos(a))) else: tmp = t_0 return tmp
function code(r, a, b) t_0 = Float64(r * tan(b)) tmp = 0.0 if (b <= -6.5e-7) tmp = t_0; elseif (b <= 8e-20) tmp = Float64(b * Float64(r * Float64(1.0 / cos(a)))); else tmp = t_0; end return tmp end
function tmp_2 = code(r, a, b) t_0 = r * tan(b); tmp = 0.0; if (b <= -6.5e-7) tmp = t_0; elseif (b <= 8e-20) tmp = b * (r * (1.0 / cos(a))); else tmp = t_0; end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -6.5e-7], t$95$0, If[LessEqual[b, 8e-20], N[(b * N[(r * N[(1.0 / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := r \cdot \tan b\\
\mathbf{if}\;b \leq -6.5 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-20}:\\
\;\;\;\;b \cdot \left(r \cdot \frac{1}{\cos a}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -6.50000000000000024e-7 or 7.99999999999999956e-20 < b Initial program 57.2%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6456.8
Simplified56.8%
lift-sin.f64N/A
*-commutativeN/A
lift-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6456.9
Applied egg-rr56.9%
if -6.50000000000000024e-7 < b < 7.99999999999999956e-20Initial program 99.7%
Taylor expanded in b around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.7
Simplified99.7%
lift-cos.f64N/A
lift-/.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f6499.8
Applied egg-rr99.8%
Final simplification77.0%
(FPCore (r a b) :precision binary64 (let* ((t_0 (* r (tan b)))) (if (<= b -6.5e-7) t_0 (if (<= b 8e-20) (* r (/ b (cos a))) t_0))))
double code(double r, double a, double b) {
double t_0 = r * tan(b);
double tmp;
if (b <= -6.5e-7) {
tmp = t_0;
} else if (b <= 8e-20) {
tmp = r * (b / 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 = r * tan(b)
if (b <= (-6.5d-7)) then
tmp = t_0
else if (b <= 8d-20) then
tmp = r * (b / 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 = r * Math.tan(b);
double tmp;
if (b <= -6.5e-7) {
tmp = t_0;
} else if (b <= 8e-20) {
tmp = r * (b / Math.cos(a));
} else {
tmp = t_0;
}
return tmp;
}
def code(r, a, b): t_0 = r * math.tan(b) tmp = 0 if b <= -6.5e-7: tmp = t_0 elif b <= 8e-20: tmp = r * (b / math.cos(a)) else: tmp = t_0 return tmp
function code(r, a, b) t_0 = Float64(r * tan(b)) tmp = 0.0 if (b <= -6.5e-7) tmp = t_0; elseif (b <= 8e-20) tmp = Float64(r * Float64(b / cos(a))); else tmp = t_0; end return tmp end
function tmp_2 = code(r, a, b) t_0 = r * tan(b); tmp = 0.0; if (b <= -6.5e-7) tmp = t_0; elseif (b <= 8e-20) tmp = r * (b / cos(a)); else tmp = t_0; end tmp_2 = tmp; end
code[r_, a_, b_] := Block[{t$95$0 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -6.5e-7], t$95$0, If[LessEqual[b, 8e-20], N[(r * N[(b / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := r \cdot \tan b\\
\mathbf{if}\;b \leq -6.5 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-20}:\\
\;\;\;\;r \cdot \frac{b}{\cos a}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -6.50000000000000024e-7 or 7.99999999999999956e-20 < b Initial program 57.2%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6456.8
Simplified56.8%
lift-sin.f64N/A
*-commutativeN/A
lift-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6456.9
Applied egg-rr56.9%
if -6.50000000000000024e-7 < b < 7.99999999999999956e-20Initial program 99.7%
Taylor expanded in b around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6499.7
Simplified99.7%
(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 77.2%
Taylor expanded in a around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sin.f64N/A
lower-cos.f6461.4
Simplified61.4%
lift-sin.f64N/A
*-commutativeN/A
lift-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
quot-tanN/A
lower-tan.f6461.4
Applied egg-rr61.4%
(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%
Taylor expanded in b around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-cos.f6449.6
Simplified49.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f6433.9
Simplified33.9%
herbie shell --seed 2024215
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))