
(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(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 6 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(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) (- (* (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(r * Float64(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[(r * N[(N[Sin[b], $MachinePrecision] / N[(N[(N[Cos[b], $MachinePrecision] * N[Cos[a], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[b], $MachinePrecision] * N[Sin[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
r \cdot \frac{\sin b}{\cos b \cdot \cos a - \sin b \cdot \sin a}
\end{array}
Initial program 78.6%
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 (pow (sin b) 2.0))
(t_1 (/ (sin b) (cos (+ a b))))
(t_2 (pow (sin a) 3.0))
(t_3 (pow (cos a) 2.0))
(t_4 (pow (cos b) 2.0))
(t_5
(*
r
(*
(sin b)
(fma
(cos a)
(* (cos b) (* (sin a) (sin b)))
(fma t_3 t_4 (* (pow (sin a) 2.0) t_0)))))))
(if (or (<= t_1 -0.01) (not (<= t_1 0.04)))
(/ t_5 (- (* (pow t_3 1.5) (pow (cos b) 3.0)) (* t_2 (pow (sin b) 3.0))))
(/ t_5 (- (* (* t_3 (cos a)) (pow t_4 1.5)) (* t_2 (pow t_0 1.5)))))))
double code(double r, double a, double b) {
double t_0 = pow(sin(b), 2.0);
double t_1 = sin(b) / cos((a + b));
double t_2 = pow(sin(a), 3.0);
double t_3 = pow(cos(a), 2.0);
double t_4 = pow(cos(b), 2.0);
double t_5 = r * (sin(b) * fma(cos(a), (cos(b) * (sin(a) * sin(b))), fma(t_3, t_4, (pow(sin(a), 2.0) * t_0))));
double tmp;
if ((t_1 <= -0.01) || !(t_1 <= 0.04)) {
tmp = t_5 / ((pow(t_3, 1.5) * pow(cos(b), 3.0)) - (t_2 * pow(sin(b), 3.0)));
} else {
tmp = t_5 / (((t_3 * cos(a)) * pow(t_4, 1.5)) - (t_2 * pow(t_0, 1.5)));
}
return tmp;
}
function code(r, a, b) t_0 = sin(b) ^ 2.0 t_1 = Float64(sin(b) / cos(Float64(a + b))) t_2 = sin(a) ^ 3.0 t_3 = cos(a) ^ 2.0 t_4 = cos(b) ^ 2.0 t_5 = Float64(r * Float64(sin(b) * fma(cos(a), Float64(cos(b) * Float64(sin(a) * sin(b))), fma(t_3, t_4, Float64((sin(a) ^ 2.0) * t_0))))) tmp = 0.0 if ((t_1 <= -0.01) || !(t_1 <= 0.04)) tmp = Float64(t_5 / Float64(Float64((t_3 ^ 1.5) * (cos(b) ^ 3.0)) - Float64(t_2 * (sin(b) ^ 3.0)))); else tmp = Float64(t_5 / Float64(Float64(Float64(t_3 * cos(a)) * (t_4 ^ 1.5)) - Float64(t_2 * (t_0 ^ 1.5)))); end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = N[Power[N[Sin[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[b], $MachinePrecision] / N[Cos[N[(a + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[a], $MachinePrecision], 3.0], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Cos[a], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[Power[N[Cos[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$5 = N[(r * N[(N[Sin[b], $MachinePrecision] * N[(N[Cos[a], $MachinePrecision] * N[(N[Cos[b], $MachinePrecision] * N[(N[Sin[a], $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$3 * t$95$4 + N[(N[Power[N[Sin[a], $MachinePrecision], 2.0], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -0.01], N[Not[LessEqual[t$95$1, 0.04]], $MachinePrecision]], N[(t$95$5 / N[(N[(N[Power[t$95$3, 1.5], $MachinePrecision] * N[Power[N[Cos[b], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(t$95$2 * N[Power[N[Sin[b], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$5 / N[(N[(N[(t$95$3 * N[Cos[a], $MachinePrecision]), $MachinePrecision] * N[Power[t$95$4, 1.5], $MachinePrecision]), $MachinePrecision] - N[(t$95$2 * N[Power[t$95$0, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\sin b}^{2}\\
t_1 := \frac{\sin b}{\cos \left(a + b\right)}\\
t_2 := {\sin a}^{3}\\
t_3 := {\cos a}^{2}\\
t_4 := {\cos b}^{2}\\
t_5 := r \cdot \left(\sin b \cdot \mathsf{fma}\left(\cos a, \cos b \cdot \left(\sin a \cdot \sin b\right), \mathsf{fma}\left(t\_3, t\_4, {\sin a}^{2} \cdot t\_0\right)\right)\right)\\
\mathbf{if}\;t\_1 \leq -0.01 \lor \neg \left(t\_1 \leq 0.04\right):\\
\;\;\;\;\frac{t\_5}{{t\_3}^{1.5} \cdot {\cos b}^{3} - t\_2 \cdot {\sin b}^{3}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_5}{\left(t\_3 \cdot \cos a\right) \cdot {t\_4}^{1.5} - t\_2 \cdot {t\_0}^{1.5}}\\
\end{array}
\end{array}
if (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < -0.0100000000000000002 or 0.0400000000000000008 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) Initial program 62.8%
lift-+.f64N/A
lift-cos.f64N/A
cos-sumN/A
flip3--N/A
lower-/.f64N/A
Applied rewrites99.1%
Taylor expanded in r around 0
Applied rewrites45.0%
lift-pow.f64N/A
lift-pow.f64N/A
lift-sin.f64N/A
pow-powN/A
metadata-evalN/A
lower-pow.f64N/A
lift-sin.f6453.7
Applied rewrites53.7%
lift-pow.f64N/A
lift-cos.f64N/A
lift-pow.f64N/A
pow-powN/A
metadata-evalN/A
lower-pow.f64N/A
lift-cos.f6482.9
Applied rewrites82.9%
if -0.0100000000000000002 < (/.f64 (sin.f64 b) (cos.f64 (+.f64 a b))) < 0.0400000000000000008Initial program 97.7%
lift-+.f64N/A
lift-cos.f64N/A
cos-sumN/A
flip3--N/A
lower-/.f64N/A
Applied rewrites99.6%
Taylor expanded in r around 0
Applied rewrites80.8%
lift-pow.f64N/A
lift-cos.f64N/A
lift-pow.f64N/A
pow-powN/A
metadata-evalN/A
unpow3N/A
unpow2N/A
lower-*.f64N/A
lift-pow.f64N/A
lift-cos.f64N/A
lift-cos.f6498.9
Applied rewrites98.9%
Final simplification90.1%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (pow (cos a) 2.0))
(t_1 (pow (sin b) 2.0))
(t_2 (pow t_1 1.5))
(t_3 (* -0.5 (* (sin b) r)))
(t_4 (* t_1 r))
(t_5 (/ t_4 (cos b)))
(t_6 (pow (cos b) 2.0))
(t_7 (pow t_6 1.5))
(t_8 (* t_2 r)))
(if (or (<= a -2.3e-5) (not (<= a 530000000.0)))
(/
(*
r
(*
(sin b)
(fma
(cos a)
(* (cos b) (* (sin a) (sin b)))
(fma t_0 t_6 (* (pow (sin a) 2.0) t_1)))))
(- (* (* t_0 (cos a)) t_7) (* (pow (sin a) 3.0) t_2)))
(fma
(fma
(-
(*
(* -1.0 a)
(fma
(/ -0.5 (cos b))
t_5
(fma
(/ 0.16666666666666666 (cos b))
t_5
(+
(/ (* (/ (* -1.0 t_8) t_7) (sin b)) (cos b))
(/ (* (/ t_3 (cos b)) (sin b)) (cos b))))))
(/ (fma t_3 t_7 (* (* -1.0 (cos b)) t_8)) (* (cos b) t_7)))
a
(/ (* 2.0 t_4) (* 2.0 t_6)))
a
(* r (tan b))))))
double code(double r, double a, double b) {
double t_0 = pow(cos(a), 2.0);
double t_1 = pow(sin(b), 2.0);
double t_2 = pow(t_1, 1.5);
double t_3 = -0.5 * (sin(b) * r);
double t_4 = t_1 * r;
double t_5 = t_4 / cos(b);
double t_6 = pow(cos(b), 2.0);
double t_7 = pow(t_6, 1.5);
double t_8 = t_2 * r;
double tmp;
if ((a <= -2.3e-5) || !(a <= 530000000.0)) {
tmp = (r * (sin(b) * fma(cos(a), (cos(b) * (sin(a) * sin(b))), fma(t_0, t_6, (pow(sin(a), 2.0) * t_1))))) / (((t_0 * cos(a)) * t_7) - (pow(sin(a), 3.0) * t_2));
} else {
tmp = fma(fma((((-1.0 * a) * fma((-0.5 / cos(b)), t_5, fma((0.16666666666666666 / cos(b)), t_5, (((((-1.0 * t_8) / t_7) * sin(b)) / cos(b)) + (((t_3 / cos(b)) * sin(b)) / cos(b)))))) - (fma(t_3, t_7, ((-1.0 * cos(b)) * t_8)) / (cos(b) * t_7))), a, ((2.0 * t_4) / (2.0 * t_6))), a, (r * tan(b)));
}
return tmp;
}
function code(r, a, b) t_0 = cos(a) ^ 2.0 t_1 = sin(b) ^ 2.0 t_2 = t_1 ^ 1.5 t_3 = Float64(-0.5 * Float64(sin(b) * r)) t_4 = Float64(t_1 * r) t_5 = Float64(t_4 / cos(b)) t_6 = cos(b) ^ 2.0 t_7 = t_6 ^ 1.5 t_8 = Float64(t_2 * r) tmp = 0.0 if ((a <= -2.3e-5) || !(a <= 530000000.0)) tmp = Float64(Float64(r * Float64(sin(b) * fma(cos(a), Float64(cos(b) * Float64(sin(a) * sin(b))), fma(t_0, t_6, Float64((sin(a) ^ 2.0) * t_1))))) / Float64(Float64(Float64(t_0 * cos(a)) * t_7) - Float64((sin(a) ^ 3.0) * t_2))); else tmp = fma(fma(Float64(Float64(Float64(-1.0 * a) * fma(Float64(-0.5 / cos(b)), t_5, fma(Float64(0.16666666666666666 / cos(b)), t_5, Float64(Float64(Float64(Float64(Float64(-1.0 * t_8) / t_7) * sin(b)) / cos(b)) + Float64(Float64(Float64(t_3 / cos(b)) * sin(b)) / cos(b)))))) - Float64(fma(t_3, t_7, Float64(Float64(-1.0 * cos(b)) * t_8)) / Float64(cos(b) * t_7))), a, Float64(Float64(2.0 * t_4) / Float64(2.0 * t_6))), a, Float64(r * tan(b))); end return tmp end
code[r_, a_, b_] := Block[{t$95$0 = N[Power[N[Cos[a], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 1.5], $MachinePrecision]}, Block[{t$95$3 = N[(-0.5 * N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$1 * r), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$4 / N[Cos[b], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[Power[N[Cos[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$7 = N[Power[t$95$6, 1.5], $MachinePrecision]}, Block[{t$95$8 = N[(t$95$2 * r), $MachinePrecision]}, If[Or[LessEqual[a, -2.3e-5], N[Not[LessEqual[a, 530000000.0]], $MachinePrecision]], N[(N[(r * N[(N[Sin[b], $MachinePrecision] * N[(N[Cos[a], $MachinePrecision] * N[(N[Cos[b], $MachinePrecision] * N[(N[Sin[a], $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * t$95$6 + N[(N[Power[N[Sin[a], $MachinePrecision], 2.0], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(t$95$0 * N[Cos[a], $MachinePrecision]), $MachinePrecision] * t$95$7), $MachinePrecision] - N[(N[Power[N[Sin[a], $MachinePrecision], 3.0], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(-0.5 / N[Cos[b], $MachinePrecision]), $MachinePrecision] * t$95$5 + N[(N[(0.16666666666666666 / N[Cos[b], $MachinePrecision]), $MachinePrecision] * t$95$5 + N[(N[(N[(N[(N[(-1.0 * t$95$8), $MachinePrecision] / t$95$7), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(t$95$3 / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(t$95$3 * t$95$7 + N[(N[(-1.0 * N[Cos[b], $MachinePrecision]), $MachinePrecision] * t$95$8), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * t$95$7), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a + N[(N[(2.0 * t$95$4), $MachinePrecision] / N[(2.0 * t$95$6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a + N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\cos a}^{2}\\
t_1 := {\sin b}^{2}\\
t_2 := {t\_1}^{1.5}\\
t_3 := -0.5 \cdot \left(\sin b \cdot r\right)\\
t_4 := t\_1 \cdot r\\
t_5 := \frac{t\_4}{\cos b}\\
t_6 := {\cos b}^{2}\\
t_7 := {t\_6}^{1.5}\\
t_8 := t\_2 \cdot r\\
\mathbf{if}\;a \leq -2.3 \cdot 10^{-5} \lor \neg \left(a \leq 530000000\right):\\
\;\;\;\;\frac{r \cdot \left(\sin b \cdot \mathsf{fma}\left(\cos a, \cos b \cdot \left(\sin a \cdot \sin b\right), \mathsf{fma}\left(t\_0, t\_6, {\sin a}^{2} \cdot t\_1\right)\right)\right)}{\left(t\_0 \cdot \cos a\right) \cdot t\_7 - {\sin a}^{3} \cdot t\_2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-0.5}{\cos b}, t\_5, \mathsf{fma}\left(\frac{0.16666666666666666}{\cos b}, t\_5, \frac{\frac{-1 \cdot t\_8}{t\_7} \cdot \sin b}{\cos b} + \frac{\frac{t\_3}{\cos b} \cdot \sin b}{\cos b}\right)\right) - \frac{\mathsf{fma}\left(t\_3, t\_7, \left(-1 \cdot \cos b\right) \cdot t\_8\right)}{\cos b \cdot t\_7}, a, \frac{2 \cdot t\_4}{2 \cdot t\_6}\right), a, r \cdot \tan b\right)\\
\end{array}
\end{array}
if a < -2.3e-5 or 5.3e8 < a Initial program 54.2%
lift-+.f64N/A
lift-cos.f64N/A
cos-sumN/A
flip3--N/A
lower-/.f64N/A
Applied rewrites99.1%
Taylor expanded in r around 0
Applied rewrites45.9%
lift-pow.f64N/A
lift-cos.f64N/A
lift-pow.f64N/A
pow-powN/A
metadata-evalN/A
unpow3N/A
unpow2N/A
lower-*.f64N/A
lift-pow.f64N/A
lift-cos.f64N/A
lift-cos.f6469.0
Applied rewrites69.0%
if -2.3e-5 < a < 5.3e8Initial program 98.8%
Taylor expanded in a around 0
Applied rewrites99.1%
Final simplification85.4%
(FPCore (r a b) :precision binary64 (/ (* r (sin b)) (fma (sin (fma 0.5 PI (/ PI 2.0))) (sin (+ b a)) (* (cos (+ b a)) (sin (* 0.5 PI))))))
double code(double r, double a, double b) {
return (r * sin(b)) / fma(sin(fma(0.5, ((double) M_PI), (((double) M_PI) / 2.0))), sin((b + a)), (cos((b + a)) * sin((0.5 * ((double) M_PI)))));
}
function code(r, a, b) return Float64(Float64(r * sin(b)) / fma(sin(fma(0.5, pi, Float64(pi / 2.0))), sin(Float64(b + a)), Float64(cos(Float64(b + a)) * sin(Float64(0.5 * pi))))) end
code[r_, a_, b_] := N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[(N[Sin[N[(0.5 * Pi + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(b + a), $MachinePrecision]], $MachinePrecision] + N[(N[Cos[N[(b + a), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(0.5 * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{r \cdot \sin b}{\mathsf{fma}\left(\sin \left(\mathsf{fma}\left(0.5, \pi, \frac{\pi}{2}\right)\right), \sin \left(b + a\right), \cos \left(b + a\right) \cdot \sin \left(0.5 \cdot \pi\right)\right)}
\end{array}
Initial program 78.6%
lift-+.f64N/A
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lower-fma.f64N/A
lower-sin.f64N/A
lift-+.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-PI.f64N/A
lower-*.f64N/A
lift-cos.f64N/A
lift-+.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-PI.f6478.3
Applied rewrites78.3%
Taylor expanded in a around -inf
lower-/.f64N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-fma.f64N/A
Applied rewrites77.9%
Final simplification77.9%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (* -0.5 (* (sin b) r)))
(t_1 (pow (sin b) 2.0))
(t_2 (* (pow t_1 1.5) r))
(t_3 (* t_1 r))
(t_4 (/ t_3 (cos b)))
(t_5 (pow (cos b) 2.0))
(t_6 (pow t_5 1.5)))
(fma
(fma
(-
(*
(* -1.0 a)
(fma
(/ -0.5 (cos b))
t_4
(fma
(/ 0.16666666666666666 (cos b))
t_4
(+
(/ (* (/ (* -1.0 t_2) t_6) (sin b)) (cos b))
(/ (* (/ t_0 (cos b)) (sin b)) (cos b))))))
(/ (fma t_0 t_6 (* (* -1.0 (cos b)) t_2)) (* (cos b) t_6)))
a
(/ (* 2.0 t_3) (* 2.0 t_5)))
a
(* r (tan b)))))
double code(double r, double a, double b) {
double t_0 = -0.5 * (sin(b) * r);
double t_1 = pow(sin(b), 2.0);
double t_2 = pow(t_1, 1.5) * r;
double t_3 = t_1 * r;
double t_4 = t_3 / cos(b);
double t_5 = pow(cos(b), 2.0);
double t_6 = pow(t_5, 1.5);
return fma(fma((((-1.0 * a) * fma((-0.5 / cos(b)), t_4, fma((0.16666666666666666 / cos(b)), t_4, (((((-1.0 * t_2) / t_6) * sin(b)) / cos(b)) + (((t_0 / cos(b)) * sin(b)) / cos(b)))))) - (fma(t_0, t_6, ((-1.0 * cos(b)) * t_2)) / (cos(b) * t_6))), a, ((2.0 * t_3) / (2.0 * t_5))), a, (r * tan(b)));
}
function code(r, a, b) t_0 = Float64(-0.5 * Float64(sin(b) * r)) t_1 = sin(b) ^ 2.0 t_2 = Float64((t_1 ^ 1.5) * r) t_3 = Float64(t_1 * r) t_4 = Float64(t_3 / cos(b)) t_5 = cos(b) ^ 2.0 t_6 = t_5 ^ 1.5 return fma(fma(Float64(Float64(Float64(-1.0 * a) * fma(Float64(-0.5 / cos(b)), t_4, fma(Float64(0.16666666666666666 / cos(b)), t_4, Float64(Float64(Float64(Float64(Float64(-1.0 * t_2) / t_6) * sin(b)) / cos(b)) + Float64(Float64(Float64(t_0 / cos(b)) * sin(b)) / cos(b)))))) - Float64(fma(t_0, t_6, Float64(Float64(-1.0 * cos(b)) * t_2)) / Float64(cos(b) * t_6))), a, Float64(Float64(2.0 * t_3) / Float64(2.0 * t_5))), a, Float64(r * tan(b))) end
code[r_, a_, b_] := Block[{t$95$0 = N[(-0.5 * N[(N[Sin[b], $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[t$95$1, 1.5], $MachinePrecision] * r), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 * r), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 / N[Cos[b], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Power[N[Cos[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$6 = N[Power[t$95$5, 1.5], $MachinePrecision]}, N[(N[(N[(N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(-0.5 / N[Cos[b], $MachinePrecision]), $MachinePrecision] * t$95$4 + N[(N[(0.16666666666666666 / N[Cos[b], $MachinePrecision]), $MachinePrecision] * t$95$4 + N[(N[(N[(N[(N[(-1.0 * t$95$2), $MachinePrecision] / t$95$6), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(t$95$0 / N[Cos[b], $MachinePrecision]), $MachinePrecision] * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(t$95$0 * t$95$6 + N[(N[(-1.0 * N[Cos[b], $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[b], $MachinePrecision] * t$95$6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a + N[(N[(2.0 * t$95$3), $MachinePrecision] / N[(2.0 * t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * a + N[(r * N[Tan[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot \left(\sin b \cdot r\right)\\
t_1 := {\sin b}^{2}\\
t_2 := {t\_1}^{1.5} \cdot r\\
t_3 := t\_1 \cdot r\\
t_4 := \frac{t\_3}{\cos b}\\
t_5 := {\cos b}^{2}\\
t_6 := {t\_5}^{1.5}\\
\mathsf{fma}\left(\mathsf{fma}\left(\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{-0.5}{\cos b}, t\_4, \mathsf{fma}\left(\frac{0.16666666666666666}{\cos b}, t\_4, \frac{\frac{-1 \cdot t\_2}{t\_6} \cdot \sin b}{\cos b} + \frac{\frac{t\_0}{\cos b} \cdot \sin b}{\cos b}\right)\right) - \frac{\mathsf{fma}\left(t\_0, t\_6, \left(-1 \cdot \cos b\right) \cdot t\_2\right)}{\cos b \cdot t\_6}, a, \frac{2 \cdot t\_3}{2 \cdot t\_5}\right), a, r \cdot \tan b\right)
\end{array}
\end{array}
Initial program 78.6%
Taylor expanded in a around 0
Applied rewrites59.6%
Final simplification59.6%
(FPCore (r a b)
:precision binary64
(let* ((t_0 (pow (cos b) 2.0))
(t_1 (pow (sin b) 2.0))
(t_2 (* r t_1))
(t_3 (/ t_2 t_0)))
(*
(* -1.0 (* (* a a) a))
(fma
-1.0
t_3
(fma
-1.0
(/ (* r (pow (sin b) 4.0)) (pow (cos b) 4.0))
(fma
-1.0
(/
(-
(fma
-1.0
(/ (* r (pow t_1 1.5)) (pow t_0 1.5))
(* -0.5 (/ (* r (sin b)) (cos b))))
(/ (fma -1.0 (* (/ r a) (tan b)) (/ (* -1.0 t_2) t_0)) (* -1.0 a)))
(* -1.0 a))
(* 0.16666666666666666 t_3)))))))
double code(double r, double a, double b) {
double t_0 = pow(cos(b), 2.0);
double t_1 = pow(sin(b), 2.0);
double t_2 = r * t_1;
double t_3 = t_2 / t_0;
return (-1.0 * ((a * a) * a)) * fma(-1.0, t_3, fma(-1.0, ((r * pow(sin(b), 4.0)) / pow(cos(b), 4.0)), fma(-1.0, ((fma(-1.0, ((r * pow(t_1, 1.5)) / pow(t_0, 1.5)), (-0.5 * ((r * sin(b)) / cos(b)))) - (fma(-1.0, ((r / a) * tan(b)), ((-1.0 * t_2) / t_0)) / (-1.0 * a))) / (-1.0 * a)), (0.16666666666666666 * t_3))));
}
function code(r, a, b) t_0 = cos(b) ^ 2.0 t_1 = sin(b) ^ 2.0 t_2 = Float64(r * t_1) t_3 = Float64(t_2 / t_0) return Float64(Float64(-1.0 * Float64(Float64(a * a) * a)) * fma(-1.0, t_3, fma(-1.0, Float64(Float64(r * (sin(b) ^ 4.0)) / (cos(b) ^ 4.0)), fma(-1.0, Float64(Float64(fma(-1.0, Float64(Float64(r * (t_1 ^ 1.5)) / (t_0 ^ 1.5)), Float64(-0.5 * Float64(Float64(r * sin(b)) / cos(b)))) - Float64(fma(-1.0, Float64(Float64(r / a) * tan(b)), Float64(Float64(-1.0 * t_2) / t_0)) / Float64(-1.0 * a))) / Float64(-1.0 * a)), Float64(0.16666666666666666 * t_3))))) end
code[r_, a_, b_] := Block[{t$95$0 = N[Power[N[Cos[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sin[b], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(r * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 / t$95$0), $MachinePrecision]}, N[(N[(-1.0 * N[(N[(a * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] * N[(-1.0 * t$95$3 + N[(-1.0 * N[(N[(r * N[Power[N[Sin[b], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] / N[Power[N[Cos[b], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 * N[(N[(N[(-1.0 * N[(N[(r * N[Power[t$95$1, 1.5], $MachinePrecision]), $MachinePrecision] / N[Power[t$95$0, 1.5], $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(N[(r * N[Sin[b], $MachinePrecision]), $MachinePrecision] / N[Cos[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[(N[(r / a), $MachinePrecision] * N[Tan[b], $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 * t$95$2), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] + N[(0.16666666666666666 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\cos b}^{2}\\
t_1 := {\sin b}^{2}\\
t_2 := r \cdot t\_1\\
t_3 := \frac{t\_2}{t\_0}\\
\left(-1 \cdot \left(\left(a \cdot a\right) \cdot a\right)\right) \cdot \mathsf{fma}\left(-1, t\_3, \mathsf{fma}\left(-1, \frac{r \cdot {\sin b}^{4}}{{\cos b}^{4}}, \mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(-1, \frac{r \cdot {t\_1}^{1.5}}{{t\_0}^{1.5}}, -0.5 \cdot \frac{r \cdot \sin b}{\cos b}\right) - \frac{\mathsf{fma}\left(-1, \frac{r}{a} \cdot \tan b, \frac{-1 \cdot t\_2}{t\_0}\right)}{-1 \cdot a}}{-1 \cdot a}, 0.16666666666666666 \cdot t\_3\right)\right)\right)
\end{array}
\end{array}
Initial program 78.6%
Taylor expanded in a around 0
Applied rewrites59.6%
Taylor expanded in a around -inf
Applied rewrites19.7%
Final simplification19.7%
herbie shell --seed 2025065
(FPCore (r a b)
:name "rsin B (should all be same)"
:precision binary64
(* r (/ (sin b) (cos (+ a b)))))