
(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));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, a, b)
use fmin_fmax_functions
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 5 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));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, a, b)
use fmin_fmax_functions
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)) (- (* (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)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, a, b)
use fmin_fmax_functions
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.3%
lift-+.f64N/A
lift-cos.f64N/A
+-commutativeN/A
cos-sumN/A
cos-neg-revN/A
mul-1-negN/A
lower--.f64N/A
mul-1-negN/A
cos-neg-revN/A
lower-*.f64N/A
lower-cos.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-sin.f6499.5
Applied rewrites99.5%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (* (cos a) (cos b))) (t_1 (* (sin a) (sin b))))
(/
(* r (fma (sin b) t_0 (* (sin b) t_1)))
(- (pow t_0 2.0) (pow t_1 2.0)))))
double code(double r, double a, double b) {
double t_0 = cos(a) * cos(b);
double t_1 = sin(a) * sin(b);
return (r * fma(sin(b), t_0, (sin(b) * t_1))) / (pow(t_0, 2.0) - pow(t_1, 2.0));
}
function code(r, a, b) t_0 = Float64(cos(a) * cos(b)) t_1 = Float64(sin(a) * sin(b)) return Float64(Float64(r * fma(sin(b), t_0, Float64(sin(b) * t_1))) / Float64((t_0 ^ 2.0) - (t_1 ^ 2.0))) end
code[r_, a_, b_] := Block[{t$95$0 = N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[a], $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]}, N[(N[(r * N[(N[Sin[b], $MachinePrecision] * t$95$0 + N[(N[Sin[b], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$0, 2.0], $MachinePrecision] - N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos a \cdot \cos b\\
t_1 := \sin a \cdot \sin b\\
\frac{r \cdot \mathsf{fma}\left(\sin b, t\_0, \sin b \cdot t\_1\right)}{{t\_0}^{2} - {t\_1}^{2}}
\end{array}
\end{array}
Initial program 78.3%
lift-+.f64N/A
lift-cos.f64N/A
cos-sumN/A
flip--N/A
lower-/.f64N/A
Applied rewrites99.4%
Taylor expanded in r around 0
pow-prod-downN/A
pow2N/A
pow-prod-downN/A
pow2N/A
lower-/.f64N/A
Applied rewrites78.0%
lift-*.f64N/A
lift-sin.f64N/A
lift--.f64N/A
lift-cos.f64N/A
cos-diff-revN/A
distribute-lft-inN/A
lower-fma.f64N/A
lift-sin.f64N/A
lift-cos.f64N/A
lift-cos.f64N/A
lift-*.f64N/A
lower-*.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-sin.f64N/A
lift-*.f6499.3
Applied rewrites99.3%
(FPCore (r a b) :precision binary64 (/ (* r (* (sin b) (cos (- a b)))) (- (pow (* (cos a) (cos b)) 2.0) (pow (* (sin a) (sin b)) 2.0))))
double code(double r, double a, double b) {
return (r * (sin(b) * cos((a - b)))) / (pow((cos(a) * cos(b)), 2.0) - pow((sin(a) * sin(b)), 2.0));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(r, a, b)
use fmin_fmax_functions
real(8), intent (in) :: r
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (r * (sin(b) * cos((a - b)))) / (((cos(a) * cos(b)) ** 2.0d0) - ((sin(a) * sin(b)) ** 2.0d0))
end function
public static double code(double r, double a, double b) {
return (r * (Math.sin(b) * Math.cos((a - b)))) / (Math.pow((Math.cos(a) * Math.cos(b)), 2.0) - Math.pow((Math.sin(a) * Math.sin(b)), 2.0));
}
def code(r, a, b): return (r * (math.sin(b) * math.cos((a - b)))) / (math.pow((math.cos(a) * math.cos(b)), 2.0) - math.pow((math.sin(a) * math.sin(b)), 2.0))
function code(r, a, b) return Float64(Float64(r * Float64(sin(b) * cos(Float64(a - b)))) / Float64((Float64(cos(a) * cos(b)) ^ 2.0) - (Float64(sin(a) * sin(b)) ^ 2.0))) end
function tmp = code(r, a, b) tmp = (r * (sin(b) * cos((a - b)))) / (((cos(a) * cos(b)) ^ 2.0) - ((sin(a) * sin(b)) ^ 2.0)); end
code[r_, a_, b_] := N[(N[(r * N[(N[Sin[b], $MachinePrecision] * N[Cos[N[(a - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Power[N[(N[Cos[a], $MachinePrecision] * N[Cos[b], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[(N[Sin[a], $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \left(\sin b \cdot \cos \left(a - b\right)\right)}{{\left(\cos a \cdot \cos b\right)}^{2} - {\left(\sin a \cdot \sin b\right)}^{2}}
\end{array}
Initial program 78.3%
lift-+.f64N/A
lift-cos.f64N/A
cos-sumN/A
flip--N/A
lower-/.f64N/A
Applied rewrites99.4%
Taylor expanded in r around 0
pow-prod-downN/A
pow2N/A
pow-prod-downN/A
pow2N/A
lower-/.f64N/A
Applied rewrites78.0%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (/ r (cos a)))
(t_1 (/ (* (sin a) r) (pow (cos a) 2.0)))
(t_2 (* r (tan b)))
(t_3 (fma -0.5 t_2 (* (- r) (pow (tan b) 3.0))))
(t_4 (* r (* (tan b) (tan b))))
(t_5
(-
(* -0.16666666666666666 t_0)
(fma t_0 -0.5 (/ (* (pow (sin a) 2.0) (- r)) (pow (cos a) 3.0))))))
(if (or (<= b -0.0018) (not (<= b 0.25)))
(fma
(fma
(-
(*
(- a)
(fma
t_4
-0.5
(fma 0.16666666666666666 t_4 (/ (* t_3 (sin b)) (cos b)))))
t_3)
a
t_4)
a
t_2)
(*
(fma
(fma
(fma
(- b)
(fma t_1 -0.3333333333333333 (/ (* t_5 (sin a)) (- (cos a))))
t_5)
b
t_1)
b
t_0)
b))))
double code(double r, double a, double b) {
double t_0 = r / cos(a);
double t_1 = (sin(a) * r) / pow(cos(a), 2.0);
double t_2 = r * tan(b);
double t_3 = fma(-0.5, t_2, (-r * pow(tan(b), 3.0)));
double t_4 = r * (tan(b) * tan(b));
double t_5 = (-0.16666666666666666 * t_0) - fma(t_0, -0.5, ((pow(sin(a), 2.0) * -r) / pow(cos(a), 3.0)));
double tmp;
if ((b <= -0.0018) || !(b <= 0.25)) {
tmp = fma(fma(((-a * fma(t_4, -0.5, fma(0.16666666666666666, t_4, ((t_3 * sin(b)) / cos(b))))) - t_3), a, t_4), a, t_2);
} else {
tmp = fma(fma(fma(-b, fma(t_1, -0.3333333333333333, ((t_5 * sin(a)) / -cos(a))), t_5), b, t_1), b, t_0) * b;
}
return tmp;
}
function code(r, a, b) t_0 = Float64(r / cos(a)) t_1 = Float64(Float64(sin(a) * r) / (cos(a) ^ 2.0)) t_2 = Float64(r * tan(b)) t_3 = fma(-0.5, t_2, Float64(Float64(-r) * (tan(b) ^ 3.0))) t_4 = Float64(r * Float64(tan(b) * tan(b))) t_5 = Float64(Float64(-0.16666666666666666 * t_0) - fma(t_0, -0.5, Float64(Float64((sin(a) ^ 2.0) * Float64(-r)) / (cos(a) ^ 3.0)))) tmp = 0.0 if ((b <= -0.0018) || !(b <= 0.25)) tmp = fma(fma(Float64(Float64(Float64(-a) * fma(t_4, -0.5, fma(0.16666666666666666, t_4, Float64(Float64(t_3 * sin(b)) / cos(b))))) - t_3), a, t_4), a, t_2); else tmp = Float64(fma(fma(fma(Float64(-b), fma(t_1, -0.3333333333333333, Float64(Float64(t_5 * sin(a)) / Float64(-cos(a)))), t_5), b, t_1), b, t_0) * b); end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sin[a], $MachinePrecision] * r), $MachinePrecision] / N[Power[N[Cos[a], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(-0.5 * t$95$2 + N[((-r) * N[Power[N[Tan[b], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(r * N[(N[Tan[b], $MachinePrecision] * N[Tan[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[(N[(-0.16666666666666666 * t$95$0), $MachinePrecision] - N[(t$95$0 * -0.5 + N[(N[(N[Power[N[Sin[a], $MachinePrecision], 2.0], $MachinePrecision] * (-r)), $MachinePrecision] / N[Power[N[Cos[a], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[b, -0.0018], N[Not[LessEqual[b, 0.25]], $MachinePrecision]], N[(N[(N[(N[((-a) * N[(t$95$4 * -0.5 + N[(0.16666666666666666 * t$95$4 + N[(N[(t$95$3 * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$3), $MachinePrecision] * a + t$95$4), $MachinePrecision] * a + t$95$2), $MachinePrecision], N[(N[(N[(N[((-b) * N[(t$95$1 * -0.3333333333333333 + N[(N[(t$95$5 * N[Sin[a], $MachinePrecision]), $MachinePrecision] / (-N[Cos[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] + t$95$5), $MachinePrecision] * b + t$95$1), $MachinePrecision] * b + t$95$0), $MachinePrecision] * b), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{r}{\cos a}\\
t_1 := \frac{\sin a \cdot r}{{\cos a}^{2}}\\
t_2 := r \cdot \tan b\\
t_3 := \mathsf{fma}\left(-0.5, t\_2, \left(-r\right) \cdot {\tan b}^{3}\right)\\
t_4 := r \cdot \left(\tan b \cdot \tan b\right)\\
t_5 := -0.16666666666666666 \cdot t\_0 - \mathsf{fma}\left(t\_0, -0.5, \frac{{\sin a}^{2} \cdot \left(-r\right)}{{\cos a}^{3}}\right)\\
\mathbf{if}\;b \leq -0.0018 \lor \neg \left(b \leq 0.25\right):\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(-a\right) \cdot \mathsf{fma}\left(t\_4, -0.5, \mathsf{fma}\left(0.16666666666666666, t\_4, \frac{t\_3 \cdot \sin b}{\cos b}\right)\right) - t\_3, a, t\_4\right), a, t\_2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-b, \mathsf{fma}\left(t\_1, -0.3333333333333333, \frac{t\_5 \cdot \sin a}{-\cos a}\right), t\_5\right), b, t\_1\right), b, t\_0\right) \cdot b\\
\end{array}
\end{array}
if b < -0.0018 or 0.25 < b Initial program 61.2%
Taylor expanded in a around 0
Applied rewrites58.3%
if -0.0018 < b < 0.25Initial program 96.8%
Taylor expanded in b around 0
Applied rewrites97.9%
Final simplification77.3%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (/ r (cos a)))
(t_1
(-
(* -0.16666666666666666 t_0)
(fma t_0 -0.5 (/ (* (pow (sin a) 2.0) (- r)) (pow (cos a) 3.0)))))
(t_2 (/ (* (sin a) r) (pow (cos a) 2.0))))
(*
(fma
(fma
(fma
(- b)
(fma t_2 -0.3333333333333333 (/ (* t_1 (sin a)) (- (cos a))))
t_1)
b
t_2)
b
t_0)
b)))
double code(double r, double a, double b) {
double t_0 = r / cos(a);
double t_1 = (-0.16666666666666666 * t_0) - fma(t_0, -0.5, ((pow(sin(a), 2.0) * -r) / pow(cos(a), 3.0)));
double t_2 = (sin(a) * r) / pow(cos(a), 2.0);
return fma(fma(fma(-b, fma(t_2, -0.3333333333333333, ((t_1 * sin(a)) / -cos(a))), t_1), b, t_2), b, t_0) * b;
}
function code(r, a, b) t_0 = Float64(r / cos(a)) t_1 = Float64(Float64(-0.16666666666666666 * t_0) - fma(t_0, -0.5, Float64(Float64((sin(a) ^ 2.0) * Float64(-r)) / (cos(a) ^ 3.0)))) t_2 = Float64(Float64(sin(a) * r) / (cos(a) ^ 2.0)) return Float64(fma(fma(fma(Float64(-b), fma(t_2, -0.3333333333333333, Float64(Float64(t_1 * sin(a)) / Float64(-cos(a)))), t_1), b, t_2), b, t_0) * b) end
code[r_, a_, b_] := Block[{t$95$0 = N[(r / N[Cos[a], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-0.16666666666666666 * t$95$0), $MachinePrecision] - N[(t$95$0 * -0.5 + N[(N[(N[Power[N[Sin[a], $MachinePrecision], 2.0], $MachinePrecision] * (-r)), $MachinePrecision] / N[Power[N[Cos[a], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Sin[a], $MachinePrecision] * r), $MachinePrecision] / N[Power[N[Cos[a], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[((-b) * N[(t$95$2 * -0.3333333333333333 + N[(N[(t$95$1 * N[Sin[a], $MachinePrecision]), $MachinePrecision] / (-N[Cos[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision] * b + t$95$2), $MachinePrecision] * b + t$95$0), $MachinePrecision] * b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{r}{\cos a}\\
t_1 := -0.16666666666666666 \cdot t\_0 - \mathsf{fma}\left(t\_0, -0.5, \frac{{\sin a}^{2} \cdot \left(-r\right)}{{\cos a}^{3}}\right)\\
t_2 := \frac{\sin a \cdot r}{{\cos a}^{2}}\\
\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-b, \mathsf{fma}\left(t\_2, -0.3333333333333333, \frac{t\_1 \cdot \sin a}{-\cos a}\right), t\_1\right), b, t\_2\right), b, t\_0\right) \cdot b
\end{array}
\end{array}
Initial program 78.3%
Taylor expanded in b around 0
Applied rewrites48.4%
Final simplification48.4%
herbie shell --seed 2025057
(FPCore (r a b)
:name "rsin A (should all be same)"
:precision binary64
(/ (* r (sin b)) (cos (+ a b))))