
(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) t) (* y 4.0)) 5e+306) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* -4.0 (* (+ (* z (/ z t)) -1.0) (* t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((((z * z) - t) * (y * 4.0)) <= 5e+306) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = -4.0 * (((z * (z / t)) + -1.0) * (t * y));
}
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) - t) * (y * 4.0d0)) <= 5d+306) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (-4.0d0) * (((z * (z / t)) + (-1.0d0)) * (t * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((((z * z) - t) * (y * 4.0)) <= 5e+306) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = -4.0 * (((z * (z / t)) + -1.0) * (t * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (((z * z) - t) * (y * 4.0)) <= 5e+306: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = -4.0 * (((z * (z / t)) + -1.0) * (t * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(Float64(z * z) - t) * Float64(y * 4.0)) <= 5e+306) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(-4.0 * Float64(Float64(Float64(z * Float64(z / t)) + -1.0) * Float64(t * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((((z * z) - t) * (y * 4.0)) <= 5e+306) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = -4.0 * (((z * (z / t)) + -1.0) * (t * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * 4.0), $MachinePrecision]), $MachinePrecision], 5e+306], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[(N[(z * N[(z / t), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(z \cdot z - t\right) \cdot \left(y \cdot 4\right) \leq 5 \cdot 10^{+306}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\left(z \cdot \frac{z}{t} + -1\right) \cdot \left(t \cdot y\right)\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t)) < 4.99999999999999993e306Initial program 96.0%
if 4.99999999999999993e306 < (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t)) Initial program 70.2%
Taylor expanded in t around inf 70.2%
unpow270.2%
*-un-lft-identity70.2%
times-frac70.2%
Applied egg-rr70.2%
Taylor expanded in x around 0 83.2%
*-commutative83.2%
associate-*r*83.1%
sub-neg83.1%
metadata-eval83.1%
Simplified83.1%
unpow270.2%
*-un-lft-identity70.2%
times-frac70.2%
Applied egg-rr85.1%
Final simplification94.0%
(FPCore (x y z t) :precision binary64 (fma x x (* (- (* z z) t) (* y -4.0))))
double code(double x, double y, double z, double t) {
return fma(x, x, (((z * z) - t) * (y * -4.0)));
}
function code(x, y, z, t) return fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))) end
code[x_, y_, z_, t_] := N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)
\end{array}
Initial program 91.3%
fma-neg93.7%
distribute-lft-neg-in93.7%
*-commutative93.7%
distribute-rgt-neg-in93.7%
metadata-eval93.7%
Simplified93.7%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (* x (- x)))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = x * -x;
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = x * -x;
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * x) + ((y * 4.0) * (t - (z * z))) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = x * -x return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(x * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * x) + ((y * 4.0) * (t - (z * z))); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = x * -x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(x * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-x\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 94.3%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 0.0%
cancel-sign-sub-inv0.0%
distribute-lft-neg-out0.0%
+-commutative0.0%
distribute-lft-neg-out0.0%
distribute-lft-neg-in0.0%
distribute-rgt-neg-in0.0%
fma-define12.5%
sub-neg12.5%
+-commutative12.5%
distribute-neg-in12.5%
remove-double-neg12.5%
sub-neg12.5%
Simplified12.5%
fma-undefine0.0%
flip-+0.0%
pow20.0%
pow20.0%
pow20.0%
pow20.0%
pow-prod-up0.0%
metadata-eval0.0%
pow20.0%
pow20.0%
Applied egg-rr0.0%
Simplified0.0%
neg-sub00.0%
metadata-eval0.0%
metadata-eval0.0%
pow-prod-up0.0%
pow-prod-down0.0%
pow20.0%
pow20.0%
neg-sub00.0%
sub-neg0.0%
add-sqr-sqrt0.0%
sqrt-unprod0.0%
sqr-neg0.0%
sqrt-prod0.0%
add-sqr-sqrt0.0%
flip--75.0%
neg-sub075.0%
distribute-lft-neg-in75.0%
Applied egg-rr75.0%
Final simplification93.7%
(FPCore (x y z t) :precision binary64 (if (<= x 7.2e+16) (* y (* t 4.0)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 7.2e+16) {
tmp = y * (t * 4.0);
} else {
tmp = x * x;
}
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 (x <= 7.2d+16) then
tmp = y * (t * 4.0d0)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 7.2e+16) {
tmp = y * (t * 4.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 7.2e+16: tmp = y * (t * 4.0) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 7.2e+16) tmp = Float64(y * Float64(t * 4.0)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 7.2e+16) tmp = y * (t * 4.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 7.2e+16], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.2 \cdot 10^{+16}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 7.2e16Initial program 92.9%
Taylor expanded in t around inf 38.5%
associate-*r*38.5%
Simplified38.5%
if 7.2e16 < x Initial program 88.0%
cancel-sign-sub-inv88.0%
distribute-lft-neg-out88.0%
+-commutative88.0%
distribute-lft-neg-out88.0%
distribute-lft-neg-in88.0%
distribute-rgt-neg-in88.0%
fma-define89.3%
sub-neg89.3%
+-commutative89.3%
distribute-neg-in89.3%
remove-double-neg89.3%
sub-neg89.3%
Simplified89.3%
fma-undefine88.0%
flip-+8.6%
pow28.6%
pow28.6%
pow28.6%
pow28.6%
pow-prod-up8.5%
metadata-eval8.5%
pow28.5%
pow28.5%
Applied egg-rr8.5%
Simplified11.5%
neg-sub011.5%
metadata-eval11.5%
metadata-eval11.5%
pow-prod-up11.5%
pow-prod-down11.5%
pow211.5%
pow211.5%
neg-sub011.5%
sub-neg11.5%
add-sqr-sqrt0.0%
sqrt-unprod0.6%
sqr-neg0.6%
sqrt-prod4.4%
add-sqr-sqrt4.4%
flip--4.7%
neg-sub04.7%
add-sqr-sqrt0.0%
sqrt-unprod56.6%
sqr-neg56.6%
sqrt-prod68.0%
add-sqr-sqrt68.0%
Applied egg-rr68.0%
Final simplification47.9%
(FPCore (x y z t) :precision binary64 (- (* x x) (* -4.0 (* t y))))
double code(double x, double y, double z, double t) {
return (x * x) - (-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 = (x * x) - ((-4.0d0) * (t * y))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (t * y));
}
def code(x, y, z, t): return (x * x) - (-4.0 * (t * y))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (-4.0 * (t * y)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - -4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 91.3%
Taylor expanded in z around 0 66.8%
*-commutative66.8%
Simplified66.8%
Final simplification66.8%
(FPCore (x y z t) :precision binary64 (* x x))
double code(double x, double y, double z, double t) {
return x * x;
}
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
public static double code(double x, double y, double z, double t) {
return x * x;
}
def code(x, y, z, t): return x * x
function code(x, y, z, t) return Float64(x * x) end
function tmp = code(x, y, z, t) tmp = x * x; end
code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 91.3%
cancel-sign-sub-inv91.3%
distribute-lft-neg-out91.3%
+-commutative91.3%
distribute-lft-neg-out91.3%
distribute-lft-neg-in91.3%
distribute-rgt-neg-in91.3%
fma-define91.7%
sub-neg91.7%
+-commutative91.7%
distribute-neg-in91.7%
remove-double-neg91.7%
sub-neg91.7%
Simplified91.7%
fma-undefine91.3%
flip-+20.8%
pow220.8%
pow220.8%
pow220.8%
pow220.8%
pow-prod-up20.8%
metadata-eval20.8%
pow220.8%
pow220.8%
Applied egg-rr20.8%
Simplified8.5%
neg-sub08.5%
metadata-eval8.5%
metadata-eval8.5%
pow-prod-up8.6%
pow-prod-down8.6%
pow28.6%
pow28.6%
neg-sub08.6%
sub-neg8.6%
add-sqr-sqrt0.0%
sqrt-unprod0.6%
sqr-neg0.6%
sqrt-prod3.4%
add-sqr-sqrt3.4%
flip--5.9%
neg-sub05.9%
add-sqr-sqrt2.3%
sqrt-unprod34.7%
sqr-neg34.7%
sqrt-prod41.6%
add-sqr-sqrt41.6%
Applied egg-rr41.6%
(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 2024110
(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))))