| Alternative 1 | |
|---|---|
| Accuracy | 93.5% |
| Cost | 2248 |
(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
(let* ((t_1 (- (* x y) (* (* z 9.0) t))))
(if (or (<= t_1 -1e+221) (not (<= t_1 2e+202)))
(- (* 0.5 (/ y (/ a x))) (* t (* z (/ 4.5 a))))
(/ t_1 (* a 2.0)))))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 t_1 = (x * y) - ((z * 9.0) * t);
double tmp;
if ((t_1 <= -1e+221) || !(t_1 <= 2e+202)) {
tmp = (0.5 * (y / (a / x))) - (t * (z * (4.5 / a)));
} else {
tmp = t_1 / (a * 2.0);
}
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) :: t_1
real(8) :: tmp
t_1 = (x * y) - ((z * 9.0d0) * t)
if ((t_1 <= (-1d+221)) .or. (.not. (t_1 <= 2d+202))) then
tmp = (0.5d0 * (y / (a / x))) - (t * (z * (4.5d0 / a)))
else
tmp = t_1 / (a * 2.0d0)
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 t_1 = (x * y) - ((z * 9.0) * t);
double tmp;
if ((t_1 <= -1e+221) || !(t_1 <= 2e+202)) {
tmp = (0.5 * (y / (a / x))) - (t * (z * (4.5 / a)));
} else {
tmp = t_1 / (a * 2.0);
}
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): t_1 = (x * y) - ((z * 9.0) * t) tmp = 0 if (t_1 <= -1e+221) or not (t_1 <= 2e+202): tmp = (0.5 * (y / (a / x))) - (t * (z * (4.5 / a))) else: tmp = t_1 / (a * 2.0) 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) t_1 = Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) tmp = 0.0 if ((t_1 <= -1e+221) || !(t_1 <= 2e+202)) tmp = Float64(Float64(0.5 * Float64(y / Float64(a / x))) - Float64(t * Float64(z * Float64(4.5 / a)))); else tmp = Float64(t_1 / Float64(a * 2.0)); 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) t_1 = (x * y) - ((z * 9.0) * t); tmp = 0.0; if ((t_1 <= -1e+221) || ~((t_1 <= 2e+202))) tmp = (0.5 * (y / (a / x))) - (t * (z * (4.5 / a))); else tmp = t_1 / (a * 2.0); 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_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -1e+221], N[Not[LessEqual[t$95$1, 2e+202]], $MachinePrecision]], N[(N[(0.5 * N[(y / N[(a / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t * N[(z * N[(4.5 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := x \cdot y - \left(z \cdot 9\right) \cdot t\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+221} \lor \neg \left(t_1 \leq 2 \cdot 10^{+202}\right):\\
\;\;\;\;0.5 \cdot \frac{y}{\frac{a}{x}} - t \cdot \left(z \cdot \frac{4.5}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{a \cdot 2}\\
\end{array}
Results
| Original | 88.3% |
|---|---|
| Target | 91.1% |
| Herbie | 98.4% |
if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -1e221 or 1.9999999999999998e202 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) Initial program 53.9%
Applied egg-rr74.6%
[Start]53.9 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
div-sub [=>]53.9 | \[ \color{blue}{\frac{x \cdot y}{a \cdot 2} - \frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}}
\] |
sub-neg [=>]53.9 | \[ \color{blue}{\frac{x \cdot y}{a \cdot 2} + \left(-\frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}\right)}
\] |
div-inv [=>]53.9 | \[ \color{blue}{\left(x \cdot y\right) \cdot \frac{1}{a \cdot 2}} + \left(-\frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}\right)
\] |
*-commutative [=>]53.9 | \[ \left(x \cdot y\right) \cdot \frac{1}{\color{blue}{2 \cdot a}} + \left(-\frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}\right)
\] |
associate-/r* [=>]53.9 | \[ \left(x \cdot y\right) \cdot \color{blue}{\frac{\frac{1}{2}}{a}} + \left(-\frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}\right)
\] |
metadata-eval [=>]53.9 | \[ \left(x \cdot y\right) \cdot \frac{\color{blue}{0.5}}{a} + \left(-\frac{\left(z \cdot 9\right) \cdot t}{a \cdot 2}\right)
\] |
times-frac [=>]74.6 | \[ \left(x \cdot y\right) \cdot \frac{0.5}{a} + \left(-\color{blue}{\frac{z \cdot 9}{a} \cdot \frac{t}{2}}\right)
\] |
Simplified75.4%
[Start]74.6 | \[ \left(x \cdot y\right) \cdot \frac{0.5}{a} + \left(-\frac{z \cdot 9}{a} \cdot \frac{t}{2}\right)
\] |
|---|---|
sub-neg [<=]74.6 | \[ \color{blue}{\left(x \cdot y\right) \cdot \frac{0.5}{a} - \frac{z \cdot 9}{a} \cdot \frac{t}{2}}
\] |
associate-*r/ [=>]74.6 | \[ \color{blue}{\frac{\left(x \cdot y\right) \cdot 0.5}{a}} - \frac{z \cdot 9}{a} \cdot \frac{t}{2}
\] |
*-commutative [=>]74.6 | \[ \frac{\color{blue}{0.5 \cdot \left(x \cdot y\right)}}{a} - \frac{z \cdot 9}{a} \cdot \frac{t}{2}
\] |
*-commutative [=>]74.6 | \[ \frac{0.5 \cdot \color{blue}{\left(y \cdot x\right)}}{a} - \frac{z \cdot 9}{a} \cdot \frac{t}{2}
\] |
associate-*r/ [<=]74.6 | \[ \color{blue}{0.5 \cdot \frac{y \cdot x}{a}} - \frac{z \cdot 9}{a} \cdot \frac{t}{2}
\] |
associate-/l* [=>]97.5 | \[ 0.5 \cdot \color{blue}{\frac{y}{\frac{a}{x}}} - \frac{z \cdot 9}{a} \cdot \frac{t}{2}
\] |
associate-/l* [=>]97.8 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{\frac{z}{\frac{a}{9}}} \cdot \frac{t}{2}
\] |
associate-*l/ [=>]75.4 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{\frac{z \cdot \frac{t}{2}}{\frac{a}{9}}}
\] |
Taylor expanded in z around 0 75.2%
Simplified97.8%
[Start]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - 4.5 \cdot \frac{t \cdot z}{a}
\] |
|---|---|
associate-*r/ [=>]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{\frac{4.5 \cdot \left(t \cdot z\right)}{a}}
\] |
metadata-eval [<=]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \frac{\color{blue}{\left(9 \cdot 0.5\right)} \cdot \left(t \cdot z\right)}{a}
\] |
*-commutative [<=]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \frac{\left(9 \cdot 0.5\right) \cdot \color{blue}{\left(z \cdot t\right)}}{a}
\] |
associate-*r* [<=]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \frac{\color{blue}{9 \cdot \left(0.5 \cdot \left(z \cdot t\right)\right)}}{a}
\] |
*-commutative [<=]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \frac{9 \cdot \color{blue}{\left(\left(z \cdot t\right) \cdot 0.5\right)}}{a}
\] |
associate-*l/ [<=]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{\frac{9}{a} \cdot \left(\left(z \cdot t\right) \cdot 0.5\right)}
\] |
*-commutative [<=]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{\left(\left(z \cdot t\right) \cdot 0.5\right) \cdot \frac{9}{a}}
\] |
associate-*l* [=>]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{\left(z \cdot t\right) \cdot \left(0.5 \cdot \frac{9}{a}\right)}
\] |
*-commutative [=>]75.2 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{\left(t \cdot z\right)} \cdot \left(0.5 \cdot \frac{9}{a}\right)
\] |
associate-*l* [=>]97.8 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - \color{blue}{t \cdot \left(z \cdot \left(0.5 \cdot \frac{9}{a}\right)\right)}
\] |
associate-*r/ [=>]97.8 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - t \cdot \left(z \cdot \color{blue}{\frac{0.5 \cdot 9}{a}}\right)
\] |
metadata-eval [=>]97.8 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} - t \cdot \left(z \cdot \frac{\color{blue}{4.5}}{a}\right)
\] |
if -1e221 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 1.9999999999999998e202Initial program 98.5%
Final simplification98.4%
| Alternative 1 | |
|---|---|
| Accuracy | 93.5% |
| Cost | 2248 |
| Alternative 2 | |
|---|---|
| Accuracy | 93.5% |
| Cost | 2120 |
| Alternative 3 | |
|---|---|
| Accuracy | 61.1% |
| Cost | 1372 |
| Alternative 4 | |
|---|---|
| Accuracy | 93.4% |
| Cost | 1352 |
| Alternative 5 | |
|---|---|
| Accuracy | 60.5% |
| Cost | 1241 |
| Alternative 6 | |
|---|---|
| Accuracy | 61.1% |
| Cost | 1240 |
| Alternative 7 | |
|---|---|
| Accuracy | 61.0% |
| Cost | 1240 |
| Alternative 8 | |
|---|---|
| Accuracy | 61.0% |
| Cost | 1240 |
| Alternative 9 | |
|---|---|
| Accuracy | 61.1% |
| Cost | 1240 |
| Alternative 10 | |
|---|---|
| Accuracy | 49.7% |
| Cost | 580 |
| Alternative 11 | |
|---|---|
| Accuracy | 49.2% |
| Cost | 448 |
| Alternative 12 | |
|---|---|
| Accuracy | 5.8% |
| Cost | 192 |
herbie shell --seed 2023147
(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)))