
(FPCore (x y z) :precision binary64 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * 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 * y) + (z * z)) + (z * z)) + (z * z)
end function
public static double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
def code(x, y, z): return (((x * y) + (z * z)) + (z * z)) + (z * z)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) + Float64(z * z)) + Float64(z * z)) + Float64(z * z)) end
function tmp = code(x, y, z) tmp = (((x * y) + (z * z)) + (z * z)) + (z * z); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * 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 * y) + (z * z)) + (z * z)) + (z * z)
end function
public static double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
def code(x, y, z): return (((x * y) + (z * z)) + (z * z)) + (z * z)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) + Float64(z * z)) + Float64(z * z)) + Float64(z * z)) end
function tmp = code(x, y, z) tmp = (((x * y) + (z * z)) + (z * z)) + (z * z); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma z (+ z z) (fma z z (* y x))))
double code(double x, double y, double z) {
return fma(z, (z + z), fma(z, z, (y * x)));
}
function code(x, y, z) return fma(z, Float64(z + z), fma(z, z, Float64(y * x))) end
code[x_, y_, z_] := N[(z * N[(z + z), $MachinePrecision] + N[(z * z + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, y \cdot x\right)\right)
\end{array}
Initial program 98.5%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
+-commutativeN/A
associate-+r+N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.0
Applied rewrites99.0%
(FPCore (x y z) :precision binary64 (fma (* 3.0 z) z (* y x)))
double code(double x, double y, double z) {
return fma((3.0 * z), z, (y * x));
}
function code(x, y, z) return fma(Float64(3.0 * z), z, Float64(y * x)) end
code[x_, y_, z_] := N[(N[(3.0 * z), $MachinePrecision] * z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3 \cdot z, z, y \cdot x\right)
\end{array}
Initial program 98.5%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
associate-+l+N/A
count-2-revN/A
pow2N/A
+-commutativeN/A
+-commutativeN/A
associate-+r+N/A
pow2N/A
distribute-lft1-inN/A
metadata-evalN/A
associate-*r*N/A
Applied rewrites99.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma z (+ z z) (* x y))))
(if (<= (* x y) -5e-201)
t_0
(if (<= (* x y) 2e-132) (fma z (+ z z) (* z z)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(z, (z + z), (x * y));
double tmp;
if ((x * y) <= -5e-201) {
tmp = t_0;
} else if ((x * y) <= 2e-132) {
tmp = fma(z, (z + z), (z * z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(z, Float64(z + z), Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -5e-201) tmp = t_0; elseif (Float64(x * y) <= 2e-132) tmp = fma(z, Float64(z + z), Float64(z * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(z + z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -5e-201], t$95$0, If[LessEqual[N[(x * y), $MachinePrecision], 2e-132], N[(z * N[(z + z), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(z, z + z, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{-201}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-132}:\\
\;\;\;\;\mathsf{fma}\left(z, z + z, z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999999e-201 or 2e-132 < (*.f64 x y) Initial program 98.1%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
+-commutativeN/A
associate-+r+N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Taylor expanded in x around inf
lower-*.f6484.9
Applied rewrites84.9%
if -4.9999999999999999e-201 < (*.f64 x y) < 2e-132Initial program 99.8%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
+-commutativeN/A
associate-+r+N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
lower-*.f6461.4
Applied rewrites61.4%
Taylor expanded in x around 0
pow2N/A
lift-*.f6483.8
Applied rewrites83.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma z (+ z z) (* x y)))) (if (<= (* x y) -5e-201) t_0 (if (<= (* x y) 2e-132) (* 3.0 (* z z)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(z, (z + z), (x * y));
double tmp;
if ((x * y) <= -5e-201) {
tmp = t_0;
} else if ((x * y) <= 2e-132) {
tmp = 3.0 * (z * z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(z, Float64(z + z), Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -5e-201) tmp = t_0; elseif (Float64(x * y) <= 2e-132) tmp = Float64(3.0 * Float64(z * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(z + z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -5e-201], t$95$0, If[LessEqual[N[(x * y), $MachinePrecision], 2e-132], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(z, z + z, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{-201}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-132}:\\
\;\;\;\;3 \cdot \left(z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999999e-201 or 2e-132 < (*.f64 x y) Initial program 98.1%
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
+-commutativeN/A
associate-+r+N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Taylor expanded in x around inf
lower-*.f6484.9
Applied rewrites84.9%
if -4.9999999999999999e-201 < (*.f64 x y) < 2e-132Initial program 99.8%
Taylor expanded in x around 0
pow2N/A
pow2N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f6483.7
Applied rewrites83.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma z z (* x y)))) (if (<= (* x y) -5e-201) t_0 (if (<= (* x y) 2e-132) (* 3.0 (* z z)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(z, z, (x * y));
double tmp;
if ((x * y) <= -5e-201) {
tmp = t_0;
} else if ((x * y) <= 2e-132) {
tmp = 3.0 * (z * z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(z, z, Float64(x * y)) tmp = 0.0 if (Float64(x * y) <= -5e-201) tmp = t_0; elseif (Float64(x * y) <= 2e-132) tmp = Float64(3.0 * Float64(z * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * z + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -5e-201], t$95$0, If[LessEqual[N[(x * y), $MachinePrecision], 2e-132], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(z, z, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{-201}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-132}:\\
\;\;\;\;3 \cdot \left(z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999999e-201 or 2e-132 < (*.f64 x y) Initial program 98.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6483.9
Applied rewrites83.9%
Taylor expanded in x around 0
pow2N/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-evalN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-eval28.7
Applied rewrites28.7%
lift-*.f64N/A
lift-+.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6428.7
Applied rewrites28.7%
Taylor expanded in x around inf
lift-*.f6484.5
Applied rewrites84.5%
if -4.9999999999999999e-201 < (*.f64 x y) < 2e-132Initial program 99.8%
Taylor expanded in x around 0
pow2N/A
pow2N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f6483.7
Applied rewrites83.7%
(FPCore (x y z) :precision binary64 (if (<= (* x y) -5e-201) (fma z z (* x y)) (if (<= (* x y) 2e-132) (* 3.0 (* z z)) (+ (* y x) (* z z)))))
double code(double x, double y, double z) {
double tmp;
if ((x * y) <= -5e-201) {
tmp = fma(z, z, (x * y));
} else if ((x * y) <= 2e-132) {
tmp = 3.0 * (z * z);
} else {
tmp = (y * x) + (z * z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x * y) <= -5e-201) tmp = fma(z, z, Float64(x * y)); elseif (Float64(x * y) <= 2e-132) tmp = Float64(3.0 * Float64(z * z)); else tmp = Float64(Float64(y * x) + Float64(z * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e-201], N[(z * z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 2e-132], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision], N[(N[(y * x), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{-201}:\\
\;\;\;\;\mathsf{fma}\left(z, z, x \cdot y\right)\\
\mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-132}:\\
\;\;\;\;3 \cdot \left(z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x + z \cdot z\\
\end{array}
\end{array}
if (*.f64 x y) < -4.9999999999999999e-201Initial program 96.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6480.8
Applied rewrites80.8%
Taylor expanded in x around 0
pow2N/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-evalN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-eval27.0
Applied rewrites27.0%
lift-*.f64N/A
lift-+.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6427.0
Applied rewrites27.0%
Taylor expanded in x around inf
lift-*.f6481.8
Applied rewrites81.8%
if -4.9999999999999999e-201 < (*.f64 x y) < 2e-132Initial program 99.8%
Taylor expanded in x around 0
pow2N/A
pow2N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f6483.7
Applied rewrites83.7%
if 2e-132 < (*.f64 x y) Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6487.4
Applied rewrites87.4%
(FPCore (x y z) :precision binary64 (if (<= z 1.02e-8) (* y x) (* 3.0 (* z z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.02e-8) {
tmp = y * x;
} else {
tmp = 3.0 * (z * 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 (z <= 1.02d-8) then
tmp = y * x
else
tmp = 3.0d0 * (z * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.02e-8) {
tmp = y * x;
} else {
tmp = 3.0 * (z * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.02e-8: tmp = y * x else: tmp = 3.0 * (z * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.02e-8) tmp = Float64(y * x); else tmp = Float64(3.0 * Float64(z * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.02e-8) tmp = y * x; else tmp = 3.0 * (z * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.02e-8], N[(y * x), $MachinePrecision], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.02 \cdot 10^{-8}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if z < 1.02000000000000003e-8Initial program 99.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6464.1
Applied rewrites64.1%
if 1.02000000000000003e-8 < z Initial program 97.2%
Taylor expanded in x around 0
pow2N/A
pow2N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f6483.2
Applied rewrites83.2%
(FPCore (x y z) :precision binary64 (if (<= z 4.5e+152) (* y x) (* (+ z z) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.5e+152) {
tmp = y * x;
} else {
tmp = (z + z) * 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 (z <= 4.5d+152) then
tmp = y * x
else
tmp = (z + z) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 4.5e+152) {
tmp = y * x;
} else {
tmp = (z + z) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 4.5e+152: tmp = y * x else: tmp = (z + z) * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 4.5e+152) tmp = Float64(y * x); else tmp = Float64(Float64(z + z) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 4.5e+152) tmp = y * x; else tmp = (z + z) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 4.5e+152], N[(y * x), $MachinePrecision], N[(N[(z + z), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.5 \cdot 10^{+152}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z + z\right) \cdot z\\
\end{array}
\end{array}
if z < 4.5000000000000001e152Initial program 99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6459.2
Applied rewrites59.2%
if 4.5000000000000001e152 < z Initial program 94.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6493.8
Applied rewrites93.8%
lift-*.f64N/A
lift-+.f64N/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
metadata-evalN/A
associate-*l/N/A
Applied rewrites10.9%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6410.9
Applied rewrites10.9%
Taylor expanded in z around inf
count-2-revN/A
pow2N/A
pow2N/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f6497.4
Applied rewrites97.4%
(FPCore (x y z) :precision binary64 (if (<= z 4.5e+152) (* y x) (fma z z 2.0)))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.5e+152) {
tmp = y * x;
} else {
tmp = fma(z, z, 2.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 4.5e+152) tmp = Float64(y * x); else tmp = fma(z, z, 2.0); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 4.5e+152], N[(y * x), $MachinePrecision], N[(z * z + 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.5 \cdot 10^{+152}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, z, 2\right)\\
\end{array}
\end{array}
if z < 4.5000000000000001e152Initial program 99.1%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6459.2
Applied rewrites59.2%
if 4.5000000000000001e152 < z Initial program 94.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6493.8
Applied rewrites93.8%
Taylor expanded in x around 0
pow2N/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-evalN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-eval97.4
Applied rewrites97.4%
lift-*.f64N/A
lift-+.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6497.4
Applied rewrites97.4%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
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 = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 98.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6453.2
Applied rewrites53.2%
(FPCore (x y z) :precision binary64 3.0)
double code(double x, double y, double z) {
return 3.0;
}
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 = 3.0d0
end function
public static double code(double x, double y, double z) {
return 3.0;
}
def code(x, y, z): return 3.0
function code(x, y, z) return 3.0 end
function tmp = code(x, y, z) tmp = 3.0; end
code[x_, y_, z_] := 3.0
\begin{array}{l}
\\
3
\end{array}
Initial program 98.5%
Taylor expanded in x around 0
pow2N/A
pow2N/A
distribute-lft1-inN/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f6453.1
Applied rewrites53.1%
Taylor expanded in z around 0
pow2N/A
*-lft-identityN/A
metadata-evalN/A
associate-*l/N/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-evalN/A
count-2-revN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
flip-+N/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites3.8%
herbie shell --seed 2025110
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
:precision binary64
(+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))