| Alternative 1 | |
|---|---|
| Error | 2.1% |
| Cost | 1225 |
(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-42)
(+ t_1 (/ t (* (* z 3.0) y)))
(if (<= (* z 3.0) 2e+62)
(+ x (/ (/ (- y (/ t y)) z) -3.0))
(+ 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) <= -5e-42) {
tmp = t_1 + (t / ((z * 3.0) * y));
} else if ((z * 3.0) <= 2e+62) {
tmp = x + (((y - (t / y)) / z) / -3.0);
} 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) <= (-5d-42)) then
tmp = t_1 + (t / ((z * 3.0d0) * y))
else if ((z * 3.0d0) <= 2d+62) then
tmp = x + (((y - (t / y)) / z) / (-3.0d0))
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) <= -5e-42) {
tmp = t_1 + (t / ((z * 3.0) * y));
} else if ((z * 3.0) <= 2e+62) {
tmp = x + (((y - (t / y)) / z) / -3.0);
} 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) <= -5e-42: tmp = t_1 + (t / ((z * 3.0) * y)) elif (z * 3.0) <= 2e+62: tmp = x + (((y - (t / y)) / z) / -3.0) 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) <= -5e-42) tmp = Float64(t_1 + Float64(t / Float64(Float64(z * 3.0) * y))); elseif (Float64(z * 3.0) <= 2e+62) tmp = Float64(x + Float64(Float64(Float64(y - Float64(t / y)) / z) / -3.0)); else tmp = Float64(t_1 + 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) t_1 = x - (y / (z * 3.0)); tmp = 0.0; if ((z * 3.0) <= -5e-42) tmp = t_1 + (t / ((z * 3.0) * y)); elseif ((z * 3.0) <= 2e+62) tmp = x + (((y - (t / y)) / z) / -3.0); 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], -5e-42], N[(t$95$1 + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 2e+62], N[(x + N[(N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] / -3.0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + 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}
t_1 := x - \frac{y}{z \cdot 3}\\
\mathbf{if}\;z \cdot 3 \leq -5 \cdot 10^{-42}:\\
\;\;\;\;t_1 + \frac{t}{\left(z \cdot 3\right) \cdot y}\\
\mathbf{elif}\;z \cdot 3 \leq 2 \cdot 10^{+62}:\\
\;\;\;\;x + \frac{\frac{y - \frac{t}{y}}{z}}{-3}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \frac{t}{z \cdot \left(3 \cdot y\right)}\\
\end{array}
Results
| Original | 5.75% |
|---|---|
| Target | 2.46% |
| Herbie | 0.95% |
if (*.f64 z 3) < -5.00000000000000003e-42Initial program 0.71
if -5.00000000000000003e-42 < (*.f64 z 3) < 2.00000000000000007e62Initial program 15
Simplified1.21
[Start]15 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\] |
|---|---|
associate-+l- [=>]15 | \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
sub-neg [=>]15 | \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)}
\] |
neg-mul-1 [=>]15 | \[ x + \color{blue}{-1 \cdot \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)}
\] |
distribute-lft-out-- [<=]15 | \[ 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/ [=>]15 | \[ 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/ [<=]15.06 | \[ 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/ [=>]15.06 | \[ 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 [=>]1.19 | \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right)
\] |
distribute-lft-out-- [=>]1.19 | \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)}
\] |
*-commutative [=>]1.19 | \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right)
\] |
associate-/r* [=>]1.21 | \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right)
\] |
metadata-eval [=>]1.21 | \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right)
\] |
Applied egg-rr1.45
if 2.00000000000000007e62 < (*.f64 z 3) Initial program 0.62
Taylor expanded in t around 0 0.63
Simplified0.61
[Start]0.63 | \[ \left(x - \frac{y}{z \cdot 3}\right) + 0.3333333333333333 \cdot \frac{t}{y \cdot z}
\] |
|---|---|
associate-/r* [=>]11.63 | \[ \left(x - \frac{y}{z \cdot 3}\right) + 0.3333333333333333 \cdot \color{blue}{\frac{\frac{t}{y}}{z}}
\] |
associate-*r/ [=>]11.63 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{0.3333333333333333 \cdot \frac{t}{y}}{z}}
\] |
associate-*l/ [<=]11.64 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{0.3333333333333333}{z} \cdot \frac{t}{y}}
\] |
metadata-eval [<=]11.64 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{\frac{1}{3}}}{z} \cdot \frac{t}{y}
\] |
associate-/r* [<=]11.64 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{1}{3 \cdot z}} \cdot \frac{t}{y}
\] |
*-commutative [<=]11.64 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{1}{\color{blue}{z \cdot 3}} \cdot \frac{t}{y}
\] |
associate-/r* [=>]11.63 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{\frac{1}{z}}{3}} \cdot \frac{t}{y}
\] |
times-frac [<=]1.67 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{\frac{1}{z} \cdot t}{3 \cdot y}}
\] |
associate-*r/ [<=]11.54 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{1}{z} \cdot \frac{t}{3 \cdot y}}
\] |
associate-*l/ [=>]11.52 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{1 \cdot \frac{t}{3 \cdot y}}{z}}
\] |
*-lft-identity [=>]11.52 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{\color{blue}{\frac{t}{3 \cdot y}}}{z}
\] |
associate-/r* [<=]0.61 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{\frac{t}{\left(3 \cdot y\right) \cdot z}}
\] |
*-commutative [=>]0.61 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\color{blue}{z \cdot \left(3 \cdot y\right)}}
\] |
*-commutative [=>]0.61 | \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{z \cdot \color{blue}{\left(y \cdot 3\right)}}
\] |
Final simplification0.95
| Alternative 1 | |
|---|---|
| Error | 2.1% |
| Cost | 1225 |
| Alternative 2 | |
|---|---|
| Error | 2.52% |
| Cost | 969 |
| Alternative 3 | |
|---|---|
| Error | 2.55% |
| Cost | 969 |
| Alternative 4 | |
|---|---|
| Error | 2.59% |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Error | 2.56% |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Error | 2.52% |
| Cost | 968 |
| Alternative 7 | |
|---|---|
| Error | 44.51% |
| Cost | 849 |
| Alternative 8 | |
|---|---|
| Error | 44.32% |
| Cost | 849 |
| Alternative 9 | |
|---|---|
| Error | 44.34% |
| Cost | 848 |
| Alternative 10 | |
|---|---|
| Error | 13.19% |
| Cost | 840 |
| Alternative 11 | |
|---|---|
| Error | 9.38% |
| Cost | 840 |
| Alternative 12 | |
|---|---|
| Error | 9.32% |
| Cost | 840 |
| Alternative 13 | |
|---|---|
| Error | 28.78% |
| Cost | 448 |
| Alternative 14 | |
|---|---|
| Error | 28.67% |
| Cost | 448 |
| Alternative 15 | |
|---|---|
| Error | 58.76% |
| Cost | 64 |
herbie shell --seed 2023121
(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))))