| Alternative 1 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 968 |

(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 (<= y -5e-55)
(+ x (/ (- y (/ t y)) (* z -3.0)))
(if (<= y 1.05e-188)
(+ x (/ (/ (* t 0.3333333333333333) z) y))
(+ x (/ (* 0.3333333333333333 (- (/ t y) y)) z)))))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 <= -5e-55) {
tmp = x + ((y - (t / y)) / (z * -3.0));
} else if (y <= 1.05e-188) {
tmp = x + (((t * 0.3333333333333333) / z) / y);
} else {
tmp = x + ((0.3333333333333333 * ((t / y) - y)) / 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 - (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 <= (-5d-55)) then
tmp = x + ((y - (t / y)) / (z * (-3.0d0)))
else if (y <= 1.05d-188) then
tmp = x + (((t * 0.3333333333333333d0) / z) / y)
else
tmp = x + ((0.3333333333333333d0 * ((t / y) - y)) / z)
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 <= -5e-55) {
tmp = x + ((y - (t / y)) / (z * -3.0));
} else if (y <= 1.05e-188) {
tmp = x + (((t * 0.3333333333333333) / z) / y);
} else {
tmp = x + ((0.3333333333333333 * ((t / y) - y)) / z);
}
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 <= -5e-55: tmp = x + ((y - (t / y)) / (z * -3.0)) elif y <= 1.05e-188: tmp = x + (((t * 0.3333333333333333) / z) / y) else: tmp = x + ((0.3333333333333333 * ((t / y) - y)) / z) 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 <= -5e-55) tmp = Float64(x + Float64(Float64(y - Float64(t / y)) / Float64(z * -3.0))); elseif (y <= 1.05e-188) tmp = Float64(x + Float64(Float64(Float64(t * 0.3333333333333333) / z) / y)); else tmp = Float64(x + Float64(Float64(0.3333333333333333 * Float64(Float64(t / y) - y)) / z)); 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 <= -5e-55) tmp = x + ((y - (t / y)) / (z * -3.0)); elseif (y <= 1.05e-188) tmp = x + (((t * 0.3333333333333333) / z) / y); else tmp = x + ((0.3333333333333333 * ((t / y) - y)) / z); 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[LessEqual[y, -5e-55], N[(x + N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / N[(z * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.05e-188], N[(x + N[(N[(N[(t * 0.3333333333333333), $MachinePrecision] / z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(0.3333333333333333 * N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision] / z), $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 -5 \cdot 10^{-55}:\\
\;\;\;\;x + \frac{y - \frac{t}{y}}{z \cdot -3}\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-188}:\\
\;\;\;\;x + \frac{\frac{t \cdot 0.3333333333333333}{z}}{y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{0.3333333333333333 \cdot \left(\frac{t}{y} - y\right)}{z}\\
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 95.5% |
|---|---|
| Target | 96.2% |
| Herbie | 97.8% |
if y < -5.0000000000000002e-55Initial program 95.9%
Simplified99.7%
[Start]95.9% | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]95.9% | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]95.9% | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
sub-neg [=>]95.9% | \[ 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 [=>]95.9% | \[ 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 [=>]95.9% | \[ 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 [=>]95.9% | \[ 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/ [=>]95.9% | \[ 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/ [<=]95.7% | \[ 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 [=>]95.7% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
neg-mul-1 [=>]95.7% | \[ 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.0% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]99.7% | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]99.7% | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]99.7% | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]99.7% | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Applied egg-rr99.7%
[Start]99.7% | \[ x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
|---|---|
clear-num [=>]99.7% | \[ x + \color{blue}{\frac{1}{\frac{z}{-0.3333333333333333}}} \cdot \left(y - \frac{t}{y}\right)
\] |
inv-pow [=>]99.7% | \[ x + \color{blue}{{\left(\frac{z}{-0.3333333333333333}\right)}^{-1}} \cdot \left(y - \frac{t}{y}\right)
\] |
Simplified99.7%
[Start]99.7% | \[ x + {\left(\frac{z}{-0.3333333333333333}\right)}^{-1} \cdot \left(y - \frac{t}{y}\right)
\] |
|---|---|
unpow-1 [=>]99.7% | \[ x + \color{blue}{\frac{1}{\frac{z}{-0.3333333333333333}}} \cdot \left(y - \frac{t}{y}\right)
\] |
Applied egg-rr99.8%
[Start]99.7% | \[ x + \frac{1}{\frac{z}{-0.3333333333333333}} \cdot \left(y - \frac{t}{y}\right)
\] |
|---|---|
associate-*l/ [=>]99.7% | \[ x + \color{blue}{\frac{1 \cdot \left(y - \frac{t}{y}\right)}{\frac{z}{-0.3333333333333333}}}
\] |
*-un-lft-identity [<=]99.7% | \[ x + \frac{\color{blue}{y - \frac{t}{y}}}{\frac{z}{-0.3333333333333333}}
\] |
div-inv [=>]99.8% | \[ x + \frac{y - \frac{t}{y}}{\color{blue}{z \cdot \frac{1}{-0.3333333333333333}}}
\] |
metadata-eval [=>]99.8% | \[ x + \frac{y - \frac{t}{y}}{z \cdot \color{blue}{-3}}
\] |
if -5.0000000000000002e-55 < y < 1.05e-188Initial program 93.1%
Simplified83.4%
[Start]93.1% | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]93.1% | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]93.1% | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
sub-neg [=>]93.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 [=>]93.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 [=>]93.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 [=>]93.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/ [=>]93.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/ [<=]93.1% | \[ 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 [=>]93.1% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
neg-mul-1 [=>]93.1% | \[ 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 [=>]83.5% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]83.5% | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]83.5% | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]83.4% | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]83.4% | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Taylor expanded in y around 0 93.0%
Simplified83.4%
[Start]93.0% | \[ x + 0.3333333333333333 \cdot \frac{t}{y \cdot z}
\] |
|---|---|
*-commutative [=>]93.0% | \[ x + \color{blue}{\frac{t}{y \cdot z} \cdot 0.3333333333333333}
\] |
associate-*l/ [=>]93.0% | \[ x + \color{blue}{\frac{t \cdot 0.3333333333333333}{y \cdot z}}
\] |
times-frac [=>]83.4% | \[ x + \color{blue}{\frac{t}{y} \cdot \frac{0.3333333333333333}{z}}
\] |
Applied egg-rr98.9%
[Start]83.4% | \[ x + \frac{t}{y} \cdot \frac{0.3333333333333333}{z}
\] |
|---|---|
associate-*l/ [=>]98.9% | \[ x + \color{blue}{\frac{t \cdot \frac{0.3333333333333333}{z}}{y}}
\] |
Applied egg-rr99.0%
[Start]98.9% | \[ x + \frac{t \cdot \frac{0.3333333333333333}{z}}{y}
\] |
|---|---|
associate-*r/ [=>]99.0% | \[ x + \frac{\color{blue}{\frac{t \cdot 0.3333333333333333}{z}}}{y}
\] |
if 1.05e-188 < y Initial program 97.8%
Simplified99.7%
[Start]97.8% | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]97.8% | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]97.8% | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
sub-neg [=>]97.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 [=>]97.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 [=>]97.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 [=>]97.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/ [=>]97.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/ [<=]97.7% | \[ 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 [=>]97.7% | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
neg-mul-1 [=>]97.7% | \[ 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 [=>]99.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-- [=>]99.7% | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]99.7% | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]99.7% | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]99.7% | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Taylor expanded in y around 0 97.8%
Simplified99.8%
[Start]97.8% | \[ x + \left(-0.3333333333333333 \cdot \frac{y}{z} + 0.3333333333333333 \cdot \frac{t}{y \cdot z}\right)
\] |
|---|---|
+-commutative [=>]97.8% | \[ x + \color{blue}{\left(0.3333333333333333 \cdot \frac{t}{y \cdot z} + -0.3333333333333333 \cdot \frac{y}{z}\right)}
\] |
metadata-eval [<=]97.8% | \[ x + \left(0.3333333333333333 \cdot \frac{t}{y \cdot z} + \color{blue}{\left(-0.3333333333333333\right)} \cdot \frac{y}{z}\right)
\] |
cancel-sign-sub-inv [<=]97.8% | \[ x + \color{blue}{\left(0.3333333333333333 \cdot \frac{t}{y \cdot z} - 0.3333333333333333 \cdot \frac{y}{z}\right)}
\] |
associate-/r* [=>]99.7% | \[ x + \left(0.3333333333333333 \cdot \color{blue}{\frac{\frac{t}{y}}{z}} - 0.3333333333333333 \cdot \frac{y}{z}\right)
\] |
associate-*r/ [=>]99.8% | \[ x + \left(\color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y}}{z}} - 0.3333333333333333 \cdot \frac{y}{z}\right)
\] |
associate-*r/ [=>]99.8% | \[ x + \left(\frac{0.3333333333333333 \cdot \frac{t}{y}}{z} - \color{blue}{\frac{0.3333333333333333 \cdot y}{z}}\right)
\] |
div-sub [<=]99.8% | \[ x + \color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y} - 0.3333333333333333 \cdot y}{z}}
\] |
distribute-lft-out-- [=>]99.8% | \[ x + \frac{\color{blue}{0.3333333333333333 \cdot \left(\frac{t}{y} - y\right)}}{z}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 968 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 1988 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 1988 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 969 |
| Alternative 6 | |
|---|---|
| Accuracy | 89.3% |
| Cost | 841 |
| Alternative 7 | |
|---|---|
| Accuracy | 89.4% |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Accuracy | 92.1% |
| Cost | 841 |
| Alternative 9 | |
|---|---|
| Accuracy | 92.0% |
| Cost | 841 |
| Alternative 10 | |
|---|---|
| Accuracy | 65.1% |
| Cost | 448 |
| Alternative 11 | |
|---|---|
| Accuracy | 65.1% |
| Cost | 448 |
| Alternative 12 | |
|---|---|
| Accuracy | 65.1% |
| Cost | 448 |
| Alternative 13 | |
|---|---|
| Accuracy | 30.6% |
| Cost | 64 |
herbie shell --seed 2023171
(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))))