
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - 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 - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))
double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - 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 - x) * 6.0d0) * ((2.0d0 / 3.0d0) - z))
end function
public static double code(double x, double y, double z) {
return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z));
}
def code(x, y, z): return x + (((y - x) * 6.0) * ((2.0 / 3.0) - z))
function code(x, y, z) return Float64(x + Float64(Float64(Float64(y - x) * 6.0) * Float64(Float64(2.0 / 3.0) - z))) end
function tmp = code(x, y, z) tmp = x + (((y - x) * 6.0) * ((2.0 / 3.0) - z)); end
code[x_, y_, z_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * 6.0), $MachinePrecision] * N[(N[(2.0 / 3.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\left(y - x\right) \cdot 6\right) \cdot \left(\frac{2}{3} - z\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y x) (fma -6.0 z 4.0) x))
double code(double x, double y, double z) {
return fma((y - x), fma(-6.0, z, 4.0), x);
}
function code(x, y, z) return fma(Float64(y - x), fma(-6.0, z, 4.0), x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * N[(-6.0 * z + 4.0), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, \mathsf{fma}\left(-6, z, 4\right), x\right)
\end{array}
Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (fma -6.0 z 4.0) y)))
(if (<= z -5.5e+80)
t_0
(if (<= z -810.0)
(* (* 6.0 x) z)
(if (<= z 8.5e-12) (fma (- y x) 4.0 x) t_0)))))
double code(double x, double y, double z) {
double t_0 = fma(-6.0, z, 4.0) * y;
double tmp;
if (z <= -5.5e+80) {
tmp = t_0;
} else if (z <= -810.0) {
tmp = (6.0 * x) * z;
} else if (z <= 8.5e-12) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(fma(-6.0, z, 4.0) * y) tmp = 0.0 if (z <= -5.5e+80) tmp = t_0; elseif (z <= -810.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 8.5e-12) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[z, -5.5e+80], t$95$0, If[LessEqual[z, -810.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 8.5e-12], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\mathbf{if}\;z \leq -5.5 \cdot 10^{+80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -810:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.49999999999999967e80 or 8.4999999999999997e-12 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-rgt-inN/A
metadata-evalN/A
fp-cancel-sign-subN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f6461.2
Applied rewrites61.2%
if -5.49999999999999967e80 < z < -810Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6480.1
Applied rewrites80.1%
Taylor expanded in z around inf
Applied rewrites77.0%
Applied rewrites77.0%
if -810 < z < 8.4999999999999997e-12Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.7
Applied rewrites97.7%
(FPCore (x y z)
:precision binary64
(if (<= z -5.5e+80)
(* (* -6.0 z) y)
(if (<= z -810.0)
(* (* 6.0 x) z)
(if (<= z 0.65) (fma (- y x) 4.0 x) (* (* -6.0 y) z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+80) {
tmp = (-6.0 * z) * y;
} else if (z <= -810.0) {
tmp = (6.0 * x) * z;
} else if (z <= 0.65) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = (-6.0 * y) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+80) tmp = Float64(Float64(-6.0 * z) * y); elseif (z <= -810.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 0.65) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(-6.0 * y) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+80], N[(N[(-6.0 * z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[z, -810.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 0.65], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(-6.0 * y), $MachinePrecision] * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+80}:\\
\;\;\;\;\left(-6 \cdot z\right) \cdot y\\
\mathbf{elif}\;z \leq -810:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 0.65:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-6 \cdot y\right) \cdot z\\
\end{array}
\end{array}
if z < -5.49999999999999967e80Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-rgt-inN/A
metadata-evalN/A
fp-cancel-sign-subN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f6460.1
Applied rewrites60.1%
Taylor expanded in z around inf
Applied rewrites60.0%
if -5.49999999999999967e80 < z < -810Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6480.1
Applied rewrites80.1%
Taylor expanded in z around inf
Applied rewrites77.0%
Applied rewrites77.0%
if -810 < z < 0.650000000000000022Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.0
Applied rewrites97.0%
if 0.650000000000000022 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.9
Applied rewrites95.9%
Applied rewrites96.0%
Taylor expanded in x around 0
Applied rewrites58.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* -6.0 y) z)))
(if (<= z -5.5e+80)
t_0
(if (<= z -810.0)
(* (* 6.0 x) z)
(if (<= z 0.65) (fma (- y x) 4.0 x) t_0)))))
double code(double x, double y, double z) {
double t_0 = (-6.0 * y) * z;
double tmp;
if (z <= -5.5e+80) {
tmp = t_0;
} else if (z <= -810.0) {
tmp = (6.0 * x) * z;
} else if (z <= 0.65) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-6.0 * y) * z) tmp = 0.0 if (z <= -5.5e+80) tmp = t_0; elseif (z <= -810.0) tmp = Float64(Float64(6.0 * x) * z); elseif (z <= 0.65) tmp = fma(Float64(y - x), 4.0, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(-6.0 * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -5.5e+80], t$95$0, If[LessEqual[z, -810.0], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[z, 0.65], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-6 \cdot y\right) \cdot z\\
\mathbf{if}\;z \leq -5.5 \cdot 10^{+80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -810:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{elif}\;z \leq 0.65:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.49999999999999967e80 or 0.650000000000000022 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6497.5
Applied rewrites97.5%
Applied rewrites97.5%
Taylor expanded in x around 0
Applied rewrites59.1%
if -5.49999999999999967e80 < z < -810Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6480.1
Applied rewrites80.1%
Taylor expanded in z around inf
Applied rewrites77.0%
Applied rewrites77.0%
if -810 < z < 0.650000000000000022Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.0
Applied rewrites97.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -0.54) (not (<= z 0.6))) (* (* -6.0 (- y x)) z) (fma -3.0 x (* 4.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.54) || !(z <= 0.6)) {
tmp = (-6.0 * (y - x)) * z;
} else {
tmp = fma(-3.0, x, (4.0 * y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -0.54) || !(z <= 0.6)) tmp = Float64(Float64(-6.0 * Float64(y - x)) * z); else tmp = fma(-3.0, x, Float64(4.0 * y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.54], N[Not[LessEqual[z, 0.6]], $MachinePrecision]], N[(N[(-6.0 * N[(y - x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(-3.0 * x + N[(4.0 * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.54 \lor \neg \left(z \leq 0.6\right):\\
\;\;\;\;\left(-6 \cdot \left(y - x\right)\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-3, x, 4 \cdot y\right)\\
\end{array}
\end{array}
if z < -0.54000000000000004 or 0.599999999999999978 < z Initial program 99.8%
Taylor expanded in z around inf
Applied rewrites99.8%
Taylor expanded in z around inf
Applied rewrites96.3%
if -0.54000000000000004 < z < 0.599999999999999978Initial program 99.3%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in z around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
+-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f6497.7
Applied rewrites97.7%
Final simplification97.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.6e+76) (not (<= x 7.8e+66))) (* (fma z 6.0 -3.0) x) (* (fma -6.0 z 4.0) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.6e+76) || !(x <= 7.8e+66)) {
tmp = fma(z, 6.0, -3.0) * x;
} else {
tmp = fma(-6.0, z, 4.0) * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -9.6e+76) || !(x <= 7.8e+66)) tmp = Float64(fma(z, 6.0, -3.0) * x); else tmp = Float64(fma(-6.0, z, 4.0) * y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.6e+76], N[Not[LessEqual[x, 7.8e+66]], $MachinePrecision]], N[(N[(z * 6.0 + -3.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(-6.0 * z + 4.0), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.6 \cdot 10^{+76} \lor \neg \left(x \leq 7.8 \cdot 10^{+66}\right):\\
\;\;\;\;\mathsf{fma}\left(z, 6, -3\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-6, z, 4\right) \cdot y\\
\end{array}
\end{array}
if x < -9.5999999999999999e76 or 7.8000000000000007e66 < x Initial program 99.5%
Taylor expanded in x around 0
Applied rewrites99.8%
Taylor expanded in x around inf
distribute-lft-inN/A
fp-cancel-sign-sub-invN/A
*-rgt-identityN/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-rgt-inN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
Applied rewrites89.4%
if -9.5999999999999999e76 < x < 7.8000000000000007e66Initial program 99.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-rgt-inN/A
metadata-evalN/A
fp-cancel-sign-subN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
+-commutativeN/A
lower-fma.f6479.7
Applied rewrites79.7%
Final simplification83.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -810.0) (not (<= z 0.6))) (* (* 6.0 x) z) (fma (- y x) 4.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -810.0) || !(z <= 0.6)) {
tmp = (6.0 * x) * z;
} else {
tmp = fma((y - x), 4.0, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -810.0) || !(z <= 0.6)) tmp = Float64(Float64(6.0 * x) * z); else tmp = fma(Float64(y - x), 4.0, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -810.0], N[Not[LessEqual[z, 0.6]], $MachinePrecision]], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -810 \lor \neg \left(z \leq 0.6\right):\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\end{array}
\end{array}
if z < -810 or 0.599999999999999978 < z Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6447.6
Applied rewrites47.6%
Taylor expanded in z around inf
Applied rewrites46.7%
Applied rewrites46.7%
if -810 < z < 0.599999999999999978Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.0
Applied rewrites97.0%
Final simplification72.6%
(FPCore (x y z) :precision binary64 (if (<= z -810.0) (* (* x z) 6.0) (if (<= z 0.6) (fma (- y x) 4.0 x) (* (* z 6.0) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -810.0) {
tmp = (x * z) * 6.0;
} else if (z <= 0.6) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = (z * 6.0) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -810.0) tmp = Float64(Float64(x * z) * 6.0); elseif (z <= 0.6) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(z * 6.0) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -810.0], N[(N[(x * z), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[z, 0.6], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(z * 6.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -810:\\
\;\;\;\;\left(x \cdot z\right) \cdot 6\\
\mathbf{elif}\;z \leq 0.6:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot 6\right) \cdot x\\
\end{array}
\end{array}
if z < -810Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6452.8
Applied rewrites52.8%
Taylor expanded in z around inf
Applied rewrites52.0%
Applied rewrites52.0%
if -810 < z < 0.599999999999999978Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.0
Applied rewrites97.0%
if 0.599999999999999978 < z Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6442.9
Applied rewrites42.9%
Taylor expanded in z around inf
Applied rewrites41.9%
(FPCore (x y z) :precision binary64 (if (<= z -810.0) (* (* x z) 6.0) (if (<= z 0.6) (fma (- y x) 4.0 x) (* (* 6.0 x) z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -810.0) {
tmp = (x * z) * 6.0;
} else if (z <= 0.6) {
tmp = fma((y - x), 4.0, x);
} else {
tmp = (6.0 * x) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -810.0) tmp = Float64(Float64(x * z) * 6.0); elseif (z <= 0.6) tmp = fma(Float64(y - x), 4.0, x); else tmp = Float64(Float64(6.0 * x) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -810.0], N[(N[(x * z), $MachinePrecision] * 6.0), $MachinePrecision], If[LessEqual[z, 0.6], N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision], N[(N[(6.0 * x), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -810:\\
\;\;\;\;\left(x \cdot z\right) \cdot 6\\
\mathbf{elif}\;z \leq 0.6:\\
\;\;\;\;\mathsf{fma}\left(y - x, 4, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(6 \cdot x\right) \cdot z\\
\end{array}
\end{array}
if z < -810Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6452.8
Applied rewrites52.8%
Taylor expanded in z around inf
Applied rewrites52.0%
Applied rewrites52.0%
if -810 < z < 0.599999999999999978Initial program 99.3%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6497.0
Applied rewrites97.0%
if 0.599999999999999978 < z Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f6442.9
Applied rewrites42.9%
Taylor expanded in z around inf
Applied rewrites41.9%
Applied rewrites41.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.12e+77) (not (<= x 1.75e-57))) (* -3.0 x) (* 4.0 y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.12e+77) || !(x <= 1.75e-57)) {
tmp = -3.0 * x;
} else {
tmp = 4.0 * 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 ((x <= (-1.12d+77)) .or. (.not. (x <= 1.75d-57))) then
tmp = (-3.0d0) * x
else
tmp = 4.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.12e+77) || !(x <= 1.75e-57)) {
tmp = -3.0 * x;
} else {
tmp = 4.0 * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.12e+77) or not (x <= 1.75e-57): tmp = -3.0 * x else: tmp = 4.0 * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.12e+77) || !(x <= 1.75e-57)) tmp = Float64(-3.0 * x); else tmp = Float64(4.0 * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.12e+77) || ~((x <= 1.75e-57))) tmp = -3.0 * x; else tmp = 4.0 * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.12e+77], N[Not[LessEqual[x, 1.75e-57]], $MachinePrecision]], N[(-3.0 * x), $MachinePrecision], N[(4.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{+77} \lor \neg \left(x \leq 1.75 \cdot 10^{-57}\right):\\
\;\;\;\;-3 \cdot x\\
\mathbf{else}:\\
\;\;\;\;4 \cdot y\\
\end{array}
\end{array}
if x < -1.1199999999999999e77 or 1.74999999999999996e-57 < x Initial program 99.6%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6448.5
Applied rewrites48.5%
Taylor expanded in x around inf
Applied rewrites42.8%
if -1.1199999999999999e77 < x < 1.74999999999999996e-57Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6455.0
Applied rewrites55.0%
Taylor expanded in x around 0
Applied rewrites46.8%
Final simplification44.8%
(FPCore (x y z) :precision binary64 (fma (- y x) 4.0 x))
double code(double x, double y, double z) {
return fma((y - x), 4.0, x);
}
function code(x, y, z) return fma(Float64(y - x), 4.0, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * 4.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, 4, x\right)
\end{array}
Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6451.7
Applied rewrites51.7%
(FPCore (x y z) :precision binary64 (* -3.0 x))
double code(double x, double y, double z) {
return -3.0 * 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 = (-3.0d0) * x
end function
public static double code(double x, double y, double z) {
return -3.0 * x;
}
def code(x, y, z): return -3.0 * x
function code(x, y, z) return Float64(-3.0 * x) end
function tmp = code(x, y, z) tmp = -3.0 * x; end
code[x_, y_, z_] := N[(-3.0 * x), $MachinePrecision]
\begin{array}{l}
\\
-3 \cdot x
\end{array}
Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6451.7
Applied rewrites51.7%
Taylor expanded in x around inf
Applied rewrites27.1%
herbie shell --seed 2024360
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, D"
:precision binary64
(+ x (* (* (- y x) 6.0) (- (/ 2.0 3.0) z))))