| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 3536 |
(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 (+ (* 0.5 (/ y (/ a x))) (* -4.5 (* z (/ t a)))))
(t_2 (- (* x y) (* (* z 9.0) t))))
(if (<= t_2 -5e+169)
t_1
(if (<= t_2 -1e-117)
(/ 0.5 (/ a (- (* x y) (* 9.0 (* z t)))))
(if (<= t_2 5e-205)
(+ (* -4.5 (* t (/ z a))) (* 0.5 (* y (/ x a))))
(if (<= t_2 4e+218)
(/ (- (* x y) (* z (* 9.0 t))) (* a 2.0))
t_1))))))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 = (0.5 * (y / (a / x))) + (-4.5 * (z * (t / a)));
double t_2 = (x * y) - ((z * 9.0) * t);
double tmp;
if (t_2 <= -5e+169) {
tmp = t_1;
} else if (t_2 <= -1e-117) {
tmp = 0.5 / (a / ((x * y) - (9.0 * (z * t))));
} else if (t_2 <= 5e-205) {
tmp = (-4.5 * (t * (z / a))) + (0.5 * (y * (x / a)));
} else if (t_2 <= 4e+218) {
tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0);
} else {
tmp = t_1;
}
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 = (0.5d0 * (y / (a / x))) + ((-4.5d0) * (z * (t / a)))
t_2 = (x * y) - ((z * 9.0d0) * t)
if (t_2 <= (-5d+169)) then
tmp = t_1
else if (t_2 <= (-1d-117)) then
tmp = 0.5d0 / (a / ((x * y) - (9.0d0 * (z * t))))
else if (t_2 <= 5d-205) then
tmp = ((-4.5d0) * (t * (z / a))) + (0.5d0 * (y * (x / a)))
else if (t_2 <= 4d+218) then
tmp = ((x * y) - (z * (9.0d0 * t))) / (a * 2.0d0)
else
tmp = t_1
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 = (0.5 * (y / (a / x))) + (-4.5 * (z * (t / a)));
double t_2 = (x * y) - ((z * 9.0) * t);
double tmp;
if (t_2 <= -5e+169) {
tmp = t_1;
} else if (t_2 <= -1e-117) {
tmp = 0.5 / (a / ((x * y) - (9.0 * (z * t))));
} else if (t_2 <= 5e-205) {
tmp = (-4.5 * (t * (z / a))) + (0.5 * (y * (x / a)));
} else if (t_2 <= 4e+218) {
tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0);
} else {
tmp = t_1;
}
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 = (0.5 * (y / (a / x))) + (-4.5 * (z * (t / a))) t_2 = (x * y) - ((z * 9.0) * t) tmp = 0 if t_2 <= -5e+169: tmp = t_1 elif t_2 <= -1e-117: tmp = 0.5 / (a / ((x * y) - (9.0 * (z * t)))) elif t_2 <= 5e-205: tmp = (-4.5 * (t * (z / a))) + (0.5 * (y * (x / a))) elif t_2 <= 4e+218: tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0) else: tmp = t_1 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(0.5 * Float64(y / Float64(a / x))) + Float64(-4.5 * Float64(z * Float64(t / a)))) t_2 = Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) tmp = 0.0 if (t_2 <= -5e+169) tmp = t_1; elseif (t_2 <= -1e-117) tmp = Float64(0.5 / Float64(a / Float64(Float64(x * y) - Float64(9.0 * Float64(z * t))))); elseif (t_2 <= 5e-205) tmp = Float64(Float64(-4.5 * Float64(t * Float64(z / a))) + Float64(0.5 * Float64(y * Float64(x / a)))); elseif (t_2 <= 4e+218) tmp = Float64(Float64(Float64(x * y) - Float64(z * Float64(9.0 * t))) / Float64(a * 2.0)); else tmp = t_1; 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 = (0.5 * (y / (a / x))) + (-4.5 * (z * (t / a))); t_2 = (x * y) - ((z * 9.0) * t); tmp = 0.0; if (t_2 <= -5e+169) tmp = t_1; elseif (t_2 <= -1e-117) tmp = 0.5 / (a / ((x * y) - (9.0 * (z * t)))); elseif (t_2 <= 5e-205) tmp = (-4.5 * (t * (z / a))) + (0.5 * (y * (x / a))); elseif (t_2 <= 4e+218) tmp = ((x * y) - (z * (9.0 * t))) / (a * 2.0); else tmp = t_1; 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[(0.5 * N[(y / N[(a / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-4.5 * N[(z * N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+169], t$95$1, If[LessEqual[t$95$2, -1e-117], N[(0.5 / N[(a / N[(N[(x * y), $MachinePrecision] - N[(9.0 * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e-205], N[(N[(-4.5 * N[(t * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 4e+218], N[(N[(N[(x * y), $MachinePrecision] - N[(z * N[(9.0 * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\begin{array}{l}
t_1 := 0.5 \cdot \frac{y}{\frac{a}{x}} + -4.5 \cdot \left(z \cdot \frac{t}{a}\right)\\
t_2 := x \cdot y - \left(z \cdot 9\right) \cdot t\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+169}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-117}:\\
\;\;\;\;\frac{0.5}{\frac{a}{x \cdot y - 9 \cdot \left(z \cdot t\right)}}\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{-205}:\\
\;\;\;\;-4.5 \cdot \left(t \cdot \frac{z}{a}\right) + 0.5 \cdot \left(y \cdot \frac{x}{a}\right)\\
\mathbf{elif}\;t_2 \leq 4 \cdot 10^{+218}:\\
\;\;\;\;\frac{x \cdot y - z \cdot \left(9 \cdot t\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 8.0 |
|---|---|
| Target | 5.6 |
| Herbie | 0.9 |
if (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -5.00000000000000017e169 or 4.00000000000000033e218 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) Initial program 27.9
Simplified27.8
[Start]27.9 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
rational.json-simplify-2 [=>]27.9 | \[ \frac{x \cdot y - \color{blue}{t \cdot \left(z \cdot 9\right)}}{a \cdot 2}
\] |
rational.json-simplify-43 [=>]27.8 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Taylor expanded in x around 0 27.6
Applied egg-rr1.4
Simplified1.5
[Start]1.4 | \[ \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) + x \cdot \left(0.5 \cdot \frac{y}{a}\right)\right) - 0
\] |
|---|---|
rational.json-simplify-48 [=>]1.4 | \[ \color{blue}{x \cdot \left(0.5 \cdot \frac{y}{a}\right) + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)}
\] |
rational.json-simplify-43 [=>]1.4 | \[ \color{blue}{0.5 \cdot \left(\frac{y}{a} \cdot x\right)} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-2 [<=]1.4 | \[ 0.5 \cdot \color{blue}{\left(x \cdot \frac{y}{a}\right)} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-49 [<=]15.1 | \[ 0.5 \cdot \color{blue}{\frac{y \cdot x}{a}} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-7 [<=]15.1 | \[ 0.5 \cdot \frac{y \cdot x}{\color{blue}{\frac{a}{1}}} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-61 [=>]15.1 | \[ 0.5 \cdot \color{blue}{\frac{1}{\frac{a}{y \cdot x}}} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-2 [=>]15.1 | \[ 0.5 \cdot \frac{1}{\frac{a}{\color{blue}{x \cdot y}}} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-46 [=>]1.4 | \[ 0.5 \cdot \frac{1}{\color{blue}{\frac{\frac{a}{x}}{y}}} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-61 [=>]1.4 | \[ 0.5 \cdot \color{blue}{\frac{y}{\frac{\frac{a}{x}}{1}}} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-7 [=>]1.4 | \[ 0.5 \cdot \frac{y}{\color{blue}{\frac{a}{x}}} + \left(t \cdot \left(-4.5 \cdot \frac{z}{a}\right) - 0\right)
\] |
rational.json-simplify-5 [=>]1.4 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} + \color{blue}{t \cdot \left(-4.5 \cdot \frac{z}{a}\right)}
\] |
rational.json-simplify-43 [=>]1.4 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} + \color{blue}{-4.5 \cdot \left(\frac{z}{a} \cdot t\right)}
\] |
rational.json-simplify-2 [=>]1.4 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} + -4.5 \cdot \color{blue}{\left(t \cdot \frac{z}{a}\right)}
\] |
rational.json-simplify-49 [<=]15.3 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} + -4.5 \cdot \color{blue}{\frac{z \cdot t}{a}}
\] |
rational.json-simplify-2 [<=]15.3 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} + -4.5 \cdot \frac{\color{blue}{t \cdot z}}{a}
\] |
rational.json-simplify-49 [=>]1.5 | \[ 0.5 \cdot \frac{y}{\frac{a}{x}} + -4.5 \cdot \color{blue}{\left(z \cdot \frac{t}{a}\right)}
\] |
if -5.00000000000000017e169 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < -1.00000000000000003e-117Initial program 0.3
Applied egg-rr0.4
Applied egg-rr0.5
if -1.00000000000000003e-117 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 5.00000000000000001e-205Initial program 6.3
Simplified6.3
[Start]6.3 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
rational.json-simplify-2 [=>]6.3 | \[ \frac{x \cdot y - \color{blue}{t \cdot \left(z \cdot 9\right)}}{a \cdot 2}
\] |
rational.json-simplify-43 [=>]6.3 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Taylor expanded in x around 0 6.4
Simplified2.5
[Start]6.4 | \[ -4.5 \cdot \frac{t \cdot z}{a} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
|---|---|
rational.json-simplify-2 [=>]6.4 | \[ -4.5 \cdot \frac{\color{blue}{z \cdot t}}{a} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
rational.json-simplify-49 [=>]4.5 | \[ -4.5 \cdot \color{blue}{\left(t \cdot \frac{z}{a}\right)} + 0.5 \cdot \frac{y \cdot x}{a}
\] |
rational.json-simplify-2 [<=]4.5 | \[ -4.5 \cdot \left(t \cdot \frac{z}{a}\right) + 0.5 \cdot \frac{\color{blue}{x \cdot y}}{a}
\] |
rational.json-simplify-49 [=>]2.5 | \[ -4.5 \cdot \left(t \cdot \frac{z}{a}\right) + 0.5 \cdot \color{blue}{\left(y \cdot \frac{x}{a}\right)}
\] |
if 5.00000000000000001e-205 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z 9) t)) < 4.00000000000000033e218Initial program 0.3
Simplified0.4
[Start]0.3 | \[ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\] |
|---|---|
rational.json-simplify-2 [=>]0.3 | \[ \frac{x \cdot y - \color{blue}{t \cdot \left(z \cdot 9\right)}}{a \cdot 2}
\] |
rational.json-simplify-43 [=>]0.4 | \[ \frac{x \cdot y - \color{blue}{z \cdot \left(9 \cdot t\right)}}{a \cdot 2}
\] |
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 3536 |
| Alternative 2 | |
|---|---|
| Error | 5.0 |
| Cost | 2384 |
| Alternative 3 | |
|---|---|
| Error | 4.7 |
| Cost | 1352 |
| Alternative 4 | |
|---|---|
| Error | 4.8 |
| Cost | 1352 |
| Alternative 5 | |
|---|---|
| Error | 4.6 |
| Cost | 1352 |
| Alternative 6 | |
|---|---|
| Error | 26.8 |
| Cost | 1240 |
| Alternative 7 | |
|---|---|
| Error | 26.7 |
| Cost | 1240 |
| Alternative 8 | |
|---|---|
| Error | 26.7 |
| Cost | 1240 |
| Alternative 9 | |
|---|---|
| Error | 26.8 |
| Cost | 1240 |
| Alternative 10 | |
|---|---|
| Error | 26.9 |
| Cost | 1240 |
| Alternative 11 | |
|---|---|
| Error | 26.9 |
| Cost | 1240 |
| Alternative 12 | |
|---|---|
| Error | 32.9 |
| Cost | 580 |
| Alternative 13 | |
|---|---|
| Error | 33.3 |
| Cost | 580 |
| Alternative 14 | |
|---|---|
| Error | 33.2 |
| Cost | 448 |
herbie shell --seed 2023064
(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)))