
(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 7 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) 2e+291) (fma (* y 4.0) (- t (* z z)) (* x x)) (* t (* y (+ 4.0 (* -4.0 (* z (/ z t))))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+291) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = t * (y * (4.0 + (-4.0 * (z * (z / t)))));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+291) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(t * Float64(y * Float64(4.0 + Float64(-4.0 * Float64(z * Float64(z / t)))))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+291], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(t * N[(y * N[(4.0 + N[(-4.0 * N[(z * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+291}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(4 + -4 \cdot \left(z \cdot \frac{z}{t}\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.9999999999999999e291Initial program 96.2%
cancel-sign-sub-inv96.2%
distribute-lft-neg-out96.2%
+-commutative96.2%
associate-*l*96.2%
distribute-lft-neg-in96.2%
associate-*l*96.2%
distribute-rgt-neg-in96.2%
fma-define99.4%
sub-neg99.4%
+-commutative99.4%
distribute-neg-in99.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
if 1.9999999999999999e291 < (*.f64 z z) Initial program 70.7%
Taylor expanded in t around inf 70.7%
+-commutative70.7%
fma-define70.7%
associate-/l*70.7%
*-commutative70.7%
Simplified70.7%
Taylor expanded in y around -inf 76.5%
unpow276.5%
*-un-lft-identity76.5%
times-frac83.3%
Applied egg-rr83.3%
Final simplification95.0%
(FPCore (x y z t) :precision binary64 (if (<= x 3.6e+174) (fma x x (* (- (* z z) t) (* y -4.0))) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 3.6e+174) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = x * x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= 3.6e+174) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(x * x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, 3.6e+174], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.6 \cdot 10^{+174}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 3.6000000000000002e174Initial program 90.4%
fma-neg92.6%
distribute-lft-neg-in92.6%
*-commutative92.6%
distribute-rgt-neg-in92.6%
metadata-eval92.6%
Simplified92.6%
if 3.6000000000000002e174 < x Initial program 77.3%
Taylor expanded in y around 0 77.3%
Simplified100.0%
Final simplification93.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* (* z z) -4.0))) (t_2 (* y (* 4.0 t))))
(if (<= x 1.25e-256)
t_2
(if (<= x 2.25e-29)
t_1
(if (<= x 1020000.0) t_2 (if (<= x 6.5e+16) t_1 (* x x)))))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((z * z) * -4.0);
double t_2 = y * (4.0 * t);
double tmp;
if (x <= 1.25e-256) {
tmp = t_2;
} else if (x <= 2.25e-29) {
tmp = t_1;
} else if (x <= 1020000.0) {
tmp = t_2;
} else if (x <= 6.5e+16) {
tmp = t_1;
} 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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = y * ((z * z) * (-4.0d0))
t_2 = y * (4.0d0 * t)
if (x <= 1.25d-256) then
tmp = t_2
else if (x <= 2.25d-29) then
tmp = t_1
else if (x <= 1020000.0d0) then
tmp = t_2
else if (x <= 6.5d+16) then
tmp = t_1
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * ((z * z) * -4.0);
double t_2 = y * (4.0 * t);
double tmp;
if (x <= 1.25e-256) {
tmp = t_2;
} else if (x <= 2.25e-29) {
tmp = t_1;
} else if (x <= 1020000.0) {
tmp = t_2;
} else if (x <= 6.5e+16) {
tmp = t_1;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * ((z * z) * -4.0) t_2 = y * (4.0 * t) tmp = 0 if x <= 1.25e-256: tmp = t_2 elif x <= 2.25e-29: tmp = t_1 elif x <= 1020000.0: tmp = t_2 elif x <= 6.5e+16: tmp = t_1 else: tmp = x * x return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(z * z) * -4.0)) t_2 = Float64(y * Float64(4.0 * t)) tmp = 0.0 if (x <= 1.25e-256) tmp = t_2; elseif (x <= 2.25e-29) tmp = t_1; elseif (x <= 1020000.0) tmp = t_2; elseif (x <= 6.5e+16) tmp = t_1; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * ((z * z) * -4.0); t_2 = y * (4.0 * t); tmp = 0.0; if (x <= 1.25e-256) tmp = t_2; elseif (x <= 2.25e-29) tmp = t_1; elseif (x <= 1020000.0) tmp = t_2; elseif (x <= 6.5e+16) tmp = t_1; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.25e-256], t$95$2, If[LessEqual[x, 2.25e-29], t$95$1, If[LessEqual[x, 1020000.0], t$95$2, If[LessEqual[x, 6.5e+16], t$95$1, N[(x * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\
t_2 := y \cdot \left(4 \cdot t\right)\\
\mathbf{if}\;x \leq 1.25 \cdot 10^{-256}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq 2.25 \cdot 10^{-29}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1020000:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{+16}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.25e-256 or 2.2499999999999999e-29 < x < 1.02e6Initial program 92.9%
Taylor expanded in t around inf 32.3%
associate-*r*32.3%
Simplified32.3%
if 1.25e-256 < x < 2.2499999999999999e-29 or 1.02e6 < x < 6.5e16Initial program 92.2%
Taylor expanded in z around inf 55.7%
associate-*r*55.7%
*-commutative55.7%
associate-*l*55.7%
Simplified55.7%
unpow255.7%
Applied egg-rr55.7%
if 6.5e16 < x Initial program 77.2%
Taylor expanded in y around 0 77.2%
Simplified77.3%
Final simplification46.7%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 7e+189) (* t (* y (+ 4.0 (/ (* z -4.0) (/ t z))))) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 7e+189) {
tmp = t * (y * (4.0 + ((z * -4.0) / (t / z))));
} 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 * x) <= 7d+189) then
tmp = t * (y * (4.0d0 + ((z * (-4.0d0)) / (t / z))))
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 * x) <= 7e+189) {
tmp = t * (y * (4.0 + ((z * -4.0) / (t / z))));
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 7e+189: tmp = t * (y * (4.0 + ((z * -4.0) / (t / z)))) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 7e+189) tmp = Float64(t * Float64(y * Float64(4.0 + Float64(Float64(z * -4.0) / Float64(t / z))))); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 7e+189) tmp = t * (y * (4.0 + ((z * -4.0) / (t / z)))); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 7e+189], N[(t * N[(y * N[(4.0 + N[(N[(z * -4.0), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 7 \cdot 10^{+189}:\\
\;\;\;\;t \cdot \left(y \cdot \left(4 + \frac{z \cdot -4}{\frac{t}{z}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 6.99999999999999991e189Initial program 95.3%
Taylor expanded in t around inf 90.0%
+-commutative90.0%
fma-define90.0%
associate-/l*88.8%
*-commutative88.8%
Simplified88.8%
Taylor expanded in y around -inf 77.5%
unpow277.5%
*-un-lft-identity77.5%
times-frac80.4%
Applied egg-rr80.4%
/-rgt-identity80.4%
associate-*r*80.4%
clear-num80.4%
un-div-inv80.4%
Applied egg-rr80.4%
if 6.99999999999999991e189 < (*.f64 x x) Initial program 79.0%
Taylor expanded in y around 0 79.0%
Simplified82.4%
Final simplification81.1%
(FPCore (x y z t) :precision binary64 (if (<= x 7.5e+142) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 7.5e+142) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} 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.5d+142) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
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.5e+142) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 7.5e+142: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 7.5e+142) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 7.5e+142) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 7.5e+142], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.5 \cdot 10^{+142}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 7.5000000000000002e142Initial program 92.3%
if 7.5000000000000002e142 < x Initial program 67.7%
Taylor expanded in y around 0 67.7%
Simplified90.3%
Final simplification92.0%
(FPCore (x y z t) :precision binary64 (if (<= x 2.1e+34) (* y (* 4.0 t)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 2.1e+34) {
tmp = y * (4.0 * t);
} 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 <= 2.1d+34) then
tmp = y * (4.0d0 * t)
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 <= 2.1e+34) {
tmp = y * (4.0 * t);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 2.1e+34: tmp = y * (4.0 * t) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 2.1e+34) tmp = Float64(y * Float64(4.0 * t)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 2.1e+34) tmp = y * (4.0 * t); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 2.1e+34], N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.1 \cdot 10^{+34}:\\
\;\;\;\;y \cdot \left(4 \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 2.10000000000000017e34Initial program 92.8%
Taylor expanded in t around inf 33.7%
associate-*r*33.7%
Simplified33.7%
if 2.10000000000000017e34 < x Initial program 75.9%
Taylor expanded in y around 0 75.9%
Simplified79.7%
Final simplification43.2%
(FPCore (x y z t) :precision binary64 (* y (* 4.0 t)))
double code(double x, double y, double z, double t) {
return y * (4.0 * 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 = y * (4.0d0 * t)
end function
public static double code(double x, double y, double z, double t) {
return y * (4.0 * t);
}
def code(x, y, z, t): return y * (4.0 * t)
function code(x, y, z, t) return Float64(y * Float64(4.0 * t)) end
function tmp = code(x, y, z, t) tmp = y * (4.0 * t); end
code[x_, y_, z_, t_] := N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(4 \cdot t\right)
\end{array}
Initial program 89.3%
Taylor expanded in t around inf 29.1%
associate-*r*29.1%
Simplified29.1%
Final simplification29.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 2024053
(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))))