
(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 7 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+251) (fma (fma z z (- t)) (* y -4.0) (* x x)) (fma (* (* z y) -4.0) z (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+251) {
tmp = fma(fma(z, z, -t), (y * -4.0), (x * x));
} else {
tmp = fma(((z * y) * -4.0), z, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+251) tmp = fma(fma(z, z, Float64(-t)), Float64(y * -4.0), Float64(x * x)); else tmp = fma(Float64(Float64(z * y) * -4.0), z, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+251], N[(N[(z * z + (-t)), $MachinePrecision] * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] * -4.0), $MachinePrecision] * z + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+251}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(z, z, -t\right), y \cdot -4, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(z \cdot y\right) \cdot -4, z, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.0000000000000005e251Initial program 98.5%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
Applied rewrites96.9%
lift-fma.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-neg.f64N/A
sub-negN/A
lift--.f64N/A
*-commutativeN/A
lift-fma.f6499.0
Applied rewrites99.0%
if 5.0000000000000005e251 < (*.f64 z z) Initial program 64.6%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6412.5
Applied rewrites12.5%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.8
Applied rewrites92.8%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e+251) (fma (- (* z z) t) (* -4.0 y) (* x x)) (fma (* (* z y) -4.0) z (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+251) {
tmp = fma(((z * z) - t), (-4.0 * y), (x * x));
} else {
tmp = fma(((z * y) * -4.0), z, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+251) tmp = fma(Float64(Float64(z * z) - t), Float64(-4.0 * y), Float64(x * x)); else tmp = fma(Float64(Float64(z * y) * -4.0), z, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+251], N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(-4.0 * y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] * -4.0), $MachinePrecision] * z + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+251}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot z - t, -4 \cdot y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(z \cdot y\right) \cdot -4, z, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.0000000000000005e251Initial program 98.5%
lift--.f64N/A
sub-negN/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-eval99.0
Applied rewrites99.0%
if 5.0000000000000005e251 < (*.f64 z z) Initial program 64.6%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6412.5
Applied rewrites12.5%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.8
Applied rewrites92.8%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e-23) (fma (* 4.0 t) y (* x x)) (fma (* (* z y) -4.0) z (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e-23) {
tmp = fma((4.0 * t), y, (x * x));
} else {
tmp = fma(((z * y) * -4.0), z, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e-23) tmp = fma(Float64(4.0 * t), y, Float64(x * x)); else tmp = fma(Float64(Float64(z * y) * -4.0), z, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-23], N[(N[(4.0 * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] * -4.0), $MachinePrecision] * z + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot t, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(z \cdot y\right) \cdot -4, z, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 9.9999999999999996e-24Initial program 98.5%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6497.0
Applied rewrites97.0%
Applied rewrites97.8%
if 9.9999999999999996e-24 < (*.f64 z z) Initial program 82.9%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6414.7
Applied rewrites14.7%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6487.7
Applied rewrites87.7%
(FPCore (x y z t) :precision binary64 (if (<= z 2.5e+85) (fma (* 4.0 t) y (* x x)) (* (* (* y z) z) -4.0)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.5e+85) {
tmp = fma((4.0 * t), y, (x * x));
} else {
tmp = ((y * z) * z) * -4.0;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 2.5e+85) tmp = fma(Float64(4.0 * t), y, Float64(x * x)); else tmp = Float64(Float64(Float64(y * z) * z) * -4.0); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 2.5e+85], N[(N[(4.0 * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * z), $MachinePrecision] * z), $MachinePrecision] * -4.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.5 \cdot 10^{+85}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot t, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y \cdot z\right) \cdot z\right) \cdot -4\\
\end{array}
\end{array}
if z < 2.5e85Initial program 94.2%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6476.3
Applied rewrites76.3%
Applied rewrites76.8%
if 2.5e85 < z Initial program 72.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6454.9
Applied rewrites54.9%
Applied rewrites67.4%
(FPCore (x y z t) :precision binary64 (if (<= z 1.2e-10) (* (* t 4.0) y) (* (* (* y z) z) -4.0)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.2e-10) {
tmp = (t * 4.0) * y;
} else {
tmp = ((y * z) * z) * -4.0;
}
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 <= 1.2d-10) then
tmp = (t * 4.0d0) * y
else
tmp = ((y * z) * z) * (-4.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.2e-10) {
tmp = (t * 4.0) * y;
} else {
tmp = ((y * z) * z) * -4.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 1.2e-10: tmp = (t * 4.0) * y else: tmp = ((y * z) * z) * -4.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 1.2e-10) tmp = Float64(Float64(t * 4.0) * y); else tmp = Float64(Float64(Float64(y * z) * z) * -4.0); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.2e-10) tmp = (t * 4.0) * y; else tmp = ((y * z) * z) * -4.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.2e-10], N[(N[(t * 4.0), $MachinePrecision] * y), $MachinePrecision], N[(N[(N[(y * z), $MachinePrecision] * z), $MachinePrecision] * -4.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.2 \cdot 10^{-10}:\\
\;\;\;\;\left(t \cdot 4\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(\left(y \cdot z\right) \cdot z\right) \cdot -4\\
\end{array}
\end{array}
if z < 1.2e-10Initial program 93.5%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6438.9
Applied rewrites38.9%
Applied rewrites38.9%
if 1.2e-10 < z Initial program 82.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6449.2
Applied rewrites49.2%
Applied rewrites57.0%
(FPCore (x y z t) :precision binary64 (* (* t 4.0) y))
double code(double x, double y, double z, double t) {
return (t * 4.0) * y;
}
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 = (t * 4.0d0) * y
end function
public static double code(double x, double y, double z, double t) {
return (t * 4.0) * y;
}
def code(x, y, z, t): return (t * 4.0) * y
function code(x, y, z, t) return Float64(Float64(t * 4.0) * y) end
function tmp = code(x, y, z, t) tmp = (t * 4.0) * y; end
code[x_, y_, z_, t_] := N[(N[(t * 4.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(t \cdot 4\right) \cdot y
\end{array}
Initial program 90.9%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6433.2
Applied rewrites33.2%
Applied rewrites33.2%
(FPCore (x y z t) :precision binary64 (* (* -4.0 y) t))
double code(double x, double y, double z, double t) {
return (-4.0 * y) * 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 = ((-4.0d0) * y) * t
end function
public static double code(double x, double y, double z, double t) {
return (-4.0 * y) * t;
}
def code(x, y, z, t): return (-4.0 * y) * t
function code(x, y, z, t) return Float64(Float64(-4.0 * y) * t) end
function tmp = code(x, y, z, t) tmp = (-4.0 * y) * t; end
code[x_, y_, z_, t_] := N[(N[(-4.0 * y), $MachinePrecision] * t), $MachinePrecision]
\begin{array}{l}
\\
\left(-4 \cdot y\right) \cdot t
\end{array}
Initial program 90.9%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6433.2
Applied rewrites33.2%
Applied rewrites33.2%
Applied rewrites5.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 2024325
(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))))