
(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+302) (fma x x (* (- (* z z) t) (* y -4.0))) (- (* x x) (* z (* z (* y 4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+302) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+302) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(Float64(x * x) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+302], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2.0000000000000002e302Initial program 96.7%
fma-neg98.9%
distribute-lft-neg-in98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
metadata-eval98.9%
Simplified98.9%
if 2.0000000000000002e302 < (*.f64 z z) Initial program 62.7%
sub-neg62.7%
flip-+0.0%
pow20.0%
pow20.0%
pow-prod-up0.0%
metadata-eval0.0%
pow20.0%
Applied egg-rr0.0%
clear-num0.0%
un-div-inv0.0%
clear-num0.0%
metadata-eval0.0%
pow-sqr0.0%
flip-+62.7%
add-sqr-sqrt32.1%
sqrt-prod48.3%
sqr-neg48.3%
sqrt-prod30.6%
add-sqr-sqrt62.7%
sub-neg62.7%
Applied egg-rr62.7%
Taylor expanded in z around inf 62.7%
associate-/r/62.7%
/-rgt-identity62.7%
unpow262.7%
associate-*r*91.4%
Applied egg-rr91.4%
Final simplification96.8%
(FPCore (x y z t)
:precision binary64
(if (or (<= (* x x) 1.06e-134)
(and (not (<= (* x x) 7e+26)) (<= (* x x) 4.5e+140)))
(* y (* t 4.0))
(* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if (((x * x) <= 1.06e-134) || (!((x * x) <= 7e+26) && ((x * x) <= 4.5e+140))) {
tmp = y * (t * 4.0);
} 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.06d-134) .or. (.not. ((x * x) <= 7d+26)) .and. ((x * x) <= 4.5d+140)) then
tmp = y * (t * 4.0d0)
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.06e-134) || (!((x * x) <= 7e+26) && ((x * x) <= 4.5e+140))) {
tmp = y * (t * 4.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((x * x) <= 1.06e-134) or (not ((x * x) <= 7e+26) and ((x * x) <= 4.5e+140)): tmp = y * (t * 4.0) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(x * x) <= 1.06e-134) || (!(Float64(x * x) <= 7e+26) && (Float64(x * x) <= 4.5e+140))) tmp = Float64(y * Float64(t * 4.0)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((x * x) <= 1.06e-134) || (~(((x * x) <= 7e+26)) && ((x * x) <= 4.5e+140))) tmp = y * (t * 4.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 1.06e-134], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 7e+26]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 4.5e+140]]], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.06 \cdot 10^{-134} \lor \neg \left(x \cdot x \leq 7 \cdot 10^{+26}\right) \land x \cdot x \leq 4.5 \cdot 10^{+140}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.06e-134 or 6.9999999999999998e26 < (*.f64 x x) < 4.5000000000000002e140Initial program 88.9%
Taylor expanded in t around inf 44.6%
associate-*r*44.6%
Simplified44.6%
if 1.06e-134 < (*.f64 x x) < 6.9999999999999998e26 or 4.5000000000000002e140 < (*.f64 x x) Initial program 85.8%
sub-neg85.8%
distribute-lft-neg-in85.8%
*-commutative85.8%
distribute-lft-neg-in85.8%
metadata-eval85.8%
*-commutative85.8%
add-sqr-sqrt35.0%
sqrt-unprod66.2%
swap-sqr66.2%
metadata-eval66.2%
metadata-eval66.2%
swap-sqr66.2%
sqrt-unprod37.0%
add-sqr-sqrt58.0%
expm1-log1p-u56.8%
add-sqr-sqrt36.3%
Applied egg-rr70.5%
Simplified67.5%
expm1-log1p-u68.9%
pow268.9%
Applied egg-rr68.9%
Final simplification57.7%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 2e+302) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* z (* z (* y 4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+302) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (z * (z * (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) <= 2d+302) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - (z * (z * (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) <= 2e+302) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 2e+302: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - (z * (z * (y * 4.0))) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+302) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 2e+302) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - (z * (z * (y * 4.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+302], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+302}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2.0000000000000002e302Initial program 96.7%
if 2.0000000000000002e302 < (*.f64 z z) Initial program 62.7%
sub-neg62.7%
flip-+0.0%
pow20.0%
pow20.0%
pow-prod-up0.0%
metadata-eval0.0%
pow20.0%
Applied egg-rr0.0%
clear-num0.0%
un-div-inv0.0%
clear-num0.0%
metadata-eval0.0%
pow-sqr0.0%
flip-+62.7%
add-sqr-sqrt32.1%
sqrt-prod48.3%
sqr-neg48.3%
sqrt-prod30.6%
add-sqr-sqrt62.7%
sub-neg62.7%
Applied egg-rr62.7%
Taylor expanded in z around inf 62.7%
associate-/r/62.7%
/-rgt-identity62.7%
unpow262.7%
associate-*r*91.4%
Applied egg-rr91.4%
Final simplification95.2%
(FPCore (x y z t) :precision binary64 (if (<= z 3.3e+41) (- (* x x) (* -4.0 (* t y))) (- (* x x) (* z (* z (* y 4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.3e+41) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = (x * x) - (z * (z * (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 <= 3.3d+41) then
tmp = (x * x) - ((-4.0d0) * (t * y))
else
tmp = (x * x) - (z * (z * (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 <= 3.3e+41) {
tmp = (x * x) - (-4.0 * (t * y));
} else {
tmp = (x * x) - (z * (z * (y * 4.0)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 3.3e+41: tmp = (x * x) - (-4.0 * (t * y)) else: tmp = (x * x) - (z * (z * (y * 4.0))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 3.3e+41) tmp = Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))); else tmp = Float64(Float64(x * x) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 3.3e+41) tmp = (x * x) - (-4.0 * (t * y)); else tmp = (x * x) - (z * (z * (y * 4.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 3.3e+41], N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.3 \cdot 10^{+41}:\\
\;\;\;\;x \cdot x - -4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if z < 3.3e41Initial program 92.2%
Taylor expanded in z around 0 76.3%
*-commutative76.3%
Simplified76.3%
if 3.3e41 < z Initial program 70.1%
sub-neg70.1%
flip-+10.8%
pow210.8%
pow210.8%
pow-prod-up10.8%
metadata-eval10.8%
pow210.8%
Applied egg-rr10.8%
clear-num10.8%
un-div-inv10.8%
clear-num10.8%
metadata-eval10.8%
pow-sqr10.7%
flip-+70.0%
add-sqr-sqrt34.3%
sqrt-prod54.1%
sqr-neg54.1%
sqrt-prod35.7%
add-sqr-sqrt70.0%
sub-neg70.0%
Applied egg-rr70.0%
Taylor expanded in z around inf 70.0%
associate-/r/70.1%
/-rgt-identity70.1%
unpow270.1%
associate-*r*92.8%
Applied egg-rr92.8%
Final simplification80.0%
(FPCore (x y z t) :precision binary64 (- (* x x) (* -4.0 (* t y))))
double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (t * y));
}
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) * (t * y))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (t * y));
}
def code(x, y, z, t): return (x * x) - (-4.0 * (t * y))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(-4.0 * Float64(t * y))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (-4.0 * (t * y)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - -4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 87.3%
Taylor expanded in z around 0 64.1%
*-commutative64.1%
Simplified64.1%
Final simplification64.1%
(FPCore (x y z t) :precision binary64 (* x x))
double code(double x, double y, double z, double t) {
return x * x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x * x;
}
def code(x, y, z, t): return x * x
function code(x, y, z, t) return Float64(x * x) end
function tmp = code(x, y, z, t) tmp = x * x; end
code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 87.3%
sub-neg87.3%
distribute-lft-neg-in87.3%
*-commutative87.3%
distribute-lft-neg-in87.3%
metadata-eval87.3%
*-commutative87.3%
add-sqr-sqrt43.5%
sqrt-unprod57.0%
swap-sqr57.0%
metadata-eval57.0%
metadata-eval57.0%
swap-sqr57.0%
sqrt-unprod22.8%
add-sqr-sqrt36.2%
expm1-log1p-u35.3%
add-sqr-sqrt22.4%
Applied egg-rr65.1%
Simplified42.0%
expm1-log1p-u42.9%
pow242.9%
Applied egg-rr42.9%
Final simplification42.9%
(FPCore (x y z t) :precision binary64 -1.0)
double code(double x, double y, double z, double t) {
return -1.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 = -1.0d0
end function
public static double code(double x, double y, double z, double t) {
return -1.0;
}
def code(x, y, z, t): return -1.0
function code(x, y, z, t) return -1.0 end
function tmp = code(x, y, z, t) tmp = -1.0; end
code[x_, y_, z_, t_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 87.3%
sub-neg87.3%
distribute-lft-neg-in87.3%
*-commutative87.3%
distribute-lft-neg-in87.3%
metadata-eval87.3%
*-commutative87.3%
add-sqr-sqrt43.5%
sqrt-unprod57.0%
swap-sqr57.0%
metadata-eval57.0%
metadata-eval57.0%
swap-sqr57.0%
sqrt-unprod22.8%
add-sqr-sqrt36.2%
expm1-log1p-u35.3%
add-sqr-sqrt22.4%
Applied egg-rr65.1%
Simplified42.0%
Taylor expanded in x around inf 17.0%
log-rec17.0%
Simplified17.0%
Taylor expanded in x around 0 1.9%
Final simplification1.9%
(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 2024050
(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))))