
(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}
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= x_m 2.6e+194) (fma x_m x_m (* (- (* z z) t) (* y -4.0))) (- (* x_m x_m) (* y (* t -4.0)))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (x_m <= 2.6e+194) {
tmp = fma(x_m, x_m, (((z * z) - t) * (y * -4.0)));
} else {
tmp = (x_m * x_m) - (y * (t * -4.0));
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (x_m <= 2.6e+194) tmp = fma(x_m, x_m, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(Float64(x_m * x_m) - Float64(y * Float64(t * -4.0))); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[x$95$m, 2.6e+194], N[(x$95$m * x$95$m + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 2.6 \cdot 10^{+194}:\\
\;\;\;\;\mathsf{fma}\left(x_m, x_m, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x_m \cdot x_m - y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if x < 2.5999999999999999e194Initial program 91.8%
fma-neg93.0%
distribute-lft-neg-in93.0%
*-commutative93.0%
distribute-rgt-neg-in93.0%
metadata-eval93.0%
Simplified93.0%
if 2.5999999999999999e194 < x Initial program 90.0%
Taylor expanded in z around 0 95.0%
*-commutative95.0%
*-commutative95.0%
associate-*l*95.0%
Simplified95.0%
Final simplification93.2%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= x_m 3.2e+152) (- (* x_m x_m) (* (- (* z z) t) (* y 4.0))) (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (x_m <= 3.2e+152) {
tmp = (x_m * x_m) - (((z * z) - t) * (y * 4.0));
} else {
tmp = pow(x_m, 2.0);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (x_m <= 3.2d+152) then
tmp = (x_m * x_m) - (((z * z) - t) * (y * 4.0d0))
else
tmp = x_m ** 2.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if (x_m <= 3.2e+152) {
tmp = (x_m * x_m) - (((z * z) - t) * (y * 4.0));
} else {
tmp = Math.pow(x_m, 2.0);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if x_m <= 3.2e+152: tmp = (x_m * x_m) - (((z * z) - t) * (y * 4.0)) else: tmp = math.pow(x_m, 2.0) return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (x_m <= 3.2e+152) tmp = Float64(Float64(x_m * x_m) - Float64(Float64(Float64(z * z) - t) * Float64(y * 4.0))); else tmp = x_m ^ 2.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if (x_m <= 3.2e+152) tmp = (x_m * x_m) - (((z * z) - t) * (y * 4.0)); else tmp = x_m ^ 2.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[x$95$m, 3.2e+152], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x$95$m, 2.0], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 3.2 \cdot 10^{+152}:\\
\;\;\;\;x_m \cdot x_m - \left(z \cdot z - t\right) \cdot \left(y \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;{x_m}^{2}\\
\end{array}
\end{array}
if x < 3.20000000000000005e152Initial program 92.3%
if 3.20000000000000005e152 < x Initial program 86.2%
Taylor expanded in x around inf 93.1%
Final simplification92.4%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (let* ((t_1 (- (* x_m x_m) (* (- (* z z) t) (* y 4.0))))) (if (<= t_1 INFINITY) t_1 (- (* x_m x_m) (* 4.0 (* t y))))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double t_1 = (x_m * x_m) - (((z * z) - t) * (y * 4.0));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = (x_m * x_m) - (4.0 * (t * y));
}
return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double t_1 = (x_m * x_m) - (((z * z) - t) * (y * 4.0));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = (x_m * x_m) - (4.0 * (t * y));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): t_1 = (x_m * x_m) - (((z * z) - t) * (y * 4.0)) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = (x_m * x_m) - (4.0 * (t * y)) return tmp
x_m = abs(x) function code(x_m, y, z, t) t_1 = Float64(Float64(x_m * x_m) - Float64(Float64(Float64(z * z) - t) * Float64(y * 4.0))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(Float64(x_m * x_m) - Float64(4.0 * Float64(t * y))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) t_1 = (x_m * x_m) - (((z * z) - t) * (y * 4.0)); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = (x_m * x_m) - (4.0 * (t * y)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_1 := x_m \cdot x_m - \left(z \cdot z - t\right) \cdot \left(y \cdot 4\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x_m \cdot x_m - 4 \cdot \left(t \cdot y\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 95.7%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) Initial program 0.0%
sub-neg0.0%
flip-+0.0%
pow20.0%
pow20.0%
pow-prod-up0.0%
metadata-eval0.0%
pow20.0%
Applied egg-rr0.0%
associate-*r/0.0%
clear-num0.0%
unpow20.0%
fma-neg0.0%
remove-double-neg0.0%
*-commutative0.0%
associate-*l*0.0%
metadata-eval0.0%
pow-prod-up0.0%
sqr-neg0.0%
difference-of-squares0.0%
remove-double-neg0.0%
sub-neg0.0%
add-sqr-sqrt0.0%
sqrt-prod0.0%
sqr-neg0.0%
sqrt-prod0.0%
add-sqr-sqrt9.1%
Applied egg-rr9.1%
*-lft-identity9.1%
times-frac9.1%
metadata-eval9.1%
*-commutative9.1%
associate-/r*9.1%
remove-double-div9.1%
associate-/r*9.1%
*-commutative9.1%
unpow29.1%
associate-*r*9.1%
rgt-mult-inverse9.1%
*-rgt-identity9.1%
Simplified9.1%
Taylor expanded in z around 0 63.6%
*-commutative63.6%
Simplified63.6%
Final simplification94.4%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (let* ((t_1 (* 4.0 (* t y)))) (if (<= (* x_m x_m) 1.8e+105) t_1 (- (* x_m x_m) t_1))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double t_1 = 4.0 * (t * y);
double tmp;
if ((x_m * x_m) <= 1.8e+105) {
tmp = t_1;
} else {
tmp = (x_m * x_m) - t_1;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = 4.0d0 * (t * y)
if ((x_m * x_m) <= 1.8d+105) then
tmp = t_1
else
tmp = (x_m * x_m) - t_1
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double t_1 = 4.0 * (t * y);
double tmp;
if ((x_m * x_m) <= 1.8e+105) {
tmp = t_1;
} else {
tmp = (x_m * x_m) - t_1;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): t_1 = 4.0 * (t * y) tmp = 0 if (x_m * x_m) <= 1.8e+105: tmp = t_1 else: tmp = (x_m * x_m) - t_1 return tmp
x_m = abs(x) function code(x_m, y, z, t) t_1 = Float64(4.0 * Float64(t * y)) tmp = 0.0 if (Float64(x_m * x_m) <= 1.8e+105) tmp = t_1; else tmp = Float64(Float64(x_m * x_m) - t_1); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) t_1 = 4.0 * (t * y); tmp = 0.0; if ((x_m * x_m) <= 1.8e+105) tmp = t_1; else tmp = (x_m * x_m) - t_1; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := Block[{t$95$1 = N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 1.8e+105], t$95$1, N[(N[(x$95$m * x$95$m), $MachinePrecision] - t$95$1), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_1 := 4 \cdot \left(t \cdot y\right)\\
\mathbf{if}\;x_m \cdot x_m \leq 1.8 \cdot 10^{+105}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x_m \cdot x_m - t_1\\
\end{array}
\end{array}
if (*.f64 x x) < 1.7999999999999999e105Initial program 94.6%
Taylor expanded in t around inf 50.2%
*-commutative50.2%
Simplified50.2%
if 1.7999999999999999e105 < (*.f64 x x) Initial program 86.8%
sub-neg86.8%
flip-+53.4%
pow253.4%
pow253.4%
pow-prod-up53.4%
metadata-eval53.4%
pow253.4%
Applied egg-rr53.4%
associate-*r/50.6%
clear-num50.6%
unpow250.6%
fma-neg50.6%
remove-double-neg50.6%
*-commutative50.6%
associate-*l*50.6%
metadata-eval50.6%
pow-prod-up50.6%
sqr-neg50.6%
difference-of-squares51.7%
remove-double-neg51.7%
sub-neg51.7%
add-sqr-sqrt25.9%
sqrt-prod49.5%
sqr-neg49.5%
sqrt-prod24.6%
add-sqr-sqrt47.1%
Applied egg-rr47.1%
*-lft-identity47.1%
times-frac47.1%
metadata-eval47.1%
*-commutative47.1%
associate-/r*48.2%
remove-double-div48.2%
associate-/r*48.2%
*-commutative48.2%
unpow248.2%
associate-*r*61.2%
rgt-mult-inverse78.7%
*-rgt-identity78.7%
Simplified78.7%
Taylor expanded in z around 0 75.0%
*-commutative75.0%
Simplified75.0%
Final simplification59.7%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (- (* x_m x_m) (* y (* t -4.0))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return (x_m * x_m) - (y * (t * -4.0));
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x_m * x_m) - (y * (t * (-4.0d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return (x_m * x_m) - (y * (t * -4.0));
}
x_m = math.fabs(x) def code(x_m, y, z, t): return (x_m * x_m) - (y * (t * -4.0))
x_m = abs(x) function code(x_m, y, z, t) return Float64(Float64(x_m * x_m) - Float64(y * Float64(t * -4.0))) end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = (x_m * x_m) - (y * (t * -4.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_m \cdot x_m - y \cdot \left(t \cdot -4\right)
\end{array}
Initial program 91.6%
Taylor expanded in z around 0 68.5%
*-commutative68.5%
*-commutative68.5%
associate-*l*68.5%
Simplified68.5%
Final simplification68.5%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (* 4.0 (* t y)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return 4.0 * (t * y);
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 4.0d0 * (t * y)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return 4.0 * (t * y);
}
x_m = math.fabs(x) def code(x_m, y, z, t): return 4.0 * (t * y)
x_m = abs(x) function code(x_m, y, z, t) return Float64(4.0 * Float64(t * y)) end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = 4.0 * (t * y); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 91.6%
Taylor expanded in t around inf 36.1%
*-commutative36.1%
Simplified36.1%
Final simplification36.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 2024021
(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))))