
(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+302) (fma x x (* (- (* z z) t) (* y -4.0))) (* -4.0 (* t (* (* z y) (/ z t))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+302) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = -4.0 * (t * ((z * y) * (z / t)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+302) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(-4.0 * Float64(t * Float64(Float64(z * y) * Float64(z / t)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+302], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(N[(z * y), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(\left(z \cdot y\right) \cdot \frac{z}{t}\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5e302Initial program 99.4%
fma-neg100.0%
distribute-lft-neg-in100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
Simplified100.0%
if 5e302 < (*.f64 z z) Initial program 67.0%
Taylor expanded in t around inf 67.0%
unpow267.0%
associate-/l*67.0%
fma-neg67.0%
metadata-eval67.0%
Simplified67.0%
Taylor expanded in x around 0 72.2%
unpow272.2%
associate-*r/81.2%
fma-neg81.2%
metadata-eval81.2%
Simplified81.2%
Taylor expanded in z around inf 72.2%
associate-/l*72.2%
unpow272.2%
associate-*r/81.2%
associate-*r*86.0%
Applied egg-rr86.0%
Final simplification96.8%
(FPCore (x y z t) :precision binary64 (if (<= z 9.5e+151) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* -4.0 (* t (* (* z y) (/ z t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 9.5e+151) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = -4.0 * (t * ((z * y) * (z / t)));
}
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 <= 9.5d+151) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (-4.0d0) * (t * ((z * y) * (z / t)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 9.5e+151) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = -4.0 * (t * ((z * y) * (z / t)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 9.5e+151: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = -4.0 * (t * ((z * y) * (z / t))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 9.5e+151) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(-4.0 * Float64(t * Float64(Float64(z * y) * Float64(z / t)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 9.5e+151) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = -4.0 * (t * ((z * y) * (z / t))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 9.5e+151], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(N[(z * y), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 9.5 \cdot 10^{+151}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(\left(z \cdot y\right) \cdot \frac{z}{t}\right)\right)\\
\end{array}
\end{array}
if z < 9.5000000000000001e151Initial program 96.9%
if 9.5000000000000001e151 < z Initial program 66.2%
Taylor expanded in t around inf 66.2%
unpow266.2%
associate-/l*66.2%
fma-neg66.2%
metadata-eval66.2%
Simplified66.2%
Taylor expanded in x around 0 73.7%
unpow273.7%
associate-*r/80.7%
fma-neg80.7%
metadata-eval80.7%
Simplified80.7%
Taylor expanded in z around inf 73.7%
associate-/l*73.7%
unpow273.7%
associate-*r/80.7%
associate-*r*83.1%
Applied egg-rr83.1%
Final simplification94.7%
(FPCore (x y z t) :precision binary64 (if (<= z 5.8e+38) (- (* x x) (* y (* t -4.0))) (* -4.0 (* t (* y (+ (/ z (/ t z)) -1.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5.8e+38) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = -4.0 * (t * (y * ((z / (t / z)) + -1.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 <= 5.8d+38) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (-4.0d0) * (t * (y * ((z / (t / z)) + (-1.0d0))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5.8e+38) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = -4.0 * (t * (y * ((z / (t / z)) + -1.0)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 5.8e+38: tmp = (x * x) - (y * (t * -4.0)) else: tmp = -4.0 * (t * (y * ((z / (t / z)) + -1.0))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 5.8e+38) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(-4.0 * Float64(t * Float64(y * Float64(Float64(z / Float64(t / z)) + -1.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 5.8e+38) tmp = (x * x) - (y * (t * -4.0)); else tmp = -4.0 * (t * (y * ((z / (t / z)) + -1.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 5.8e+38], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(y * N[(N[(z / N[(t / z), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.8 \cdot 10^{+38}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(y \cdot \left(\frac{z}{\frac{t}{z}} + -1\right)\right)\right)\\
\end{array}
\end{array}
if z < 5.80000000000000013e38Initial program 96.5%
Taylor expanded in z around 0 80.2%
*-commutative80.2%
*-commutative80.2%
associate-*l*80.2%
Simplified80.2%
if 5.80000000000000013e38 < z Initial program 79.8%
Taylor expanded in t around inf 74.1%
unpow274.1%
associate-/l*74.1%
fma-neg74.1%
metadata-eval74.1%
Simplified74.1%
Taylor expanded in x around 0 70.2%
unpow270.2%
*-un-lft-identity70.2%
times-frac74.4%
Applied egg-rr74.4%
/-rgt-identity74.4%
clear-num74.4%
un-div-inv74.4%
Applied egg-rr74.4%
Final simplification78.7%
(FPCore (x y z t) :precision binary64 (if (<= z 2.4e+83) (- (* x x) (* y (* t -4.0))) (* -4.0 (* t (* (* z y) (/ z t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.4e+83) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = -4.0 * (t * ((z * y) * (z / t)));
}
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 <= 2.4d+83) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (-4.0d0) * (t * ((z * y) * (z / t)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.4e+83) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = -4.0 * (t * ((z * y) * (z / t)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 2.4e+83: tmp = (x * x) - (y * (t * -4.0)) else: tmp = -4.0 * (t * ((z * y) * (z / t))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 2.4e+83) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(-4.0 * Float64(t * Float64(Float64(z * y) * Float64(z / t)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 2.4e+83) tmp = (x * x) - (y * (t * -4.0)); else tmp = -4.0 * (t * ((z * y) * (z / t))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 2.4e+83], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(N[(z * y), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.4 \cdot 10^{+83}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(\left(z \cdot y\right) \cdot \frac{z}{t}\right)\right)\\
\end{array}
\end{array}
if z < 2.39999999999999991e83Initial program 96.6%
Taylor expanded in z around 0 78.0%
*-commutative78.0%
*-commutative78.0%
associate-*l*78.0%
Simplified78.0%
if 2.39999999999999991e83 < z Initial program 75.9%
Taylor expanded in t around inf 70.7%
unpow270.7%
associate-/l*70.7%
fma-neg70.7%
metadata-eval70.7%
Simplified70.7%
Taylor expanded in x around 0 74.3%
unpow274.3%
associate-*r/79.4%
fma-neg79.4%
metadata-eval79.4%
Simplified79.4%
Taylor expanded in z around inf 69.0%
associate-/l*69.0%
unpow269.0%
associate-*r/74.0%
associate-*r*75.7%
Applied egg-rr75.7%
Final simplification77.5%
(FPCore (x y z t) :precision binary64 (- (* x x) (* y (* t -4.0))))
double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
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 * (t * (-4.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
def code(x, y, z, t): return (x * x) - (y * (t * -4.0))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (y * (t * -4.0)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - y \cdot \left(t \cdot -4\right)
\end{array}
Initial program 92.1%
Taylor expanded in z around 0 66.7%
*-commutative66.7%
*-commutative66.7%
associate-*l*66.7%
Simplified66.7%
(FPCore (x y z t) :precision binary64 (* 4.0 (* t y)))
double code(double x, double y, double z, double t) {
return 4.0 * (t * 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 = 4.0d0 * (t * y)
end function
public static double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
def code(x, y, z, t): return 4.0 * (t * y)
function code(x, y, z, t) return Float64(4.0 * Float64(t * y)) end
function tmp = code(x, y, z, t) tmp = 4.0 * (t * y); end
code[x_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 92.1%
Taylor expanded in t around inf 37.1%
*-commutative37.1%
Simplified37.1%
Final simplification37.1%
(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 2024108
(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))))