| Alternative 1 | |
|---|---|
| Accuracy | 95.9% |
| Cost | 969 |

(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.4e-188) (not (<= y 3.6e-251))) (+ x (/ (- y (/ t y)) (* z -3.0))) (+ x (/ t (* z (* 3.0 y))))))
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.4e-188) || !(y <= 3.6e-251)) {
tmp = x + ((y - (t / y)) / (z * -3.0));
} else {
tmp = x + (t / (z * (3.0 * y)));
}
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.4d-188)) .or. (.not. (y <= 3.6d-251))) then
tmp = x + ((y - (t / y)) / (z * (-3.0d0)))
else
tmp = x + (t / (z * (3.0d0 * y)))
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.4e-188) || !(y <= 3.6e-251)) {
tmp = x + ((y - (t / y)) / (z * -3.0));
} else {
tmp = x + (t / (z * (3.0 * y)));
}
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.4e-188) or not (y <= 3.6e-251): tmp = x + ((y - (t / y)) / (z * -3.0)) else: tmp = x + (t / (z * (3.0 * y))) 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.4e-188) || !(y <= 3.6e-251)) tmp = Float64(x + Float64(Float64(y - Float64(t / y)) / Float64(z * -3.0))); else tmp = Float64(x + Float64(t / Float64(z * Float64(3.0 * y)))); 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.4e-188) || ~((y <= 3.6e-251))) tmp = x + ((y - (t / y)) / (z * -3.0)); else tmp = x + (t / (z * (3.0 * y))); 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.4e-188], N[Not[LessEqual[y, 3.6e-251]], $MachinePrecision]], N[(x + N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / N[(z * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(t / N[(z * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{-188} \lor \neg \left(y \leq 3.6 \cdot 10^{-251}\right):\\
\;\;\;\;x + \frac{y - \frac{t}{y}}{z \cdot -3}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{t}{z \cdot \left(3 \cdot y\right)}\\
\end{array}
\end{array}
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 95.2% |
|---|---|
| Target | 95.5% |
| Herbie | 95.9% |
if y < -6.40000000000000044e-188 or 3.6000000000000001e-251 < y Initial program 94.1%
Simplified98.8%
[Start]94.1% | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]94.1% | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]94.1% | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
sub-neg [=>]94.1% | \[ x + \left(-\color{blue}{\left(\frac{y}{z \cdot 3} + \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}\right)
\] |
distribute-neg-in [=>]94.1% | \[ x + \color{blue}{\left(\left(-\frac{y}{z \cdot 3}\right) + \left(-\left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)\right)}
\] |
unsub-neg [=>]94.1% | \[ x + \color{blue}{\left(\left(-\frac{y}{z \cdot 3}\right) - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]94.1% | \[ x + \left(\color{blue}{-1 \cdot \frac{y}{z \cdot 3}} - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)
\] |
associate-*r/ [=>]94.1% | \[ x + \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)
\] |
associate-*l/ [<=]94.0% | \[ x + \left(\color{blue}{\frac{-1}{z \cdot 3} \cdot y} - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)
\] |
distribute-neg-frac [=>]94.0% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
neg-mul-1 [=>]94.0% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \frac{\color{blue}{-1 \cdot t}}{\left(z \cdot 3\right) \cdot y}\right)
\] |
times-frac [=>]97.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.8% | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]98.8% | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]98.8% | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]98.8% | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Applied egg-rr98.9%
[Start]98.8% | \[ x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
|---|---|
*-commutative [=>]98.8% | \[ x + \color{blue}{\left(y - \frac{t}{y}\right) \cdot \frac{-0.3333333333333333}{z}}
\] |
clear-num [=>]98.8% | \[ x + \left(y - \frac{t}{y}\right) \cdot \color{blue}{\frac{1}{\frac{z}{-0.3333333333333333}}}
\] |
un-div-inv [=>]98.9% | \[ x + \color{blue}{\frac{y - \frac{t}{y}}{\frac{z}{-0.3333333333333333}}}
\] |
div-inv [=>]98.9% | \[ x + \frac{y - \frac{t}{y}}{\color{blue}{z \cdot \frac{1}{-0.3333333333333333}}}
\] |
metadata-eval [=>]98.9% | \[ x + \frac{y - \frac{t}{y}}{z \cdot \color{blue}{-3}}
\] |
if -6.40000000000000044e-188 < y < 3.6000000000000001e-251Initial program 99.8%
Simplified75.6%
[Start]99.8% | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]99.8% | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]99.8% | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
sub-neg [=>]99.8% | \[ x + \left(-\color{blue}{\left(\frac{y}{z \cdot 3} + \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}\right)
\] |
distribute-neg-in [=>]99.8% | \[ x + \color{blue}{\left(\left(-\frac{y}{z \cdot 3}\right) + \left(-\left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)\right)}
\] |
unsub-neg [=>]99.8% | \[ x + \color{blue}{\left(\left(-\frac{y}{z \cdot 3}\right) - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]99.8% | \[ x + \left(\color{blue}{-1 \cdot \frac{y}{z \cdot 3}} - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)
\] |
associate-*r/ [=>]99.8% | \[ x + \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)
\] |
associate-*l/ [<=]99.8% | \[ x + \left(\color{blue}{\frac{-1}{z \cdot 3} \cdot y} - \left(-\frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)
\] |
distribute-neg-frac [=>]99.8% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
neg-mul-1 [=>]99.8% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \frac{\color{blue}{-1 \cdot t}}{\left(z \cdot 3\right) \cdot y}\right)
\] |
times-frac [=>]75.6% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]75.6% | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]75.6% | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]75.6% | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]75.6% | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Taylor expanded in y around 0 99.7%
Simplified75.6%
[Start]99.7% | \[ x + 0.3333333333333333 \cdot \frac{t}{y \cdot z}
\] |
|---|---|
*-commutative [=>]99.7% | \[ x + \color{blue}{\frac{t}{y \cdot z} \cdot 0.3333333333333333}
\] |
associate-*l/ [=>]99.8% | \[ x + \color{blue}{\frac{t \cdot 0.3333333333333333}{y \cdot z}}
\] |
times-frac [=>]75.6% | \[ x + \color{blue}{\frac{t}{y} \cdot \frac{0.3333333333333333}{z}}
\] |
Applied egg-rr99.8%
[Start]75.6% | \[ x + \frac{t}{y} \cdot \frac{0.3333333333333333}{z}
\] |
|---|---|
*-commutative [=>]75.6% | \[ x + \color{blue}{\frac{0.3333333333333333}{z} \cdot \frac{t}{y}}
\] |
clear-num [=>]75.6% | \[ x + \color{blue}{\frac{1}{\frac{z}{0.3333333333333333}}} \cdot \frac{t}{y}
\] |
frac-times [=>]99.7% | \[ x + \color{blue}{\frac{1 \cdot t}{\frac{z}{0.3333333333333333} \cdot y}}
\] |
*-un-lft-identity [<=]99.7% | \[ x + \frac{\color{blue}{t}}{\frac{z}{0.3333333333333333} \cdot y}
\] |
div-inv [=>]99.8% | \[ x + \frac{t}{\color{blue}{\left(z \cdot \frac{1}{0.3333333333333333}\right)} \cdot y}
\] |
metadata-eval [=>]99.8% | \[ x + \frac{t}{\left(z \cdot \color{blue}{3}\right) \cdot y}
\] |
Taylor expanded in z around 0 99.8%
Simplified99.9%
[Start]99.8% | \[ x + \frac{t}{3 \cdot \left(y \cdot z\right)}
\] |
|---|---|
associate-*r* [=>]99.9% | \[ x + \frac{t}{\color{blue}{\left(3 \cdot y\right) \cdot z}}
\] |
*-commutative [<=]99.9% | \[ x + \frac{t}{\color{blue}{z \cdot \left(3 \cdot y\right)}}
\] |
*-commutative [=>]99.9% | \[ x + \frac{t}{z \cdot \color{blue}{\left(y \cdot 3\right)}}
\] |
Final simplification99.1%
| Alternative 1 | |
|---|---|
| Accuracy | 95.9% |
| Cost | 969 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 1220 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 1220 |
| Alternative 4 | |
|---|---|
| Accuracy | 60.4% |
| Cost | 980 |
| Alternative 5 | |
|---|---|
| Accuracy | 60.2% |
| Cost | 980 |
| Alternative 6 | |
|---|---|
| Accuracy | 87.4% |
| Cost | 972 |
| Alternative 7 | |
|---|---|
| Accuracy | 95.9% |
| Cost | 969 |
| Alternative 8 | |
|---|---|
| Accuracy | 76.1% |
| Cost | 844 |
| Alternative 9 | |
|---|---|
| Accuracy | 80.5% |
| Cost | 840 |
| Alternative 10 | |
|---|---|
| Accuracy | 87.8% |
| Cost | 840 |
| Alternative 11 | |
|---|---|
| Accuracy | 88.2% |
| Cost | 840 |
| Alternative 12 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 713 |
| Alternative 13 | |
|---|---|
| Accuracy | 75.8% |
| Cost | 712 |
| Alternative 14 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 712 |
| Alternative 15 | |
|---|---|
| Accuracy | 46.9% |
| Cost | 584 |
| Alternative 16 | |
|---|---|
| Accuracy | 46.8% |
| Cost | 584 |
| Alternative 17 | |
|---|---|
| Accuracy | 29.7% |
| Cost | 64 |
herbie shell --seed 2023167
(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))))