
(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 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));
}
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) 1e+301) (fma x x (* (* y 4.0) (- t (* z z)))) (* z (* z (* y -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+301) {
tmp = fma(x, x, ((y * 4.0) * (t - (z * z))));
} else {
tmp = z * (z * (y * -4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+301) tmp = fma(x, x, Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(z * Float64(z * Float64(y * -4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+301], N[(x * x + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+301}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.00000000000000005e301Initial program 96.1%
fma-neg97.2%
distribute-rgt-neg-in97.2%
sub-neg97.2%
+-commutative97.2%
distribute-neg-in97.2%
remove-double-neg97.2%
sub-neg97.2%
Simplified97.2%
if 1.00000000000000005e301 < (*.f64 z z) Initial program 70.6%
Taylor expanded in z around inf 82.9%
associate-*r*82.9%
unpow282.9%
associate-*r*89.3%
Applied egg-rr89.3%
Final simplification95.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z 4.3e+32) (and (not (<= z 4.5e+91)) (<= z 1.25e+101))) (- (* x x) (* -4.0 (* y t))) (* z (* z (* y -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= 4.3e+32) || (!(z <= 4.5e+91) && (z <= 1.25e+101))) {
tmp = (x * x) - (-4.0 * (y * t));
} else {
tmp = z * (z * (y * -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 <= 4.3d+32) .or. (.not. (z <= 4.5d+91)) .and. (z <= 1.25d+101)) then
tmp = (x * x) - ((-4.0d0) * (y * t))
else
tmp = z * (z * (y * (-4.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= 4.3e+32) || (!(z <= 4.5e+91) && (z <= 1.25e+101))) {
tmp = (x * x) - (-4.0 * (y * t));
} else {
tmp = z * (z * (y * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= 4.3e+32) or (not (z <= 4.5e+91) and (z <= 1.25e+101)): tmp = (x * x) - (-4.0 * (y * t)) else: tmp = z * (z * (y * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= 4.3e+32) || (!(z <= 4.5e+91) && (z <= 1.25e+101))) tmp = Float64(Float64(x * x) - Float64(-4.0 * Float64(y * t))); else tmp = Float64(z * Float64(z * Float64(y * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= 4.3e+32) || (~((z <= 4.5e+91)) && (z <= 1.25e+101))) tmp = (x * x) - (-4.0 * (y * t)); else tmp = z * (z * (y * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, 4.3e+32], And[N[Not[LessEqual[z, 4.5e+91]], $MachinePrecision], LessEqual[z, 1.25e+101]]], N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.3 \cdot 10^{+32} \lor \neg \left(z \leq 4.5 \cdot 10^{+91}\right) \land z \leq 1.25 \cdot 10^{+101}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if z < 4.2999999999999997e32 or 4.5e91 < z < 1.24999999999999997e101Initial program 92.2%
Taylor expanded in z around 0 73.6%
*-commutative73.6%
Simplified73.6%
if 4.2999999999999997e32 < z < 4.5e91 or 1.24999999999999997e101 < z Initial program 78.6%
Taylor expanded in z around inf 77.3%
associate-*r*77.3%
unpow277.3%
associate-*r*81.5%
Applied egg-rr81.5%
Final simplification75.5%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+301) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* z (* z (* y -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+301) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = z * (z * (y * -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 * z) <= 1d+301) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = z * (z * (y * (-4.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+301) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = z * (z * (y * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 1e+301: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = z * (z * (y * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+301) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(z * Float64(z * Float64(y * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 1e+301) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = z * (z * (y * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+301], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+301}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.00000000000000005e301Initial program 96.1%
if 1.00000000000000005e301 < (*.f64 z z) Initial program 70.6%
Taylor expanded in z around inf 82.9%
associate-*r*82.9%
unpow282.9%
associate-*r*89.3%
Applied egg-rr89.3%
Final simplification94.2%
(FPCore (x y z t) :precision binary64 (if (<= z 0.13) (* 4.0 (* y t)) (* z (* z (* y -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 0.13) {
tmp = 4.0 * (y * t);
} else {
tmp = z * (z * (y * -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 <= 0.13d0) then
tmp = 4.0d0 * (y * t)
else
tmp = z * (z * (y * (-4.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 0.13) {
tmp = 4.0 * (y * t);
} else {
tmp = z * (z * (y * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 0.13: tmp = 4.0 * (y * t) else: tmp = z * (z * (y * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 0.13) tmp = Float64(4.0 * Float64(y * t)); else tmp = Float64(z * Float64(z * Float64(y * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 0.13) tmp = 4.0 * (y * t); else tmp = z * (z * (y * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 0.13], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.13:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if z < 0.13Initial program 91.9%
Taylor expanded in t around inf 34.9%
if 0.13 < z Initial program 81.0%
Taylor expanded in z around inf 71.7%
associate-*r*71.7%
unpow271.7%
associate-*r*75.5%
Applied egg-rr75.5%
Final simplification46.3%
(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(4.0 * Float64(y * t)) end
function tmp = code(x, y, z, t) tmp = 4.0 * (y * t); end
code[x_, y_, z_, t_] := N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(y \cdot t\right)
\end{array}
Initial program 88.8%
Taylor expanded in t around inf 29.8%
Final simplification29.8%
(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 2024096
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))