
(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]
\frac{x \cdot \frac{\sin y}{y}}{z}
Herbie found 9 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]
\frac{x \cdot \frac{\sin y}{y}}{z}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (sin y) y)))
(*
(copysign 1.0 x)
(if (<= (fabs x) 3e-24) (* t_0 (/ (fabs x) z)) (/ (* (fabs x) t_0) z)))))double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double tmp;
if (fabs(x) <= 3e-24) {
tmp = t_0 * (fabs(x) / z);
} else {
tmp = (fabs(x) * t_0) / z;
}
return copysign(1.0, x) * tmp;
}
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) / y;
double tmp;
if (Math.abs(x) <= 3e-24) {
tmp = t_0 * (Math.abs(x) / z);
} else {
tmp = (Math.abs(x) * t_0) / z;
}
return Math.copySign(1.0, x) * tmp;
}
def code(x, y, z): t_0 = math.sin(y) / y tmp = 0 if math.fabs(x) <= 3e-24: tmp = t_0 * (math.fabs(x) / z) else: tmp = (math.fabs(x) * t_0) / z return math.copysign(1.0, x) * tmp
function code(x, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if (abs(x) <= 3e-24) tmp = Float64(t_0 * Float64(abs(x) / z)); else tmp = Float64(Float64(abs(x) * t_0) / z); end return Float64(copysign(1.0, x) * tmp) end
function tmp_2 = code(x, y, z) t_0 = sin(y) / y; tmp = 0.0; if (abs(x) <= 3e-24) tmp = t_0 * (abs(x) / z); else tmp = (abs(x) * t_0) / z; end tmp_2 = (sign(x) * abs(1.0)) * tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 3e-24], N[(t$95$0 * N[(N[Abs[x], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(N[Abs[x], $MachinePrecision] * t$95$0), $MachinePrecision] / z), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 3 \cdot 10^{-24}:\\
\;\;\;\;t\_0 \cdot \frac{\left|x\right|}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|x\right| \cdot t\_0}{z}\\
\end{array}
\end{array}
if x < 2.99999999999999995e-24Initial program 95.8%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6496.1
Applied rewrites96.1%
if 2.99999999999999995e-24 < x Initial program 95.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (sin y) y)))
(*
(copysign 1.0 x)
(*
(copysign 1.0 z)
(if (<= (/ (* (fabs x) t_0) (fabs z)) -1e-32)
(* (/ (sin y) (* (fabs z) y)) (fabs x))
(* t_0 (/ (fabs x) (fabs z))))))))double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double tmp;
if (((fabs(x) * t_0) / fabs(z)) <= -1e-32) {
tmp = (sin(y) / (fabs(z) * y)) * fabs(x);
} else {
tmp = t_0 * (fabs(x) / fabs(z));
}
return copysign(1.0, x) * (copysign(1.0, z) * tmp);
}
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) / y;
double tmp;
if (((Math.abs(x) * t_0) / Math.abs(z)) <= -1e-32) {
tmp = (Math.sin(y) / (Math.abs(z) * y)) * Math.abs(x);
} else {
tmp = t_0 * (Math.abs(x) / Math.abs(z));
}
return Math.copySign(1.0, x) * (Math.copySign(1.0, z) * tmp);
}
def code(x, y, z): t_0 = math.sin(y) / y tmp = 0 if ((math.fabs(x) * t_0) / math.fabs(z)) <= -1e-32: tmp = (math.sin(y) / (math.fabs(z) * y)) * math.fabs(x) else: tmp = t_0 * (math.fabs(x) / math.fabs(z)) return math.copysign(1.0, x) * (math.copysign(1.0, z) * tmp)
function code(x, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if (Float64(Float64(abs(x) * t_0) / abs(z)) <= -1e-32) tmp = Float64(Float64(sin(y) / Float64(abs(z) * y)) * abs(x)); else tmp = Float64(t_0 * Float64(abs(x) / abs(z))); end return Float64(copysign(1.0, x) * Float64(copysign(1.0, z) * tmp)) end
function tmp_2 = code(x, y, z) t_0 = sin(y) / y; tmp = 0.0; if (((abs(x) * t_0) / abs(z)) <= -1e-32) tmp = (sin(y) / (abs(z) * y)) * abs(x); else tmp = t_0 * (abs(x) / abs(z)); end tmp_2 = (sign(x) * abs(1.0)) * ((sign(z) * abs(1.0)) * tmp); end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Abs[x], $MachinePrecision] * t$95$0), $MachinePrecision] / N[Abs[z], $MachinePrecision]), $MachinePrecision], -1e-32], N[(N[(N[Sin[y], $MachinePrecision] / N[(N[Abs[z], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[Abs[x], $MachinePrecision] / N[Abs[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathsf{copysign}\left(1, x\right) \cdot \left(\mathsf{copysign}\left(1, z\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\left|x\right| \cdot t\_0}{\left|z\right|} \leq -1 \cdot 10^{-32}:\\
\;\;\;\;\frac{\sin y}{\left|z\right| \cdot y} \cdot \left|x\right|\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{\left|x\right|}{\left|z\right|}\\
\end{array}\right)
\end{array}
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < -1.00000000000000006e-32Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.9
Applied rewrites87.9%
if -1.00000000000000006e-32 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 95.8%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6496.1
Applied rewrites96.1%
(FPCore (x y z) :precision binary64 (if (<= (/ (sin y) y) 0.9999999999999993) (* (/ (sin y) (* z y)) x) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((sin(y) / y) <= 0.9999999999999993) {
tmp = (sin(y) / (z * y)) * x;
} else {
tmp = x / z;
}
return tmp;
}
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
real(8) :: tmp
if ((sin(y) / y) <= 0.9999999999999993d0) then
tmp = (sin(y) / (z * y)) * x
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((Math.sin(y) / y) <= 0.9999999999999993) {
tmp = (Math.sin(y) / (z * y)) * x;
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (math.sin(y) / y) <= 0.9999999999999993: tmp = (math.sin(y) / (z * y)) * x else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(sin(y) / y) <= 0.9999999999999993) tmp = Float64(Float64(sin(y) / Float64(z * y)) * x); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((sin(y) / y) <= 0.9999999999999993) tmp = (sin(y) / (z * y)) * x; else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 0.9999999999999993], N[(N[(N[Sin[y], $MachinePrecision] / N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 0.9999999999999993:\\
\;\;\;\;\frac{\sin y}{z \cdot y} \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
if (/.f64 (sin.f64 y) y) < 0.99999999999999933Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.9
Applied rewrites87.9%
if 0.99999999999999933 < (/.f64 (sin.f64 y) y) Initial program 95.8%
Taylor expanded in y around 0
lower-/.f6458.6
Applied rewrites58.6%
(FPCore (x y z) :precision binary64 (if (<= (fabs y) 4e-18) (/ x z) (* (/ x (* z (fabs y))) (sin (fabs y)))))
double code(double x, double y, double z) {
double tmp;
if (fabs(y) <= 4e-18) {
tmp = x / z;
} else {
tmp = (x / (z * fabs(y))) * sin(fabs(y));
}
return tmp;
}
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
real(8) :: tmp
if (abs(y) <= 4d-18) then
tmp = x / z
else
tmp = (x / (z * abs(y))) * sin(abs(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (Math.abs(y) <= 4e-18) {
tmp = x / z;
} else {
tmp = (x / (z * Math.abs(y))) * Math.sin(Math.abs(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if math.fabs(y) <= 4e-18: tmp = x / z else: tmp = (x / (z * math.fabs(y))) * math.sin(math.fabs(y)) return tmp
function code(x, y, z) tmp = 0.0 if (abs(y) <= 4e-18) tmp = Float64(x / z); else tmp = Float64(Float64(x / Float64(z * abs(y))) * sin(abs(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (abs(y) <= 4e-18) tmp = x / z; else tmp = (x / (z * abs(y))) * sin(abs(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[Abs[y], $MachinePrecision], 4e-18], N[(x / z), $MachinePrecision], N[(N[(x / N[(z * N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[N[Abs[y], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|y\right| \leq 4 \cdot 10^{-18}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z \cdot \left|y\right|} \cdot \sin \left(\left|y\right|\right)\\
\end{array}
if y < 4.0000000000000003e-18Initial program 95.8%
Taylor expanded in y around 0
lower-/.f6458.6
Applied rewrites58.6%
if 4.0000000000000003e-18 < y Initial program 95.8%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
*-commutativeN/A
mult-flip-revN/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6483.7
Applied rewrites83.7%
(FPCore (x y z) :precision binary64 (if (<= (fabs y) 1550.0) (/ (fma (* -0.16666666666666666 (fabs y)) (* x (fabs y)) x) z) (* (- (/ (+ z (/ 1.0 z)) 2.0) (/ (- z (/ 1.0 z)) 2.0)) x)))
double code(double x, double y, double z) {
double tmp;
if (fabs(y) <= 1550.0) {
tmp = fma((-0.16666666666666666 * fabs(y)), (x * fabs(y)), x) / z;
} else {
tmp = (((z + (1.0 / z)) / 2.0) - ((z - (1.0 / z)) / 2.0)) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (abs(y) <= 1550.0) tmp = Float64(fma(Float64(-0.16666666666666666 * abs(y)), Float64(x * abs(y)), x) / z); else tmp = Float64(Float64(Float64(Float64(z + Float64(1.0 / z)) / 2.0) - Float64(Float64(z - Float64(1.0 / z)) / 2.0)) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[Abs[y], $MachinePrecision], 1550.0], N[(N[(N[(-0.16666666666666666 * N[Abs[y], $MachinePrecision]), $MachinePrecision] * N[(x * N[Abs[y], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] / z), $MachinePrecision], N[(N[(N[(N[(z + N[(1.0 / z), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] - N[(N[(z - N[(1.0 / z), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|y\right| \leq 1550:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.16666666666666666 \cdot \left|y\right|, x \cdot \left|y\right|, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{z + \frac{1}{z}}{2} - \frac{z - \frac{1}{z}}{2}\right) \cdot x\\
\end{array}
if y < 1550Initial program 95.8%
Taylor expanded in y around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-/.f6451.5
Applied rewrites51.5%
lift-fma.f64N/A
+-commutativeN/A
lift-/.f64N/A
associate-*r/N/A
lift-/.f64N/A
div-add-revN/A
mult-flipN/A
lift-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6453.5
lift-pow.f64N/A
unpow2N/A
lower-*.f6453.5
Applied rewrites53.5%
lift-*.f64N/A
lift-/.f64N/A
mult-flip-revN/A
lower-/.f6453.7
lift-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.7
Applied rewrites53.7%
if 1550 < y Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.9
Applied rewrites87.9%
Taylor expanded in y around 0
lower-/.f6458.5
Applied rewrites58.5%
lift-/.f64N/A
inv-powN/A
pow-to-expN/A
lower-unsound-exp.f64N/A
lower-unsound-*.f64N/A
lower-unsound-log.f6428.1
Applied rewrites28.1%
lift-exp.f64N/A
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
sinh---cosh-revN/A
cosh-neg-revN/A
mul-1-negN/A
*-commutativeN/A
lift-*.f64N/A
lower--.f64N/A
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
cosh-neg-revN/A
cosh-defN/A
lower-/.f64N/A
lift-log.f64N/A
rem-exp-logN/A
rec-expN/A
lift-log.f64N/A
rem-exp-logN/A
lower-+.f64N/A
lower-/.f64N/A
Applied rewrites46.1%
(FPCore (x y z)
:precision binary64
(*
(copysign 1.0 z)
(if (<= (fabs z) 1.06e+28)
(* (/ y (fabs z)) (/ x y))
(* (/ y (* (fabs z) y)) x))))double code(double x, double y, double z) {
double tmp;
if (fabs(z) <= 1.06e+28) {
tmp = (y / fabs(z)) * (x / y);
} else {
tmp = (y / (fabs(z) * y)) * x;
}
return copysign(1.0, z) * tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if (Math.abs(z) <= 1.06e+28) {
tmp = (y / Math.abs(z)) * (x / y);
} else {
tmp = (y / (Math.abs(z) * y)) * x;
}
return Math.copySign(1.0, z) * tmp;
}
def code(x, y, z): tmp = 0 if math.fabs(z) <= 1.06e+28: tmp = (y / math.fabs(z)) * (x / y) else: tmp = (y / (math.fabs(z) * y)) * x return math.copysign(1.0, z) * tmp
function code(x, y, z) tmp = 0.0 if (abs(z) <= 1.06e+28) tmp = Float64(Float64(y / abs(z)) * Float64(x / y)); else tmp = Float64(Float64(y / Float64(abs(z) * y)) * x); end return Float64(copysign(1.0, z) * tmp) end
function tmp_2 = code(x, y, z) tmp = 0.0; if (abs(z) <= 1.06e+28) tmp = (y / abs(z)) * (x / y); else tmp = (y / (abs(z) * y)) * x; end tmp_2 = (sign(z) * abs(1.0)) * tmp; end
code[x_, y_, z_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[z], $MachinePrecision], 1.06e+28], N[(N[(y / N[Abs[z], $MachinePrecision]), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(N[(y / N[(N[Abs[z], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, z\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|z\right| \leq 1.06 \cdot 10^{+28}:\\
\;\;\;\;\frac{y}{\left|z\right|} \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\left|z\right| \cdot y} \cdot x\\
\end{array}
if z < 1.0600000000000001e28Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
associate-/l*N/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
mult-flip-revN/A
lower-/.f6483.6
Applied rewrites83.6%
Taylor expanded in y around 0
Applied rewrites49.0%
if 1.0600000000000001e28 < z Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.9
Applied rewrites87.9%
Taylor expanded in y around 0
Applied rewrites55.0%
(FPCore (x y z) :precision binary64 (if (<= (/ (sin y) y) 2e-132) (* (/ y (* z y)) x) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((sin(y) / y) <= 2e-132) {
tmp = (y / (z * y)) * x;
} else {
tmp = x / z;
}
return tmp;
}
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
real(8) :: tmp
if ((sin(y) / y) <= 2d-132) then
tmp = (y / (z * y)) * x
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((Math.sin(y) / y) <= 2e-132) {
tmp = (y / (z * y)) * x;
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (math.sin(y) / y) <= 2e-132: tmp = (y / (z * y)) * x else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(sin(y) / y) <= 2e-132) tmp = Float64(Float64(y / Float64(z * y)) * x); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((sin(y) / y) <= 2e-132) tmp = (y / (z * y)) * x; else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], 2e-132], N[(N[(y / N[(z * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{\sin y}{y} \leq 2 \cdot 10^{-132}:\\
\;\;\;\;\frac{y}{z \cdot y} \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
if (/.f64 (sin.f64 y) y) < 2e-132Initial program 95.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.9
Applied rewrites87.9%
Taylor expanded in y around 0
Applied rewrites55.0%
if 2e-132 < (/.f64 (sin.f64 y) y) Initial program 95.8%
Taylor expanded in y around 0
lower-/.f6458.6
Applied rewrites58.6%
(FPCore (x y z)
:precision binary64
(*
(copysign 1.0 x)
(*
(copysign 1.0 z)
(if (<= (/ (* (fabs x) (/ (sin y) y)) (fabs z)) 2e-305)
(/ (* (fabs x) (fabs z)) (* (fabs z) (fabs z)))
(/ (fabs x) (fabs z))))))double code(double x, double y, double z) {
double tmp;
if (((fabs(x) * (sin(y) / y)) / fabs(z)) <= 2e-305) {
tmp = (fabs(x) * fabs(z)) / (fabs(z) * fabs(z));
} else {
tmp = fabs(x) / fabs(z);
}
return copysign(1.0, x) * (copysign(1.0, z) * tmp);
}
public static double code(double x, double y, double z) {
double tmp;
if (((Math.abs(x) * (Math.sin(y) / y)) / Math.abs(z)) <= 2e-305) {
tmp = (Math.abs(x) * Math.abs(z)) / (Math.abs(z) * Math.abs(z));
} else {
tmp = Math.abs(x) / Math.abs(z);
}
return Math.copySign(1.0, x) * (Math.copySign(1.0, z) * tmp);
}
def code(x, y, z): tmp = 0 if ((math.fabs(x) * (math.sin(y) / y)) / math.fabs(z)) <= 2e-305: tmp = (math.fabs(x) * math.fabs(z)) / (math.fabs(z) * math.fabs(z)) else: tmp = math.fabs(x) / math.fabs(z) return math.copysign(1.0, x) * (math.copysign(1.0, z) * tmp)
function code(x, y, z) tmp = 0.0 if (Float64(Float64(abs(x) * Float64(sin(y) / y)) / abs(z)) <= 2e-305) tmp = Float64(Float64(abs(x) * abs(z)) / Float64(abs(z) * abs(z))); else tmp = Float64(abs(x) / abs(z)); end return Float64(copysign(1.0, x) * Float64(copysign(1.0, z) * tmp)) end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((abs(x) * (sin(y) / y)) / abs(z)) <= 2e-305) tmp = (abs(x) * abs(z)) / (abs(z) * abs(z)); else tmp = abs(x) / abs(z); end tmp_2 = (sign(x) * abs(1.0)) * ((sign(z) * abs(1.0)) * tmp); end
code[x_, y_, z_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(N[Abs[x], $MachinePrecision] * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / N[Abs[z], $MachinePrecision]), $MachinePrecision], 2e-305], N[(N[(N[Abs[x], $MachinePrecision] * N[Abs[z], $MachinePrecision]), $MachinePrecision] / N[(N[Abs[z], $MachinePrecision] * N[Abs[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[x], $MachinePrecision] / N[Abs[z], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \left(\mathsf{copysign}\left(1, z\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{\left|x\right| \cdot \frac{\sin y}{y}}{\left|z\right|} \leq 2 \cdot 10^{-305}:\\
\;\;\;\;\frac{\left|x\right| \cdot \left|z\right|}{\left|z\right| \cdot \left|z\right|}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|x\right|}{\left|z\right|}\\
\end{array}\right)
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < 1.99999999999999999e-305Initial program 95.8%
Taylor expanded in y around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-/.f6451.5
Applied rewrites51.5%
lift-fma.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-/.f64N/A
associate-*r/N/A
common-denominatorN/A
lower-/.f64N/A
distribute-rgt-outN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-pow.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6435.8
Applied rewrites35.8%
Taylor expanded in y around 0
lower-*.f6442.4
Applied rewrites42.4%
if 1.99999999999999999e-305 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 95.8%
Taylor expanded in y around 0
lower-/.f6458.6
Applied rewrites58.6%
(FPCore (x y z) :precision binary64 (/ x z))
double code(double x, double y, double z) {
return x / 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 / z
end function
public static double code(double x, double y, double z) {
return x / z;
}
def code(x, y, z): return x / z
function code(x, y, z) return Float64(x / z) end
function tmp = code(x, y, z) tmp = x / z; end
code[x_, y_, z_] := N[(x / z), $MachinePrecision]
\frac{x}{z}
Initial program 95.8%
Taylor expanded in y around 0
lower-/.f6458.6
Applied rewrites58.6%
herbie shell --seed 2025172
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
(/ (* x (/ (sin y) y)) z))