
(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) 4e+277) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* z (* -4.0 (* z y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 4e+277) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = z * (-4.0 * (z * y));
}
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) <= 4d+277) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = z * ((-4.0d0) * (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 4e+277) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 4e+277: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = z * (-4.0 * (z * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 4e+277) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(z * Float64(-4.0 * Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 4e+277) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = z * (-4.0 * (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 4e+277], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+277}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 4.00000000000000001e277Initial program 97.6%
if 4.00000000000000001e277 < (*.f64 z z) Initial program 81.3%
Taylor expanded in z around inf
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6496.3
Simplified96.3%
Final simplification97.2%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+172) (fma 4.0 (* y t) (* x x)) (* z (* -4.0 (* z y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+172) {
tmp = fma(4.0, (y * t), (x * x));
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+172) tmp = fma(4.0, Float64(y * t), Float64(x * x)); else tmp = Float64(z * Float64(-4.0 * Float64(z * y))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+172], N[(4.0 * N[(y * t), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+172}:\\
\;\;\;\;\mathsf{fma}\left(4, y \cdot t, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e172Initial program 97.9%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6488.8
Simplified88.8%
if 1.0000000000000001e172 < (*.f64 z z) Initial program 84.1%
Taylor expanded in z around inf
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6492.0
Simplified92.0%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+172) (* x x) (* z (* -4.0 (* z y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+172) {
tmp = x * x;
} else {
tmp = z * (-4.0 * (z * y));
}
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) <= 1d+172) then
tmp = x * x
else
tmp = z * ((-4.0d0) * (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+172) {
tmp = x * x;
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 1e+172: tmp = x * x else: tmp = z * (-4.0 * (z * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+172) tmp = Float64(x * x); else tmp = Float64(z * Float64(-4.0 * Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 1e+172) tmp = x * x; else tmp = z * (-4.0 * (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+172], N[(x * x), $MachinePrecision], N[(z * N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+172}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e172Initial program 97.9%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6459.1
Simplified59.1%
if 1.0000000000000001e172 < (*.f64 z z) Initial program 84.1%
Taylor expanded in z around inf
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6492.0
Simplified92.0%
Final simplification72.3%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 2.05e+172) (* x x) (* -4.0 (* (* z z) y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2.05e+172) {
tmp = x * x;
} else {
tmp = -4.0 * ((z * z) * y);
}
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) <= 2.05d+172) then
tmp = x * x
else
tmp = (-4.0d0) * ((z * z) * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2.05e+172) {
tmp = x * x;
} else {
tmp = -4.0 * ((z * z) * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 2.05e+172: tmp = x * x else: tmp = -4.0 * ((z * z) * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2.05e+172) tmp = Float64(x * x); else tmp = Float64(-4.0 * Float64(Float64(z * z) * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 2.05e+172) tmp = x * x; else tmp = -4.0 * ((z * z) * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2.05e+172], N[(x * x), $MachinePrecision], N[(-4.0 * N[(N[(z * z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2.05 \cdot 10^{+172}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\left(z \cdot z\right) \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2.05e172Initial program 97.9%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6459.1
Simplified59.1%
if 2.05e172 < (*.f64 z z) Initial program 84.1%
Taylor expanded in z around inf
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
associate-+l+N/A
distribute-rgt-inN/A
Simplified83.1%
Taylor expanded in z around inf
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6483.9
Simplified83.9%
Final simplification69.1%
(FPCore (x y z t) :precision binary64 (if (<= x 400000.0) (* 4.0 (* y t)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 400000.0) {
tmp = 4.0 * (y * t);
} 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 <= 400000.0d0) then
tmp = 4.0d0 * (y * t)
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 <= 400000.0) {
tmp = 4.0 * (y * t);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 400000.0: tmp = 4.0 * (y * t) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 400000.0) tmp = Float64(4.0 * Float64(y * t)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 400000.0) tmp = 4.0 * (y * t); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 400000.0], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 400000:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 4e5Initial program 94.2%
Taylor expanded in t around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6432.6
Simplified32.6%
if 4e5 < x Initial program 87.6%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6477.0
Simplified77.0%
(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 92.3%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6444.9
Simplified44.9%
(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 2024215
(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))))