| Alternative 1 | |
|---|---|
| Error | 7.28% |
| Cost | 2632 |
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
(FPCore (x y z t a)
:precision binary64
(if (<= (* x y) -5e+165)
(* 0.5 (* x (/ y a)))
(if (<= (* x y) -1e-78)
(+ (* (* x y) (/ 0.5 a)) (* (/ t 2.0) (/ (* z -9.0) a)))
(if (<= (* x y) 4e+237)
(/ (+ (* x y) (* z (* t -9.0))) (* a 2.0))
(* 0.5 (/ y (/ a x)))))))double code(double x, double y, double z, double t, double a) {
return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((x * y) <= -5e+165) {
tmp = 0.5 * (x * (y / a));
} else if ((x * y) <= -1e-78) {
tmp = ((x * y) * (0.5 / a)) + ((t / 2.0) * ((z * -9.0) / a));
} else if ((x * y) <= 4e+237) {
tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0);
} else {
tmp = 0.5 * (y / (a / x));
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = ((x * y) - ((z * 9.0d0) * t)) / (a * 2.0d0)
end function
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if ((x * y) <= (-5d+165)) then
tmp = 0.5d0 * (x * (y / a))
else if ((x * y) <= (-1d-78)) then
tmp = ((x * y) * (0.5d0 / a)) + ((t / 2.0d0) * ((z * (-9.0d0)) / a))
else if ((x * y) <= 4d+237) then
tmp = ((x * y) + (z * (t * (-9.0d0)))) / (a * 2.0d0)
else
tmp = 0.5d0 * (y / (a / x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((x * y) <= -5e+165) {
tmp = 0.5 * (x * (y / a));
} else if ((x * y) <= -1e-78) {
tmp = ((x * y) * (0.5 / a)) + ((t / 2.0) * ((z * -9.0) / a));
} else if ((x * y) <= 4e+237) {
tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0);
} else {
tmp = 0.5 * (y / (a / x));
}
return tmp;
}
def code(x, y, z, t, a): return ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
def code(x, y, z, t, a): tmp = 0 if (x * y) <= -5e+165: tmp = 0.5 * (x * (y / a)) elif (x * y) <= -1e-78: tmp = ((x * y) * (0.5 / a)) + ((t / 2.0) * ((z * -9.0) / a)) elif (x * y) <= 4e+237: tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0) else: tmp = 0.5 * (y / (a / x)) return tmp
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0)) end
function code(x, y, z, t, a) tmp = 0.0 if (Float64(x * y) <= -5e+165) tmp = Float64(0.5 * Float64(x * Float64(y / a))); elseif (Float64(x * y) <= -1e-78) tmp = Float64(Float64(Float64(x * y) * Float64(0.5 / a)) + Float64(Float64(t / 2.0) * Float64(Float64(z * -9.0) / a))); elseif (Float64(x * y) <= 4e+237) tmp = Float64(Float64(Float64(x * y) + Float64(z * Float64(t * -9.0))) / Float64(a * 2.0)); else tmp = Float64(0.5 * Float64(y / Float64(a / x))); end return tmp end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - ((z * 9.0) * t)) / (a * 2.0); end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((x * y) <= -5e+165) tmp = 0.5 * (x * (y / a)); elseif ((x * y) <= -1e-78) tmp = ((x * y) * (0.5 / a)) + ((t / 2.0) * ((z * -9.0) / a)); elseif ((x * y) <= 4e+237) tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0); else tmp = 0.5 * (y / (a / x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e+165], N[(0.5 * N[(x * N[(y / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -1e-78], N[(N[(N[(x * y), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(t / 2.0), $MachinePrecision] * N[(N[(z * -9.0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4e+237], N[(N[(N[(x * y), $MachinePrecision] + N[(z * N[(t * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y / N[(a / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+165}:\\
\;\;\;\;0.5 \cdot \left(x \cdot \frac{y}{a}\right)\\
\mathbf{elif}\;x \cdot y \leq -1 \cdot 10^{-78}:\\
\;\;\;\;\left(x \cdot y\right) \cdot \frac{0.5}{a} + \frac{t}{2} \cdot \frac{z \cdot -9}{a}\\
\mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{+237}:\\
\;\;\;\;\frac{x \cdot y + z \cdot \left(t \cdot -9\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y}{\frac{a}{x}}\\
\end{array}
Results
| Original | 12.03% |
|---|---|
| Target | 8.38% |
| Herbie | 7.78% |
if (*.f64 x y) < -4.9999999999999997e165Initial program 41.02
Simplified41.02
[Start]41.02 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
associate-*l* [=>]41.02 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Taylor expanded in x around inf 46.37
Simplified16.87
[Start]46.37 | \[ 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
associate-/l* [=>]17.43 | \[ 0.5 \cdot \color{blue}{\frac{y}{\frac{a}{x}}}
\] |
associate-/r/ [=>]16.87 | \[ 0.5 \cdot \color{blue}{\left(\frac{y}{a} \cdot x\right)}
\] |
if -4.9999999999999997e165 < (*.f64 x y) < -9.99999999999999999e-79Initial program 5.64
Applied egg-rr6.45
if -9.99999999999999999e-79 < (*.f64 x y) < 3.99999999999999976e237Initial program 7.08
Simplified7.02
[Start]7.08 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
associate-*l* [=>]7.02 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
if 3.99999999999999976e237 < (*.f64 x y) Initial program 56.85
Simplified56.94
[Start]56.85 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]56.85 | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
remove-double-neg [<=]56.85 | \[ \frac{\color{blue}{\left(-\left(-x \cdot y\right)\right)} + \left(-\left(z \cdot 9\right) \cdot t\right)}{a \cdot 2}
\] |
distribute-neg-in [<=]56.85 | \[ \frac{\color{blue}{-\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [<=]56.85 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}}{a \cdot 2}
\] |
sub-neg [<=]56.85 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]56.85 | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]56.94 | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]56.93 | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
sub-neg [=>]56.93 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}
\] |
+-commutative [=>]56.93 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}
\] |
neg-sub0 [=>]56.93 | \[ \frac{-1}{a \cdot 2} \cdot \left(\color{blue}{\left(0 - x \cdot y\right)} + \left(z \cdot 9\right) \cdot t\right)
\] |
associate-+l- [=>]56.93 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(0 - \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
sub0-neg [=>]56.93 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(-\left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)\right)}
\] |
distribute-rgt-neg-out [=>]56.93 | \[ \color{blue}{-\frac{-1}{a \cdot 2} \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
distribute-lft-neg-in [=>]56.93 | \[ \color{blue}{\left(-\frac{-1}{a \cdot 2}\right) \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
Taylor expanded in x around inf 58.1
Simplified8.39
[Start]58.1 | \[ 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
associate-/l* [=>]8.39 | \[ 0.5 \cdot \color{blue}{\frac{y}{\frac{a}{x}}}
\] |
Final simplification7.78
| Alternative 1 | |
|---|---|
| Error | 7.28% |
| Cost | 2632 |
| Alternative 2 | |
|---|---|
| Error | 13.69% |
| Cost | 1096 |
| Alternative 3 | |
|---|---|
| Error | 41.17% |
| Cost | 977 |
| Alternative 4 | |
|---|---|
| Error | 41.22% |
| Cost | 977 |
| Alternative 5 | |
|---|---|
| Error | 41.06% |
| Cost | 976 |
| Alternative 6 | |
|---|---|
| Error | 37.13% |
| Cost | 976 |
| Alternative 7 | |
|---|---|
| Error | 41.17% |
| Cost | 976 |
| Alternative 8 | |
|---|---|
| Error | 50.57% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Error | 48.19% |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Error | 50.22% |
| Cost | 580 |
| Alternative 11 | |
|---|---|
| Error | 50.39% |
| Cost | 448 |
herbie shell --seed 2023121
(FPCore (x y z t a)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, I"
:precision binary64
:herbie-target
(if (< a -2.090464557976709e+86) (- (* 0.5 (/ (* y x) a)) (* 4.5 (/ t (/ a z)))) (if (< a 2.144030707833976e+99) (/ (- (* x y) (* z (* 9.0 t))) (* a 2.0)) (- (* (/ y a) (* x 0.5)) (* (/ t a) (* z 4.5)))))
(/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))