
(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));
}
real(8) function code(x, y, z, t)
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}
Sampling outcomes in binary64 precision:
Herbie found 6 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));
}
real(8) function code(x, y, z, t)
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}
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e+168) (fma x x (* (* (- (* z z) t) -4.0) y)) (fma (* -4.0 z) (* y z) (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+168) {
tmp = fma(x, x, ((((z * z) - t) * -4.0) * y));
} else {
tmp = fma((-4.0 * z), (y * z), (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+168) tmp = fma(x, x, Float64(Float64(Float64(Float64(z * z) - t) * -4.0) * y)); else tmp = fma(Float64(-4.0 * z), Float64(y * z), Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+168], N[(x * x + N[(N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * -4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(N[(-4.0 * z), $MachinePrecision] * N[(y * z), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+168}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(\left(z \cdot z - t\right) \cdot -4\right) \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-4 \cdot z, y \cdot z, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 4.99999999999999967e168Initial program 98.1%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval98.7
Applied rewrites98.7%
if 4.99999999999999967e168 < (*.f64 z z) Initial program 80.0%
Taylor expanded in t around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6480.0
Applied rewrites80.0%
Applied rewrites97.8%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e-324) (* (* t 4.0) y) (if (<= (* z z) 1e+144) (* x x) (* (* (* -4.0 y) z) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e-324) {
tmp = (t * 4.0) * y;
} else if ((z * z) <= 1e+144) {
tmp = x * x;
} else {
tmp = ((-4.0 * y) * z) * z;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z * z) <= 5d-324) then
tmp = (t * 4.0d0) * y
else if ((z * z) <= 1d+144) then
tmp = x * x
else
tmp = (((-4.0d0) * y) * z) * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e-324) {
tmp = (t * 4.0) * y;
} else if ((z * z) <= 1e+144) {
tmp = x * x;
} else {
tmp = ((-4.0 * y) * z) * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 5e-324: tmp = (t * 4.0) * y elif (z * z) <= 1e+144: tmp = x * x else: tmp = ((-4.0 * y) * z) * z return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e-324) tmp = Float64(Float64(t * 4.0) * y); elseif (Float64(z * z) <= 1e+144) tmp = Float64(x * x); else tmp = Float64(Float64(Float64(-4.0 * y) * z) * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 5e-324) tmp = (t * 4.0) * y; elseif ((z * z) <= 1e+144) tmp = x * x; else tmp = ((-4.0 * y) * z) * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e-324], N[(N[(t * 4.0), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+144], N[(x * x), $MachinePrecision], N[(N[(N[(-4.0 * y), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-324}:\\
\;\;\;\;\left(t \cdot 4\right) \cdot y\\
\mathbf{elif}\;z \cdot z \leq 10^{+144}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-4 \cdot y\right) \cdot z\right) \cdot z\\
\end{array}
\end{array}
if (*.f64 z z) < 4.94066e-324Initial program 100.0%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6464.3
Applied rewrites64.3%
Applied rewrites64.3%
if 4.94066e-324 < (*.f64 z z) < 1.00000000000000002e144Initial program 97.6%
Taylor expanded in t around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6470.7
Applied rewrites70.7%
Taylor expanded in x around inf
Applied rewrites64.2%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6458.1
Applied rewrites58.1%
if 1.00000000000000002e144 < (*.f64 z z) Initial program 80.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6475.6
Applied rewrites75.6%
Applied rewrites84.6%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+42) (fma (* t 4.0) y (* x x)) (fma (* -4.0 z) (* y z) (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+42) {
tmp = fma((t * 4.0), y, (x * x));
} else {
tmp = fma((-4.0 * z), (y * z), (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+42) tmp = fma(Float64(t * 4.0), y, Float64(x * x)); else tmp = fma(Float64(-4.0 * z), Float64(y * z), Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+42], N[(N[(t * 4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(-4.0 * z), $MachinePrecision] * N[(y * z), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(t \cdot 4, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-4 \cdot z, y \cdot z, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.00000000000000004e42Initial program 98.5%
Taylor expanded in z around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6493.2
Applied rewrites93.2%
Applied rewrites93.9%
if 1.00000000000000004e42 < (*.f64 z z) Initial program 83.0%
Taylor expanded in t around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6480.6
Applied rewrites80.6%
Applied rewrites95.0%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+144) (fma (* t 4.0) y (* x x)) (* (* (* -4.0 y) z) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+144) {
tmp = fma((t * 4.0), y, (x * x));
} else {
tmp = ((-4.0 * y) * z) * z;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+144) tmp = fma(Float64(t * 4.0), y, Float64(x * x)); else tmp = Float64(Float64(Float64(-4.0 * y) * z) * z); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+144], N[(N[(t * 4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-4.0 * y), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+144}:\\
\;\;\;\;\mathsf{fma}\left(t \cdot 4, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-4 \cdot y\right) \cdot z\right) \cdot z\\
\end{array}
\end{array}
if (*.f64 z z) < 1.00000000000000002e144Initial program 98.7%
Taylor expanded in z around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6491.9
Applied rewrites91.9%
Applied rewrites92.6%
if 1.00000000000000002e144 < (*.f64 z z) Initial program 80.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6475.6
Applied rewrites75.6%
Applied rewrites84.6%
(FPCore (x y z t) :precision binary64 (if (<= x 4.8e+92) (* (* t 4.0) y) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 4.8e+92) {
tmp = (t * 4.0) * y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y, z, t)
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+92) then
tmp = (t * 4.0d0) * y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 4.8e+92) {
tmp = (t * 4.0) * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 4.8e+92: tmp = (t * 4.0) * y else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 4.8e+92) tmp = Float64(Float64(t * 4.0) * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 4.8e+92) tmp = (t * 4.0) * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 4.8e+92], N[(N[(t * 4.0), $MachinePrecision] * y), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.8 \cdot 10^{+92}:\\
\;\;\;\;\left(t \cdot 4\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 4.80000000000000009e92Initial program 91.5%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6437.0
Applied rewrites37.0%
Applied rewrites37.0%
if 4.80000000000000009e92 < x Initial program 90.2%
Taylor expanded in t around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.7
Applied rewrites92.7%
Taylor expanded in x around inf
Applied rewrites100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6483.6
Applied rewrites83.6%
(FPCore (x y z t) :precision binary64 (* x x))
double code(double x, double y, double z, double t) {
return x * x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x * x
end function
public static double code(double x, double y, double z, double t) {
return x * x;
}
def code(x, y, z, t): return x * x
function code(x, y, z, t) return Float64(x * x) end
function tmp = code(x, y, z, t) tmp = x * x; end
code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 91.3%
Taylor expanded in t around 0
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6467.6
Applied rewrites67.6%
Taylor expanded in x around inf
Applied rewrites64.4%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6440.7
Applied rewrites40.7%
(FPCore (x y z t) :precision binary64 (- (* x x) (* 4.0 (* y (- (* z z) t)))))
double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * x) - (4.0d0 * (y * ((z * z) - t)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
def code(x, y, z, t): return (x * x) - (4.0 * (y * ((z * z) - t)))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(4.0 * Float64(y * Float64(Float64(z * z) - t)))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (4.0 * (y * ((z * z) - t))); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)
\end{array}
herbie shell --seed 2024320
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))