| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 3537 |
(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 (/ (* y 0.5) (/ a x)))
(t_2 (+ (* x y) (* t (* z -9.0))))
(t_3 (/ (* t -4.5) (/ a z))))
(if (<= t_2 -5e+282)
(+ t_1 t_3)
(if (<= t_2 -2e-241)
(+ (* -4.5 (/ (* z t) a)) (* 0.5 (/ (* x y) a)))
(if (<= t_2 5e-103)
(+ (* x (* y (/ 0.5 a))) t_3)
(if (<= t_2 5e+282)
(/ (+ (* x y) (* z (* t -9.0))) (* a 2.0))
(+ t_1 (* (/ z a) (/ -9.0 (/ 2.0 t))))))))))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 = (y * 0.5) / (a / x);
double t_2 = (x * y) + (t * (z * -9.0));
double t_3 = (t * -4.5) / (a / z);
double tmp;
if (t_2 <= -5e+282) {
tmp = t_1 + t_3;
} else if (t_2 <= -2e-241) {
tmp = (-4.5 * ((z * t) / a)) + (0.5 * ((x * y) / a));
} else if (t_2 <= 5e-103) {
tmp = (x * (y * (0.5 / a))) + t_3;
} else if (t_2 <= 5e+282) {
tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0);
} else {
tmp = t_1 + ((z / a) * (-9.0 / (2.0 / t)));
}
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) :: t_3
real(8) :: tmp
t_1 = (y * 0.5d0) / (a / x)
t_2 = (x * y) + (t * (z * (-9.0d0)))
t_3 = (t * (-4.5d0)) / (a / z)
if (t_2 <= (-5d+282)) then
tmp = t_1 + t_3
else if (t_2 <= (-2d-241)) then
tmp = ((-4.5d0) * ((z * t) / a)) + (0.5d0 * ((x * y) / a))
else if (t_2 <= 5d-103) then
tmp = (x * (y * (0.5d0 / a))) + t_3
else if (t_2 <= 5d+282) then
tmp = ((x * y) + (z * (t * (-9.0d0)))) / (a * 2.0d0)
else
tmp = t_1 + ((z / a) * ((-9.0d0) / (2.0d0 / t)))
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 = (y * 0.5) / (a / x);
double t_2 = (x * y) + (t * (z * -9.0));
double t_3 = (t * -4.5) / (a / z);
double tmp;
if (t_2 <= -5e+282) {
tmp = t_1 + t_3;
} else if (t_2 <= -2e-241) {
tmp = (-4.5 * ((z * t) / a)) + (0.5 * ((x * y) / a));
} else if (t_2 <= 5e-103) {
tmp = (x * (y * (0.5 / a))) + t_3;
} else if (t_2 <= 5e+282) {
tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0);
} else {
tmp = t_1 + ((z / a) * (-9.0 / (2.0 / t)));
}
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 = (y * 0.5) / (a / x) t_2 = (x * y) + (t * (z * -9.0)) t_3 = (t * -4.5) / (a / z) tmp = 0 if t_2 <= -5e+282: tmp = t_1 + t_3 elif t_2 <= -2e-241: tmp = (-4.5 * ((z * t) / a)) + (0.5 * ((x * y) / a)) elif t_2 <= 5e-103: tmp = (x * (y * (0.5 / a))) + t_3 elif t_2 <= 5e+282: tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0) else: tmp = t_1 + ((z / a) * (-9.0 / (2.0 / t))) 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(y * 0.5) / Float64(a / x)) t_2 = Float64(Float64(x * y) + Float64(t * Float64(z * -9.0))) t_3 = Float64(Float64(t * -4.5) / Float64(a / z)) tmp = 0.0 if (t_2 <= -5e+282) tmp = Float64(t_1 + t_3); elseif (t_2 <= -2e-241) tmp = Float64(Float64(-4.5 * Float64(Float64(z * t) / a)) + Float64(0.5 * Float64(Float64(x * y) / a))); elseif (t_2 <= 5e-103) tmp = Float64(Float64(x * Float64(y * Float64(0.5 / a))) + t_3); elseif (t_2 <= 5e+282) tmp = Float64(Float64(Float64(x * y) + Float64(z * Float64(t * -9.0))) / Float64(a * 2.0)); else tmp = Float64(t_1 + Float64(Float64(z / a) * Float64(-9.0 / Float64(2.0 / t)))); 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 = (y * 0.5) / (a / x); t_2 = (x * y) + (t * (z * -9.0)); t_3 = (t * -4.5) / (a / z); tmp = 0.0; if (t_2 <= -5e+282) tmp = t_1 + t_3; elseif (t_2 <= -2e-241) tmp = (-4.5 * ((z * t) / a)) + (0.5 * ((x * y) / a)); elseif (t_2 <= 5e-103) tmp = (x * (y * (0.5 / a))) + t_3; elseif (t_2 <= 5e+282) tmp = ((x * y) + (z * (t * -9.0))) / (a * 2.0); else tmp = t_1 + ((z / a) * (-9.0 / (2.0 / t))); 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[(y * 0.5), $MachinePrecision] / N[(a / x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] + N[(t * N[(z * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(t * -4.5), $MachinePrecision] / N[(a / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+282], N[(t$95$1 + t$95$3), $MachinePrecision], If[LessEqual[t$95$2, -2e-241], N[(N[(-4.5 * N[(N[(z * t), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(N[(x * y), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e-103], N[(N[(x * N[(y * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$3), $MachinePrecision], If[LessEqual[t$95$2, 5e+282], N[(N[(N[(x * y), $MachinePrecision] + N[(z * N[(t * -9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(z / a), $MachinePrecision] * N[(-9.0 / N[(2.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := \frac{y \cdot 0.5}{\frac{a}{x}}\\
t_2 := x \cdot y + t \cdot \left(z \cdot -9\right)\\
t_3 := \frac{t \cdot -4.5}{\frac{a}{z}}\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+282}:\\
\;\;\;\;t_1 + t_3\\
\mathbf{elif}\;t_2 \leq -2 \cdot 10^{-241}:\\
\;\;\;\;-4.5 \cdot \frac{z \cdot t}{a} + 0.5 \cdot \frac{x \cdot y}{a}\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{-103}:\\
\;\;\;\;x \cdot \left(y \cdot \frac{0.5}{a}\right) + t_3\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+282}:\\
\;\;\;\;\frac{x \cdot y + z \cdot \left(t \cdot -9\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \frac{z}{a} \cdot \frac{-9}{\frac{2}{t}}\\
\end{array}
Results
| Original | 8.1 |
|---|---|
| Target | 5.8 |
| Herbie | 0.8 |
if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -4.99999999999999978e282Initial program 52.1
Simplified51.4
[Start]52.1 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
associate-*l* [=>]51.4 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Applied egg-rr26.6
Simplified0.9
[Start]26.6 | \[ \left(x \cdot y\right) \cdot \frac{0.5}{a} + \left(-\frac{z}{a} \cdot \frac{9 \cdot t}{2}\right)
\] |
|---|---|
sub-neg [<=]26.6 | \[ \color{blue}{\left(x \cdot y\right) \cdot \frac{0.5}{a} - \frac{z}{a} \cdot \frac{9 \cdot t}{2}}
\] |
associate-*l* [=>]0.9 | \[ \color{blue}{x \cdot \left(y \cdot \frac{0.5}{a}\right)} - \frac{z}{a} \cdot \frac{9 \cdot t}{2}
\] |
associate-/l* [=>]0.9 | \[ x \cdot \left(y \cdot \frac{0.5}{a}\right) - \frac{z}{a} \cdot \color{blue}{\frac{9}{\frac{2}{t}}}
\] |
Applied egg-rr1.0
Applied egg-rr0.9
if -4.99999999999999978e282 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -1.9999999999999999e-241Initial program 0.3
Simplified0.4
[Start]0.3 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
sub-neg [=>]0.3 | \[ \frac{\color{blue}{x \cdot y + \left(-\left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
remove-double-neg [<=]0.3 | \[ \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 [<=]0.3 | \[ \frac{\color{blue}{-\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}}{a \cdot 2}
\] |
+-commutative [<=]0.3 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}}{a \cdot 2}
\] |
sub-neg [<=]0.3 | \[ \frac{-\color{blue}{\left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
neg-mul-1 [=>]0.3 | \[ \frac{\color{blue}{-1 \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}}{a \cdot 2}
\] |
associate-/l* [=>]0.6 | \[ \color{blue}{\frac{-1}{\frac{a \cdot 2}{\left(z \cdot 9\right) \cdot t - x \cdot y}}}
\] |
associate-/r/ [=>]0.4 | \[ \color{blue}{\frac{-1}{a \cdot 2} \cdot \left(\left(z \cdot 9\right) \cdot t - x \cdot y\right)}
\] |
sub-neg [=>]0.4 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(z \cdot 9\right) \cdot t + \left(-x \cdot y\right)\right)}
\] |
+-commutative [=>]0.4 | \[ \frac{-1}{a \cdot 2} \cdot \color{blue}{\left(\left(-x \cdot y\right) + \left(z \cdot 9\right) \cdot t\right)}
\] |
neg-sub0 [=>]0.4 | \[ \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- [=>]0.4 | \[ \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 [=>]0.4 | \[ \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 [=>]0.4 | \[ \color{blue}{-\frac{-1}{a \cdot 2} \cdot \left(x \cdot y - \left(z \cdot 9\right) \cdot t\right)}
\] |
distribute-lft-neg-in [=>]0.4 | \[ \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 0 0.3
if -1.9999999999999999e-241 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 4.99999999999999966e-103Initial program 5.2
Simplified5.2
[Start]5.2 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
associate-*l* [=>]5.2 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Applied egg-rr4.3
Simplified4.2
[Start]4.3 | \[ \left(x \cdot y\right) \cdot \frac{0.5}{a} + \left(-\frac{z}{a} \cdot \frac{9 \cdot t}{2}\right)
\] |
|---|---|
sub-neg [<=]4.3 | \[ \color{blue}{\left(x \cdot y\right) \cdot \frac{0.5}{a} - \frac{z}{a} \cdot \frac{9 \cdot t}{2}}
\] |
associate-*l* [=>]4.2 | \[ \color{blue}{x \cdot \left(y \cdot \frac{0.5}{a}\right)} - \frac{z}{a} \cdot \frac{9 \cdot t}{2}
\] |
associate-/l* [=>]4.2 | \[ x \cdot \left(y \cdot \frac{0.5}{a}\right) - \frac{z}{a} \cdot \color{blue}{\frac{9}{\frac{2}{t}}}
\] |
Applied egg-rr3.9
if 4.99999999999999966e-103 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 4.99999999999999978e282Initial program 0.3
Simplified0.4
[Start]0.3 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
associate-*l* [=>]0.4 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
if 4.99999999999999978e282 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) Initial program 54.1
Simplified54.0
[Start]54.1 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
associate-*l* [=>]54.0 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Applied egg-rr30.9
Simplified0.4
[Start]30.9 | \[ \left(x \cdot y\right) \cdot \frac{0.5}{a} + \left(-\frac{z}{a} \cdot \frac{9 \cdot t}{2}\right)
\] |
|---|---|
sub-neg [<=]30.9 | \[ \color{blue}{\left(x \cdot y\right) \cdot \frac{0.5}{a} - \frac{z}{a} \cdot \frac{9 \cdot t}{2}}
\] |
associate-*l* [=>]0.5 | \[ \color{blue}{x \cdot \left(y \cdot \frac{0.5}{a}\right)} - \frac{z}{a} \cdot \frac{9 \cdot t}{2}
\] |
associate-/l* [=>]0.4 | \[ x \cdot \left(y \cdot \frac{0.5}{a}\right) - \frac{z}{a} \cdot \color{blue}{\frac{9}{\frac{2}{t}}}
\] |
Applied egg-rr0.3
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 3537 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 3536 |
| Alternative 3 | |
|---|---|
| Error | 4.4 |
| Cost | 2632 |
| Alternative 4 | |
|---|---|
| Error | 4.4 |
| Cost | 1352 |
| Alternative 5 | |
|---|---|
| Error | 24.5 |
| Cost | 1241 |
| Alternative 6 | |
|---|---|
| Error | 24.5 |
| Cost | 1240 |
| Alternative 7 | |
|---|---|
| Error | 24.4 |
| Cost | 1240 |
| Alternative 8 | |
|---|---|
| Error | 24.4 |
| Cost | 1240 |
| Alternative 9 | |
|---|---|
| Error | 24.4 |
| Cost | 1240 |
| Alternative 10 | |
|---|---|
| Error | 24.4 |
| Cost | 1240 |
| Alternative 11 | |
|---|---|
| Error | 7.3 |
| Cost | 1229 |
| Alternative 12 | |
|---|---|
| Error | 23.9 |
| Cost | 977 |
| Alternative 13 | |
|---|---|
| Error | 31.8 |
| Cost | 712 |
| Alternative 14 | |
|---|---|
| Error | 32.9 |
| Cost | 448 |
| Alternative 15 | |
|---|---|
| Error | 32.9 |
| Cost | 448 |
herbie shell --seed 2023073
(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)))