| Alternative 1 | |
|---|---|
| Error | 38.8 |
| Cost | 1892 |
(FPCore (x y z t a b c) :precision binary64 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
(FPCore (x y z t a b c)
:precision binary64
(let* ((t_1 (/ (+ (/ b z) (* t (* -4.0 a))) c))
(t_2 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c))))
(if (<= t_2 (- INFINITY))
(* (/ (* a t) c) -4.0)
(if (<= t_2 -1e-278)
t_2
(if (<= t_2 2e-247) t_1 (if (<= t_2 5e+307) t_2 t_1))))))double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
double code(double x, double y, double z, double t, double a, double b, double c) {
double t_1 = ((b / z) + (t * (-4.0 * a))) / c;
double t_2 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = ((a * t) / c) * -4.0;
} else if (t_2 <= -1e-278) {
tmp = t_2;
} else if (t_2 <= 2e-247) {
tmp = t_1;
} else if (t_2 <= 5e+307) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
public static double code(double x, double y, double z, double t, double a, double b, double c) {
double t_1 = ((b / z) + (t * (-4.0 * a))) / c;
double t_2 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = ((a * t) / c) * -4.0;
} else if (t_2 <= -1e-278) {
tmp = t_2;
} else if (t_2 <= 2e-247) {
tmp = t_1;
} else if (t_2 <= 5e+307) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a, b, c): return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c)
def code(x, y, z, t, a, b, c): t_1 = ((b / z) + (t * (-4.0 * a))) / c t_2 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c) tmp = 0 if t_2 <= -math.inf: tmp = ((a * t) / c) * -4.0 elif t_2 <= -1e-278: tmp = t_2 elif t_2 <= 2e-247: tmp = t_1 elif t_2 <= 5e+307: tmp = t_2 else: tmp = t_1 return tmp
function code(x, y, z, t, a, b, c) return Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c)) end
function code(x, y, z, t, a, b, c) t_1 = Float64(Float64(Float64(b / z) + Float64(t * Float64(-4.0 * a))) / c) t_2 = Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c)) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(Float64(Float64(a * t) / c) * -4.0); elseif (t_2 <= -1e-278) tmp = t_2; elseif (t_2 <= 2e-247) tmp = t_1; elseif (t_2 <= 5e+307) tmp = t_2; else tmp = t_1; end return tmp end
function tmp = code(x, y, z, t, a, b, c) tmp = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c); end
function tmp_2 = code(x, y, z, t, a, b, c) t_1 = ((b / z) + (t * (-4.0 * a))) / c; t_2 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c); tmp = 0.0; if (t_2 <= -Inf) tmp = ((a * t) / c) * -4.0; elseif (t_2 <= -1e-278) tmp = t_2; elseif (t_2 <= 2e-247) tmp = t_1; elseif (t_2 <= 5e+307) tmp = t_2; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(N[(b / z), $MachinePrecision] + N[(t * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(N[(a * t), $MachinePrecision] / c), $MachinePrecision] * -4.0), $MachinePrecision], If[LessEqual[t$95$2, -1e-278], t$95$2, If[LessEqual[t$95$2, 2e-247], t$95$1, If[LessEqual[t$95$2, 5e+307], t$95$2, t$95$1]]]]]]
\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\begin{array}{l}
t_1 := \frac{\frac{b}{z} + t \cdot \left(-4 \cdot a\right)}{c}\\
t_2 := \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\frac{a \cdot t}{c} \cdot -4\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-278}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_2 \leq 2 \cdot 10^{-247}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 20.8 |
|---|---|
| Target | 14.3 |
| Herbie | 9.2 |
if (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -inf.0Initial program 64.0
Simplified49.3
[Start]64.0 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
rational_best-simplify-2 [=>]64.0 | \[ \frac{\left(\color{blue}{y \cdot \left(x \cdot 9\right)} - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
rational_best-simplify-44 [=>]63.7 | \[ \frac{\left(\color{blue}{x \cdot \left(y \cdot 9\right)} - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
rational_best-simplify-2 [=>]63.7 | \[ \frac{\left(x \cdot \color{blue}{\left(9 \cdot y\right)} - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
rational_best-simplify-2 [=>]63.7 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - \color{blue}{a \cdot \left(\left(z \cdot 4\right) \cdot t\right)}\right) + b}{z \cdot c}
\] |
rational_best-simplify-44 [=>]49.6 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - \color{blue}{\left(z \cdot 4\right) \cdot \left(a \cdot t\right)}\right) + b}{z \cdot c}
\] |
rational_best-simplify-2 [=>]49.6 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - \color{blue}{\left(a \cdot t\right) \cdot \left(z \cdot 4\right)}\right) + b}{z \cdot c}
\] |
rational_best-simplify-44 [=>]49.3 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - \color{blue}{z \cdot \left(\left(a \cdot t\right) \cdot 4\right)}\right) + b}{z \cdot c}
\] |
rational_best-simplify-2 [<=]49.3 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - z \cdot \color{blue}{\left(4 \cdot \left(a \cdot t\right)\right)}\right) + b}{z \cdot c}
\] |
rational_best-simplify-2 [=>]49.3 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - z \cdot \left(4 \cdot \color{blue}{\left(t \cdot a\right)}\right)\right) + b}{z \cdot c}
\] |
Taylor expanded in z around inf 34.3
Simplified34.3
[Start]34.3 | \[ -4 \cdot \frac{a \cdot t}{c}
\] |
|---|---|
rational_best-simplify-2 [=>]34.3 | \[ \color{blue}{\frac{a \cdot t}{c} \cdot -4}
\] |
if -inf.0 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -9.99999999999999938e-279 or 2e-247 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 5e307Initial program 0.6
if -9.99999999999999938e-279 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 2e-247 or 5e307 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) Initial program 52.1
Taylor expanded in x around 0 52.3
Simplified52.4
[Start]52.3 | \[ \frac{b - 4 \cdot \left(a \cdot \left(t \cdot z\right)\right)}{c \cdot z}
\] |
|---|---|
rational_best-simplify-44 [=>]52.4 | \[ \frac{b - \color{blue}{a \cdot \left(4 \cdot \left(t \cdot z\right)\right)}}{c \cdot z}
\] |
rational_best-simplify-2 [<=]52.4 | \[ \frac{b - a \cdot \left(4 \cdot \left(t \cdot z\right)\right)}{\color{blue}{z \cdot c}}
\] |
Taylor expanded in b around 0 26.6
Taylor expanded in c around 0 20.9
Simplified20.9
[Start]20.9 | \[ \frac{\frac{b}{z} + -4 \cdot \left(a \cdot t\right)}{c}
\] |
|---|---|
rational_best-simplify-2 [=>]20.9 | \[ \frac{\frac{b}{z} + -4 \cdot \color{blue}{\left(t \cdot a\right)}}{c}
\] |
rational_best-simplify-44 [=>]20.9 | \[ \frac{\frac{b}{z} + \color{blue}{t \cdot \left(-4 \cdot a\right)}}{c}
\] |
Final simplification9.2
| Alternative 1 | |
|---|---|
| Error | 38.8 |
| Cost | 1892 |
| Alternative 2 | |
|---|---|
| Error | 23.8 |
| Cost | 1880 |
| Alternative 3 | |
|---|---|
| Error | 23.7 |
| Cost | 1624 |
| Alternative 4 | |
|---|---|
| Error | 36.2 |
| Cost | 1504 |
| Alternative 5 | |
|---|---|
| Error | 36.1 |
| Cost | 1504 |
| Alternative 6 | |
|---|---|
| Error | 19.3 |
| Cost | 1488 |
| Alternative 7 | |
|---|---|
| Error | 13.8 |
| Cost | 1480 |
| Alternative 8 | |
|---|---|
| Error | 23.3 |
| Cost | 1232 |
| Alternative 9 | |
|---|---|
| Error | 19.3 |
| Cost | 1232 |
| Alternative 10 | |
|---|---|
| Error | 35.0 |
| Cost | 976 |
| Alternative 11 | |
|---|---|
| Error | 25.1 |
| Cost | 968 |
| Alternative 12 | |
|---|---|
| Error | 43.3 |
| Cost | 320 |
herbie shell --seed 2023092
(FPCore (x y z t a b c)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, J"
:precision binary64
:herbie-target
(if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) -1.100156740804105e-171) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 0.0) (/ (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) z) c) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.1708877911747488e-53) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 2.876823679546137e+130) (- (+ (* (* 9.0 (/ y c)) (/ x z)) (/ b (* c z))) (* 4.0 (/ (* a t) c))) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.3838515042456319e+158) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (- (+ (* 9.0 (* (/ y (* c z)) x)) (/ b (* c z))) (* 4.0 (/ (* a t) c))))))))
(/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))