
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* x 0.5)))) (/ (* (* (/ 8.0 3.0) t_0) t_0) (sin x))))
double code(double x) {
double t_0 = sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / sin(x);
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = (((8.0d0 / 3.0d0) * t_0) * t_0) / sin(x)
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / Math.sin(x);
}
def code(x): t_0 = math.sin((x * 0.5)) return (((8.0 / 3.0) * t_0) * t_0) / math.sin(x)
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(Float64(Float64(Float64(8.0 / 3.0) * t_0) * t_0) / sin(x)) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = (((8.0 / 3.0) * t_0) * t_0) / sin(x); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(8.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
\frac{\left(\frac{8}{3} \cdot t\_0\right) \cdot t\_0}{\sin x}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* x 0.5)))) (/ (* (* (/ 8.0 3.0) t_0) t_0) (sin x))))
double code(double x) {
double t_0 = sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / sin(x);
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((x * 0.5d0))
code = (((8.0d0 / 3.0d0) * t_0) * t_0) / sin(x)
end function
public static double code(double x) {
double t_0 = Math.sin((x * 0.5));
return (((8.0 / 3.0) * t_0) * t_0) / Math.sin(x);
}
def code(x): t_0 = math.sin((x * 0.5)) return (((8.0 / 3.0) * t_0) * t_0) / math.sin(x)
function code(x) t_0 = sin(Float64(x * 0.5)) return Float64(Float64(Float64(Float64(8.0 / 3.0) * t_0) * t_0) / sin(x)) end
function tmp = code(x) t_0 = sin((x * 0.5)); tmp = (((8.0 / 3.0) * t_0) * t_0) / sin(x); end
code[x_] := Block[{t$95$0 = N[Sin[N[(x * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(8.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \sin \left(x \cdot 0.5\right)\\
\frac{\left(\frac{8}{3} \cdot t\_0\right) \cdot t\_0}{\sin x}
\end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (sin (* 0.5 x)))) (/ (* t_0 (/ t_0 (sin x))) 0.375)))
double code(double x) {
double t_0 = sin((0.5 * x));
return (t_0 * (t_0 / sin(x))) / 0.375;
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sin((0.5d0 * x))
code = (t_0 * (t_0 / sin(x))) / 0.375d0
end function
public static double code(double x) {
double t_0 = Math.sin((0.5 * x));
return (t_0 * (t_0 / Math.sin(x))) / 0.375;
}
def code(x): t_0 = math.sin((0.5 * x)) return (t_0 * (t_0 / math.sin(x))) / 0.375
function code(x) t_0 = sin(Float64(0.5 * x)) return Float64(Float64(t_0 * Float64(t_0 / sin(x))) / 0.375) end
function tmp = code(x) t_0 = sin((0.5 * x)); tmp = (t_0 * (t_0 / sin(x))) / 0.375; end
code[x_] := Block[{t$95$0 = N[Sin[N[(0.5 * x), $MachinePrecision]], $MachinePrecision]}, N[(N[(t$95$0 * N[(t$95$0 / N[Sin[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 0.375), $MachinePrecision]]
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot x\right)\\
\frac{t\_0 \cdot \frac{t\_0}{\sin x}}{0.375}
\end{array}
Initial program 77.3%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
mult-flip-revN/A
lower-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
mult-flip-revN/A
lower-/.f6499.2%
lift-/.f64N/A
metadata-eval99.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2%
lift-*.f64N/A
*-commutativeN/A
Applied rewrites99.2%
metadata-evalN/A
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
metadata-eval99.1%
Applied rewrites99.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sin.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-sin.f64N/A
lower-*.f6499.1%
Applied rewrites99.1%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*r*N/A
metadata-evalN/A
mult-flip-revN/A
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
lower-/.f6499.5%
Applied rewrites99.5%
(FPCore (x)
:precision binary64
(*
(copysign 1.0 x)
(if (<= (fabs x) 1e-7)
(fma
(fabs x)
0.6666666666666666
(* (* (fabs x) 0.05555555555555555) (* (fabs x) (fabs x))))
(/
(* 2.6666666666666665 (pow (sin (* 0.5 (fabs x))) 2.0))
(sin (fabs x))))))double code(double x) {
double tmp;
if (fabs(x) <= 1e-7) {
tmp = fma(fabs(x), 0.6666666666666666, ((fabs(x) * 0.05555555555555555) * (fabs(x) * fabs(x))));
} else {
tmp = (2.6666666666666665 * pow(sin((0.5 * fabs(x))), 2.0)) / sin(fabs(x));
}
return copysign(1.0, x) * tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 1e-7) tmp = fma(abs(x), 0.6666666666666666, Float64(Float64(abs(x) * 0.05555555555555555) * Float64(abs(x) * abs(x)))); else tmp = Float64(Float64(2.6666666666666665 * (sin(Float64(0.5 * abs(x))) ^ 2.0)) / sin(abs(x))); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 1e-7], N[(N[Abs[x], $MachinePrecision] * 0.6666666666666666 + N[(N[(N[Abs[x], $MachinePrecision] * 0.05555555555555555), $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.6666666666666665 * N[Power[N[Sin[N[(0.5 * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[Sin[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right|, 0.6666666666666666, \left(\left|x\right| \cdot 0.05555555555555555\right) \cdot \left(\left|x\right| \cdot \left|x\right|\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2.6666666666666665 \cdot {\sin \left(0.5 \cdot \left|x\right|\right)}^{2}}{\sin \left(\left|x\right|\right)}\\
\end{array}
if x < 9.9999999999999995e-8Initial program 77.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites51.1%
lift-*.f64N/A
lift-+.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6451.1%
lift-pow.f64N/A
unpow2N/A
lower-*.f6451.1%
Applied rewrites51.1%
if 9.9999999999999995e-8 < x Initial program 77.3%
Taylor expanded in x around inf
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f6477.3%
Applied rewrites77.3%
(FPCore (x) :precision binary64 (* (/ (sin (* 0.5 x)) (sin x)) (* (sin (* -0.5 x)) -2.6666666666666665)))
double code(double x) {
return (sin((0.5 * x)) / sin(x)) * (sin((-0.5 * x)) * -2.6666666666666665);
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (sin((0.5d0 * x)) / sin(x)) * (sin(((-0.5d0) * x)) * (-2.6666666666666665d0))
end function
public static double code(double x) {
return (Math.sin((0.5 * x)) / Math.sin(x)) * (Math.sin((-0.5 * x)) * -2.6666666666666665);
}
def code(x): return (math.sin((0.5 * x)) / math.sin(x)) * (math.sin((-0.5 * x)) * -2.6666666666666665)
function code(x) return Float64(Float64(sin(Float64(0.5 * x)) / sin(x)) * Float64(sin(Float64(-0.5 * x)) * -2.6666666666666665)) end
function tmp = code(x) tmp = (sin((0.5 * x)) / sin(x)) * (sin((-0.5 * x)) * -2.6666666666666665); end
code[x_] := N[(N[(N[Sin[N[(0.5 * x), $MachinePrecision]], $MachinePrecision] / N[Sin[x], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[N[(-0.5 * x), $MachinePrecision]], $MachinePrecision] * -2.6666666666666665), $MachinePrecision]), $MachinePrecision]
\frac{\sin \left(0.5 \cdot x\right)}{\sin x} \cdot \left(\sin \left(-0.5 \cdot x\right) \cdot -2.6666666666666665\right)
Initial program 77.3%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6499.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2%
remove-double-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
Applied rewrites99.2%
(FPCore (x)
:precision binary64
(*
(copysign 1.0 x)
(if (<= (fabs x) 1e-7)
(fma
(fabs x)
0.6666666666666666
(* (* (fabs x) 0.05555555555555555) (* (fabs x) (fabs x))))
(*
2.6666666666666665
(/ (pow (sin (* 0.5 (fabs x))) 2.0) (sin (fabs x)))))))double code(double x) {
double tmp;
if (fabs(x) <= 1e-7) {
tmp = fma(fabs(x), 0.6666666666666666, ((fabs(x) * 0.05555555555555555) * (fabs(x) * fabs(x))));
} else {
tmp = 2.6666666666666665 * (pow(sin((0.5 * fabs(x))), 2.0) / sin(fabs(x)));
}
return copysign(1.0, x) * tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 1e-7) tmp = fma(abs(x), 0.6666666666666666, Float64(Float64(abs(x) * 0.05555555555555555) * Float64(abs(x) * abs(x)))); else tmp = Float64(2.6666666666666665 * Float64((sin(Float64(0.5 * abs(x))) ^ 2.0) / sin(abs(x)))); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 1e-7], N[(N[Abs[x], $MachinePrecision] * 0.6666666666666666 + N[(N[(N[Abs[x], $MachinePrecision] * 0.05555555555555555), $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.6666666666666665 * N[(N[Power[N[Sin[N[(0.5 * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] / N[Sin[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(\left|x\right|, 0.6666666666666666, \left(\left|x\right| \cdot 0.05555555555555555\right) \cdot \left(\left|x\right| \cdot \left|x\right|\right)\right)\\
\mathbf{else}:\\
\;\;\;\;2.6666666666666665 \cdot \frac{{\sin \left(0.5 \cdot \left|x\right|\right)}^{2}}{\sin \left(\left|x\right|\right)}\\
\end{array}
if x < 9.9999999999999995e-8Initial program 77.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites51.1%
lift-*.f64N/A
lift-+.f64N/A
distribute-lft-inN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6451.1%
lift-pow.f64N/A
unpow2N/A
lower-*.f6451.1%
Applied rewrites51.1%
if 9.9999999999999995e-8 < x Initial program 77.3%
Taylor expanded in x around inf
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-sin.f6477.3%
Applied rewrites77.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(*
(copysign 1.0 x)
(if (<= (fabs x) 0.00135)
(*
(fma
(*
(fma
(fma 0.0005621693121693122 t_0 0.005555555555555556)
t_0
0.05555555555555555)
(fabs x))
(fabs x)
0.6666666666666666)
(fabs x))
(/
1.0
(/
(sin (fabs x))
(fma (cos (fabs x)) -1.3333333333333333 1.3333333333333333)))))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 0.00135) {
tmp = fma((fma(fma(0.0005621693121693122, t_0, 0.005555555555555556), t_0, 0.05555555555555555) * fabs(x)), fabs(x), 0.6666666666666666) * fabs(x);
} else {
tmp = 1.0 / (sin(fabs(x)) / fma(cos(fabs(x)), -1.3333333333333333, 1.3333333333333333));
}
return copysign(1.0, x) * tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 0.00135) tmp = Float64(fma(Float64(fma(fma(0.0005621693121693122, t_0, 0.005555555555555556), t_0, 0.05555555555555555) * abs(x)), abs(x), 0.6666666666666666) * abs(x)); else tmp = Float64(1.0 / Float64(sin(abs(x)) / fma(cos(abs(x)), -1.3333333333333333, 1.3333333333333333))); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 0.00135], N[(N[(N[(N[(N[(0.0005621693121693122 * t$95$0 + 0.005555555555555556), $MachinePrecision] * t$95$0 + 0.05555555555555555), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision] + 0.6666666666666666), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Sin[N[Abs[x], $MachinePrecision]], $MachinePrecision] / N[(N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision] * -1.3333333333333333 + 1.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.00135:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0005621693121693122, t\_0, 0.005555555555555556\right), t\_0, 0.05555555555555555\right) \cdot \left|x\right|, \left|x\right|, 0.6666666666666666\right) \cdot \left|x\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\sin \left(\left|x\right|\right)}{\mathsf{fma}\left(\cos \left(\left|x\right|\right), -1.3333333333333333, 1.3333333333333333\right)}}\\
\end{array}
\end{array}
if x < 0.0013500000000000001Initial program 77.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.0%
Applied rewrites51.0%
if 0.0013500000000000001 < x Initial program 77.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sin.f64N/A
lift-sin.f64N/A
sqr-sin-aN/A
sub-flipN/A
distribute-rgt-inN/A
lower-+.f64N/A
lift-/.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites52.2%
metadata-evalN/A
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval52.3%
Applied rewrites52.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(*
(copysign 1.0 x)
(if (<= (fabs x) 0.00135)
(*
(fma
(*
(fma
(fma 0.0005621693121693122 t_0 0.005555555555555556)
t_0
0.05555555555555555)
(fabs x))
(fabs x)
0.6666666666666666)
(fabs x))
(/ (- (cos (fabs x)) 1.0) (* -0.75 (sin (fabs x))))))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 0.00135) {
tmp = fma((fma(fma(0.0005621693121693122, t_0, 0.005555555555555556), t_0, 0.05555555555555555) * fabs(x)), fabs(x), 0.6666666666666666) * fabs(x);
} else {
tmp = (cos(fabs(x)) - 1.0) / (-0.75 * sin(fabs(x)));
}
return copysign(1.0, x) * tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 0.00135) tmp = Float64(fma(Float64(fma(fma(0.0005621693121693122, t_0, 0.005555555555555556), t_0, 0.05555555555555555) * abs(x)), abs(x), 0.6666666666666666) * abs(x)); else tmp = Float64(Float64(cos(abs(x)) - 1.0) / Float64(-0.75 * sin(abs(x)))); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 0.00135], N[(N[(N[(N[(N[(0.0005621693121693122 * t$95$0 + 0.005555555555555556), $MachinePrecision] * t$95$0 + 0.05555555555555555), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision] + 0.6666666666666666), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision] / N[(-0.75 * N[Sin[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.00135:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0005621693121693122, t\_0, 0.005555555555555556\right), t\_0, 0.05555555555555555\right) \cdot \left|x\right|, \left|x\right|, 0.6666666666666666\right) \cdot \left|x\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(\left|x\right|\right) - 1}{-0.75 \cdot \sin \left(\left|x\right|\right)}\\
\end{array}
\end{array}
if x < 0.0013500000000000001Initial program 77.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.0%
Applied rewrites51.0%
if 0.0013500000000000001 < x Initial program 77.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sin.f64N/A
lift-sin.f64N/A
sqr-sin-aN/A
sub-flipN/A
distribute-rgt-inN/A
lower-+.f64N/A
lift-/.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites52.2%
metadata-evalN/A
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval52.2%
Applied rewrites52.2%
lift-/.f64N/A
lift--.f64N/A
metadata-evalN/A
metadata-evalN/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
mult-flip-revN/A
div-subN/A
lift--.f64N/A
div-flip-revN/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
Applied rewrites52.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (fabs x) (fabs x))))
(*
(copysign 1.0 x)
(if (<= (fabs x) 0.00135)
(*
(fma
(*
(fma
(fma 0.0005621693121693122 t_0 0.005555555555555556)
t_0
0.05555555555555555)
(fabs x))
(fabs x)
0.6666666666666666)
(fabs x))
(/
(fma (cos (fabs x)) -1.3333333333333333 1.3333333333333333)
(sin (fabs x)))))))double code(double x) {
double t_0 = fabs(x) * fabs(x);
double tmp;
if (fabs(x) <= 0.00135) {
tmp = fma((fma(fma(0.0005621693121693122, t_0, 0.005555555555555556), t_0, 0.05555555555555555) * fabs(x)), fabs(x), 0.6666666666666666) * fabs(x);
} else {
tmp = fma(cos(fabs(x)), -1.3333333333333333, 1.3333333333333333) / sin(fabs(x));
}
return copysign(1.0, x) * tmp;
}
function code(x) t_0 = Float64(abs(x) * abs(x)) tmp = 0.0 if (abs(x) <= 0.00135) tmp = Float64(fma(Float64(fma(fma(0.0005621693121693122, t_0, 0.005555555555555556), t_0, 0.05555555555555555) * abs(x)), abs(x), 0.6666666666666666) * abs(x)); else tmp = Float64(fma(cos(abs(x)), -1.3333333333333333, 1.3333333333333333) / sin(abs(x))); end return Float64(copysign(1.0, x) * tmp) end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 0.00135], N[(N[(N[(N[(N[(0.0005621693121693122 * t$95$0 + 0.005555555555555556), $MachinePrecision] * t$95$0 + 0.05555555555555555), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision] + 0.6666666666666666), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[N[Abs[x], $MachinePrecision]], $MachinePrecision] * -1.3333333333333333 + 1.3333333333333333), $MachinePrecision] / N[Sin[N[Abs[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \left|x\right| \cdot \left|x\right|\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.00135:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.0005621693121693122, t\_0, 0.005555555555555556\right), t\_0, 0.05555555555555555\right) \cdot \left|x\right|, \left|x\right|, 0.6666666666666666\right) \cdot \left|x\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\cos \left(\left|x\right|\right), -1.3333333333333333, 1.3333333333333333\right)}{\sin \left(\left|x\right|\right)}\\
\end{array}
\end{array}
if x < 0.0013500000000000001Initial program 77.3%
Taylor expanded in x around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6451.0%
Applied rewrites51.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.0%
Applied rewrites51.0%
if 0.0013500000000000001 < x Initial program 77.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sin.f64N/A
lift-sin.f64N/A
sqr-sin-aN/A
sub-flipN/A
distribute-rgt-inN/A
lower-+.f64N/A
lift-/.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
Applied rewrites52.2%
metadata-evalN/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval52.3%
Applied rewrites52.3%
(FPCore (x) :precision binary64 (* 1.3333333333333333 (sin (* 0.5 x))))
double code(double x) {
return 1.3333333333333333 * sin((0.5 * x));
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 1.3333333333333333d0 * sin((0.5d0 * x))
end function
public static double code(double x) {
return 1.3333333333333333 * Math.sin((0.5 * x));
}
def code(x): return 1.3333333333333333 * math.sin((0.5 * x))
function code(x) return Float64(1.3333333333333333 * sin(Float64(0.5 * x))) end
function tmp = code(x) tmp = 1.3333333333333333 * sin((0.5 * x)); end
code[x_] := N[(1.3333333333333333 * N[Sin[N[(0.5 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
1.3333333333333333 \cdot \sin \left(0.5 \cdot x\right)
Initial program 77.3%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
mult-flip-revN/A
lower-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
mult-flip-revN/A
lower-/.f6499.2%
lift-/.f64N/A
metadata-eval99.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2%
lift-*.f64N/A
*-commutativeN/A
Applied rewrites99.2%
Taylor expanded in x around 0
Applied rewrites55.2%
(FPCore (x) :precision binary64 (* 0.6666666666666666 x))
double code(double x) {
return 0.6666666666666666 * x;
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 0.6666666666666666d0 * x
end function
public static double code(double x) {
return 0.6666666666666666 * x;
}
def code(x): return 0.6666666666666666 * x
function code(x) return Float64(0.6666666666666666 * x) end
function tmp = code(x) tmp = 0.6666666666666666 * x; end
code[x_] := N[(0.6666666666666666 * x), $MachinePrecision]
0.6666666666666666 \cdot x
Initial program 77.3%
Taylor expanded in x around 0
lower-*.f6451.3%
Applied rewrites51.3%
herbie shell --seed 2025183
(FPCore (x)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, A"
:precision binary64
(/ (* (* (/ 8.0 3.0) (sin (* x 0.5))) (sin (* x 0.5))) (sin x)))