| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13952 |
\[x \cdot x + \left(y \cdot \left(4 \cdot t\right) - {\left(\sqrt[3]{z \cdot \left(z \cdot \left(y \cdot 4\right)\right)}\right)}^{3}\right)
\]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.2e+129) (not (<= z 1e+152))) (+ (* x x) (* z (* z (* y -4.0)))) (+ (* x x) (* 4.0 (- (* y t) (* y (* z z)))))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.2e+129) || !(z <= 1e+152)) {
tmp = (x * x) + (z * (z * (y * -4.0)));
} else {
tmp = (x * x) + (4.0 * ((y * t) - (y * (z * z))));
}
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
code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end 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 <= (-3.2d+129)) .or. (.not. (z <= 1d+152))) then
tmp = (x * x) + (z * (z * (y * (-4.0d0))))
else
tmp = (x * x) + (4.0d0 * ((y * t) - (y * (z * z))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.2e+129) || !(z <= 1e+152)) {
tmp = (x * x) + (z * (z * (y * -4.0)));
} else {
tmp = (x * x) + (4.0 * ((y * t) - (y * (z * z))));
}
return tmp;
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
def code(x, y, z, t): tmp = 0 if (z <= -3.2e+129) or not (z <= 1e+152): tmp = (x * x) + (z * (z * (y * -4.0))) else: tmp = (x * x) + (4.0 * ((y * t) - (y * (z * z)))) return tmp
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.2e+129) || !(z <= 1e+152)) tmp = Float64(Float64(x * x) + Float64(z * Float64(z * Float64(y * -4.0)))); else tmp = Float64(Float64(x * x) + Float64(4.0 * Float64(Float64(y * t) - Float64(y * Float64(z * z))))); end return tmp end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - t)); end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.2e+129) || ~((z <= 1e+152))) tmp = (x * x) + (z * (z * (y * -4.0))); else tmp = (x * x) + (4.0 * ((y * t) - (y * (z * z)))); end tmp_2 = tmp; 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]
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.2e+129], N[Not[LessEqual[z, 1e+152]], $MachinePrecision]], N[(N[(x * x), $MachinePrecision] + N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(4.0 * N[(N[(y * t), $MachinePrecision] - N[(y * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{+129} \lor \neg \left(z \leq 10^{+152}\right):\\
\;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + 4 \cdot \left(y \cdot t - y \cdot \left(z \cdot z\right)\right)\\
\end{array}
Results
| Original | 5.7 |
|---|---|
| Target | 5.7 |
| Herbie | 0.2 |
if z < -3.2000000000000002e129 or 1e152 < z Initial program 53.6
Simplified53.8
[Start]53.6 | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\] |
|---|---|
associate-*l* [=>]53.8 | \[ x \cdot x - \color{blue}{y \cdot \left(4 \cdot \left(z \cdot z - t\right)\right)}
\] |
Taylor expanded in z around inf 54.2
Simplified0.9
[Start]54.2 | \[ x \cdot x - 4 \cdot \left(y \cdot {z}^{2}\right)
\] |
|---|---|
*-commutative [=>]54.2 | \[ x \cdot x - \color{blue}{\left(y \cdot {z}^{2}\right) \cdot 4}
\] |
*-commutative [=>]54.2 | \[ x \cdot x - \color{blue}{\left({z}^{2} \cdot y\right)} \cdot 4
\] |
unpow2 [=>]54.2 | \[ x \cdot x - \left(\color{blue}{\left(z \cdot z\right)} \cdot y\right) \cdot 4
\] |
associate-*r* [<=]54.2 | \[ x \cdot x - \color{blue}{\left(z \cdot z\right) \cdot \left(y \cdot 4\right)}
\] |
associate-*l* [=>]0.9 | \[ x \cdot x - \color{blue}{z \cdot \left(z \cdot \left(y \cdot 4\right)\right)}
\] |
*-commutative [=>]0.9 | \[ x \cdot x - z \cdot \left(z \cdot \color{blue}{\left(4 \cdot y\right)}\right)
\] |
if -3.2000000000000002e129 < z < 1e152Initial program 0.1
Simplified0.1
[Start]0.1 | \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\] |
|---|---|
associate-*l* [=>]0.1 | \[ x \cdot x - \color{blue}{y \cdot \left(4 \cdot \left(z \cdot z - t\right)\right)}
\] |
Applied egg-rr0.1
Applied egg-rr0.1
Simplified0.1
[Start]0.1 | \[ x \cdot x - 4 \cdot \left(z \cdot \left(z \cdot y\right) - y \cdot t\right)
\] |
|---|---|
associate-*r* [=>]0.1 | \[ x \cdot x - 4 \cdot \left(\color{blue}{\left(z \cdot z\right) \cdot y} - y \cdot t\right)
\] |
*-commutative [<=]0.1 | \[ x \cdot x - 4 \cdot \left(\color{blue}{y \cdot \left(z \cdot z\right)} - y \cdot t\right)
\] |
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13952 |
| Alternative 2 | |
|---|---|
| Error | 27.7 |
| Cost | 1373 |
| Alternative 3 | |
|---|---|
| Error | 27.7 |
| Cost | 1372 |
| Alternative 4 | |
|---|---|
| Error | 8.2 |
| Cost | 1104 |
| Alternative 5 | |
|---|---|
| Error | 0.2 |
| Cost | 1097 |
| Alternative 6 | |
|---|---|
| Error | 6.3 |
| Cost | 969 |
| Alternative 7 | |
|---|---|
| Error | 14.9 |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Error | 25.3 |
| Cost | 584 |
| Alternative 9 | |
|---|---|
| Error | 41.3 |
| Cost | 192 |
herbie shell --seed 2023017
(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))))