
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / y)) / z;
}
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, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (sin(y) / y)) / z
end function
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / y)) / z;
}
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, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (sin(y) / y)) / z
end function
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) (FPCore (z_s x_s x_m y z_m) :precision binary64 (let* ((t_0 (/ (* x_m (/ (sin y) y)) z_m))) (* z_s (* x_s (if (<= t_0 0.0) (* (/ (sin y) (* z_m y)) x_m) t_0)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double t_0 = (x_m * (sin(y) / y)) / z_m;
double tmp;
if (t_0 <= 0.0) {
tmp = (sin(y) / (z_m * y)) * x_m;
} else {
tmp = t_0;
}
return z_s * (x_s * tmp);
}
x\_m = private
x\_s = private
z\_m = private
z\_s = private
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(z_s, x_s, x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: t_0
real(8) :: tmp
t_0 = (x_m * (sin(y) / y)) / z_m
if (t_0 <= 0.0d0) then
tmp = (sin(y) / (z_m * y)) * x_m
else
tmp = t_0
end if
code = z_s * (x_s * tmp)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
public static double code(double z_s, double x_s, double x_m, double y, double z_m) {
double t_0 = (x_m * (Math.sin(y) / y)) / z_m;
double tmp;
if (t_0 <= 0.0) {
tmp = (Math.sin(y) / (z_m * y)) * x_m;
} else {
tmp = t_0;
}
return z_s * (x_s * tmp);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) def code(z_s, x_s, x_m, y, z_m): t_0 = (x_m * (math.sin(y) / y)) / z_m tmp = 0 if t_0 <= 0.0: tmp = (math.sin(y) / (z_m * y)) * x_m else: tmp = t_0 return z_s * (x_s * tmp)
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) t_0 = Float64(Float64(x_m * Float64(sin(y) / y)) / z_m) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(sin(y) / Float64(z_m * y)) * x_m); else tmp = t_0; end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); z\_m = abs(z); z\_s = sign(z) * abs(1.0); function tmp_2 = code(z_s, x_s, x_m, y, z_m) t_0 = (x_m * (sin(y) / y)) / z_m; tmp = 0.0; if (t_0 <= 0.0) tmp = (sin(y) / (z_m * y)) * x_m; else tmp = t_0; end tmp_2 = z_s * (x_s * tmp); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := Block[{t$95$0 = N[(N[(x$95$m * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z$95$m), $MachinePrecision]}, N[(z$95$s * N[(x$95$s * If[LessEqual[t$95$0, 0.0], N[(N[(N[Sin[y], $MachinePrecision] / N[(z$95$m * y), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision], t$95$0]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
\begin{array}{l}
t_0 := \frac{x\_m \cdot \frac{\sin y}{y}}{z\_m}\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\sin y}{z\_m \cdot y} \cdot x\_m\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\right)
\end{array}
\end{array}
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < -0.0Initial program 90.7%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-/l*N/A
associate-/r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f6494.6
Applied rewrites94.6%
if -0.0 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 99.7%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) (FPCore (z_s x_s x_m y z_m) :precision binary64 (* z_s (* x_s (if (<= y 7.8e-11) (/ x_m z_m) (* (/ (sin y) z_m) (/ x_m y))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if (y <= 7.8e-11) {
tmp = x_m / z_m;
} else {
tmp = (sin(y) / z_m) * (x_m / y);
}
return z_s * (x_s * tmp);
}
x\_m = private
x\_s = private
z\_m = private
z\_s = private
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(z_s, x_s, x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if (y <= 7.8d-11) then
tmp = x_m / z_m
else
tmp = (sin(y) / z_m) * (x_m / y)
end if
code = z_s * (x_s * tmp)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
public static double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if (y <= 7.8e-11) {
tmp = x_m / z_m;
} else {
tmp = (Math.sin(y) / z_m) * (x_m / y);
}
return z_s * (x_s * tmp);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) def code(z_s, x_s, x_m, y, z_m): tmp = 0 if y <= 7.8e-11: tmp = x_m / z_m else: tmp = (math.sin(y) / z_m) * (x_m / y) return z_s * (x_s * tmp)
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (y <= 7.8e-11) tmp = Float64(x_m / z_m); else tmp = Float64(Float64(sin(y) / z_m) * Float64(x_m / y)); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); z\_m = abs(z); z\_s = sign(z) * abs(1.0); function tmp_2 = code(z_s, x_s, x_m, y, z_m) tmp = 0.0; if (y <= 7.8e-11) tmp = x_m / z_m; else tmp = (sin(y) / z_m) * (x_m / y); end tmp_2 = z_s * (x_s * tmp); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[y, 7.8e-11], N[(x$95$m / z$95$m), $MachinePrecision], N[(N[(N[Sin[y], $MachinePrecision] / z$95$m), $MachinePrecision] * N[(x$95$m / y), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 7.8 \cdot 10^{-11}:\\
\;\;\;\;\frac{x\_m}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin y}{z\_m} \cdot \frac{x\_m}{y}\\
\end{array}\right)
\end{array}
if y < 7.80000000000000021e-11Initial program 97.5%
Taylor expanded in y around 0
Applied rewrites72.4%
if 7.80000000000000021e-11 < y Initial program 92.3%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-*r/N/A
associate-/r*N/A
times-fracN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
lower-/.f6492.3
Applied rewrites92.3%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) (FPCore (z_s x_s x_m y z_m) :precision binary64 (* z_s (* x_s (if (<= y 7.8e-11) (/ x_m z_m) (* (/ (sin y) (* z_m y)) x_m)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if (y <= 7.8e-11) {
tmp = x_m / z_m;
} else {
tmp = (sin(y) / (z_m * y)) * x_m;
}
return z_s * (x_s * tmp);
}
x\_m = private
x\_s = private
z\_m = private
z\_s = private
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(z_s, x_s, x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if (y <= 7.8d-11) then
tmp = x_m / z_m
else
tmp = (sin(y) / (z_m * y)) * x_m
end if
code = z_s * (x_s * tmp)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
public static double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if (y <= 7.8e-11) {
tmp = x_m / z_m;
} else {
tmp = (Math.sin(y) / (z_m * y)) * x_m;
}
return z_s * (x_s * tmp);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) def code(z_s, x_s, x_m, y, z_m): tmp = 0 if y <= 7.8e-11: tmp = x_m / z_m else: tmp = (math.sin(y) / (z_m * y)) * x_m return z_s * (x_s * tmp)
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (y <= 7.8e-11) tmp = Float64(x_m / z_m); else tmp = Float64(Float64(sin(y) / Float64(z_m * y)) * x_m); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); z\_m = abs(z); z\_s = sign(z) * abs(1.0); function tmp_2 = code(z_s, x_s, x_m, y, z_m) tmp = 0.0; if (y <= 7.8e-11) tmp = x_m / z_m; else tmp = (sin(y) / (z_m * y)) * x_m; end tmp_2 = z_s * (x_s * tmp); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[y, 7.8e-11], N[(x$95$m / z$95$m), $MachinePrecision], N[(N[(N[Sin[y], $MachinePrecision] / N[(z$95$m * y), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 7.8 \cdot 10^{-11}:\\
\;\;\;\;\frac{x\_m}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin y}{z\_m \cdot y} \cdot x\_m\\
\end{array}\right)
\end{array}
if y < 7.80000000000000021e-11Initial program 97.5%
Taylor expanded in y around 0
Applied rewrites72.4%
if 7.80000000000000021e-11 < y Initial program 92.3%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-/l*N/A
associate-/r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f6492.0
Applied rewrites92.0%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) (FPCore (z_s x_s x_m y z_m) :precision binary64 (* z_s (* x_s (if (<= y 1e-17) (/ x_m z_m) (* (sin y) (/ x_m (* z_m y)))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if (y <= 1e-17) {
tmp = x_m / z_m;
} else {
tmp = sin(y) * (x_m / (z_m * y));
}
return z_s * (x_s * tmp);
}
x\_m = private
x\_s = private
z\_m = private
z\_s = private
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(z_s, x_s, x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if (y <= 1d-17) then
tmp = x_m / z_m
else
tmp = sin(y) * (x_m / (z_m * y))
end if
code = z_s * (x_s * tmp)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
public static double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if (y <= 1e-17) {
tmp = x_m / z_m;
} else {
tmp = Math.sin(y) * (x_m / (z_m * y));
}
return z_s * (x_s * tmp);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) def code(z_s, x_s, x_m, y, z_m): tmp = 0 if y <= 1e-17: tmp = x_m / z_m else: tmp = math.sin(y) * (x_m / (z_m * y)) return z_s * (x_s * tmp)
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (y <= 1e-17) tmp = Float64(x_m / z_m); else tmp = Float64(sin(y) * Float64(x_m / Float64(z_m * y))); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); z\_m = abs(z); z\_s = sign(z) * abs(1.0); function tmp_2 = code(z_s, x_s, x_m, y, z_m) tmp = 0.0; if (y <= 1e-17) tmp = x_m / z_m; else tmp = sin(y) * (x_m / (z_m * y)); end tmp_2 = z_s * (x_s * tmp); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[y, 1e-17], N[(x$95$m / z$95$m), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(x$95$m / N[(z$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq 10^{-17}:\\
\;\;\;\;\frac{x\_m}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{x\_m}{z\_m \cdot y}\\
\end{array}\right)
\end{array}
if y < 1.00000000000000007e-17Initial program 97.5%
Taylor expanded in y around 0
Applied rewrites72.3%
if 1.00000000000000007e-17 < y Initial program 92.4%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-*r/N/A
associate-/r*N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6492.1
Applied rewrites92.1%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
(FPCore (z_s x_s x_m y z_m)
:precision binary64
(*
z_s
(*
x_s
(if (<= z_m 8.6e-128)
(/ (fma (* (* y y) x_m) -0.16666666666666666 x_m) z_m)
(*
(/ (/ (- y) (fma (* -0.16666666666666666 y) y -1.0)) (* z_m y))
x_m)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if (z_m <= 8.6e-128) {
tmp = fma(((y * y) * x_m), -0.16666666666666666, x_m) / z_m;
} else {
tmp = ((-y / fma((-0.16666666666666666 * y), y, -1.0)) / (z_m * y)) * x_m;
}
return z_s * (x_s * tmp);
}
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (z_m <= 8.6e-128) tmp = Float64(fma(Float64(Float64(y * y) * x_m), -0.16666666666666666, x_m) / z_m); else tmp = Float64(Float64(Float64(Float64(-y) / fma(Float64(-0.16666666666666666 * y), y, -1.0)) / Float64(z_m * y)) * x_m); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[z$95$m, 8.6e-128], N[(N[(N[(N[(y * y), $MachinePrecision] * x$95$m), $MachinePrecision] * -0.16666666666666666 + x$95$m), $MachinePrecision] / z$95$m), $MachinePrecision], N[(N[(N[((-y) / N[(N[(-0.16666666666666666 * y), $MachinePrecision] * y + -1.0), $MachinePrecision]), $MachinePrecision] / N[(z$95$m * y), $MachinePrecision]), $MachinePrecision] * x$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 8.6 \cdot 10^{-128}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(y \cdot y\right) \cdot x\_m, -0.16666666666666666, x\_m\right)}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-y}{\mathsf{fma}\left(-0.16666666666666666 \cdot y, y, -1\right)}}{z\_m \cdot y} \cdot x\_m\\
\end{array}\right)
\end{array}
if z < 8.59999999999999988e-128Initial program 89.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6453.6
Applied rewrites53.6%
if 8.59999999999999988e-128 < z Initial program 98.7%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-/l*N/A
associate-/r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f6491.9
Applied rewrites91.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6450.7
Applied rewrites50.7%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
*-commutativeN/A
flip-+N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites49.4%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6469.2
Applied rewrites69.2%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
(FPCore (z_s x_s x_m y z_m)
:precision binary64
(*
z_s
(*
x_s
(if (<= (/ (sin y) y) 0.04)
(* y (/ (/ x_m y) z_m))
(/ (* x_m (fma (* y y) -0.16666666666666666 1.0)) z_m)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if ((sin(y) / y) <= 0.04) {
tmp = y * ((x_m / y) / z_m);
} else {
tmp = (x_m * fma((y * y), -0.16666666666666666, 1.0)) / z_m;
}
return z_s * (x_s * tmp);
}
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (Float64(sin(y) / y) <= 0.04) tmp = Float64(y * Float64(Float64(x_m / y) / z_m)); else tmp = Float64(Float64(x_m * fma(Float64(y * y), -0.16666666666666666, 1.0)) / z_m); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.04], N[(y * N[(N[(x$95$m / y), $MachinePrecision] / z$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * N[(N[(y * y), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision]), $MachinePrecision] / z$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 0.04:\\
\;\;\;\;y \cdot \frac{\frac{x\_m}{y}}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m \cdot \mathsf{fma}\left(y \cdot y, -0.16666666666666666, 1\right)}{z\_m}\\
\end{array}\right)
\end{array}
if (/.f64 (sin.f64 y) y) < 0.0400000000000000008Initial program 92.3%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-*r/N/A
associate-/r*N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.4
Applied rewrites91.4%
Taylor expanded in y around 0
Applied rewrites33.1%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lift-/.f6433.2
Applied rewrites33.2%
if 0.0400000000000000008 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6499.6
Applied rewrites99.6%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
(FPCore (z_s x_s x_m y z_m)
:precision binary64
(*
z_s
(*
x_s
(if (<= (/ (sin y) y) 0.04)
(* y (/ (/ x_m y) z_m))
(/ (fma (* (* y y) x_m) -0.16666666666666666 x_m) z_m)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if ((sin(y) / y) <= 0.04) {
tmp = y * ((x_m / y) / z_m);
} else {
tmp = fma(((y * y) * x_m), -0.16666666666666666, x_m) / z_m;
}
return z_s * (x_s * tmp);
}
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (Float64(sin(y) / y) <= 0.04) tmp = Float64(y * Float64(Float64(x_m / y) / z_m)); else tmp = Float64(fma(Float64(Float64(y * y) * x_m), -0.16666666666666666, x_m) / z_m); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.04], N[(y * N[(N[(x$95$m / y), $MachinePrecision] / z$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(y * y), $MachinePrecision] * x$95$m), $MachinePrecision] * -0.16666666666666666 + x$95$m), $MachinePrecision] / z$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 0.04:\\
\;\;\;\;y \cdot \frac{\frac{x\_m}{y}}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(y \cdot y\right) \cdot x\_m, -0.16666666666666666, x\_m\right)}{z\_m}\\
\end{array}\right)
\end{array}
if (/.f64 (sin.f64 y) y) < 0.0400000000000000008Initial program 92.3%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-*r/N/A
associate-/r*N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.4
Applied rewrites91.4%
Taylor expanded in y around 0
Applied rewrites33.1%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lift-/.f6433.2
Applied rewrites33.2%
if 0.0400000000000000008 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.6
Applied rewrites99.6%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
z\_m = (fabs.f64 z)
z\_s = (copysign.f64 #s(literal 1 binary64) z)
(FPCore (z_s x_s x_m y z_m)
:precision binary64
(*
z_s
(*
x_s
(if (<= (/ (sin y) y) 0.04)
(* y (/ (/ x_m y) z_m))
(* (/ (fma (* y y) -0.16666666666666666 1.0) z_m) x_m)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if ((sin(y) / y) <= 0.04) {
tmp = y * ((x_m / y) / z_m);
} else {
tmp = (fma((y * y), -0.16666666666666666, 1.0) / z_m) * x_m;
}
return z_s * (x_s * tmp);
}
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (Float64(sin(y) / y) <= 0.04) tmp = Float64(y * Float64(Float64(x_m / y) / z_m)); else tmp = Float64(Float64(fma(Float64(y * y), -0.16666666666666666, 1.0) / z_m) * x_m); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.04], N[(y * N[(N[(x$95$m / y), $MachinePrecision] / z$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(y * y), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] / z$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 0.04:\\
\;\;\;\;y \cdot \frac{\frac{x\_m}{y}}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y \cdot y, -0.16666666666666666, 1\right)}{z\_m} \cdot x\_m\\
\end{array}\right)
\end{array}
if (/.f64 (sin.f64 y) y) < 0.0400000000000000008Initial program 92.3%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-*r/N/A
associate-/r*N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.4
Applied rewrites91.4%
Taylor expanded in y around 0
Applied rewrites33.1%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lift-/.f6433.2
Applied rewrites33.2%
if 0.0400000000000000008 < (/.f64 (sin.f64 y) y) Initial program 100.0%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-/l*N/A
associate-/r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f6485.1
Applied rewrites85.1%
Taylor expanded in y around 0
+-commutativeN/A
associate-*r/N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6499.3
Applied rewrites99.3%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) (FPCore (z_s x_s x_m y z_m) :precision binary64 (* z_s (* x_s (if (<= (/ (sin y) y) 5e-10) (* y (/ (/ x_m y) z_m)) (/ x_m z_m)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if ((sin(y) / y) <= 5e-10) {
tmp = y * ((x_m / y) / z_m);
} else {
tmp = x_m / z_m;
}
return z_s * (x_s * tmp);
}
x\_m = private
x\_s = private
z\_m = private
z\_s = private
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(z_s, x_s, x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if ((sin(y) / y) <= 5d-10) then
tmp = y * ((x_m / y) / z_m)
else
tmp = x_m / z_m
end if
code = z_s * (x_s * tmp)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
public static double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if ((Math.sin(y) / y) <= 5e-10) {
tmp = y * ((x_m / y) / z_m);
} else {
tmp = x_m / z_m;
}
return z_s * (x_s * tmp);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) def code(z_s, x_s, x_m, y, z_m): tmp = 0 if (math.sin(y) / y) <= 5e-10: tmp = y * ((x_m / y) / z_m) else: tmp = x_m / z_m return z_s * (x_s * tmp)
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (Float64(sin(y) / y) <= 5e-10) tmp = Float64(y * Float64(Float64(x_m / y) / z_m)); else tmp = Float64(x_m / z_m); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); z\_m = abs(z); z\_s = sign(z) * abs(1.0); function tmp_2 = code(z_s, x_s, x_m, y, z_m) tmp = 0.0; if ((sin(y) / y) <= 5e-10) tmp = y * ((x_m / y) / z_m); else tmp = x_m / z_m; end tmp_2 = z_s * (x_s * tmp); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 5e-10], N[(y * N[(N[(x$95$m / y), $MachinePrecision] / z$95$m), $MachinePrecision]), $MachinePrecision], N[(x$95$m / z$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 5 \cdot 10^{-10}:\\
\;\;\;\;y \cdot \frac{\frac{x\_m}{y}}{z\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{z\_m}\\
\end{array}\right)
\end{array}
if (/.f64 (sin.f64 y) y) < 5.00000000000000031e-10Initial program 92.2%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-*r/N/A
associate-/r*N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.3
Applied rewrites91.3%
Taylor expanded in y around 0
Applied rewrites33.1%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lift-/.f6433.2
Applied rewrites33.2%
if 5.00000000000000031e-10 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.3%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) (FPCore (z_s x_s x_m y z_m) :precision binary64 (* z_s (* x_s (if (<= (/ (sin y) y) 0.999999) (* y (/ x_m (* z_m y))) (/ x_m z_m)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if ((sin(y) / y) <= 0.999999) {
tmp = y * (x_m / (z_m * y));
} else {
tmp = x_m / z_m;
}
return z_s * (x_s * tmp);
}
x\_m = private
x\_s = private
z\_m = private
z\_s = private
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(z_s, x_s, x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8) :: tmp
if ((sin(y) / y) <= 0.999999d0) then
tmp = y * (x_m / (z_m * y))
else
tmp = x_m / z_m
end if
code = z_s * (x_s * tmp)
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
public static double code(double z_s, double x_s, double x_m, double y, double z_m) {
double tmp;
if ((Math.sin(y) / y) <= 0.999999) {
tmp = y * (x_m / (z_m * y));
} else {
tmp = x_m / z_m;
}
return z_s * (x_s * tmp);
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) def code(z_s, x_s, x_m, y, z_m): tmp = 0 if (math.sin(y) / y) <= 0.999999: tmp = y * (x_m / (z_m * y)) else: tmp = x_m / z_m return z_s * (x_s * tmp)
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) tmp = 0.0 if (Float64(sin(y) / y) <= 0.999999) tmp = Float64(y * Float64(x_m / Float64(z_m * y))); else tmp = Float64(x_m / z_m); end return Float64(z_s * Float64(x_s * tmp)) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); z\_m = abs(z); z\_s = sign(z) * abs(1.0); function tmp_2 = code(z_s, x_s, x_m, y, z_m) tmp = 0.0; if ((sin(y) / y) <= 0.999999) tmp = y * (x_m / (z_m * y)); else tmp = x_m / z_m; end tmp_2 = z_s * (x_s * tmp); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.999999], N[(y * N[(x$95$m / N[(z$95$m * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m / z$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 0.999999:\\
\;\;\;\;y \cdot \frac{x\_m}{z\_m \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{z\_m}\\
\end{array}\right)
\end{array}
if (/.f64 (sin.f64 y) y) < 0.999998999999999971Initial program 92.4%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-sin.f64N/A
associate-*r/N/A
associate-/r*N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-sin.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.5
Applied rewrites91.5%
Taylor expanded in y around 0
Applied rewrites33.3%
if 0.999998999999999971 < (/.f64 (sin.f64 y) y) Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites99.7%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) z\_m = (fabs.f64 z) z\_s = (copysign.f64 #s(literal 1 binary64) z) (FPCore (z_s x_s x_m y z_m) :precision binary64 (* z_s (* x_s (/ x_m z_m))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
z\_m = fabs(z);
z\_s = copysign(1.0, z);
double code(double z_s, double x_s, double x_m, double y, double z_m) {
return z_s * (x_s * (x_m / z_m));
}
x\_m = private
x\_s = private
z\_m = private
z\_s = private
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(z_s, x_s, x_m, y, z_m)
use fmin_fmax_functions
real(8), intent (in) :: z_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z_m
code = z_s * (x_s * (x_m / z_m))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
z\_m = Math.abs(z);
z\_s = Math.copySign(1.0, z);
public static double code(double z_s, double x_s, double x_m, double y, double z_m) {
return z_s * (x_s * (x_m / z_m));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) z\_m = math.fabs(z) z\_s = math.copysign(1.0, z) def code(z_s, x_s, x_m, y, z_m): return z_s * (x_s * (x_m / z_m))
x\_m = abs(x) x\_s = copysign(1.0, x) z\_m = abs(z) z\_s = copysign(1.0, z) function code(z_s, x_s, x_m, y, z_m) return Float64(z_s * Float64(x_s * Float64(x_m / z_m))) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); z\_m = abs(z); z\_s = sign(z) * abs(1.0); function tmp = code(z_s, x_s, x_m, y, z_m) tmp = z_s * (x_s * (x_m / z_m)); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
z\_m = N[Abs[z], $MachinePrecision]
z\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[z$95$s_, x$95$s_, x$95$m_, y_, z$95$m_] := N[(z$95$s * N[(x$95$s * N[(x$95$m / z$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
z\_m = \left|z\right|
\\
z\_s = \mathsf{copysign}\left(1, z\right)
\\
z\_s \cdot \left(x\_s \cdot \frac{x\_m}{z\_m}\right)
\end{array}
Initial program 96.1%
Taylor expanded in y around 0
Applied rewrites58.8%
herbie shell --seed 2025112
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
(/ (* x (/ (sin y) y)) z))