
(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) 1e+305) (fma (* y 4.0) (- t (* z z)) (* x x)) (- (* 4.0 (* z (* z (- y)))) (* t (* y -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+305) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = (4.0 * (z * (z * -y))) - (t * (y * -4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+305) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(Float64(4.0 * Float64(z * Float64(z * Float64(-y)))) - Float64(t * Float64(y * -4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+305], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(4.0 * N[(z * N[(z * (-y)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(z \cdot \left(z \cdot \left(-y\right)\right)\right) - t \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 9.9999999999999994e304Initial program 96.9%
cancel-sign-sub-inv96.9%
distribute-lft-neg-out96.9%
+-commutative96.9%
distribute-lft-neg-out96.9%
distribute-lft-neg-in96.9%
distribute-rgt-neg-in96.9%
fma-define99.4%
sub-neg99.4%
+-commutative99.4%
distribute-neg-in99.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
if 9.9999999999999994e304 < (*.f64 z z) Initial program 61.3%
Taylor expanded in z around 0 57.9%
Taylor expanded in x around 0 63.0%
+-commutative63.0%
add-sqr-sqrt19.4%
*-commutative19.4%
*-commutative19.4%
associate-*r*19.4%
fma-define19.4%
sqrt-prod19.4%
metadata-eval19.4%
*-commutative19.4%
sqrt-prod19.4%
sqrt-pow110.5%
metadata-eval10.5%
pow110.5%
sqrt-prod10.5%
metadata-eval10.5%
*-commutative10.5%
sqrt-prod10.5%
sqrt-pow132.2%
metadata-eval32.2%
pow132.2%
associate-*r*32.2%
Applied egg-rr32.2%
fma-undefine30.5%
swap-sqr30.5%
metadata-eval30.5%
unpow230.5%
associate-*r*30.5%
*-commutative30.5%
Simplified30.5%
unpow230.5%
*-commutative30.5%
*-commutative30.5%
swap-sqr19.4%
add-sqr-sqrt63.0%
associate-*r*83.1%
Applied egg-rr83.1%
Final simplification95.7%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+305) (fma x x (* (* y -4.0) (- (* z z) t))) (- (* 4.0 (* z (* z (- y)))) (* t (* y -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+305) {
tmp = fma(x, x, ((y * -4.0) * ((z * z) - t)));
} else {
tmp = (4.0 * (z * (z * -y))) - (t * (y * -4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+305) tmp = fma(x, x, Float64(Float64(y * -4.0) * Float64(Float64(z * z) - t))); else tmp = Float64(Float64(4.0 * Float64(z * Float64(z * Float64(-y)))) - Float64(t * Float64(y * -4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+305], N[(x * x + N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(4.0 * N[(z * N[(z * (-y)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+305}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\right)\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(z \cdot \left(z \cdot \left(-y\right)\right)\right) - t \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 9.9999999999999994e304Initial program 96.9%
fmm-def97.4%
distribute-lft-neg-in97.4%
*-commutative97.4%
distribute-rgt-neg-in97.4%
metadata-eval97.4%
Simplified97.4%
if 9.9999999999999994e304 < (*.f64 z z) Initial program 61.3%
Taylor expanded in z around 0 57.9%
Taylor expanded in x around 0 63.0%
+-commutative63.0%
add-sqr-sqrt19.4%
*-commutative19.4%
*-commutative19.4%
associate-*r*19.4%
fma-define19.4%
sqrt-prod19.4%
metadata-eval19.4%
*-commutative19.4%
sqrt-prod19.4%
sqrt-pow110.5%
metadata-eval10.5%
pow110.5%
sqrt-prod10.5%
metadata-eval10.5%
*-commutative10.5%
sqrt-prod10.5%
sqrt-pow132.2%
metadata-eval32.2%
pow132.2%
associate-*r*32.2%
Applied egg-rr32.2%
fma-undefine30.5%
swap-sqr30.5%
metadata-eval30.5%
unpow230.5%
associate-*r*30.5%
*-commutative30.5%
Simplified30.5%
unpow230.5%
*-commutative30.5%
*-commutative30.5%
swap-sqr19.4%
add-sqr-sqrt63.0%
associate-*r*83.1%
Applied egg-rr83.1%
Final simplification94.1%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+305) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* 4.0 (* z (* z (- y)))) (* t (* y -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+305) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (4.0 * (z * (z * -y))) - (t * (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+305) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (4.0d0 * (z * (z * -y))) - (t * (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+305) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (4.0 * (z * (z * -y))) - (t * (y * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 1e+305: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (4.0 * (z * (z * -y))) - (t * (y * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+305) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(4.0 * Float64(z * Float64(z * Float64(-y)))) - Float64(t * Float64(y * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 1e+305) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (4.0 * (z * (z * -y))) - (t * (y * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+305], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(4.0 * N[(z * N[(z * (-y)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+305}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;4 \cdot \left(z \cdot \left(z \cdot \left(-y\right)\right)\right) - t \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 9.9999999999999994e304Initial program 96.9%
if 9.9999999999999994e304 < (*.f64 z z) Initial program 61.3%
Taylor expanded in z around 0 57.9%
Taylor expanded in x around 0 63.0%
+-commutative63.0%
add-sqr-sqrt19.4%
*-commutative19.4%
*-commutative19.4%
associate-*r*19.4%
fma-define19.4%
sqrt-prod19.4%
metadata-eval19.4%
*-commutative19.4%
sqrt-prod19.4%
sqrt-pow110.5%
metadata-eval10.5%
pow110.5%
sqrt-prod10.5%
metadata-eval10.5%
*-commutative10.5%
sqrt-prod10.5%
sqrt-pow132.2%
metadata-eval32.2%
pow132.2%
associate-*r*32.2%
Applied egg-rr32.2%
fma-undefine30.5%
swap-sqr30.5%
metadata-eval30.5%
unpow230.5%
associate-*r*30.5%
*-commutative30.5%
Simplified30.5%
unpow230.5%
*-commutative30.5%
*-commutative30.5%
swap-sqr19.4%
add-sqr-sqrt63.0%
associate-*r*83.1%
Applied egg-rr83.1%
Final simplification93.7%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.16e+305) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.16e+305) {
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 * x) <= 1.16d+305) 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 * x) <= 1.16e+305) {
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 * x) <= 1.16e+305: 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 (Float64(x * x) <= 1.16e+305) 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 * x) <= 1.16e+305) 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[N[(x * x), $MachinePrecision], 1.16e+305], 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 \cdot x \leq 1.16 \cdot 10^{+305}:\\
\;\;\;\;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 (*.f64 x x) < 1.1600000000000001e305Initial program 92.8%
if 1.1600000000000001e305 < (*.f64 x x) Initial program 75.6%
Taylor expanded in y around 0 75.6%
Simplified93.4%
Final simplification92.9%
(FPCore (x y z t) :precision binary64 (if (<= x 1.02e-14) (* 4.0 (* y t)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 1.02e-14) {
tmp = 4.0 * (y * 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 <= 1.02d-14) then
tmp = 4.0d0 * (y * 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 <= 1.02e-14) {
tmp = 4.0 * (y * t);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 1.02e-14: tmp = 4.0 * (y * t) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 1.02e-14) tmp = Float64(4.0 * Float64(y * t)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 1.02e-14) tmp = 4.0 * (y * t); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 1.02e-14], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.02 \cdot 10^{-14}:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.02e-14Initial program 90.6%
Taylor expanded in t around inf 42.3%
*-commutative42.3%
Simplified42.3%
if 1.02e-14 < x Initial program 83.7%
Taylor expanded in y around 0 83.7%
Simplified71.6%
Final simplification50.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 88.7%
Taylor expanded in z around 0 69.5%
*-commutative69.5%
*-commutative69.5%
associate-*l*69.5%
Simplified69.5%
Final simplification69.5%
(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.7%
Taylor expanded in t around inf 34.5%
*-commutative34.5%
Simplified34.5%
Final simplification34.5%
(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 2024095
(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))))