
(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}
NOTE: x should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= x 2e+163) (fma x x (* (- (* z z) t) (* y -4.0))) (pow x 2.0)))
x = abs(x);
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 2e+163) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = pow(x, 2.0);
}
return tmp;
}
x = abs(x) function code(x, y, z, t) tmp = 0.0 if (x <= 2e+163) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = x ^ 2.0; end return tmp end
NOTE: x should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[x, 2e+163], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x, 2.0], $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+163}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{2}\\
\end{array}
\end{array}
if x < 1.9999999999999999e163Initial program 90.4%
fma-neg91.8%
distribute-lft-neg-in91.8%
*-commutative91.8%
distribute-rgt-neg-in91.8%
metadata-eval91.8%
Simplified91.8%
if 1.9999999999999999e163 < x Initial program 83.3%
associate-*l*83.3%
Simplified83.3%
Taylor expanded in x around inf 97.2%
Final simplification92.6%
NOTE: x should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= x 5.5e+149) (+ (* x x) (* y (* 4.0 (- t (* z z))))) (pow x 2.0)))
x = abs(x);
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 5.5e+149) {
tmp = (x * x) + (y * (4.0 * (t - (z * z))));
} else {
tmp = pow(x, 2.0);
}
return tmp;
}
NOTE: x should be positive before calling this function
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 <= 5.5d+149) then
tmp = (x * x) + (y * (4.0d0 * (t - (z * z))))
else
tmp = x ** 2.0d0
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 5.5e+149) {
tmp = (x * x) + (y * (4.0 * (t - (z * z))));
} else {
tmp = Math.pow(x, 2.0);
}
return tmp;
}
x = abs(x) def code(x, y, z, t): tmp = 0 if x <= 5.5e+149: tmp = (x * x) + (y * (4.0 * (t - (z * z)))) else: tmp = math.pow(x, 2.0) return tmp
x = abs(x) function code(x, y, z, t) tmp = 0.0 if (x <= 5.5e+149) tmp = Float64(Float64(x * x) + Float64(y * Float64(4.0 * Float64(t - Float64(z * z))))); else tmp = x ^ 2.0; end return tmp end
x = abs(x) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 5.5e+149) tmp = (x * x) + (y * (4.0 * (t - (z * z)))); else tmp = x ^ 2.0; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[x, 5.5e+149], N[(N[(x * x), $MachinePrecision] + N[(y * N[(4.0 * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x, 2.0], $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{+149}:\\
\;\;\;\;x \cdot x + y \cdot \left(4 \cdot \left(t - z \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{2}\\
\end{array}
\end{array}
if x < 5.49999999999999999e149Initial program 90.6%
associate-*l*91.1%
Simplified91.1%
if 5.49999999999999999e149 < x Initial program 83.3%
associate-*l*83.3%
Simplified83.3%
Taylor expanded in x around inf 95.2%
Final simplification91.8%
NOTE: x should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= (+ (* x x) (* (* y 4.0) (- t (* z z)))) INFINITY) (- (* x x) (* y (* (- (* z z) t) 4.0))) (- (* x x) (* y (* t -4.0)))))
x = abs(x);
double code(double x, double y, double z, double t) {
double tmp;
if (((x * x) + ((y * 4.0) * (t - (z * z)))) <= ((double) INFINITY)) {
tmp = (x * x) - (y * (((z * z) - t) * 4.0));
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
x = Math.abs(x);
public static double code(double x, double y, double z, double t) {
double tmp;
if (((x * x) + ((y * 4.0) * (t - (z * z)))) <= Double.POSITIVE_INFINITY) {
tmp = (x * x) - (y * (((z * z) - t) * 4.0));
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
x = abs(x) def code(x, y, z, t): tmp = 0 if ((x * x) + ((y * 4.0) * (t - (z * z)))) <= math.inf: tmp = (x * x) - (y * (((z * z) - t) * 4.0)) else: tmp = (x * x) - (y * (t * -4.0)) return tmp
x = abs(x) function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))) <= Inf) tmp = Float64(Float64(x * x) - Float64(y * Float64(Float64(Float64(z * z) - t) * 4.0))); else tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); end return tmp end
x = abs(x) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((x * x) + ((y * 4.0) * (t - (z * z)))) <= Inf) tmp = (x * x) - (y * (((z * z) - t) * 4.0)); else tmp = (x * x) - (y * (t * -4.0)); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(x * x), $MachinePrecision] - N[(y * N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right) \leq \infty:\\
\;\;\;\;x \cdot x - y \cdot \left(\left(z \cdot z - t\right) \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 94.6%
associate-*l*95.0%
Simplified95.0%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) Initial program 0.0%
associate-*l*0.0%
Simplified0.0%
Taylor expanded in z around 0 42.9%
*-commutative42.9%
*-commutative42.9%
associate-*l*42.9%
Simplified42.9%
Final simplification92.1%
NOTE: x should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= z 9e+129) (- (* x x) (* y (* t -4.0))) (* (* y -4.0) (* z z))))
x = abs(x);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 9e+129) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (y * -4.0) * (z * z);
}
return tmp;
}
NOTE: x should be positive before calling this function
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 <= 9d+129) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (y * (-4.0d0)) * (z * z)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 9e+129) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (y * -4.0) * (z * z);
}
return tmp;
}
x = abs(x) def code(x, y, z, t): tmp = 0 if z <= 9e+129: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (y * -4.0) * (z * z) return tmp
x = abs(x) function code(x, y, z, t) tmp = 0.0 if (z <= 9e+129) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(y * -4.0) * Float64(z * z)); end return tmp end
x = abs(x) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 9e+129) tmp = (x * x) - (y * (t * -4.0)); else tmp = (y * -4.0) * (z * z); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[z, 9e+129], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * -4.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 9 \cdot 10^{+129}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if z < 9.0000000000000003e129Initial program 92.6%
associate-*l*93.1%
Simplified93.1%
Taylor expanded in z around 0 77.6%
*-commutative77.6%
*-commutative77.6%
associate-*l*77.6%
Simplified77.6%
if 9.0000000000000003e129 < z Initial program 73.2%
associate-*l*73.2%
Simplified73.2%
add-sqr-sqrt41.1%
difference-of-squares41.1%
Applied egg-rr41.1%
Taylor expanded in z around inf 41.3%
+-commutative41.3%
associate-*r*41.3%
associate-*r*41.3%
distribute-lft-out41.3%
unpow241.3%
*-commutative41.3%
distribute-rgt1-in41.3%
metadata-eval41.3%
mul0-lft73.3%
distribute-rgt-out73.3%
Simplified73.3%
Final simplification76.9%
NOTE: x should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= z 4.6e+16) (* 4.0 (* t y)) (* (* y -4.0) (* z z))))
x = abs(x);
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 4.6e+16) {
tmp = 4.0 * (t * y);
} else {
tmp = (y * -4.0) * (z * z);
}
return tmp;
}
NOTE: x should be positive before calling this function
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 <= 4.6d+16) then
tmp = 4.0d0 * (t * y)
else
tmp = (y * (-4.0d0)) * (z * z)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 4.6e+16) {
tmp = 4.0 * (t * y);
} else {
tmp = (y * -4.0) * (z * z);
}
return tmp;
}
x = abs(x) def code(x, y, z, t): tmp = 0 if z <= 4.6e+16: tmp = 4.0 * (t * y) else: tmp = (y * -4.0) * (z * z) return tmp
x = abs(x) function code(x, y, z, t) tmp = 0.0 if (z <= 4.6e+16) tmp = Float64(4.0 * Float64(t * y)); else tmp = Float64(Float64(y * -4.0) * Float64(z * z)); end return tmp end
x = abs(x) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 4.6e+16) tmp = 4.0 * (t * y); else tmp = (y * -4.0) * (z * z); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[z, 4.6e+16], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(N[(y * -4.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.6 \cdot 10^{+16}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if z < 4.6e16Initial program 93.1%
associate-*l*93.5%
Simplified93.5%
Taylor expanded in t around inf 38.1%
*-commutative38.1%
Simplified38.1%
if 4.6e16 < z Initial program 77.0%
associate-*l*77.0%
Simplified77.0%
add-sqr-sqrt46.9%
difference-of-squares46.9%
Applied egg-rr46.9%
Taylor expanded in z around inf 38.6%
+-commutative38.6%
associate-*r*38.6%
associate-*r*38.6%
distribute-lft-out38.6%
unpow238.6%
*-commutative38.6%
distribute-rgt1-in38.6%
metadata-eval38.6%
mul0-lft65.2%
distribute-rgt-out65.2%
Simplified65.2%
Final simplification44.3%
NOTE: x should be positive before calling this function (FPCore (x y z t) :precision binary64 (if (<= x 2.65e+236) (* 4.0 (* t y)) (* t (* 4.0 (- y)))))
x = abs(x);
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 2.65e+236) {
tmp = 4.0 * (t * y);
} else {
tmp = t * (4.0 * -y);
}
return tmp;
}
NOTE: x should be positive before calling this function
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.65d+236) then
tmp = 4.0d0 * (t * y)
else
tmp = t * (4.0d0 * -y)
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 2.65e+236) {
tmp = 4.0 * (t * y);
} else {
tmp = t * (4.0 * -y);
}
return tmp;
}
x = abs(x) def code(x, y, z, t): tmp = 0 if x <= 2.65e+236: tmp = 4.0 * (t * y) else: tmp = t * (4.0 * -y) return tmp
x = abs(x) function code(x, y, z, t) tmp = 0.0 if (x <= 2.65e+236) tmp = Float64(4.0 * Float64(t * y)); else tmp = Float64(t * Float64(4.0 * Float64(-y))); end return tmp end
x = abs(x) function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 2.65e+236) tmp = 4.0 * (t * y); else tmp = t * (4.0 * -y); end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_, z_, t_] := If[LessEqual[x, 2.65e+236], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(t * N[(4.0 * (-y)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.65 \cdot 10^{+236}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(4 \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if x < 2.64999999999999989e236Initial program 90.4%
associate-*l*90.8%
Simplified90.8%
Taylor expanded in t around inf 33.4%
*-commutative33.4%
Simplified33.4%
if 2.64999999999999989e236 < x Initial program 73.3%
associate-*l*73.3%
Simplified73.3%
Taylor expanded in t around inf 1.1%
*-commutative1.1%
Simplified1.1%
*-commutative1.1%
metadata-eval1.1%
distribute-rgt-neg-in1.1%
associate-*r*1.1%
add-sqr-sqrt0.2%
sqrt-unprod0.8%
associate-*r*0.8%
associate-*r*0.8%
swap-sqr0.8%
metadata-eval0.8%
metadata-eval0.8%
swap-sqr0.8%
*-commutative0.8%
*-commutative0.8%
sqrt-unprod0.6%
add-sqr-sqrt15.6%
associate-*r*15.6%
*-commutative15.6%
Applied egg-rr15.6%
Final simplification32.3%
NOTE: x should be positive before calling this function (FPCore (x y z t) :precision binary64 (* 4.0 (* t y)))
x = abs(x);
double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
NOTE: x should be positive before calling this function
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
x = Math.abs(x);
public static double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
x = abs(x) def code(x, y, z, t): return 4.0 * (t * y)
x = abs(x) function code(x, y, z, t) return Float64(4.0 * Float64(t * y)) end
x = abs(x) function tmp = code(x, y, z, t) tmp = 4.0 * (t * y); end
NOTE: x should be positive before calling this function code[x_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 89.4%
associate-*l*89.8%
Simplified89.8%
Taylor expanded in t around inf 31.5%
*-commutative31.5%
Simplified31.5%
Final simplification31.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 2023336
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:herbie-target
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))