| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 1480 |
(FPCore (x y z t) :precision binary64 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ y (* z 3.0)))))
(if (<= (* z 3.0) -2e+93)
(+ t_1 (/ t (* z (* 3.0 y))))
(if (<= (* z 3.0) 4e-34)
(+ x (/ 0.3333333333333333 (/ z (- (/ t y) y))))
(+ t_1 (/ (/ 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 t_1 = x - (y / (z * 3.0));
double tmp;
if ((z * 3.0) <= -2e+93) {
tmp = t_1 + (t / (z * (3.0 * y)));
} else if ((z * 3.0) <= 4e-34) {
tmp = x + (0.3333333333333333 / (z / ((t / y) - y)));
} else {
tmp = t_1 + ((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) :: t_1
real(8) :: tmp
t_1 = x - (y / (z * 3.0d0))
if ((z * 3.0d0) <= (-2d+93)) then
tmp = t_1 + (t / (z * (3.0d0 * y)))
else if ((z * 3.0d0) <= 4d-34) then
tmp = x + (0.3333333333333333d0 / (z / ((t / y) - y)))
else
tmp = t_1 + ((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 t_1 = x - (y / (z * 3.0));
double tmp;
if ((z * 3.0) <= -2e+93) {
tmp = t_1 + (t / (z * (3.0 * y)));
} else if ((z * 3.0) <= 4e-34) {
tmp = x + (0.3333333333333333 / (z / ((t / y) - y)));
} else {
tmp = t_1 + ((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): t_1 = x - (y / (z * 3.0)) tmp = 0 if (z * 3.0) <= -2e+93: tmp = t_1 + (t / (z * (3.0 * y))) elif (z * 3.0) <= 4e-34: tmp = x + (0.3333333333333333 / (z / ((t / y) - y))) else: tmp = t_1 + ((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) t_1 = Float64(x - Float64(y / Float64(z * 3.0))) tmp = 0.0 if (Float64(z * 3.0) <= -2e+93) tmp = Float64(t_1 + Float64(t / Float64(z * Float64(3.0 * y)))); elseif (Float64(z * 3.0) <= 4e-34) tmp = Float64(x + Float64(0.3333333333333333 / Float64(z / Float64(Float64(t / y) - y)))); else tmp = Float64(t_1 + Float64(Float64(t / Float64(z * 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) t_1 = x - (y / (z * 3.0)); tmp = 0.0; if ((z * 3.0) <= -2e+93) tmp = t_1 + (t / (z * (3.0 * y))); elseif ((z * 3.0) <= 4e-34) tmp = x + (0.3333333333333333 / (z / ((t / y) - y))); else tmp = t_1 + ((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_] := Block[{t$95$1 = N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * 3.0), $MachinePrecision], -2e+93], N[(t$95$1 + N[(t / N[(z * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 4e-34], N[(x + N[(0.3333333333333333 / N[(z / N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(t / N[(z * 3.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
t_1 := x - \frac{y}{z \cdot 3}\\
\mathbf{if}\;z \cdot 3 \leq -2 \cdot 10^{+93}:\\
\;\;\;\;t_1 + \frac{t}{z \cdot \left(3 \cdot y\right)}\\
\mathbf{elif}\;z \cdot 3 \leq 4 \cdot 10^{-34}:\\
\;\;\;\;x + \frac{0.3333333333333333}{\frac{z}{\frac{t}{y} - y}}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \frac{\frac{t}{z \cdot 3}}{y}\\
\end{array}
Results
| Original | 94.4% |
|---|---|
| Target | 97.2% |
| Herbie | 98.4% |
if (*.f64 z 3) < -2.00000000000000009e93Initial program 99.1%
Taylor expanded in z around 0 99.2%
Simplified99.2%
[Start]99.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{3 \cdot \left(y \cdot z\right)}
\] |
|---|---|
associate-*r* [=>]99.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\color{blue}{\left(3 \cdot y\right) \cdot z}}
\] |
*-commutative [<=]99.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\color{blue}{z \cdot \left(3 \cdot y\right)}}
\] |
*-commutative [=>]99.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{z \cdot \color{blue}{\left(y \cdot 3\right)}}
\] |
if -2.00000000000000009e93 < (*.f64 z 3) < 3.99999999999999971e-34Initial program 87.2%
Simplified95.8%
[Start]87.2 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-/r* [=>]95.8 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{\frac{t}{z \cdot 3}}{y}}
\] |
Taylor expanded in x around 0 86.8%
Simplified98.5%
[Start]86.8 | \[ \left(0.3333333333333333 \cdot \frac{t}{y \cdot z} + x\right) - 0.3333333333333333 \cdot \frac{y}{z}
\] |
|---|---|
cancel-sign-sub-inv [=>]86.8 | \[ \color{blue}{\left(0.3333333333333333 \cdot \frac{t}{y \cdot z} + x\right) + \left(-0.3333333333333333\right) \cdot \frac{y}{z}}
\] |
metadata-eval [=>]86.8 | \[ \left(0.3333333333333333 \cdot \frac{t}{y \cdot z} + x\right) + \color{blue}{-0.3333333333333333} \cdot \frac{y}{z}
\] |
+-commutative [=>]86.8 | \[ \color{blue}{\left(x + 0.3333333333333333 \cdot \frac{t}{y \cdot z}\right)} + -0.3333333333333333 \cdot \frac{y}{z}
\] |
associate-*r/ [=>]86.9 | \[ \left(x + \color{blue}{\frac{0.3333333333333333 \cdot t}{y \cdot z}}\right) + -0.3333333333333333 \cdot \frac{y}{z}
\] |
associate-*l/ [<=]85.5 | \[ \left(x + \color{blue}{\frac{0.3333333333333333}{y \cdot z} \cdot t}\right) + -0.3333333333333333 \cdot \frac{y}{z}
\] |
*-commutative [=>]85.5 | \[ \left(x + \color{blue}{t \cdot \frac{0.3333333333333333}{y \cdot z}}\right) + -0.3333333333333333 \cdot \frac{y}{z}
\] |
associate-+l+ [=>]85.5 | \[ \color{blue}{x + \left(t \cdot \frac{0.3333333333333333}{y \cdot z} + -0.3333333333333333 \cdot \frac{y}{z}\right)}
\] |
metadata-eval [<=]85.5 | \[ x + \left(t \cdot \frac{0.3333333333333333}{y \cdot z} + \color{blue}{\left(-0.3333333333333333\right)} \cdot \frac{y}{z}\right)
\] |
cancel-sign-sub-inv [<=]85.5 | \[ x + \color{blue}{\left(t \cdot \frac{0.3333333333333333}{y \cdot z} - 0.3333333333333333 \cdot \frac{y}{z}\right)}
\] |
*-commutative [<=]85.5 | \[ x + \left(\color{blue}{\frac{0.3333333333333333}{y \cdot z} \cdot t} - 0.3333333333333333 \cdot \frac{y}{z}\right)
\] |
associate-*l/ [=>]86.9 | \[ x + \left(\color{blue}{\frac{0.3333333333333333 \cdot t}{y \cdot z}} - 0.3333333333333333 \cdot \frac{y}{z}\right)
\] |
associate-*r/ [<=]86.8 | \[ x + \left(\color{blue}{0.3333333333333333 \cdot \frac{t}{y \cdot z}} - 0.3333333333333333 \cdot \frac{y}{z}\right)
\] |
associate-/r* [=>]98.3 | \[ x + \left(0.3333333333333333 \cdot \color{blue}{\frac{\frac{t}{y}}{z}} - 0.3333333333333333 \cdot \frac{y}{z}\right)
\] |
associate-*r/ [=>]98.4 | \[ x + \left(\color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y}}{z}} - 0.3333333333333333 \cdot \frac{y}{z}\right)
\] |
associate-*r/ [=>]98.5 | \[ x + \left(\frac{0.3333333333333333 \cdot \frac{t}{y}}{z} - \color{blue}{\frac{0.3333333333333333 \cdot y}{z}}\right)
\] |
div-sub [<=]98.5 | \[ x + \color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y} - 0.3333333333333333 \cdot y}{z}}
\] |
distribute-lft-out-- [=>]98.5 | \[ x + \frac{\color{blue}{0.3333333333333333 \cdot \left(\frac{t}{y} - y\right)}}{z}
\] |
associate-/l* [=>]98.5 | \[ x + \color{blue}{\frac{0.3333333333333333}{\frac{z}{\frac{t}{y} - y}}}
\] |
if 3.99999999999999971e-34 < (*.f64 z 3) Initial program 99.1%
Simplified97.9%
[Start]99.1 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-/r* [=>]97.9 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{\frac{t}{z \cdot 3}}{y}}
\] |
Final simplification98.4%
| Alternative 1 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 1480 |
| Alternative 2 | |
|---|---|
| Accuracy | 56.2% |
| Cost | 1244 |
| Alternative 3 | |
|---|---|
| Accuracy | 56.4% |
| Cost | 1244 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 1225 |
| Alternative 5 | |
|---|---|
| Accuracy | 57.1% |
| Cost | 980 |
| Alternative 6 | |
|---|---|
| Accuracy | 93.7% |
| Cost | 969 |
| Alternative 7 | |
|---|---|
| Accuracy | 93.7% |
| Cost | 968 |
| Alternative 8 | |
|---|---|
| Accuracy | 57.1% |
| Cost | 848 |
| Alternative 9 | |
|---|---|
| Accuracy | 81.7% |
| Cost | 841 |
| Alternative 10 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 713 |
| Alternative 11 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 712 |
| Alternative 13 | |
|---|---|
| Accuracy | 74.0% |
| Cost | 712 |
| Alternative 14 | |
|---|---|
| Accuracy | 74.1% |
| Cost | 712 |
| Alternative 15 | |
|---|---|
| Accuracy | 56.9% |
| Cost | 584 |
| Alternative 16 | |
|---|---|
| Accuracy | 42.0% |
| Cost | 64 |
herbie shell --seed 2023137
(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))))