
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * y) - (z * y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t): return ((x * y) - (z * y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x * y) - (z * y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * y) - (z * y)) * t
end function
public static double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
def code(x, y, z, t): return ((x * y) - (z * y)) * t
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function tmp = code(x, y, z, t) tmp = ((x * y) - (z * y)) * t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}
y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) t\_m = (fabs.f64 t) t\_s = (copysign.f64 #s(literal 1 binary64) t) NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function. (FPCore (t_s y_s x y_m z t_m) :precision binary64 (* t_s (* y_s (* (- (* x y_m) (* z y_m)) t_m))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
t\_m = fabs(t);
t\_s = copysign(1.0, t);
assert(x < y_m && y_m < z && z < t_m);
double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
return t_s * (y_s * (((x * y_m) - (z * y_m)) * t_m));
}
y\_m = private
y\_s = private
t\_m = private
t\_s = private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(t_s, y_s, x, y_m, z, t_m)
use fmin_fmax_functions
real(8), intent (in) :: t_s
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t_m
code = t_s * (y_s * (((x * y_m) - (z * y_m)) * t_m))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
t\_m = Math.abs(t);
t\_s = Math.copySign(1.0, t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
return t_s * (y_s * (((x * y_m) - (z * y_m)) * t_m));
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) t\_m = math.fabs(t) t\_s = math.copysign(1.0, t) [x, y_m, z, t_m] = sort([x, y_m, z, t_m]) def code(t_s, y_s, x, y_m, z, t_m): return t_s * (y_s * (((x * y_m) - (z * y_m)) * t_m))
y\_m = abs(y) y\_s = copysign(1.0, y) t\_m = abs(t) t\_s = copysign(1.0, t) x, y_m, z, t_m = sort([x, y_m, z, t_m]) function code(t_s, y_s, x, y_m, z, t_m) return Float64(t_s * Float64(y_s * Float64(Float64(Float64(x * y_m) - Float64(z * y_m)) * t_m))) end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
t\_m = abs(t);
t\_s = sign(t) * abs(1.0);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp = code(t_s, y_s, x, y_m, z, t_m)
tmp = t_s * (y_s * (((x * y_m) - (z * y_m)) * t_m));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[t$95$s_, y$95$s_, x_, y$95$m_, z_, t$95$m_] := N[(t$95$s * N[(y$95$s * N[(N[(N[(x * y$95$m), $MachinePrecision] - N[(z * y$95$m), $MachinePrecision]), $MachinePrecision] * t$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
t\_s \cdot \left(y\_s \cdot \left(\left(x \cdot y\_m - z \cdot y\_m\right) \cdot t\_m\right)\right)
\end{array}
Initial program 96.5%
y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) t\_m = (fabs.f64 t) t\_s = (copysign.f64 #s(literal 1 binary64) t) NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function. (FPCore (t_s y_s x y_m z t_m) :precision binary64 (* t_s (* y_s (* (* (- x z) y_m) t_m))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
t\_m = fabs(t);
t\_s = copysign(1.0, t);
assert(x < y_m && y_m < z && z < t_m);
double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
return t_s * (y_s * (((x - z) * y_m) * t_m));
}
y\_m = private
y\_s = private
t\_m = private
t\_s = private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(t_s, y_s, x, y_m, z, t_m)
use fmin_fmax_functions
real(8), intent (in) :: t_s
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t_m
code = t_s * (y_s * (((x - z) * y_m) * t_m))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
t\_m = Math.abs(t);
t\_s = Math.copySign(1.0, t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
return t_s * (y_s * (((x - z) * y_m) * t_m));
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) t\_m = math.fabs(t) t\_s = math.copysign(1.0, t) [x, y_m, z, t_m] = sort([x, y_m, z, t_m]) def code(t_s, y_s, x, y_m, z, t_m): return t_s * (y_s * (((x - z) * y_m) * t_m))
y\_m = abs(y) y\_s = copysign(1.0, y) t\_m = abs(t) t\_s = copysign(1.0, t) x, y_m, z, t_m = sort([x, y_m, z, t_m]) function code(t_s, y_s, x, y_m, z, t_m) return Float64(t_s * Float64(y_s * Float64(Float64(Float64(x - z) * y_m) * t_m))) end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
t\_m = abs(t);
t\_s = sign(t) * abs(1.0);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp = code(t_s, y_s, x, y_m, z, t_m)
tmp = t_s * (y_s * (((x - z) * y_m) * t_m));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[t$95$s_, y$95$s_, x_, y$95$m_, z_, t$95$m_] := N[(t$95$s * N[(y$95$s * N[(N[(N[(x - z), $MachinePrecision] * y$95$m), $MachinePrecision] * t$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
t\_s \cdot \left(y\_s \cdot \left(\left(\left(x - z\right) \cdot y\_m\right) \cdot t\_m\right)\right)
\end{array}
Initial program 96.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6497.1
Applied rewrites97.1%
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
t\_m = (fabs.f64 t)
t\_s = (copysign.f64 #s(literal 1 binary64) t)
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
(FPCore (t_s y_s x y_m z t_m)
:precision binary64
(let* ((t_2 (* t_m (* x y_m))))
(*
t_s
(*
y_s
(if (<= x -7e+149)
t_2
(if (<= x 4.2e+204) (* (* (- x z) t_m) y_m) t_2))))))y\_m = fabs(y);
y\_s = copysign(1.0, y);
t\_m = fabs(t);
t\_s = copysign(1.0, t);
assert(x < y_m && y_m < z && z < t_m);
double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
double t_2 = t_m * (x * y_m);
double tmp;
if (x <= -7e+149) {
tmp = t_2;
} else if (x <= 4.2e+204) {
tmp = ((x - z) * t_m) * y_m;
} else {
tmp = t_2;
}
return t_s * (y_s * tmp);
}
y\_m = private
y\_s = private
t\_m = private
t\_s = private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(t_s, y_s, x, y_m, z, t_m)
use fmin_fmax_functions
real(8), intent (in) :: t_s
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t_m
real(8) :: t_2
real(8) :: tmp
t_2 = t_m * (x * y_m)
if (x <= (-7d+149)) then
tmp = t_2
else if (x <= 4.2d+204) then
tmp = ((x - z) * t_m) * y_m
else
tmp = t_2
end if
code = t_s * (y_s * tmp)
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
t\_m = Math.abs(t);
t\_s = Math.copySign(1.0, t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
double t_2 = t_m * (x * y_m);
double tmp;
if (x <= -7e+149) {
tmp = t_2;
} else if (x <= 4.2e+204) {
tmp = ((x - z) * t_m) * y_m;
} else {
tmp = t_2;
}
return t_s * (y_s * tmp);
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) t\_m = math.fabs(t) t\_s = math.copysign(1.0, t) [x, y_m, z, t_m] = sort([x, y_m, z, t_m]) def code(t_s, y_s, x, y_m, z, t_m): t_2 = t_m * (x * y_m) tmp = 0 if x <= -7e+149: tmp = t_2 elif x <= 4.2e+204: tmp = ((x - z) * t_m) * y_m else: tmp = t_2 return t_s * (y_s * tmp)
y\_m = abs(y) y\_s = copysign(1.0, y) t\_m = abs(t) t\_s = copysign(1.0, t) x, y_m, z, t_m = sort([x, y_m, z, t_m]) function code(t_s, y_s, x, y_m, z, t_m) t_2 = Float64(t_m * Float64(x * y_m)) tmp = 0.0 if (x <= -7e+149) tmp = t_2; elseif (x <= 4.2e+204) tmp = Float64(Float64(Float64(x - z) * t_m) * y_m); else tmp = t_2; end return Float64(t_s * Float64(y_s * tmp)) end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
t\_m = abs(t);
t\_s = sign(t) * abs(1.0);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp_2 = code(t_s, y_s, x, y_m, z, t_m)
t_2 = t_m * (x * y_m);
tmp = 0.0;
if (x <= -7e+149)
tmp = t_2;
elseif (x <= 4.2e+204)
tmp = ((x - z) * t_m) * y_m;
else
tmp = t_2;
end
tmp_2 = t_s * (y_s * tmp);
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[t$95$s_, y$95$s_, x_, y$95$m_, z_, t$95$m_] := Block[{t$95$2 = N[(t$95$m * N[(x * y$95$m), $MachinePrecision]), $MachinePrecision]}, N[(t$95$s * N[(y$95$s * If[LessEqual[x, -7e+149], t$95$2, If[LessEqual[x, 4.2e+204], N[(N[(N[(x - z), $MachinePrecision] * t$95$m), $MachinePrecision] * y$95$m), $MachinePrecision], t$95$2]]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
\begin{array}{l}
t_2 := t\_m \cdot \left(x \cdot y\_m\right)\\
t\_s \cdot \left(y\_s \cdot \begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+149}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{+204}:\\
\;\;\;\;\left(\left(x - z\right) \cdot t\_m\right) \cdot y\_m\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}\right)
\end{array}
\end{array}
if x < -7.00000000000000023e149 or 4.2000000000000001e204 < x Initial program 96.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f6455.8
Applied rewrites55.8%
if -7.00000000000000023e149 < x < 4.2000000000000001e204Initial program 96.5%
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower--.f6487.7
Applied rewrites87.7%
y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) t\_m = (fabs.f64 t) t\_s = (copysign.f64 #s(literal 1 binary64) t) NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function. (FPCore (t_s y_s x y_m z t_m) :precision binary64 (* t_s (* y_s (* t_m (* x y_m)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
t\_m = fabs(t);
t\_s = copysign(1.0, t);
assert(x < y_m && y_m < z && z < t_m);
double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
return t_s * (y_s * (t_m * (x * y_m)));
}
y\_m = private
y\_s = private
t\_m = private
t\_s = private
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
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(t_s, y_s, x, y_m, z, t_m)
use fmin_fmax_functions
real(8), intent (in) :: t_s
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8), intent (in) :: t_m
code = t_s * (y_s * (t_m * (x * y_m)))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
t\_m = Math.abs(t);
t\_s = Math.copySign(1.0, t);
assert x < y_m && y_m < z && z < t_m;
public static double code(double t_s, double y_s, double x, double y_m, double z, double t_m) {
return t_s * (y_s * (t_m * (x * y_m)));
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) t\_m = math.fabs(t) t\_s = math.copysign(1.0, t) [x, y_m, z, t_m] = sort([x, y_m, z, t_m]) def code(t_s, y_s, x, y_m, z, t_m): return t_s * (y_s * (t_m * (x * y_m)))
y\_m = abs(y) y\_s = copysign(1.0, y) t\_m = abs(t) t\_s = copysign(1.0, t) x, y_m, z, t_m = sort([x, y_m, z, t_m]) function code(t_s, y_s, x, y_m, z, t_m) return Float64(t_s * Float64(y_s * Float64(t_m * Float64(x * y_m)))) end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
t\_m = abs(t);
t\_s = sign(t) * abs(1.0);
x, y_m, z, t_m = num2cell(sort([x, y_m, z, t_m])){:}
function tmp = code(t_s, y_s, x, y_m, z, t_m)
tmp = t_s * (y_s * (t_m * (x * y_m)));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y_m, z, and t_m should be sorted in increasing order before calling this function.
code[t$95$s_, y$95$s_, x_, y$95$m_, z_, t$95$m_] := N[(t$95$s * N[(y$95$s * N[(t$95$m * N[(x * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
[x, y_m, z, t_m] = \mathsf{sort}([x, y_m, z, t_m])\\
\\
t\_s \cdot \left(y\_s \cdot \left(t\_m \cdot \left(x \cdot y\_m\right)\right)\right)
\end{array}
Initial program 96.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f6455.8
Applied rewrites55.8%
herbie shell --seed 2025162
(FPCore (x y z t)
:name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
:precision binary64
(* (- (* x y) (* z y)) t))