
(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]
\left(x \cdot y - z \cdot y\right) \cdot t
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]
\left(x \cdot y - z \cdot y\right) \cdot t
(FPCore (x y z t) :precision binary64 (* (copysign 1.0 y) (* (copysign 1.0 t) (* (* (- x z) (fmin (fabs y) (fabs t))) (fmax (fabs y) (fabs t))))))
double code(double x, double y, double z, double t) {
return copysign(1.0, y) * (copysign(1.0, t) * (((x - z) * fmin(fabs(y), fabs(t))) * fmax(fabs(y), fabs(t))));
}
public static double code(double x, double y, double z, double t) {
return Math.copySign(1.0, y) * (Math.copySign(1.0, t) * (((x - z) * fmin(Math.abs(y), Math.abs(t))) * fmax(Math.abs(y), Math.abs(t))));
}
def code(x, y, z, t): return math.copysign(1.0, y) * (math.copysign(1.0, t) * (((x - z) * fmin(math.fabs(y), math.fabs(t))) * fmax(math.fabs(y), math.fabs(t))))
function code(x, y, z, t) return Float64(copysign(1.0, y) * Float64(copysign(1.0, t) * Float64(Float64(Float64(x - z) * fmin(abs(y), abs(t))) * fmax(abs(y), abs(t))))) end
function tmp = code(x, y, z, t) tmp = (sign(y) * abs(1.0)) * ((sign(t) * abs(1.0)) * (((x - z) * min(abs(y), abs(t))) * max(abs(y), abs(t)))); end
code[x_, y_, z_, t_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[(N[(x - z), $MachinePrecision] * N[Min[N[Abs[y], $MachinePrecision], N[Abs[t], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Max[N[Abs[y], $MachinePrecision], N[Abs[t], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, y\right) \cdot \left(\mathsf{copysign}\left(1, t\right) \cdot \left(\left(\left(x - z\right) \cdot \mathsf{min}\left(\left|y\right|, \left|t\right|\right)\right) \cdot \mathsf{max}\left(\left|y\right|, \left|t\right|\right)\right)\right)
Initial program 90.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.7%
Applied rewrites91.7%
(FPCore (x y z t) :precision binary64 (if (<= x 4.8e+216) (* (* (- x z) (fmax y t)) (fmin y t)) (* (fmax y t) (* x (fmin y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 4.8e+216) {
tmp = ((x - z) * fmax(y, t)) * fmin(y, t);
} else {
tmp = fmax(y, t) * (x * fmin(y, t));
}
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, 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
real(8) :: tmp
if (x <= 4.8d+216) then
tmp = ((x - z) * fmax(y, t)) * fmin(y, t)
else
tmp = fmax(y, t) * (x * fmin(y, t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 4.8e+216) {
tmp = ((x - z) * fmax(y, t)) * fmin(y, t);
} else {
tmp = fmax(y, t) * (x * fmin(y, t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 4.8e+216: tmp = ((x - z) * fmax(y, t)) * fmin(y, t) else: tmp = fmax(y, t) * (x * fmin(y, t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 4.8e+216) tmp = Float64(Float64(Float64(x - z) * fmax(y, t)) * fmin(y, t)); else tmp = Float64(fmax(y, t) * Float64(x * fmin(y, t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 4.8e+216) tmp = ((x - z) * max(y, t)) * min(y, t); else tmp = max(y, t) * (x * min(y, t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 4.8e+216], N[(N[(N[(x - z), $MachinePrecision] * N[Max[y, t], $MachinePrecision]), $MachinePrecision] * N[Min[y, t], $MachinePrecision]), $MachinePrecision], N[(N[Max[y, t], $MachinePrecision] * N[(x * N[Min[y, t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;x \leq 4.8 \cdot 10^{+216}:\\
\;\;\;\;\left(\left(x - z\right) \cdot \mathsf{max}\left(y, t\right)\right) \cdot \mathsf{min}\left(y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{max}\left(y, t\right) \cdot \left(x \cdot \mathsf{min}\left(y, t\right)\right)\\
\end{array}
if x < 4.7999999999999999e216Initial program 90.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.7%
Applied rewrites91.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6491.9%
Applied rewrites91.9%
if 4.7999999999999999e216 < x Initial program 90.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f6452.2%
Applied rewrites52.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fmax (fabs y) (fabs t)))
(t_2 (fmin (fabs y) (fabs t)))
(t_3 (- (* t_1 (* t_2 z)))))
(*
(copysign 1.0 y)
(*
(copysign 1.0 t)
(if (<= z -9.2e+34)
t_3
(if (<= z 5000000000.0) (* t_1 (* x t_2)) t_3))))))double code(double x, double y, double z, double t) {
double t_1 = fmax(fabs(y), fabs(t));
double t_2 = fmin(fabs(y), fabs(t));
double t_3 = -(t_1 * (t_2 * z));
double tmp;
if (z <= -9.2e+34) {
tmp = t_3;
} else if (z <= 5000000000.0) {
tmp = t_1 * (x * t_2);
} else {
tmp = t_3;
}
return copysign(1.0, y) * (copysign(1.0, t) * tmp);
}
public static double code(double x, double y, double z, double t) {
double t_1 = fmax(Math.abs(y), Math.abs(t));
double t_2 = fmin(Math.abs(y), Math.abs(t));
double t_3 = -(t_1 * (t_2 * z));
double tmp;
if (z <= -9.2e+34) {
tmp = t_3;
} else if (z <= 5000000000.0) {
tmp = t_1 * (x * t_2);
} else {
tmp = t_3;
}
return Math.copySign(1.0, y) * (Math.copySign(1.0, t) * tmp);
}
def code(x, y, z, t): t_1 = fmax(math.fabs(y), math.fabs(t)) t_2 = fmin(math.fabs(y), math.fabs(t)) t_3 = -(t_1 * (t_2 * z)) tmp = 0 if z <= -9.2e+34: tmp = t_3 elif z <= 5000000000.0: tmp = t_1 * (x * t_2) else: tmp = t_3 return math.copysign(1.0, y) * (math.copysign(1.0, t) * tmp)
function code(x, y, z, t) t_1 = fmax(abs(y), abs(t)) t_2 = fmin(abs(y), abs(t)) t_3 = Float64(-Float64(t_1 * Float64(t_2 * z))) tmp = 0.0 if (z <= -9.2e+34) tmp = t_3; elseif (z <= 5000000000.0) tmp = Float64(t_1 * Float64(x * t_2)); else tmp = t_3; end return Float64(copysign(1.0, y) * Float64(copysign(1.0, t) * tmp)) end
function tmp_2 = code(x, y, z, t) t_1 = max(abs(y), abs(t)); t_2 = min(abs(y), abs(t)); t_3 = -(t_1 * (t_2 * z)); tmp = 0.0; if (z <= -9.2e+34) tmp = t_3; elseif (z <= 5000000000.0) tmp = t_1 * (x * t_2); else tmp = t_3; end tmp_2 = (sign(y) * abs(1.0)) * ((sign(t) * abs(1.0)) * tmp); end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Max[N[Abs[y], $MachinePrecision], N[Abs[t], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Min[N[Abs[y], $MachinePrecision], N[Abs[t], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = (-N[(t$95$1 * N[(t$95$2 * z), $MachinePrecision]), $MachinePrecision])}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[z, -9.2e+34], t$95$3, If[LessEqual[z, 5000000000.0], N[(t$95$1 * N[(x * t$95$2), $MachinePrecision]), $MachinePrecision], t$95$3]]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_1 := \mathsf{max}\left(\left|y\right|, \left|t\right|\right)\\
t_2 := \mathsf{min}\left(\left|y\right|, \left|t\right|\right)\\
t_3 := -t\_1 \cdot \left(t\_2 \cdot z\right)\\
\mathsf{copysign}\left(1, y\right) \cdot \left(\mathsf{copysign}\left(1, t\right) \cdot \begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+34}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;z \leq 5000000000:\\
\;\;\;\;t\_1 \cdot \left(x \cdot t\_2\right)\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}\right)
\end{array}
if z < -9.1999999999999993e34 or 5e9 < z Initial program 90.3%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
distribute-lft-out--N/A
lower--.f64N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6485.7%
Applied rewrites85.7%
Applied rewrites74.1%
Taylor expanded in x around 0
lower-*.f64N/A
lower-*.f6453.7%
Applied rewrites53.7%
if -9.1999999999999993e34 < z < 5e9Initial program 90.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f6452.2%
Applied rewrites52.2%
(FPCore (x y z t) :precision binary64 (* (copysign 1.0 y) (* (copysign 1.0 t) (* (fmax (fabs y) (fabs t)) (* x (fmin (fabs y) (fabs t)))))))
double code(double x, double y, double z, double t) {
return copysign(1.0, y) * (copysign(1.0, t) * (fmax(fabs(y), fabs(t)) * (x * fmin(fabs(y), fabs(t)))));
}
public static double code(double x, double y, double z, double t) {
return Math.copySign(1.0, y) * (Math.copySign(1.0, t) * (fmax(Math.abs(y), Math.abs(t)) * (x * fmin(Math.abs(y), Math.abs(t)))));
}
def code(x, y, z, t): return math.copysign(1.0, y) * (math.copysign(1.0, t) * (fmax(math.fabs(y), math.fabs(t)) * (x * fmin(math.fabs(y), math.fabs(t)))))
function code(x, y, z, t) return Float64(copysign(1.0, y) * Float64(copysign(1.0, t) * Float64(fmax(abs(y), abs(t)) * Float64(x * fmin(abs(y), abs(t)))))) end
function tmp = code(x, y, z, t) tmp = (sign(y) * abs(1.0)) * ((sign(t) * abs(1.0)) * (max(abs(y), abs(t)) * (x * min(abs(y), abs(t))))); end
code[x_, y_, z_, t_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[Max[N[Abs[y], $MachinePrecision], N[Abs[t], $MachinePrecision]], $MachinePrecision] * N[(x * N[Min[N[Abs[y], $MachinePrecision], N[Abs[t], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, y\right) \cdot \left(\mathsf{copysign}\left(1, t\right) \cdot \left(\mathsf{max}\left(\left|y\right|, \left|t\right|\right) \cdot \left(x \cdot \mathsf{min}\left(\left|y\right|, \left|t\right|\right)\right)\right)\right)
Initial program 90.3%
Taylor expanded in x around inf
lower-*.f64N/A
lower-*.f6452.2%
Applied rewrites52.2%
herbie shell --seed 2025258
(FPCore (x y z t)
:name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
:precision binary64
(* (- (* x y) (* z y)) t))