| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 1481 |
(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) -5e-119)
(+ t_1 (/ t (* y (* z 3.0))))
(if (<= (* z 3.0) 3e+137)
(+ x (/ (/ (- (/ t y) y) 3.0) z))
(+ t_1 (* t (/ (/ 0.3333333333333333 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 t_1 = x - (y / (z * 3.0));
double tmp;
if ((z * 3.0) <= -5e-119) {
tmp = t_1 + (t / (y * (z * 3.0)));
} else if ((z * 3.0) <= 3e+137) {
tmp = x + ((((t / y) - y) / 3.0) / z);
} else {
tmp = t_1 + (t * ((0.3333333333333333 / 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) :: t_1
real(8) :: tmp
t_1 = x - (y / (z * 3.0d0))
if ((z * 3.0d0) <= (-5d-119)) then
tmp = t_1 + (t / (y * (z * 3.0d0)))
else if ((z * 3.0d0) <= 3d+137) then
tmp = x + ((((t / y) - y) / 3.0d0) / z)
else
tmp = t_1 + (t * ((0.3333333333333333d0 / 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 t_1 = x - (y / (z * 3.0));
double tmp;
if ((z * 3.0) <= -5e-119) {
tmp = t_1 + (t / (y * (z * 3.0)));
} else if ((z * 3.0) <= 3e+137) {
tmp = x + ((((t / y) - y) / 3.0) / z);
} else {
tmp = t_1 + (t * ((0.3333333333333333 / 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): t_1 = x - (y / (z * 3.0)) tmp = 0 if (z * 3.0) <= -5e-119: tmp = t_1 + (t / (y * (z * 3.0))) elif (z * 3.0) <= 3e+137: tmp = x + ((((t / y) - y) / 3.0) / z) else: tmp = t_1 + (t * ((0.3333333333333333 / 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) t_1 = Float64(x - Float64(y / Float64(z * 3.0))) tmp = 0.0 if (Float64(z * 3.0) <= -5e-119) tmp = Float64(t_1 + Float64(t / Float64(y * Float64(z * 3.0)))); elseif (Float64(z * 3.0) <= 3e+137) tmp = Float64(x + Float64(Float64(Float64(Float64(t / y) - y) / 3.0) / z)); else tmp = Float64(t_1 + Float64(t * Float64(Float64(0.3333333333333333 / 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) t_1 = x - (y / (z * 3.0)); tmp = 0.0; if ((z * 3.0) <= -5e-119) tmp = t_1 + (t / (y * (z * 3.0))); elseif ((z * 3.0) <= 3e+137) tmp = x + ((((t / y) - y) / 3.0) / z); else tmp = t_1 + (t * ((0.3333333333333333 / 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_] := Block[{t$95$1 = N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * 3.0), $MachinePrecision], -5e-119], N[(t$95$1 + N[(t / N[(y * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 3e+137], N[(x + N[(N[(N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision] / 3.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(t * N[(N[(0.3333333333333333 / y), $MachinePrecision] / z), $MachinePrecision]), $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 -5 \cdot 10^{-119}:\\
\;\;\;\;t_1 + \frac{t}{y \cdot \left(z \cdot 3\right)}\\
\mathbf{elif}\;z \cdot 3 \leq 3 \cdot 10^{+137}:\\
\;\;\;\;x + \frac{\frac{\frac{t}{y} - y}{3}}{z}\\
\mathbf{else}:\\
\;\;\;\;t_1 + t \cdot \frac{\frac{0.3333333333333333}{y}}{z}\\
\end{array}
Results
| Original | 94.2% |
|---|---|
| Target | 97.5% |
| Herbie | 98.4% |
if (*.f64 z 3) < -4.99999999999999993e-119Initial program 98.5%
if -4.99999999999999993e-119 < (*.f64 z 3) < 3.0000000000000001e137Initial program 86.5%
Simplified97.6%
[Start]86.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]86.5 | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]86.5 | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
sub-neg [=>]86.5 | \[ 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 [=>]86.5 | \[ 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 [=>]86.5 | \[ 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 [=>]86.5 | \[ 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/ [=>]86.5 | \[ 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/ [<=]86.4 | \[ 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 [=>]86.4 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-t}{\left(z \cdot 3\right) \cdot y}}\right)
\] |
neg-mul-1 [=>]86.4 | \[ 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.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-- [=>]97.6 | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]97.6 | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]97.6 | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]97.6 | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Taylor expanded in z around 0 97.5%
Simplified97.7%
[Start]97.5 | \[ x + -0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z}
\] |
|---|---|
metadata-eval [<=]97.5 | \[ x + \color{blue}{\frac{0.3333333333333333}{-1}} \cdot \frac{y - \frac{t}{y}}{z}
\] |
times-frac [<=]97.6 | \[ x + \color{blue}{\frac{0.3333333333333333 \cdot \left(y - \frac{t}{y}\right)}{-1 \cdot z}}
\] |
metadata-eval [<=]97.6 | \[ x + \frac{\color{blue}{\left(--0.3333333333333333\right)} \cdot \left(y - \frac{t}{y}\right)}{-1 \cdot z}
\] |
distribute-lft-neg-in [<=]97.6 | \[ x + \frac{\color{blue}{--0.3333333333333333 \cdot \left(y - \frac{t}{y}\right)}}{-1 \cdot z}
\] |
associate-/r* [=>]97.6 | \[ x + \color{blue}{\frac{\frac{--0.3333333333333333 \cdot \left(y - \frac{t}{y}\right)}{-1}}{z}}
\] |
*-commutative [=>]97.6 | \[ x + \frac{\frac{-\color{blue}{\left(y - \frac{t}{y}\right) \cdot -0.3333333333333333}}{-1}}{z}
\] |
distribute-lft-neg-in [=>]97.6 | \[ x + \frac{\frac{\color{blue}{\left(-\left(y - \frac{t}{y}\right)\right) \cdot -0.3333333333333333}}{-1}}{z}
\] |
associate-/l* [=>]97.7 | \[ x + \frac{\color{blue}{\frac{-\left(y - \frac{t}{y}\right)}{\frac{-1}{-0.3333333333333333}}}}{z}
\] |
neg-sub0 [=>]97.7 | \[ x + \frac{\frac{\color{blue}{0 - \left(y - \frac{t}{y}\right)}}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
sub-neg [=>]97.7 | \[ x + \frac{\frac{0 - \color{blue}{\left(y + \left(-\frac{t}{y}\right)\right)}}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
distribute-frac-neg [<=]97.7 | \[ x + \frac{\frac{0 - \left(y + \color{blue}{\frac{-t}{y}}\right)}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
+-commutative [=>]97.7 | \[ x + \frac{\frac{0 - \color{blue}{\left(\frac{-t}{y} + y\right)}}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
associate--r+ [=>]97.7 | \[ x + \frac{\frac{\color{blue}{\left(0 - \frac{-t}{y}\right) - y}}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
neg-sub0 [<=]97.7 | \[ x + \frac{\frac{\color{blue}{\left(-\frac{-t}{y}\right)} - y}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
distribute-frac-neg [=>]97.7 | \[ x + \frac{\frac{\left(-\color{blue}{\left(-\frac{t}{y}\right)}\right) - y}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
remove-double-neg [=>]97.7 | \[ x + \frac{\frac{\color{blue}{\frac{t}{y}} - y}{\frac{-1}{-0.3333333333333333}}}{z}
\] |
metadata-eval [=>]97.7 | \[ x + \frac{\frac{\frac{t}{y} - y}{\color{blue}{3}}}{z}
\] |
if 3.0000000000000001e137 < (*.f64 z 3) Initial program 99.4%
Taylor expanded in t around 0 99.4%
Simplified99.5%
[Start]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + 0.3333333333333333 \cdot \frac{t}{y \cdot z}
\] |
|---|---|
associate-*r/ [=>]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{0.3333333333333333 \cdot t}{y \cdot z}}
\] |
*-commutative [=>]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{t \cdot 0.3333333333333333}}{y \cdot z}
\] |
*-commutative [=>]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t \cdot 0.3333333333333333}{\color{blue}{z \cdot y}}
\] |
associate-*r/ [<=]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{t \cdot \frac{0.3333333333333333}{z \cdot y}}
\] |
*-commutative [<=]99.4 | \[ \left(x - \frac{y}{z \cdot 3}\right) + t \cdot \frac{0.3333333333333333}{\color{blue}{y \cdot z}}
\] |
associate-/r* [=>]99.5 | \[ \left(x - \frac{y}{z \cdot 3}\right) + t \cdot \color{blue}{\frac{\frac{0.3333333333333333}{y}}{z}}
\] |
Final simplification98.4%
| Alternative 1 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 1481 |
| Alternative 2 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 977 |
| Alternative 3 | |
|---|---|
| Accuracy | 74.2% |
| Cost | 976 |
| Alternative 4 | |
|---|---|
| Accuracy | 74.4% |
| Cost | 976 |
| Alternative 5 | |
|---|---|
| Accuracy | 74.4% |
| Cost | 976 |
| Alternative 6 | |
|---|---|
| Accuracy | 86.4% |
| Cost | 972 |
| Alternative 7 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 969 |
| Alternative 8 | |
|---|---|
| Accuracy | 97.0% |
| Cost | 969 |
| Alternative 9 | |
|---|---|
| Accuracy | 97.1% |
| Cost | 969 |
| Alternative 10 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 960 |
| Alternative 11 | |
|---|---|
| Accuracy | 56.4% |
| Cost | 848 |
| Alternative 12 | |
|---|---|
| Accuracy | 56.3% |
| Cost | 848 |
| Alternative 13 | |
|---|---|
| Accuracy | 85.8% |
| Cost | 841 |
| Alternative 14 | |
|---|---|
| Accuracy | 91.0% |
| Cost | 841 |
| Alternative 15 | |
|---|---|
| Accuracy | 56.5% |
| Cost | 584 |
| Alternative 16 | |
|---|---|
| Accuracy | 56.6% |
| Cost | 584 |
| Alternative 17 | |
|---|---|
| Accuracy | 42.0% |
| Cost | 64 |
herbie shell --seed 2023151
(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))))