| Alternative 1 | |
|---|---|
| Accuracy | 48.6% |
| Cost | 1112 |
(FPCore (x y z t) :precision binary64 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
(FPCore (x y z t) :precision binary64 (if (or (<= y -6.6e-76) (not (<= y 8.6e-129))) (+ x (/ (- y (/ t y)) (* z -3.0))) (+ x (/ 0.3333333333333333 (* y (/ z t))))))
double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.6e-76) || !(y <= 8.6e-129)) {
tmp = x + ((y - (t / y)) / (z * -3.0));
} else {
tmp = x + (0.3333333333333333 / (y * (z / t)));
}
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 - (y / (z * 3.0d0))) + (t / ((z * 3.0d0) * y))
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 ((y <= (-6.6d-76)) .or. (.not. (y <= 8.6d-129))) then
tmp = x + ((y - (t / y)) / (z * (-3.0d0)))
else
tmp = x + (0.3333333333333333d0 / (y * (z / t)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6.6e-76) || !(y <= 8.6e-129)) {
tmp = x + ((y - (t / y)) / (z * -3.0));
} else {
tmp = x + (0.3333333333333333 / (y * (z / t)));
}
return tmp;
}
def code(x, y, z, t): return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y))
def code(x, y, z, t): tmp = 0 if (y <= -6.6e-76) or not (y <= 8.6e-129): tmp = x + ((y - (t / y)) / (z * -3.0)) else: tmp = x + (0.3333333333333333 / (y * (z / t))) return tmp
function code(x, y, z, t) return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y))) end
function code(x, y, z, t) tmp = 0.0 if ((y <= -6.6e-76) || !(y <= 8.6e-129)) tmp = Float64(x + Float64(Float64(y - Float64(t / y)) / Float64(z * -3.0))); else tmp = Float64(x + Float64(0.3333333333333333 / Float64(y * Float64(z / t)))); end return tmp end
function tmp = code(x, y, z, t) tmp = (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y)); end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -6.6e-76) || ~((y <= 8.6e-129))) tmp = x + ((y - (t / y)) / (z * -3.0)); else tmp = x + (0.3333333333333333 / (y * (z / t))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6.6e-76], N[Not[LessEqual[y, 8.6e-129]], $MachinePrecision]], N[(x + N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / N[(z * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(0.3333333333333333 / N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{-76} \lor \neg \left(y \leq 8.6 \cdot 10^{-129}\right):\\
\;\;\;\;x + \frac{y - \frac{t}{y}}{z \cdot -3}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{0.3333333333333333}{y \cdot \frac{z}{t}}\\
\end{array}
Results
| Original | 93.5% |
|---|---|
| Target | 97.4% |
| Herbie | 97.6% |
if y < -6.59999999999999967e-76 or 8.59999999999999962e-129 < y Initial program 98.0%
Simplified98.5%
[Start]98.0 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]98.0 | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]98.0 | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]98.0 | \[ x + \color{blue}{-1 \cdot \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
distribute-lft-out-- [<=]98.0 | \[ x + \color{blue}{\left(-1 \cdot \frac{y}{z \cdot 3} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
associate-*r/ [=>]98.0 | \[ x + \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*l/ [<=]97.9 | \[ x + \left(\color{blue}{\frac{-1}{z \cdot 3} \cdot y} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*r/ [=>]97.9 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1 \cdot t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
times-frac [=>]98.4 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]98.4 | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]98.4 | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]98.5 | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]98.5 | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Applied egg-rr98.5%
[Start]98.5 | \[ x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
|---|---|
clear-num [=>]98.3 | \[ x + \color{blue}{\frac{1}{\frac{z}{-0.3333333333333333}}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-*l/ [=>]98.4 | \[ x + \color{blue}{\frac{1 \cdot \left(y - \frac{t}{y}\right)}{\frac{z}{-0.3333333333333333}}}
\] |
*-un-lft-identity [<=]98.4 | \[ x + \frac{\color{blue}{y - \frac{t}{y}}}{\frac{z}{-0.3333333333333333}}
\] |
div-inv [=>]98.5 | \[ x + \frac{y - \frac{t}{y}}{\color{blue}{z \cdot \frac{1}{-0.3333333333333333}}}
\] |
metadata-eval [=>]98.5 | \[ x + \frac{y - \frac{t}{y}}{z \cdot \color{blue}{-3}}
\] |
if -6.59999999999999967e-76 < y < 8.59999999999999962e-129Initial program 83.4%
Simplified82.8%
[Start]83.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]83.4 | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]83.4 | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]83.4 | \[ x + \color{blue}{-1 \cdot \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
distribute-lft-out-- [<=]83.4 | \[ x + \color{blue}{\left(-1 \cdot \frac{y}{z \cdot 3} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
associate-*r/ [=>]83.4 | \[ x + \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*l/ [<=]83.4 | \[ x + \left(\color{blue}{\frac{-1}{z \cdot 3} \cdot y} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)
\] |
associate-*r/ [=>]83.4 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1 \cdot t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
times-frac [=>]82.8 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]82.8 | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]82.8 | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]82.8 | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]82.8 | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Taylor expanded in y around 0 81.5%
Simplified81.5%
[Start]81.5 | \[ x + \frac{-0.3333333333333333}{z} \cdot \left(-1 \cdot \frac{t}{y}\right)
\] |
|---|---|
mul-1-neg [=>]81.5 | \[ x + \frac{-0.3333333333333333}{z} \cdot \color{blue}{\left(-\frac{t}{y}\right)}
\] |
Applied egg-rr95.5%
[Start]81.5 | \[ x + \frac{-0.3333333333333333}{z} \cdot \left(-\frac{t}{y}\right)
\] |
|---|---|
distribute-rgt-neg-out [=>]81.5 | \[ x + \color{blue}{\left(-\frac{-0.3333333333333333}{z} \cdot \frac{t}{y}\right)}
\] |
distribute-lft-neg-in [=>]81.5 | \[ x + \color{blue}{\left(-\frac{-0.3333333333333333}{z}\right) \cdot \frac{t}{y}}
\] |
add-sqr-sqrt [=>]40.7 | \[ x + \left(-\frac{-0.3333333333333333}{z}\right) \cdot \color{blue}{\left(\sqrt{\frac{t}{y}} \cdot \sqrt{\frac{t}{y}}\right)}
\] |
sqrt-unprod [=>]44.0 | \[ x + \left(-\frac{-0.3333333333333333}{z}\right) \cdot \color{blue}{\sqrt{\frac{t}{y} \cdot \frac{t}{y}}}
\] |
sqr-neg [<=]44.0 | \[ x + \left(-\frac{-0.3333333333333333}{z}\right) \cdot \sqrt{\color{blue}{\left(-\frac{t}{y}\right) \cdot \left(-\frac{t}{y}\right)}}
\] |
sqrt-unprod [<=]18.5 | \[ x + \left(-\frac{-0.3333333333333333}{z}\right) \cdot \color{blue}{\left(\sqrt{-\frac{t}{y}} \cdot \sqrt{-\frac{t}{y}}\right)}
\] |
add-sqr-sqrt [<=]37.1 | \[ x + \left(-\frac{-0.3333333333333333}{z}\right) \cdot \color{blue}{\left(-\frac{t}{y}\right)}
\] |
cancel-sign-sub-inv [<=]37.1 | \[ \color{blue}{x - \frac{-0.3333333333333333}{z} \cdot \left(-\frac{t}{y}\right)}
\] |
associate-/r/ [<=]37.1 | \[ x - \color{blue}{\frac{-0.3333333333333333}{\frac{z}{-\frac{t}{y}}}}
\] |
add-sqr-sqrt [=>]18.5 | \[ x - \frac{-0.3333333333333333}{\frac{z}{\color{blue}{\sqrt{-\frac{t}{y}} \cdot \sqrt{-\frac{t}{y}}}}}
\] |
sqrt-unprod [=>]44.0 | \[ x - \frac{-0.3333333333333333}{\frac{z}{\color{blue}{\sqrt{\left(-\frac{t}{y}\right) \cdot \left(-\frac{t}{y}\right)}}}}
\] |
sqr-neg [=>]44.0 | \[ x - \frac{-0.3333333333333333}{\frac{z}{\sqrt{\color{blue}{\frac{t}{y} \cdot \frac{t}{y}}}}}
\] |
sqrt-unprod [<=]40.7 | \[ x - \frac{-0.3333333333333333}{\frac{z}{\color{blue}{\sqrt{\frac{t}{y}} \cdot \sqrt{\frac{t}{y}}}}}
\] |
add-sqr-sqrt [<=]81.5 | \[ x - \frac{-0.3333333333333333}{\frac{z}{\color{blue}{\frac{t}{y}}}}
\] |
associate-/r/ [=>]95.5 | \[ x - \frac{-0.3333333333333333}{\color{blue}{\frac{z}{t} \cdot y}}
\] |
Final simplification97.6%
| Alternative 1 | |
|---|---|
| Accuracy | 48.6% |
| Cost | 1112 |
| Alternative 2 | |
|---|---|
| Accuracy | 49.4% |
| Cost | 1112 |
| Alternative 3 | |
|---|---|
| Accuracy | 49.3% |
| Cost | 1112 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.6% |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 960 |
| Alternative 6 | |
|---|---|
| Accuracy | 97.6% |
| Cost | 960 |
| Alternative 7 | |
|---|---|
| Accuracy | 80.9% |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Accuracy | 86.0% |
| Cost | 841 |
| Alternative 9 | |
|---|---|
| Accuracy | 91.2% |
| Cost | 841 |
| Alternative 10 | |
|---|---|
| Accuracy | 72.1% |
| Cost | 713 |
| Alternative 11 | |
|---|---|
| Accuracy | 72.0% |
| Cost | 713 |
| Alternative 12 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 584 |
| Alternative 13 | |
|---|---|
| Accuracy | 55.5% |
| Cost | 584 |
| Alternative 14 | |
|---|---|
| Accuracy | 41.8% |
| Cost | 64 |
herbie shell --seed 2023138
(FPCore (x y z t)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, H"
:precision binary64
:herbie-target
(+ (- x (/ y (* z 3.0))) (/ (/ t (* z 3.0)) y))
(+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))