
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - 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 * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - 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 * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= x_m 1.42e+184) (fma x_m x_m (* (* -4.0 y) (- (* z z) t))) (fma (* -1.0 t) (* -4.0 y) (* x_m x_m))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (x_m <= 1.42e+184) {
tmp = fma(x_m, x_m, ((-4.0 * y) * ((z * z) - t)));
} else {
tmp = fma((-1.0 * t), (-4.0 * y), (x_m * x_m));
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (x_m <= 1.42e+184) tmp = fma(x_m, x_m, Float64(Float64(-4.0 * y) * Float64(Float64(z * z) - t))); else tmp = fma(Float64(-1.0 * t), Float64(-4.0 * y), Float64(x_m * x_m)); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[x$95$m, 1.42e+184], N[(x$95$m * x$95$m + N[(N[(-4.0 * y), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * t), $MachinePrecision] * N[(-4.0 * y), $MachinePrecision] + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.42 \cdot 10^{+184}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(-4 \cdot y\right) \cdot \left(z \cdot z - t\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1 \cdot t, -4 \cdot y, x\_m \cdot x\_m\right)\\
\end{array}
\end{array}
if x < 1.42000000000000002e184Initial program 90.2%
lift--.f64N/A
sub-flipN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval92.5
Applied rewrites92.5%
if 1.42000000000000002e184 < x Initial program 90.2%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval91.3
Applied rewrites91.3%
Taylor expanded in z around 0
lower-*.f6467.3
Applied rewrites67.3%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (fma (* -1.0 t) (* -4.0 y) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return fma((-1.0 * t), (-4.0 * y), (x_m * x_m));
}
x_m = abs(x) function code(x_m, y, z, t) return fma(Float64(-1.0 * t), Float64(-4.0 * y), Float64(x_m * x_m)) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(N[(-1.0 * t), $MachinePrecision] * N[(-4.0 * y), $MachinePrecision] + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\mathsf{fma}\left(-1 \cdot t, -4 \cdot y, x\_m \cdot x\_m\right)
\end{array}
Initial program 90.2%
lift--.f64N/A
sub-flipN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval91.3
Applied rewrites91.3%
Taylor expanded in z around 0
lower-*.f6467.3
Applied rewrites67.3%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (fma x_m x_m (* 4.0 (* t y))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return fma(x_m, x_m, (4.0 * (t * y)));
}
x_m = abs(x) function code(x_m, y, z, t) return fma(x_m, x_m, Float64(4.0 * Float64(t * y))) end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(x$95$m * x$95$m + N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\mathsf{fma}\left(x\_m, x\_m, 4 \cdot \left(t \cdot y\right)\right)
\end{array}
Initial program 90.2%
lift--.f64N/A
sub-flipN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval92.5
Applied rewrites92.5%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
flip--N/A
difference-of-squares-revN/A
lift-*.f64N/A
lift-fma.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
associate-*l/N/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
Applied rewrites54.7%
Taylor expanded in z around 0
lower-*.f64N/A
lower-*.f6466.9
Applied rewrites66.9%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= (- (* x_m x_m) (* (* y 4.0) (- (* z z) t))) -5e-216) (* 4.0 (* t y)) (fabs (/ 1.0 (/ 0.25 (* y t))))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (((x_m * x_m) - ((y * 4.0) * ((z * z) - t))) <= -5e-216) {
tmp = 4.0 * (t * y);
} else {
tmp = fabs((1.0 / (0.25 / (y * t))));
}
return tmp;
}
x_m = private
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_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (((x_m * x_m) - ((y * 4.0d0) * ((z * z) - t))) <= (-5d-216)) then
tmp = 4.0d0 * (t * y)
else
tmp = abs((1.0d0 / (0.25d0 / (y * t))))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if (((x_m * x_m) - ((y * 4.0) * ((z * z) - t))) <= -5e-216) {
tmp = 4.0 * (t * y);
} else {
tmp = Math.abs((1.0 / (0.25 / (y * t))));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if ((x_m * x_m) - ((y * 4.0) * ((z * z) - t))) <= -5e-216: tmp = 4.0 * (t * y) else: tmp = math.fabs((1.0 / (0.25 / (y * t)))) return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (Float64(Float64(x_m * x_m) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) <= -5e-216) tmp = Float64(4.0 * Float64(t * y)); else tmp = abs(Float64(1.0 / Float64(0.25 / Float64(y * t)))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if (((x_m * x_m) - ((y * 4.0) * ((z * z) - t))) <= -5e-216) tmp = 4.0 * (t * y); else tmp = abs((1.0 / (0.25 / (y * t)))); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -5e-216], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[Abs[N[(1.0 / N[(0.25 / N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \leq -5 \cdot 10^{-216}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{1}{\frac{0.25}{y \cdot t}}\right|\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < -5.00000000000000021e-216Initial program 90.2%
Taylor expanded in t around inf
lower-*.f64N/A
lower-*.f6431.6
Applied rewrites31.6%
if -5.00000000000000021e-216 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 90.2%
lift--.f64N/A
flip--N/A
div-flipN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites25.4%
Taylor expanded in t around inf
lower-/.f64N/A
lower-*.f6431.5
Applied rewrites31.5%
lift-/.f64N/A
inv-powN/A
pow-to-expN/A
exp-fabsN/A
pow-to-expN/A
Applied rewrites20.0%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (* 4.0 (* t y)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return 4.0 * (t * y);
}
x_m = private
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_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 4.0d0 * (t * y)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return 4.0 * (t * y);
}
x_m = math.fabs(x) def code(x_m, y, z, t): return 4.0 * (t * y)
x_m = abs(x) function code(x_m, y, z, t) return Float64(4.0 * Float64(t * y)) end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = 4.0 * (t * y); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 90.2%
Taylor expanded in t around inf
lower-*.f64N/A
lower-*.f6431.6
Applied rewrites31.6%
herbie shell --seed 2025150
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
(- (* x x) (* (* y 4.0) (- (* z z) t))))