
(FPCore (z1 z0 z2) :precision binary64 (/ (* z1 z0) z2))
double code(double z1, double z0, double z2) {
return (z1 * z0) / z2;
}
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(z1, z0, z2)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
code = (z1 * z0) / z2
end function
public static double code(double z1, double z0, double z2) {
return (z1 * z0) / z2;
}
def code(z1, z0, z2): return (z1 * z0) / z2
function code(z1, z0, z2) return Float64(Float64(z1 * z0) / z2) end
function tmp = code(z1, z0, z2) tmp = (z1 * z0) / z2; end
code[z1_, z0_, z2_] := N[(N[(z1 * z0), $MachinePrecision] / z2), $MachinePrecision]
\frac{z1 \cdot z0}{z2}
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (z1 z0 z2) :precision binary64 (/ (* z1 z0) z2))
double code(double z1, double z0, double z2) {
return (z1 * z0) / z2;
}
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(z1, z0, z2)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
code = (z1 * z0) / z2
end function
public static double code(double z1, double z0, double z2) {
return (z1 * z0) / z2;
}
def code(z1, z0, z2): return (z1 * z0) / z2
function code(z1, z0, z2) return Float64(Float64(z1 * z0) / z2) end
function tmp = code(z1, z0, z2) tmp = (z1 * z0) / z2; end
code[z1_, z0_, z2_] := N[(N[(z1 * z0), $MachinePrecision] / z2), $MachinePrecision]
\frac{z1 \cdot z0}{z2}
(FPCore (z1 z0 z2)
:precision binary64
(let* ((t_0 (fmin (fabs z1) (fabs z0)))
(t_1 (fmax (fabs z1) (fabs z0))))
(*
(copysign 1.0 z1)
(*
(copysign 1.0 z0)
(*
(copysign 1.0 z2)
(if (<= (/ (* t_0 t_1) (fabs z2)) 1.8e-44)
(* (/ t_1 (fabs z2)) t_0)
(* (/ t_0 (fabs z2)) t_1)))))))double code(double z1, double z0, double z2) {
double t_0 = fmin(fabs(z1), fabs(z0));
double t_1 = fmax(fabs(z1), fabs(z0));
double tmp;
if (((t_0 * t_1) / fabs(z2)) <= 1.8e-44) {
tmp = (t_1 / fabs(z2)) * t_0;
} else {
tmp = (t_0 / fabs(z2)) * t_1;
}
return copysign(1.0, z1) * (copysign(1.0, z0) * (copysign(1.0, z2) * tmp));
}
public static double code(double z1, double z0, double z2) {
double t_0 = fmin(Math.abs(z1), Math.abs(z0));
double t_1 = fmax(Math.abs(z1), Math.abs(z0));
double tmp;
if (((t_0 * t_1) / Math.abs(z2)) <= 1.8e-44) {
tmp = (t_1 / Math.abs(z2)) * t_0;
} else {
tmp = (t_0 / Math.abs(z2)) * t_1;
}
return Math.copySign(1.0, z1) * (Math.copySign(1.0, z0) * (Math.copySign(1.0, z2) * tmp));
}
def code(z1, z0, z2): t_0 = fmin(math.fabs(z1), math.fabs(z0)) t_1 = fmax(math.fabs(z1), math.fabs(z0)) tmp = 0 if ((t_0 * t_1) / math.fabs(z2)) <= 1.8e-44: tmp = (t_1 / math.fabs(z2)) * t_0 else: tmp = (t_0 / math.fabs(z2)) * t_1 return math.copysign(1.0, z1) * (math.copysign(1.0, z0) * (math.copysign(1.0, z2) * tmp))
function code(z1, z0, z2) t_0 = fmin(abs(z1), abs(z0)) t_1 = fmax(abs(z1), abs(z0)) tmp = 0.0 if (Float64(Float64(t_0 * t_1) / abs(z2)) <= 1.8e-44) tmp = Float64(Float64(t_1 / abs(z2)) * t_0); else tmp = Float64(Float64(t_0 / abs(z2)) * t_1); end return Float64(copysign(1.0, z1) * Float64(copysign(1.0, z0) * Float64(copysign(1.0, z2) * tmp))) end
function tmp_2 = code(z1, z0, z2) t_0 = min(abs(z1), abs(z0)); t_1 = max(abs(z1), abs(z0)); tmp = 0.0; if (((t_0 * t_1) / abs(z2)) <= 1.8e-44) tmp = (t_1 / abs(z2)) * t_0; else tmp = (t_0 / abs(z2)) * t_1; end tmp_2 = (sign(z1) * abs(1.0)) * ((sign(z0) * abs(1.0)) * ((sign(z2) * abs(1.0)) * tmp)); end
code[z1_, z0_, z2_] := Block[{t$95$0 = N[Min[N[Abs[z1], $MachinePrecision], N[Abs[z0], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Abs[z1], $MachinePrecision], N[Abs[z0], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(t$95$0 * t$95$1), $MachinePrecision] / N[Abs[z2], $MachinePrecision]), $MachinePrecision], 1.8e-44], N[(N[(t$95$1 / N[Abs[z2], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[(t$95$0 / N[Abs[z2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(\left|z1\right|, \left|z0\right|\right)\\
t_1 := \mathsf{max}\left(\left|z1\right|, \left|z0\right|\right)\\
\mathsf{copysign}\left(1, z1\right) \cdot \left(\mathsf{copysign}\left(1, z0\right) \cdot \left(\mathsf{copysign}\left(1, z2\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{t\_0 \cdot t\_1}{\left|z2\right|} \leq 1.8 \cdot 10^{-44}:\\
\;\;\;\;\frac{t\_1}{\left|z2\right|} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\left|z2\right|} \cdot t\_1\\
\end{array}\right)\right)
\end{array}
if (/.f64 (*.f64 z1 z0) z2) < 1.7999999999999999e-44Initial program 91.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6492.3%
Applied rewrites92.3%
if 1.7999999999999999e-44 < (/.f64 (*.f64 z1 z0) z2) Initial program 91.9%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6492.3%
Applied rewrites92.3%
(FPCore (z1 z0 z2) :precision binary64 (* (/ (fmax z1 z0) z2) (fmin z1 z0)))
double code(double z1, double z0, double z2) {
return (fmax(z1, z0) / z2) * fmin(z1, z0);
}
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(z1, z0, z2)
use fmin_fmax_functions
real(8), intent (in) :: z1
real(8), intent (in) :: z0
real(8), intent (in) :: z2
code = (fmax(z1, z0) / z2) * fmin(z1, z0)
end function
public static double code(double z1, double z0, double z2) {
return (fmax(z1, z0) / z2) * fmin(z1, z0);
}
def code(z1, z0, z2): return (fmax(z1, z0) / z2) * fmin(z1, z0)
function code(z1, z0, z2) return Float64(Float64(fmax(z1, z0) / z2) * fmin(z1, z0)) end
function tmp = code(z1, z0, z2) tmp = (max(z1, z0) / z2) * min(z1, z0); end
code[z1_, z0_, z2_] := N[(N[(N[Max[z1, z0], $MachinePrecision] / z2), $MachinePrecision] * N[Min[z1, z0], $MachinePrecision]), $MachinePrecision]
\frac{\mathsf{max}\left(z1, z0\right)}{z2} \cdot \mathsf{min}\left(z1, z0\right)
Initial program 91.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6492.3%
Applied rewrites92.3%
herbie shell --seed 2025250
(FPCore (z1 z0 z2)
:name "(/ (* z1 z0) z2)"
:precision binary64
(/ (* z1 z0) z2))