| Alternative 1 | |
|---|---|
| Error | 5.1 |
| Cost | 1736 |
(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 (* (* z 9.0) t)) (t_2 (* 0.5 (/ (* y x) a))))
(if (<= t_1 -2e+276)
(+ t_2 (* -4.5 (* (/ z a) t)))
(if (<= t_1 1.56e+133)
(+ (* -4.5 (/ (* t z) a)) (* (/ x a) (* y 0.5)))
(+ t_2 (* t (* (/ z a) -4.5)))))))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 = (z * 9.0) * t;
double t_2 = 0.5 * ((y * x) / a);
double tmp;
if (t_1 <= -2e+276) {
tmp = t_2 + (-4.5 * ((z / a) * t));
} else if (t_1 <= 1.56e+133) {
tmp = (-4.5 * ((t * z) / a)) + ((x / a) * (y * 0.5));
} else {
tmp = t_2 + (t * ((z / a) * -4.5));
}
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) :: t_2
real(8) :: tmp
t_1 = (z * 9.0d0) * t
t_2 = 0.5d0 * ((y * x) / a)
if (t_1 <= (-2d+276)) then
tmp = t_2 + ((-4.5d0) * ((z / a) * t))
else if (t_1 <= 1.56d+133) then
tmp = ((-4.5d0) * ((t * z) / a)) + ((x / a) * (y * 0.5d0))
else
tmp = t_2 + (t * ((z / a) * (-4.5d0)))
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 = (z * 9.0) * t;
double t_2 = 0.5 * ((y * x) / a);
double tmp;
if (t_1 <= -2e+276) {
tmp = t_2 + (-4.5 * ((z / a) * t));
} else if (t_1 <= 1.56e+133) {
tmp = (-4.5 * ((t * z) / a)) + ((x / a) * (y * 0.5));
} else {
tmp = t_2 + (t * ((z / a) * -4.5));
}
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 = (z * 9.0) * t t_2 = 0.5 * ((y * x) / a) tmp = 0 if t_1 <= -2e+276: tmp = t_2 + (-4.5 * ((z / a) * t)) elif t_1 <= 1.56e+133: tmp = (-4.5 * ((t * z) / a)) + ((x / a) * (y * 0.5)) else: tmp = t_2 + (t * ((z / a) * -4.5)) 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(z * 9.0) * t) t_2 = Float64(0.5 * Float64(Float64(y * x) / a)) tmp = 0.0 if (t_1 <= -2e+276) tmp = Float64(t_2 + Float64(-4.5 * Float64(Float64(z / a) * t))); elseif (t_1 <= 1.56e+133) tmp = Float64(Float64(-4.5 * Float64(Float64(t * z) / a)) + Float64(Float64(x / a) * Float64(y * 0.5))); else tmp = Float64(t_2 + Float64(t * Float64(Float64(z / a) * -4.5))); 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 = (z * 9.0) * t; t_2 = 0.5 * ((y * x) / a); tmp = 0.0; if (t_1 <= -2e+276) tmp = t_2 + (-4.5 * ((z / a) * t)); elseif (t_1 <= 1.56e+133) tmp = (-4.5 * ((t * z) / a)) + ((x / a) * (y * 0.5)); else tmp = t_2 + (t * ((z / a) * -4.5)); 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[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]}, Block[{t$95$2 = N[(0.5 * N[(N[(y * x), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+276], N[(t$95$2 + N[(-4.5 * N[(N[(z / a), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.56e+133], N[(N[(-4.5 * N[(N[(t * z), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(N[(x / a), $MachinePrecision] * N[(y * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$2 + N[(t * N[(N[(z / a), $MachinePrecision] * -4.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := \left(z \cdot 9\right) \cdot t\\
t_2 := 0.5 \cdot \frac{y \cdot x}{a}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+276}:\\
\;\;\;\;t_2 + -4.5 \cdot \left(\frac{z}{a} \cdot t\right)\\
\mathbf{elif}\;t_1 \leq 1.56 \cdot 10^{+133}:\\
\;\;\;\;-4.5 \cdot \frac{t \cdot z}{a} + \frac{x}{a} \cdot \left(y \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;t_2 + t \cdot \left(\frac{z}{a} \cdot -4.5\right)\\
\end{array}
Results
| Original | 7.5 |
|---|---|
| Target | 5.3 |
| Herbie | 5.1 |
if (*.f64 (*.f64 z 9) t) < -2.0000000000000001e276Initial program 47.2
Simplified46.8
[Start]47.2 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
rational.json-simplify-2 [=>]47.2 | \[ \frac{x \cdot y - \color{blue}{t \cdot \left(z \cdot 9\right)}}{a \cdot 2}
\] |
rational.json-simplify-43 [=>]46.8 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Applied egg-rr63.6
Taylor expanded in t around 0 6.1
Simplified6.1
[Start]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + 0.5 \cdot \left(\left(-18 \cdot \frac{z}{a} - -9 \cdot \frac{z}{a}\right) \cdot t\right)
\] |
|---|---|
rational.json-simplify-43 [<=]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + \color{blue}{t \cdot \left(0.5 \cdot \left(-18 \cdot \frac{z}{a} - -9 \cdot \frac{z}{a}\right)\right)}
\] |
rational.json-simplify-2 [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(0.5 \cdot \left(\color{blue}{\frac{z}{a} \cdot -18} - -9 \cdot \frac{z}{a}\right)\right)
\] |
rational.json-simplify-48 [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(0.5 \cdot \color{blue}{\left(\frac{z}{a} \cdot \left(-18 - -9\right)\right)}\right)
\] |
metadata-eval [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(0.5 \cdot \left(\frac{z}{a} \cdot \color{blue}{-9}\right)\right)
\] |
rational.json-simplify-43 [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \color{blue}{\left(\frac{z}{a} \cdot \left(-9 \cdot 0.5\right)\right)}
\] |
metadata-eval [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(\frac{z}{a} \cdot \color{blue}{-4.5}\right)
\] |
Applied egg-rr6.1
Simplified6.1
[Start]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + \left(t \cdot \left(\frac{z}{a} \cdot -4.5\right) + 0\right)
\] |
|---|---|
rational.json-simplify-4 [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + \color{blue}{t \cdot \left(\frac{z}{a} \cdot -4.5\right)}
\] |
rational.json-simplify-2 [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \color{blue}{\left(-4.5 \cdot \frac{z}{a}\right)}
\] |
rational.json-simplify-43 [=>]6.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + \color{blue}{-4.5 \cdot \left(\frac{z}{a} \cdot t\right)}
\] |
if -2.0000000000000001e276 < (*.f64 (*.f64 z 9) t) < 1.56e133Initial program 4.0
Simplified4.0
[Start]4.0 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
rational.json-simplify-2 [=>]4.0 | \[ \frac{x \cdot y - \color{blue}{t \cdot \left(z \cdot 9\right)}}{a \cdot 2}
\] |
rational.json-simplify-43 [=>]4.0 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Applied egg-rr20.6
Taylor expanded in y around 0 4.9
Simplified4.9
[Start]4.9 | \[ -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \left(y \cdot \left(2 \cdot \frac{x}{a} - \frac{x}{a}\right)\right)
\] |
|---|---|
rational.json-simplify-2 [=>]4.9 | \[ -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \color{blue}{\left(\left(2 \cdot \frac{x}{a} - \frac{x}{a}\right) \cdot y\right)}
\] |
rational.json-simplify-43 [=>]4.9 | \[ -4.5 \cdot \frac{t \cdot z}{a} + \color{blue}{\left(2 \cdot \frac{x}{a} - \frac{x}{a}\right) \cdot \left(y \cdot 0.5\right)}
\] |
Taylor expanded in x around 0 4.9
if 1.56e133 < (*.f64 (*.f64 z 9) t) Initial program 20.9
Simplified20.7
[Start]20.9 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
rational.json-simplify-2 [=>]20.9 | \[ \frac{x \cdot y - \color{blue}{t \cdot \left(z \cdot 9\right)}}{a \cdot 2}
\] |
rational.json-simplify-43 [=>]20.7 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Applied egg-rr58.2
Taylor expanded in t around 0 7.1
Simplified7.0
[Start]7.1 | \[ 0.5 \cdot \frac{y \cdot x}{a} + 0.5 \cdot \left(\left(-18 \cdot \frac{z}{a} - -9 \cdot \frac{z}{a}\right) \cdot t\right)
\] |
|---|---|
rational.json-simplify-43 [<=]7.0 | \[ 0.5 \cdot \frac{y \cdot x}{a} + \color{blue}{t \cdot \left(0.5 \cdot \left(-18 \cdot \frac{z}{a} - -9 \cdot \frac{z}{a}\right)\right)}
\] |
rational.json-simplify-2 [=>]7.0 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(0.5 \cdot \left(\color{blue}{\frac{z}{a} \cdot -18} - -9 \cdot \frac{z}{a}\right)\right)
\] |
rational.json-simplify-48 [=>]7.0 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(0.5 \cdot \color{blue}{\left(\frac{z}{a} \cdot \left(-18 - -9\right)\right)}\right)
\] |
metadata-eval [=>]7.0 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(0.5 \cdot \left(\frac{z}{a} \cdot \color{blue}{-9}\right)\right)
\] |
rational.json-simplify-43 [=>]7.0 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \color{blue}{\left(\frac{z}{a} \cdot \left(-9 \cdot 0.5\right)\right)}
\] |
metadata-eval [=>]7.0 | \[ 0.5 \cdot \frac{y \cdot x}{a} + t \cdot \left(\frac{z}{a} \cdot \color{blue}{-4.5}\right)
\] |
Final simplification5.1
| Alternative 1 | |
|---|---|
| Error | 5.1 |
| Cost | 1736 |
| Alternative 2 | |
|---|---|
| Error | 4.7 |
| Cost | 1480 |
| Alternative 3 | |
|---|---|
| Error | 24.2 |
| Cost | 840 |
| Alternative 4 | |
|---|---|
| Error | 24.2 |
| Cost | 840 |
| Alternative 5 | |
|---|---|
| Error | 7.5 |
| Cost | 832 |
| Alternative 6 | |
|---|---|
| Error | 24.2 |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Error | 33.3 |
| Cost | 448 |
herbie shell --seed 2023077
(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)))