
(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}
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= x_m 1.5e+239) (fma x_m x_m (* (- (* z z) t) (* y -4.0))) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (x_m <= 1.5e+239) {
tmp = fma(x_m, x_m, (((z * z) - t) * (y * -4.0)));
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (x_m <= 1.5e+239) tmp = fma(x_m, x_m, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(x_m * x_m); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[x$95$m, 1.5e+239], N[(x$95$m * x$95$m + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.5 \cdot 10^{+239}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\
\end{array}
\end{array}
if x < 1.4999999999999999e239Initial program 93.9%
fma-neg96.0%
distribute-lft-neg-in96.0%
*-commutative96.0%
distribute-rgt-neg-in96.0%
metadata-eval96.0%
Simplified96.0%
if 1.4999999999999999e239 < x Initial program 66.7%
Taylor expanded in y around 0 66.7%
Simplified100.0%
Final simplification96.2%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= t 9.2e+188) (- (* x_m x_m) (+ (* -4.0 (* t y)) (* z (* z (* y 4.0))))) (+ (* x_m x_m) (* (* y 4.0) (- t (* z z))))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (t <= 9.2e+188) {
tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0))));
} else {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= 9.2d+188) then
tmp = (x_m * x_m) - (((-4.0d0) * (t * y)) + (z * (z * (y * 4.0d0))))
else
tmp = (x_m * x_m) + ((y * 4.0d0) * (t - (z * z)))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if (t <= 9.2e+188) {
tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0))));
} else {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if t <= 9.2e+188: tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0)))) else: tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))) return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (t <= 9.2e+188) tmp = Float64(Float64(x_m * x_m) - Float64(Float64(-4.0 * Float64(t * y)) + Float64(z * Float64(z * Float64(y * 4.0))))); else tmp = Float64(Float64(x_m * x_m) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if (t <= 9.2e+188) tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0)))); else tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[t, 9.2e+188], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision] + N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;t \leq 9.2 \cdot 10^{+188}:\\
\;\;\;\;x\_m \cdot x\_m - \left(-4 \cdot \left(t \cdot y\right) + z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\end{array}
\end{array}
if t < 9.20000000000000046e188Initial program 92.9%
Taylor expanded in z around 0 92.5%
+-commutative92.5%
add-sqr-sqrt59.3%
*-commutative59.3%
fma-define59.3%
Applied egg-rr49.5%
fma-undefine49.5%
unpow249.5%
*-commutative49.5%
associate-*l*49.5%
*-commutative49.5%
Simplified49.5%
unpow-prod-down45.6%
unpow245.6%
associate-*l*49.5%
*-commutative49.5%
unpow-prod-down49.5%
pow249.5%
metadata-eval49.5%
add-sqr-sqrt96.4%
Applied egg-rr96.4%
if 9.20000000000000046e188 < t Initial program 90.3%
Final simplification95.7%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= (* x_m x_m) 3.9e+300) (+ (* x_m x_m) (* (* y 4.0) (- t (* z z)))) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if ((x_m * x_m) <= 3.9e+300) {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x_m * x_m) <= 3.9d+300) then
tmp = (x_m * x_m) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = x_m * x_m
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if ((x_m * x_m) <= 3.9e+300) {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if (x_m * x_m) <= 3.9e+300: tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))) else: tmp = x_m * x_m return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (Float64(x_m * x_m) <= 3.9e+300) tmp = Float64(Float64(x_m * x_m) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(x_m * x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if ((x_m * x_m) <= 3.9e+300) tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))); else tmp = x_m * x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 3.9e+300], N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 3.9 \cdot 10^{+300}:\\
\;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\
\end{array}
\end{array}
if (*.f64 x x) < 3.8999999999999999e300Initial program 95.9%
if 3.8999999999999999e300 < (*.f64 x x) Initial program 82.8%
Taylor expanded in y around 0 82.8%
Simplified92.2%
Final simplification95.0%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= (* x_m x_m) 5e-10) (* y (* t 4.0)) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if ((x_m * x_m) <= 5e-10) {
tmp = y * (t * 4.0);
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x_m * x_m) <= 5d-10) then
tmp = y * (t * 4.0d0)
else
tmp = x_m * x_m
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if ((x_m * x_m) <= 5e-10) {
tmp = y * (t * 4.0);
} else {
tmp = x_m * x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if (x_m * x_m) <= 5e-10: tmp = y * (t * 4.0) else: tmp = x_m * x_m return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (Float64(x_m * x_m) <= 5e-10) tmp = Float64(y * Float64(t * 4.0)); else tmp = Float64(x_m * x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if ((x_m * x_m) <= 5e-10) tmp = y * (t * 4.0); else tmp = x_m * x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 5e-10], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 5 \cdot 10^{-10}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\
\end{array}
\end{array}
if (*.f64 x x) < 5.00000000000000031e-10Initial program 96.4%
Taylor expanded in t around inf 47.4%
associate-*r*47.4%
Simplified47.4%
if 5.00000000000000031e-10 < (*.f64 x x) Initial program 88.5%
Taylor expanded in y around 0 88.5%
Simplified75.3%
Final simplification60.6%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (- (* x_m x_m) (* -4.0 (* t y))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return (x_m * x_m) - (-4.0 * (t * y));
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x_m * x_m) - ((-4.0d0) * (t * y))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return (x_m * x_m) - (-4.0 * (t * y));
}
x_m = math.fabs(x) def code(x_m, y, z, t): return (x_m * x_m) - (-4.0 * (t * y))
x_m = abs(x) function code(x_m, y, z, t) return Float64(Float64(x_m * x_m) - Float64(-4.0 * Float64(t * y))) end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = (x_m * x_m) - (-4.0 * (t * y)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot x\_m - -4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 92.6%
Taylor expanded in z around 0 66.6%
*-commutative66.6%
Simplified66.6%
Final simplification66.6%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (* y (* t 4.0)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return y * (t * 4.0);
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = y * (t * 4.0d0)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return y * (t * 4.0);
}
x_m = math.fabs(x) def code(x_m, y, z, t): return y * (t * 4.0)
x_m = abs(x) function code(x_m, y, z, t) return Float64(y * Float64(t * 4.0)) end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = y * (t * 4.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y \cdot \left(t \cdot 4\right)
\end{array}
Initial program 92.6%
Taylor expanded in t around inf 32.7%
associate-*r*32.7%
Simplified32.7%
Final simplification32.7%
(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 2024079
(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))))