| Alternative 1 | |
|---|---|
| Error | 5.9 |
| Cost | 832 |
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 5e+203) (- (* x x) (+ (* y (* t -4.0)) (* 64.0 (* (pow (/ z 4.0) 2.0) y)))) (- (* x x) (* t (* y -4.0)))))
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 ((x * x) <= 5e+203) {
tmp = (x * x) - ((y * (t * -4.0)) + (64.0 * (pow((z / 4.0), 2.0) * y)));
} else {
tmp = (x * x) - (t * (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
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 ((x * x) <= 5d+203) then
tmp = (x * x) - ((y * (t * (-4.0d0))) + (64.0d0 * (((z / 4.0d0) ** 2.0d0) * y)))
else
tmp = (x * x) - (t * (y * (-4.0d0)))
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 ((x * x) <= 5e+203) {
tmp = (x * x) - ((y * (t * -4.0)) + (64.0 * (Math.pow((z / 4.0), 2.0) * y)));
} else {
tmp = (x * x) - (t * (y * -4.0));
}
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 (x * x) <= 5e+203: tmp = (x * x) - ((y * (t * -4.0)) + (64.0 * (math.pow((z / 4.0), 2.0) * y))) else: tmp = (x * x) - (t * (y * -4.0)) 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 (Float64(x * x) <= 5e+203) tmp = Float64(Float64(x * x) - Float64(Float64(y * Float64(t * -4.0)) + Float64(64.0 * Float64((Float64(z / 4.0) ^ 2.0) * y)))); else tmp = Float64(Float64(x * x) - Float64(t * Float64(y * -4.0))); 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 ((x * x) <= 5e+203) tmp = (x * x) - ((y * (t * -4.0)) + (64.0 * (((z / 4.0) ^ 2.0) * y))); else tmp = (x * x) - (t * (y * -4.0)); 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[LessEqual[N[(x * x), $MachinePrecision], 5e+203], N[(N[(x * x), $MachinePrecision] - N[(N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision] + N[(64.0 * N[(N[Power[N[(z / 4.0), $MachinePrecision], 2.0], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(t * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{+203}:\\
\;\;\;\;x \cdot x - \left(y \cdot \left(t \cdot -4\right) + 64 \cdot \left({\left(\frac{z}{4}\right)}^{2} \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\
\end{array}
Results
| Original | 5.9 |
|---|---|
| Target | 5.8 |
| Herbie | 5.6 |
if (*.f64 x x) < 4.99999999999999994e203Initial program 5.8
Taylor expanded in z around 0 5.8
Simplified5.8
[Start]5.8 | \[ x \cdot x - \left(4 \cdot \left(y \cdot {z}^{2}\right) + -4 \cdot \left(y \cdot t\right)\right)
\] |
|---|---|
rational.json-simplify-1 [<=]5.8 | \[ x \cdot x - \color{blue}{\left(-4 \cdot \left(y \cdot t\right) + 4 \cdot \left(y \cdot {z}^{2}\right)\right)}
\] |
rational.json-simplify-43 [=>]5.8 | \[ x \cdot x - \left(\color{blue}{y \cdot \left(t \cdot -4\right)} + 4 \cdot \left(y \cdot {z}^{2}\right)\right)
\] |
rational.json-simplify-2 [=>]5.8 | \[ x \cdot x - \left(y \cdot \left(t \cdot -4\right) + 4 \cdot \color{blue}{\left({z}^{2} \cdot y\right)}\right)
\] |
Applied egg-rr5.9
Applied egg-rr5.8
Simplified5.8
[Start]5.8 | \[ x \cdot x - \left(y \cdot \left(t \cdot -4\right) + 32 \cdot \left(\left(y + y\right) \cdot {\left(\frac{z}{4}\right)}^{2}\right)\right)
\] |
|---|---|
rational.json-simplify-43 [=>]5.9 | \[ x \cdot x - \left(y \cdot \left(t \cdot -4\right) + \color{blue}{\left(y + y\right) \cdot \left({\left(\frac{z}{4}\right)}^{2} \cdot 32\right)}\right)
\] |
rational.json-simplify-2 [=>]5.9 | \[ x \cdot x - \left(y \cdot \left(t \cdot -4\right) + \left(y + y\right) \cdot \color{blue}{\left(32 \cdot {\left(\frac{z}{4}\right)}^{2}\right)}\right)
\] |
rational.json-simplify-53 [=>]5.8 | \[ x \cdot x - \left(y \cdot \left(t \cdot -4\right) + \color{blue}{\left(32 + 32\right) \cdot \left({\left(\frac{z}{4}\right)}^{2} \cdot y\right)}\right)
\] |
metadata-eval [=>]5.8 | \[ x \cdot x - \left(y \cdot \left(t \cdot -4\right) + \color{blue}{64} \cdot \left({\left(\frac{z}{4}\right)}^{2} \cdot y\right)\right)
\] |
if 4.99999999999999994e203 < (*.f64 x x) Initial program 6.2
Taylor expanded in z around 0 4.4
Simplified4.5
[Start]4.4 | \[ x \cdot x - -4 \cdot \left(y \cdot t\right)
\] |
|---|---|
rational.json-simplify-43 [<=]4.5 | \[ x \cdot x - \color{blue}{t \cdot \left(-4 \cdot y\right)}
\] |
rational.json-simplify-2 [<=]4.5 | \[ x \cdot x - t \cdot \color{blue}{\left(y \cdot -4\right)}
\] |
Final simplification5.6
| Alternative 1 | |
|---|---|
| Error | 5.9 |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Error | 17.7 |
| Cost | 576 |
| Alternative 3 | |
|---|---|
| Error | 37.2 |
| Cost | 320 |
herbie shell --seed 2023074
(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))))