
(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 (/ (* (fabs x) (/ (sin y) y)) (fabs z))))
(*
(copysign 1.0 x)
(*
(copysign 1.0 z)
(if (<= t_0 0.0) (* (/ (fabs x) (* (fabs z) y)) (sin y)) t_0)))))double code(double x, double y, double z) {
double t_0 = (fabs(x) * (sin(y) / y)) / fabs(z);
double tmp;
if (t_0 <= 0.0) {
tmp = (fabs(x) / (fabs(z) * y)) * sin(y);
} else {
tmp = t_0;
}
return copysign(1.0, x) * (copysign(1.0, z) * tmp);
}
public static double code(double x, double y, double z) {
double t_0 = (Math.abs(x) * (Math.sin(y) / y)) / Math.abs(z);
double tmp;
if (t_0 <= 0.0) {
tmp = (Math.abs(x) / (Math.abs(z) * y)) * Math.sin(y);
} else {
tmp = t_0;
}
return Math.copySign(1.0, x) * (Math.copySign(1.0, z) * tmp);
}
def code(x, y, z): t_0 = (math.fabs(x) * (math.sin(y) / y)) / math.fabs(z) tmp = 0 if t_0 <= 0.0: tmp = (math.fabs(x) / (math.fabs(z) * y)) * math.sin(y) else: tmp = t_0 return math.copysign(1.0, x) * (math.copysign(1.0, z) * tmp)
function code(x, y, z) t_0 = Float64(Float64(abs(x) * Float64(sin(y) / y)) / abs(z)) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(abs(x) / Float64(abs(z) * y)) * sin(y)); else tmp = t_0; end return Float64(copysign(1.0, x) * Float64(copysign(1.0, z) * tmp)) end
function tmp_2 = code(x, y, z) t_0 = (abs(x) * (sin(y) / y)) / abs(z); tmp = 0.0; if (t_0 <= 0.0) tmp = (abs(x) / (abs(z) * y)) * sin(y); else tmp = t_0; 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[(N[Abs[x], $MachinePrecision] * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / N[Abs[z], $MachinePrecision]), $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[t$95$0, 0.0], N[(N[(N[Abs[x], $MachinePrecision] / N[(N[Abs[z], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := \frac{\left|x\right| \cdot \frac{\sin y}{y}}{\left|z\right|}\\
\mathsf{copysign}\left(1, x\right) \cdot \left(\mathsf{copysign}\left(1, z\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\left|x\right|}{\left|z\right| \cdot y} \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\right)
\end{array}
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < -0.0Initial program 96.0%
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.9%
Applied rewrites83.9%
if -0.0 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 96.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (sin y) y)))
(if (<= t_0 -2e-295)
(* (/ x (* z y)) (sin y))
(if (<= t_0 0.99999999998) (* (/ (sin y) z) (/ x y)) (/ x z)))))double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double tmp;
if (t_0 <= -2e-295) {
tmp = (x / (z * y)) * sin(y);
} else if (t_0 <= 0.99999999998) {
tmp = (sin(y) / z) * (x / y);
} 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) :: t_0
real(8) :: tmp
t_0 = sin(y) / y
if (t_0 <= (-2d-295)) then
tmp = (x / (z * y)) * sin(y)
else if (t_0 <= 0.99999999998d0) then
tmp = (sin(y) / z) * (x / y)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) / y;
double tmp;
if (t_0 <= -2e-295) {
tmp = (x / (z * y)) * Math.sin(y);
} else if (t_0 <= 0.99999999998) {
tmp = (Math.sin(y) / z) * (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) / y tmp = 0 if t_0 <= -2e-295: tmp = (x / (z * y)) * math.sin(y) elif t_0 <= 0.99999999998: tmp = (math.sin(y) / z) * (x / y) else: tmp = x / z return tmp
function code(x, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if (t_0 <= -2e-295) tmp = Float64(Float64(x / Float64(z * y)) * sin(y)); elseif (t_0 <= 0.99999999998) tmp = Float64(Float64(sin(y) / z) * Float64(x / y)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) / y; tmp = 0.0; if (t_0 <= -2e-295) tmp = (x / (z * y)) * sin(y); elseif (t_0 <= 0.99999999998) tmp = (sin(y) / z) * (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-295], N[(N[(x / N[(z * y), $MachinePrecision]), $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.99999999998], N[(N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-295}:\\
\;\;\;\;\frac{x}{z \cdot y} \cdot \sin y\\
\mathbf{elif}\;t\_0 \leq 0.99999999998:\\
\;\;\;\;\frac{\sin y}{z} \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
if (/.f64 (sin.f64 y) y) < -2.0000000000000001e-295Initial program 96.0%
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.9%
Applied rewrites83.9%
if -2.0000000000000001e-295 < (/.f64 (sin.f64 y) y) < 0.99999999998Initial program 96.0%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
mult-flip-revN/A
lower-/.f6488.2%
Applied rewrites88.2%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-*r/N/A
lift-sin.f64N/A
mult-flipN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-sin.f64N/A
associate-/l/N/A
*-commutativeN/A
lift-*.f64N/A
lower-/.f6488.0%
Applied rewrites88.0%
lift-*.f64N/A
lift-sin.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-sin.f64N/A
lower-/.f6484.7%
Applied rewrites84.7%
if 0.99999999998 < (/.f64 (sin.f64 y) y) Initial program 96.0%
Taylor expanded in y around 0
lower-/.f6457.4%
Applied rewrites57.4%
(FPCore (x y z) :precision binary64 (if (<= (fabs y) 1.3e-5) (/ x z) (* (/ x (* z (fabs y))) (sin (fabs y)))))
double code(double x, double y, double z) {
double tmp;
if (fabs(y) <= 1.3e-5) {
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) <= 1.3d-5) 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) <= 1.3e-5) {
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) <= 1.3e-5: 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) <= 1.3e-5) 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) <= 1.3e-5) 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], 1.3e-5], 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 1.3 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z \cdot \left|y\right|} \cdot \sin \left(\left|y\right|\right)\\
\end{array}
if y < 1.2999999999999999e-5Initial program 96.0%
Taylor expanded in y around 0
lower-/.f6457.4%
Applied rewrites57.4%
if 1.2999999999999999e-5 < y Initial program 96.0%
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.9%
Applied rewrites83.9%
(FPCore (x y z) :precision binary64 (/ 1.0 (fma 0.16666666666666666 (/ (* (pow y 2.0) z) x) (/ z x))))
double code(double x, double y, double z) {
return 1.0 / fma(0.16666666666666666, ((pow(y, 2.0) * z) / x), (z / x));
}
function code(x, y, z) return Float64(1.0 / fma(0.16666666666666666, Float64(Float64((y ^ 2.0) * z) / x), Float64(z / x))) end
code[x_, y_, z_] := N[(1.0 / N[(0.16666666666666666 * N[(N[(N[Power[y, 2.0], $MachinePrecision] * z), $MachinePrecision] / x), $MachinePrecision] + N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\mathsf{fma}\left(0.16666666666666666, \frac{{y}^{2} \cdot z}{x}, \frac{z}{x}\right)}
Initial program 96.0%
Taylor expanded in y around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6452.0%
Applied rewrites52.0%
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6451.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.7%
lift-pow.f64N/A
unpow2N/A
lower-*.f6451.7%
Applied rewrites51.7%
Taylor expanded in y around 0
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-/.f6464.9%
Applied rewrites64.9%
(FPCore (x y z) :precision binary64 (if (<= (fabs y) 1.35) (/ x (/ z (fma -0.16666666666666666 (* (fabs y) (fabs y)) 1.0))) (* (/ (+ (- (/ 1.0 z) z) (+ (/ 1.0 z) z)) 2.0) x)))
double code(double x, double y, double z) {
double tmp;
if (fabs(y) <= 1.35) {
tmp = x / (z / fma(-0.16666666666666666, (fabs(y) * fabs(y)), 1.0));
} else {
tmp = ((((1.0 / z) - z) + ((1.0 / z) + z)) / 2.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (abs(y) <= 1.35) tmp = Float64(x / Float64(z / fma(-0.16666666666666666, Float64(abs(y) * abs(y)), 1.0))); else tmp = Float64(Float64(Float64(Float64(Float64(1.0 / z) - z) + Float64(Float64(1.0 / z) + z)) / 2.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[Abs[y], $MachinePrecision], 1.35], N[(x / N[(z / N[(-0.16666666666666666 * N[(N[Abs[y], $MachinePrecision] * N[Abs[y], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(1.0 / z), $MachinePrecision] - z), $MachinePrecision] + N[(N[(1.0 / z), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|y\right| \leq 1.35:\\
\;\;\;\;\frac{x}{\frac{z}{\mathsf{fma}\left(-0.16666666666666666, \left|y\right| \cdot \left|y\right|, 1\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{z} - z\right) + \left(\frac{1}{z} + z\right)}{2} \cdot x\\
\end{array}
if y < 1.3500000000000001Initial program 96.0%
Taylor expanded in y around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6452.0%
Applied rewrites52.0%
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6451.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.7%
lift-pow.f64N/A
unpow2N/A
lower-*.f6451.7%
Applied rewrites51.7%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
div-flip-revN/A
lower-/.f64N/A
lower-/.f6452.0%
lift-fma.f64N/A
*-commutativeN/A
rem-exp-logN/A
lift-log.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-+.f6452.0%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites52.0%
if 1.3500000000000001 < y Initial program 96.0%
Taylor expanded in y around 0
lower-/.f6457.4%
Applied rewrites57.4%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6457.2%
Applied rewrites57.2%
lift-/.f64N/A
inv-powN/A
pow-to-expN/A
lower-unsound-exp.f64N/A
lower-unsound-*.f64N/A
lower-unsound-log.f6426.9%
Applied rewrites26.9%
lift-exp.f64N/A
sinh-+-cosh-revN/A
+-commutativeN/A
sinh-defN/A
cosh-defN/A
div-add-revN/A
lower-/.f64N/A
Applied rewrites46.2%
(FPCore (x y z) :precision binary64 (if (<= (fabs y) 1.35) (/ x (/ z (fma -0.16666666666666666 (* (fabs y) (fabs y)) 1.0))) (/ (* x (fabs y)) (* z (fabs y)))))
double code(double x, double y, double z) {
double tmp;
if (fabs(y) <= 1.35) {
tmp = x / (z / fma(-0.16666666666666666, (fabs(y) * fabs(y)), 1.0));
} else {
tmp = (x * fabs(y)) / (z * fabs(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (abs(y) <= 1.35) tmp = Float64(x / Float64(z / fma(-0.16666666666666666, Float64(abs(y) * abs(y)), 1.0))); else tmp = Float64(Float64(x * abs(y)) / Float64(z * abs(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[Abs[y], $MachinePrecision], 1.35], N[(x / N[(z / N[(-0.16666666666666666 * N[(N[Abs[y], $MachinePrecision] * N[Abs[y], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Abs[y], $MachinePrecision]), $MachinePrecision] / N[(z * N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|y\right| \leq 1.35:\\
\;\;\;\;\frac{x}{\frac{z}{\mathsf{fma}\left(-0.16666666666666666, \left|y\right| \cdot \left|y\right|, 1\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left|y\right|}{z \cdot \left|y\right|}\\
\end{array}
if y < 1.3500000000000001Initial program 96.0%
Taylor expanded in y around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6452.0%
Applied rewrites52.0%
lift-/.f64N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f6451.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6451.7%
lift-pow.f64N/A
unpow2N/A
lower-*.f6451.7%
Applied rewrites51.7%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
div-flip-revN/A
lower-/.f64N/A
lower-/.f6452.0%
lift-fma.f64N/A
*-commutativeN/A
rem-exp-logN/A
lift-log.f64N/A
lift-exp.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-+.f6452.0%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites52.0%
if 1.3500000000000001 < y Initial program 96.0%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-/l/N/A
frac-2negN/A
distribute-neg-frac2N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
distribute-rgt-neg-inN/A
remove-double-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6484.2%
Applied rewrites84.2%
Taylor expanded in y around 0
lower-*.f6448.9%
Applied rewrites48.9%
(FPCore (x y z) :precision binary64 (if (<= (fabs y) 1.35) (* (/ x z) (fma (* (fabs y) (fabs y)) -0.16666666666666666 1.0)) (/ (* x (fabs y)) (* z (fabs y)))))
double code(double x, double y, double z) {
double tmp;
if (fabs(y) <= 1.35) {
tmp = (x / z) * fma((fabs(y) * fabs(y)), -0.16666666666666666, 1.0);
} else {
tmp = (x * fabs(y)) / (z * fabs(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (abs(y) <= 1.35) tmp = Float64(Float64(x / z) * fma(Float64(abs(y) * abs(y)), -0.16666666666666666, 1.0)); else tmp = Float64(Float64(x * abs(y)) / Float64(z * abs(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[Abs[y], $MachinePrecision], 1.35], N[(N[(x / z), $MachinePrecision] * N[(N[(N[Abs[y], $MachinePrecision] * N[Abs[y], $MachinePrecision]), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Abs[y], $MachinePrecision]), $MachinePrecision] / N[(z * N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|y\right| \leq 1.35:\\
\;\;\;\;\frac{x}{z} \cdot \mathsf{fma}\left(\left|y\right| \cdot \left|y\right|, -0.16666666666666666, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left|y\right|}{z \cdot \left|y\right|}\\
\end{array}
if y < 1.3500000000000001Initial program 96.0%
Taylor expanded in y around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6452.0%
Applied rewrites52.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6453.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6453.6%
lift-pow.f64N/A
unpow2N/A
lower-*.f6453.6%
Applied rewrites53.6%
if 1.3500000000000001 < y Initial program 96.0%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-/l/N/A
frac-2negN/A
distribute-neg-frac2N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
distribute-rgt-neg-inN/A
remove-double-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6484.2%
Applied rewrites84.2%
Taylor expanded in y around 0
lower-*.f6448.9%
Applied rewrites48.9%
(FPCore (x y z)
:precision binary64
(*
(copysign 1.0 x)
(*
(copysign 1.0 z)
(if (<= (/ (* (fabs x) (/ (sin y) y)) (fabs z)) 0.0)
(/ (* (fabs x) y) (* (fabs z) y))
(/ (fabs x) (fabs z))))))double code(double x, double y, double z) {
double tmp;
if (((fabs(x) * (sin(y) / y)) / fabs(z)) <= 0.0) {
tmp = (fabs(x) * y) / (fabs(z) * y);
} 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)) <= 0.0) {
tmp = (Math.abs(x) * y) / (Math.abs(z) * y);
} 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)) <= 0.0: tmp = (math.fabs(x) * y) / (math.fabs(z) * y) 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)) <= 0.0) tmp = Float64(Float64(abs(x) * y) / Float64(abs(z) * y)); 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)) <= 0.0) tmp = (abs(x) * y) / (abs(z) * y); 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], 0.0], N[(N[(N[Abs[x], $MachinePrecision] * y), $MachinePrecision] / N[(N[Abs[z], $MachinePrecision] * y), $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 0:\\
\;\;\;\;\frac{\left|x\right| \cdot y}{\left|z\right| \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|x\right|}{\left|z\right|}\\
\end{array}\right)
if (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) < -0.0Initial program 96.0%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
associate-/l/N/A
frac-2negN/A
distribute-neg-frac2N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
distribute-rgt-neg-inN/A
remove-double-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6484.2%
Applied rewrites84.2%
Taylor expanded in y around 0
lower-*.f6448.9%
Applied rewrites48.9%
if -0.0 < (/.f64 (*.f64 x (/.f64 (sin.f64 y) y)) z) Initial program 96.0%
Taylor expanded in y around 0
lower-/.f6457.4%
Applied rewrites57.4%
(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 96.0%
Taylor expanded in y around 0
lower-/.f6457.4%
Applied rewrites57.4%
herbie shell --seed 2025212
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
(/ (* x (/ (sin y) y)) z))