
(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}
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= z 8.2e+161) (- (* x x) (* y (* 4.0 (- (* z z) t)))) (* z (* -4.0 (* z y)))))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 8.2e+161) {
tmp = (x * x) - (y * (4.0 * ((z * z) - t)));
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
NOTE: z should be positive before calling this function
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 <= 8.2d+161) then
tmp = (x * x) - (y * (4.0d0 * ((z * z) - t)))
else
tmp = z * ((-4.0d0) * (z * y))
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 8.2e+161) {
tmp = (x * x) - (y * (4.0 * ((z * z) - t)));
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if z <= 8.2e+161: tmp = (x * x) - (y * (4.0 * ((z * z) - t))) else: tmp = z * (-4.0 * (z * y)) return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (z <= 8.2e+161) tmp = Float64(Float64(x * x) - Float64(y * Float64(4.0 * Float64(Float64(z * z) - t)))); else tmp = Float64(z * Float64(-4.0 * Float64(z * y))); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 8.2e+161) tmp = (x * x) - (y * (4.0 * ((z * z) - t))); else tmp = z * (-4.0 * (z * y)); end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[z, 8.2e+161], N[(N[(x * x), $MachinePrecision] - N[(y * N[(4.0 * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 8.2 \cdot 10^{+161}:\\
\;\;\;\;x \cdot x - y \cdot \left(4 \cdot \left(z \cdot z - t\right)\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\
\end{array}
\end{array}
if z < 8.2000000000000002e161Initial program 93.5%
associate-*l*93.9%
Simplified93.9%
if 8.2000000000000002e161 < z Initial program 59.7%
associate-*l*59.7%
Simplified59.7%
Taylor expanded in z around inf 63.6%
unpow263.6%
associate-*r*63.6%
*-commutative63.6%
associate-*r*92.3%
*-commutative92.3%
*-commutative92.3%
associate-*l*92.3%
Simplified92.3%
Final simplification93.7%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= z 1.45e+45) (- (* x x) (* t (* y -4.0))) (if (<= z 1.02e+162) (* (- (* z z) t) (* y -4.0)) (* z (* -4.0 (* z y))))))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.45e+45) {
tmp = (x * x) - (t * (y * -4.0));
} else if (z <= 1.02e+162) {
tmp = ((z * z) - t) * (y * -4.0);
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
NOTE: z should be positive before calling this function
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.45d+45) then
tmp = (x * x) - (t * (y * (-4.0d0)))
else if (z <= 1.02d+162) then
tmp = ((z * z) - t) * (y * (-4.0d0))
else
tmp = z * ((-4.0d0) * (z * y))
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.45e+45) {
tmp = (x * x) - (t * (y * -4.0));
} else if (z <= 1.02e+162) {
tmp = ((z * z) - t) * (y * -4.0);
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if z <= 1.45e+45: tmp = (x * x) - (t * (y * -4.0)) elif z <= 1.02e+162: tmp = ((z * z) - t) * (y * -4.0) else: tmp = z * (-4.0 * (z * y)) return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (z <= 1.45e+45) tmp = Float64(Float64(x * x) - Float64(t * Float64(y * -4.0))); elseif (z <= 1.02e+162) tmp = Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0)); else tmp = Float64(z * Float64(-4.0 * Float64(z * y))); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.45e+45) tmp = (x * x) - (t * (y * -4.0)); elseif (z <= 1.02e+162) tmp = ((z * z) - t) * (y * -4.0); else tmp = z * (-4.0 * (z * y)); end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[z, 1.45e+45], N[(N[(x * x), $MachinePrecision] - N[(t * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.02e+162], N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision], N[(z * N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.45 \cdot 10^{+45}:\\
\;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\
\mathbf{elif}\;z \leq 1.02 \cdot 10^{+162}:\\
\;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\
\end{array}
\end{array}
if z < 1.4499999999999999e45Initial program 93.5%
associate-*l*93.9%
Simplified93.9%
Taylor expanded in z around 0 78.5%
associate-*r*78.5%
*-commutative78.5%
Simplified78.5%
if 1.4499999999999999e45 < z < 1.01999999999999993e162Initial program 94.2%
associate-*l*94.2%
Simplified94.2%
sub-neg94.2%
+-commutative94.2%
distribute-rgt-neg-in94.2%
distribute-lft-neg-in94.2%
metadata-eval94.2%
associate-*l*94.2%
*-commutative94.2%
add-cube-cbrt93.7%
associate-*l*93.8%
fma-def93.8%
pow293.8%
Applied egg-rr93.8%
Taylor expanded in y around inf 67.3%
pow-base-167.3%
associate-*r*67.3%
*-rgt-identity67.3%
*-rgt-identity67.3%
unpow267.3%
*-commutative67.3%
associate-*r*67.3%
*-rgt-identity67.3%
Simplified67.3%
if 1.01999999999999993e162 < z Initial program 59.7%
associate-*l*59.7%
Simplified59.7%
Taylor expanded in z around inf 63.6%
unpow263.6%
associate-*r*63.6%
*-commutative63.6%
associate-*r*92.3%
*-commutative92.3%
*-commutative92.3%
associate-*l*92.3%
Simplified92.3%
Final simplification79.1%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= (* x x) 4.8e+194) (* (- (* z z) t) (* y -4.0)) (* x x)))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 4.8e+194) {
tmp = ((z * z) - t) * (y * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: z should be positive before calling this function
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 * x) <= 4.8d+194) then
tmp = ((z * z) - t) * (y * (-4.0d0))
else
tmp = x * x
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 4.8e+194) {
tmp = ((z * z) - t) * (y * -4.0);
} else {
tmp = x * x;
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if (x * x) <= 4.8e+194: tmp = ((z * z) - t) * (y * -4.0) else: tmp = x * x return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 4.8e+194) tmp = Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0)); else tmp = Float64(x * x); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 4.8e+194) tmp = ((z * z) - t) * (y * -4.0); else tmp = x * x; end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 4.8e+194], N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4.8 \cdot 10^{+194}:\\
\;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 4.8e194Initial program 94.4%
associate-*l*94.9%
Simplified94.9%
sub-neg94.9%
+-commutative94.9%
distribute-rgt-neg-in94.9%
distribute-lft-neg-in94.9%
metadata-eval94.9%
associate-*l*94.4%
*-commutative94.4%
add-cube-cbrt93.6%
associate-*l*93.6%
fma-def93.6%
pow293.6%
Applied egg-rr93.6%
Taylor expanded in y around inf 82.1%
pow-base-182.1%
associate-*r*82.1%
*-rgt-identity82.1%
*-rgt-identity82.1%
unpow282.1%
*-commutative82.1%
associate-*r*81.6%
*-rgt-identity81.6%
Simplified81.6%
if 4.8e194 < (*.f64 x x) Initial program 81.9%
associate-*l*81.9%
Simplified81.9%
Taylor expanded in x around inf 90.0%
unpow290.0%
Simplified90.0%
Final simplification84.5%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= z 4.5e-118) (* t (* y 4.0)) (if (<= z 2.6e+49) (* x x) (* z (* -4.0 (* z y))))))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 4.5e-118) {
tmp = t * (y * 4.0);
} else if (z <= 2.6e+49) {
tmp = x * x;
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
NOTE: z should be positive before calling this function
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 <= 4.5d-118) then
tmp = t * (y * 4.0d0)
else if (z <= 2.6d+49) then
tmp = x * x
else
tmp = z * ((-4.0d0) * (z * y))
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 4.5e-118) {
tmp = t * (y * 4.0);
} else if (z <= 2.6e+49) {
tmp = x * x;
} else {
tmp = z * (-4.0 * (z * y));
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if z <= 4.5e-118: tmp = t * (y * 4.0) elif z <= 2.6e+49: tmp = x * x else: tmp = z * (-4.0 * (z * y)) return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (z <= 4.5e-118) tmp = Float64(t * Float64(y * 4.0)); elseif (z <= 2.6e+49) tmp = Float64(x * x); else tmp = Float64(z * Float64(-4.0 * Float64(z * y))); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 4.5e-118) tmp = t * (y * 4.0); elseif (z <= 2.6e+49) tmp = x * x; else tmp = z * (-4.0 * (z * y)); end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[z, 4.5e-118], N[(t * N[(y * 4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.6e+49], N[(x * x), $MachinePrecision], N[(z * N[(-4.0 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.5 \cdot 10^{-118}:\\
\;\;\;\;t \cdot \left(y \cdot 4\right)\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{+49}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\
\end{array}
\end{array}
if z < 4.5e-118Initial program 92.1%
associate-*l*92.6%
Simplified92.6%
Taylor expanded in t around inf 41.5%
associate-*r*41.5%
Simplified41.5%
if 4.5e-118 < z < 2.59999999999999989e49Initial program 100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in x around inf 61.8%
unpow261.8%
Simplified61.8%
if 2.59999999999999989e49 < z Initial program 73.8%
associate-*l*73.8%
Simplified73.8%
Taylor expanded in z around inf 63.1%
unpow263.1%
associate-*r*63.1%
*-commutative63.1%
associate-*r*77.9%
*-commutative77.9%
*-commutative77.9%
associate-*l*77.9%
Simplified77.9%
Final simplification50.7%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.55e+110) (* t (* y 4.0)) (* x x)))
z = abs(z);
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.55e+110) {
tmp = t * (y * 4.0);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: z should be positive before calling this function
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 * x) <= 1.55d+110) then
tmp = t * (y * 4.0d0)
else
tmp = x * x
end if
code = tmp
end function
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.55e+110) {
tmp = t * (y * 4.0);
} else {
tmp = x * x;
}
return tmp;
}
z = abs(z) def code(x, y, z, t): tmp = 0 if (x * x) <= 1.55e+110: tmp = t * (y * 4.0) else: tmp = x * x return tmp
z = abs(z) function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 1.55e+110) tmp = Float64(t * Float64(y * 4.0)); else tmp = Float64(x * x); end return tmp end
z = abs(z) function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 1.55e+110) tmp = t * (y * 4.0); else tmp = x * x; end tmp_2 = tmp; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.55e+110], N[(t * N[(y * 4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.55 \cdot 10^{+110}:\\
\;\;\;\;t \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.55000000000000009e110Initial program 93.6%
associate-*l*94.2%
Simplified94.2%
Taylor expanded in t around inf 52.0%
associate-*r*52.0%
Simplified52.0%
if 1.55000000000000009e110 < (*.f64 x x) Initial program 85.3%
associate-*l*85.3%
Simplified85.3%
Taylor expanded in x around inf 80.4%
unpow280.4%
Simplified80.4%
Final simplification64.0%
NOTE: z should be positive before calling this function (FPCore (x y z t) :precision binary64 (* x x))
z = abs(z);
double code(double x, double y, double z, double t) {
return x * x;
}
NOTE: z should be positive before calling this function
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
z = Math.abs(z);
public static double code(double x, double y, double z, double t) {
return x * x;
}
z = abs(z) def code(x, y, z, t): return x * x
z = abs(z) function code(x, y, z, t) return Float64(x * x) end
z = abs(z) function tmp = code(x, y, z, t) tmp = x * x; end
NOTE: z should be positive before calling this function code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
z = |z|\\
\\
x \cdot x
\end{array}
Initial program 90.1%
associate-*l*90.4%
Simplified90.4%
Taylor expanded in x around inf 41.5%
unpow241.5%
Simplified41.5%
Final simplification41.5%
(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 2023230
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:herbie-target
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))