
(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}
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (if (<= z_m 2e+143) (fma (* y 4.0) (- t (* z_m z_m)) (* x x)) (* (* z_m z_m) (* y -4.0))))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
double tmp;
if (z_m <= 2e+143) {
tmp = fma((y * 4.0), (t - (z_m * z_m)), (x * x));
} else {
tmp = (z_m * z_m) * (y * -4.0);
}
return tmp;
}
z_m = abs(z) function code(x, y, z_m, t) tmp = 0.0 if (z_m <= 2e+143) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z_m * z_m)), Float64(x * x)); else tmp = Float64(Float64(z_m * z_m) * Float64(y * -4.0)); end return tmp end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := If[LessEqual[z$95$m, 2e+143], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(z$95$m * z$95$m), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;z\_m \leq 2 \cdot 10^{+143}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z\_m \cdot z\_m, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z\_m \cdot z\_m\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 2e143Initial program 93.6%
cancel-sign-sub-inv93.6%
distribute-lft-neg-out93.6%
+-commutative93.6%
associate-*l*93.6%
distribute-lft-neg-in93.6%
associate-*l*93.6%
distribute-rgt-neg-in93.6%
fma-define96.4%
sub-neg96.4%
+-commutative96.4%
distribute-neg-in96.4%
remove-double-neg96.4%
sub-neg96.4%
Simplified96.4%
if 2e143 < z Initial program 73.7%
fma-neg81.2%
distribute-lft-neg-in81.2%
*-commutative81.2%
distribute-rgt-neg-in81.2%
metadata-eval81.2%
Simplified81.2%
Taylor expanded in z around inf 81.2%
associate-*r*81.2%
*-commutative81.2%
Simplified81.2%
unpow281.2%
Applied egg-rr81.2%
Final simplification94.0%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (fma x x (* (* y -4.0) (- (* z_m z_m) t))))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
return fma(x, x, ((y * -4.0) * ((z_m * z_m) - t)));
}
z_m = abs(z) function code(x, y, z_m, t) return fma(x, x, Float64(Float64(y * -4.0) * Float64(Float64(z_m * z_m) - t))) end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := N[(x * x + N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z$95$m * z$95$m), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z\_m \cdot z\_m - t\right)\right)
\end{array}
Initial program 90.5%
fma-neg93.2%
distribute-lft-neg-in93.2%
*-commutative93.2%
distribute-rgt-neg-in93.2%
metadata-eval93.2%
Simplified93.2%
Final simplification93.2%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z_m z_m)))))) (if (<= t_1 INFINITY) t_1 (* y (* t -4.0)))))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z_m * z_m)));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = y * (t * -4.0);
}
return tmp;
}
z_m = Math.abs(z);
public static double code(double x, double y, double z_m, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z_m * z_m)));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = y * (t * -4.0);
}
return tmp;
}
z_m = math.fabs(z) def code(x, y, z_m, t): t_1 = (x * x) + ((y * 4.0) * (t - (z_m * z_m))) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = y * (t * -4.0) return tmp
z_m = abs(z) function code(x, y, z_m, t) t_1 = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z_m * z_m)))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(y * Float64(t * -4.0)); end return tmp end
z_m = abs(z); function tmp_2 = code(x, y, z_m, t) t_1 = (x * x) + ((y * 4.0) * (t - (z_m * z_m))); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = y * (t * -4.0); end tmp_2 = tmp; end
z_m = N[Abs[z], $MachinePrecision]
code[x_, y_, z$95$m_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z_m = \left|z\right|
\\
\begin{array}{l}
t_1 := x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z\_m \cdot z\_m\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot -4\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 95.7%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 0.0%
*-commutative0.0%
add-sqr-sqrt0.0%
sqrt-unprod21.4%
swap-sqr21.4%
metadata-eval21.4%
metadata-eval21.4%
swap-sqr21.4%
sqrt-unprod21.4%
add-sqr-sqrt50.0%
add-cube-cbrt50.0%
pow350.0%
Applied egg-rr0.0%
rem-cbrt-cube0.0%
*-un-lft-identity0.0%
unpow30.0%
add-cube-cbrt0.0%
unpow20.0%
fma-neg0.0%
add-sqr-sqrt0.0%
sqrt-unprod21.4%
sqr-neg21.4%
sqrt-unprod21.4%
add-sqr-sqrt35.7%
Applied egg-rr35.7%
*-lft-identity35.7%
Simplified35.7%
Taylor expanded in t around inf 51.7%
associate-*r*51.7%
rem-cube-cbrt51.7%
neg-mul-151.7%
distribute-lft-neg-in51.7%
associate-*r*51.7%
*-commutative51.7%
distribute-rgt-neg-in51.7%
metadata-eval51.7%
associate-*r*51.7%
Simplified51.7%
Final simplification93.3%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (if (<= z_m 2.3e-95) (* 4.0 (* y t)) (if (<= z_m 3.1e+42) (* x x) (* (* z_m z_m) (* y -4.0)))))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
double tmp;
if (z_m <= 2.3e-95) {
tmp = 4.0 * (y * t);
} else if (z_m <= 3.1e+42) {
tmp = x * x;
} else {
tmp = (z_m * z_m) * (y * -4.0);
}
return tmp;
}
z_m = abs(z)
real(8) function code(x, y, z_m, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t
real(8) :: tmp
if (z_m <= 2.3d-95) then
tmp = 4.0d0 * (y * t)
else if (z_m <= 3.1d+42) then
tmp = x * x
else
tmp = (z_m * z_m) * (y * (-4.0d0))
end if
code = tmp
end function
z_m = Math.abs(z);
public static double code(double x, double y, double z_m, double t) {
double tmp;
if (z_m <= 2.3e-95) {
tmp = 4.0 * (y * t);
} else if (z_m <= 3.1e+42) {
tmp = x * x;
} else {
tmp = (z_m * z_m) * (y * -4.0);
}
return tmp;
}
z_m = math.fabs(z) def code(x, y, z_m, t): tmp = 0 if z_m <= 2.3e-95: tmp = 4.0 * (y * t) elif z_m <= 3.1e+42: tmp = x * x else: tmp = (z_m * z_m) * (y * -4.0) return tmp
z_m = abs(z) function code(x, y, z_m, t) tmp = 0.0 if (z_m <= 2.3e-95) tmp = Float64(4.0 * Float64(y * t)); elseif (z_m <= 3.1e+42) tmp = Float64(x * x); else tmp = Float64(Float64(z_m * z_m) * Float64(y * -4.0)); end return tmp end
z_m = abs(z); function tmp_2 = code(x, y, z_m, t) tmp = 0.0; if (z_m <= 2.3e-95) tmp = 4.0 * (y * t); elseif (z_m <= 3.1e+42) tmp = x * x; else tmp = (z_m * z_m) * (y * -4.0); end tmp_2 = tmp; end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := If[LessEqual[z$95$m, 2.3e-95], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z$95$m, 3.1e+42], N[(x * x), $MachinePrecision], N[(N[(z$95$m * z$95$m), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;z\_m \leq 2.3 \cdot 10^{-95}:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\
\mathbf{elif}\;z\_m \leq 3.1 \cdot 10^{+42}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z\_m \cdot z\_m\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 2.29999999999999999e-95Initial program 93.8%
fma-neg96.3%
distribute-lft-neg-in96.3%
*-commutative96.3%
distribute-rgt-neg-in96.3%
metadata-eval96.3%
Simplified96.3%
Taylor expanded in t around inf 39.6%
*-commutative39.6%
Simplified39.6%
if 2.29999999999999999e-95 < z < 3.1000000000000002e42Initial program 93.9%
Taylor expanded in y around 0 93.9%
Simplified46.7%
--rgt-identity46.7%
Applied egg-rr46.7%
if 3.1000000000000002e42 < z Initial program 80.6%
fma-neg85.3%
distribute-lft-neg-in85.3%
*-commutative85.3%
distribute-rgt-neg-in85.3%
metadata-eval85.3%
Simplified85.3%
Taylor expanded in z around inf 73.6%
associate-*r*73.6%
*-commutative73.6%
Simplified73.6%
unpow273.6%
Applied egg-rr73.6%
Final simplification49.1%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (if (<= z_m 7.2e+54) (- (* x x) (* y (* t -4.0))) (* (* z_m z_m) (* y -4.0))))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
double tmp;
if (z_m <= 7.2e+54) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z_m * z_m) * (y * -4.0);
}
return tmp;
}
z_m = abs(z)
real(8) function code(x, y, z_m, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t
real(8) :: tmp
if (z_m <= 7.2d+54) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (z_m * z_m) * (y * (-4.0d0))
end if
code = tmp
end function
z_m = Math.abs(z);
public static double code(double x, double y, double z_m, double t) {
double tmp;
if (z_m <= 7.2e+54) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z_m * z_m) * (y * -4.0);
}
return tmp;
}
z_m = math.fabs(z) def code(x, y, z_m, t): tmp = 0 if z_m <= 7.2e+54: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (z_m * z_m) * (y * -4.0) return tmp
z_m = abs(z) function code(x, y, z_m, t) tmp = 0.0 if (z_m <= 7.2e+54) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(z_m * z_m) * Float64(y * -4.0)); end return tmp end
z_m = abs(z); function tmp_2 = code(x, y, z_m, t) tmp = 0.0; if (z_m <= 7.2e+54) tmp = (x * x) - (y * (t * -4.0)); else tmp = (z_m * z_m) * (y * -4.0); end tmp_2 = tmp; end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := If[LessEqual[z$95$m, 7.2e+54], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z$95$m * z$95$m), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;z\_m \leq 7.2 \cdot 10^{+54}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z\_m \cdot z\_m\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 7.2000000000000003e54Initial program 93.9%
Taylor expanded in z around 0 74.7%
*-commutative74.7%
*-commutative74.7%
associate-*l*74.7%
Simplified74.7%
if 7.2000000000000003e54 < z Initial program 80.0%
fma-neg84.8%
distribute-lft-neg-in84.8%
*-commutative84.8%
distribute-rgt-neg-in84.8%
metadata-eval84.8%
Simplified84.8%
Taylor expanded in z around inf 74.3%
associate-*r*74.3%
*-commutative74.3%
Simplified74.3%
unpow274.3%
Applied egg-rr74.3%
Final simplification74.6%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (if (<= (* x x) 1.9e+51) (* 4.0 (* y t)) (* x x)))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
double tmp;
if ((x * x) <= 1.9e+51) {
tmp = 4.0 * (y * t);
} else {
tmp = x * x;
}
return tmp;
}
z_m = abs(z)
real(8) function code(x, y, z_m, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t
real(8) :: tmp
if ((x * x) <= 1.9d+51) then
tmp = 4.0d0 * (y * t)
else
tmp = x * x
end if
code = tmp
end function
z_m = Math.abs(z);
public static double code(double x, double y, double z_m, double t) {
double tmp;
if ((x * x) <= 1.9e+51) {
tmp = 4.0 * (y * t);
} else {
tmp = x * x;
}
return tmp;
}
z_m = math.fabs(z) def code(x, y, z_m, t): tmp = 0 if (x * x) <= 1.9e+51: tmp = 4.0 * (y * t) else: tmp = x * x return tmp
z_m = abs(z) function code(x, y, z_m, t) tmp = 0.0 if (Float64(x * x) <= 1.9e+51) tmp = Float64(4.0 * Float64(y * t)); else tmp = Float64(x * x); end return tmp end
z_m = abs(z); function tmp_2 = code(x, y, z_m, t) tmp = 0.0; if ((x * x) <= 1.9e+51) tmp = 4.0 * (y * t); else tmp = x * x; end tmp_2 = tmp; end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.9e+51], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.9 \cdot 10^{+51}:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.8999999999999999e51Initial program 93.2%
fma-neg93.2%
distribute-lft-neg-in93.2%
*-commutative93.2%
distribute-rgt-neg-in93.2%
metadata-eval93.2%
Simplified93.2%
Taylor expanded in t around inf 49.1%
*-commutative49.1%
Simplified49.1%
if 1.8999999999999999e51 < (*.f64 x x) Initial program 86.4%
Taylor expanded in y around 0 86.4%
Simplified69.7%
--rgt-identity69.7%
Applied egg-rr69.7%
z_m = (fabs.f64 z) (FPCore (x y z_m t) :precision binary64 (* x x))
z_m = fabs(z);
double code(double x, double y, double z_m, double t) {
return x * x;
}
z_m = abs(z)
real(8) function code(x, y, z_m, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t
code = x * x
end function
z_m = Math.abs(z);
public static double code(double x, double y, double z_m, double t) {
return x * x;
}
z_m = math.fabs(z) def code(x, y, z_m, t): return x * x
z_m = abs(z) function code(x, y, z_m, t) return Float64(x * x) end
z_m = abs(z); function tmp = code(x, y, z_m, t) tmp = x * x; end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x \cdot x
\end{array}
Initial program 90.5%
Taylor expanded in y around 0 90.5%
Simplified35.3%
--rgt-identity35.3%
Applied egg-rr35.3%
(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 2024135
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))