| Alternative 1 | |
|---|---|
| Error | 10.7 |
| Cost | 5068 |
(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 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
(t_2 (/ (+ (/ b z) (* a (* -4.0 t))) c)))
(if (<= t_1 -5e-257)
(- (+ (/ b (* c z)) (* 9.0 (/ (* y x) (* c z)))) (* 4.0 (/ (* a t) c)))
(if (<= t_1 0.0) t_2 (if (<= t_1 1e+304) t_1 t_2)))))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 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
double t_2 = ((b / z) + (a * (-4.0 * t))) / c;
double tmp;
if (t_1 <= -5e-257) {
tmp = ((b / (c * z)) + (9.0 * ((y * x) / (c * z)))) - (4.0 * ((a * t) / c));
} else if (t_1 <= 0.0) {
tmp = t_2;
} else if (t_1 <= 1e+304) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b, c)
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), intent (in) :: b
real(8), intent (in) :: c
code = ((((x * 9.0d0) * y) - (((z * 4.0d0) * t) * a)) + b) / (z * c)
end function
real(8) function code(x, y, z, t, a, b, c)
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), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = ((((x * 9.0d0) * y) - (((z * 4.0d0) * t) * a)) + b) / (z * c)
t_2 = ((b / z) + (a * ((-4.0d0) * t))) / c
if (t_1 <= (-5d-257)) then
tmp = ((b / (c * z)) + (9.0d0 * ((y * x) / (c * z)))) - (4.0d0 * ((a * t) / c))
else if (t_1 <= 0.0d0) then
tmp = t_2
else if (t_1 <= 1d+304) then
tmp = t_1
else
tmp = t_2
end if
code = tmp
end function
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 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
double t_2 = ((b / z) + (a * (-4.0 * t))) / c;
double tmp;
if (t_1 <= -5e-257) {
tmp = ((b / (c * z)) + (9.0 * ((y * x) / (c * z)))) - (4.0 * ((a * t) / c));
} else if (t_1 <= 0.0) {
tmp = t_2;
} else if (t_1 <= 1e+304) {
tmp = t_1;
} else {
tmp = t_2;
}
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 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c) t_2 = ((b / z) + (a * (-4.0 * t))) / c tmp = 0 if t_1 <= -5e-257: tmp = ((b / (c * z)) + (9.0 * ((y * x) / (c * z)))) - (4.0 * ((a * t) / c)) elif t_1 <= 0.0: tmp = t_2 elif t_1 <= 1e+304: tmp = t_1 else: tmp = t_2 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(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c)) t_2 = Float64(Float64(Float64(b / z) + Float64(a * Float64(-4.0 * t))) / c) tmp = 0.0 if (t_1 <= -5e-257) tmp = Float64(Float64(Float64(b / Float64(c * z)) + Float64(9.0 * Float64(Float64(y * x) / Float64(c * z)))) - Float64(4.0 * Float64(Float64(a * t) / c))); elseif (t_1 <= 0.0) tmp = t_2; elseif (t_1 <= 1e+304) tmp = t_1; else tmp = t_2; 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 = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c); t_2 = ((b / z) + (a * (-4.0 * t))) / c; tmp = 0.0; if (t_1 <= -5e-257) tmp = ((b / (c * z)) + (9.0 * ((y * x) / (c * z)))) - (4.0 * ((a * t) / c)); elseif (t_1 <= 0.0) tmp = t_2; elseif (t_1 <= 1e+304) tmp = t_1; else tmp = t_2; 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[(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]}, Block[{t$95$2 = N[(N[(N[(b / z), $MachinePrecision] + N[(a * N[(-4.0 * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[t$95$1, -5e-257], N[(N[(N[(b / N[(c * z), $MachinePrecision]), $MachinePrecision] + N[(9.0 * N[(N[(y * x), $MachinePrecision] / N[(c * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(4.0 * N[(N[(a * t), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], t$95$2, If[LessEqual[t$95$1, 1e+304], t$95$1, t$95$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}
\begin{array}{l}
t_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}\\
t_2 := \frac{\frac{b}{z} + a \cdot \left(-4 \cdot t\right)}{c}\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{-257}:\\
\;\;\;\;\left(\frac{b}{c \cdot z} + 9 \cdot \frac{y \cdot x}{c \cdot z}\right) - 4 \cdot \frac{a \cdot t}{c}\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq 10^{+304}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
Results
| Original | 20.3 |
|---|---|
| Target | 14.7 |
| Herbie | 9.3 |
if (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -4.99999999999999989e-257Initial program 12.0
Simplified10.9
[Start]12.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_oopsla_all_46_json_45_simplify-74 [=>]12.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_oopsla_all_46_json_45_simplify-7 [=>]11.9 | \[ \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_oopsla_all_46_json_45_simplify-74 [=>]11.9 | \[ \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_oopsla_all_46_json_45_simplify-74 [=>]11.9 | \[ \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_oopsla_all_46_json_45_simplify-7 [=>]10.9 | \[ \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_oopsla_all_46_json_45_simplify-74 [=>]10.9 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - \left(z \cdot 4\right) \cdot \color{blue}{\left(t \cdot a\right)}\right) + b}{z \cdot c}
\] |
Taylor expanded in x around 0 7.4
if -4.99999999999999989e-257 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < -0.0 or 9.9999999999999994e303 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) Initial program 52.6
Simplified48.6
[Start]52.6 | \[ \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_oopsla_all_46_json_45_simplify-74 [=>]52.6 | \[ \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_oopsla_all_46_json_45_simplify-7 [=>]52.6 | \[ \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_oopsla_all_46_json_45_simplify-74 [=>]52.6 | \[ \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_oopsla_all_46_json_45_simplify-74 [=>]52.6 | \[ \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_oopsla_all_46_json_45_simplify-7 [=>]48.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_oopsla_all_46_json_45_simplify-74 [=>]48.6 | \[ \frac{\left(x \cdot \left(9 \cdot y\right) - \left(z \cdot 4\right) \cdot \color{blue}{\left(t \cdot a\right)}\right) + b}{z \cdot c}
\] |
Taylor expanded in x around 0 53.1
Simplified50.0
[Start]53.1 | \[ \frac{-4 \cdot \left(a \cdot \left(t \cdot z\right)\right) + b}{z \cdot c}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-7 [=>]50.0 | \[ \frac{-4 \cdot \color{blue}{\left(t \cdot \left(a \cdot z\right)\right)} + b}{z \cdot c}
\] |
rational_best_oopsla_all_46_json_45_simplify-7 [=>]50.0 | \[ \frac{\color{blue}{t \cdot \left(-4 \cdot \left(a \cdot z\right)\right)} + b}{z \cdot c}
\] |
rational_best_oopsla_all_46_json_45_simplify-7 [<=]50.0 | \[ \frac{t \cdot \color{blue}{\left(a \cdot \left(-4 \cdot z\right)\right)} + b}{z \cdot c}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]50.0 | \[ \frac{t \cdot \left(a \cdot \color{blue}{\left(z \cdot -4\right)}\right) + b}{z \cdot c}
\] |
Taylor expanded in t around 0 27.3
Taylor expanded in c around 0 21.2
Simplified21.2
[Start]21.2 | \[ \frac{\frac{b}{z} + -4 \cdot \left(a \cdot t\right)}{c}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-7 [=>]21.2 | \[ \frac{\frac{b}{z} + \color{blue}{a \cdot \left(-4 \cdot t\right)}}{c}
\] |
if -0.0 < (/.f64 (+.f64 (-.f64 (*.f64 (*.f64 x 9) y) (*.f64 (*.f64 (*.f64 z 4) t) a)) b) (*.f64 z c)) < 9.9999999999999994e303Initial program 0.6
Final simplification9.3
| Alternative 1 | |
|---|---|
| Error | 10.7 |
| Cost | 5068 |
| Alternative 2 | |
|---|---|
| Error | 28.6 |
| Cost | 1760 |
| Alternative 3 | |
|---|---|
| Error | 38.2 |
| Cost | 1504 |
| Alternative 4 | |
|---|---|
| Error | 14.6 |
| Cost | 1480 |
| Alternative 5 | |
|---|---|
| Error | 19.0 |
| Cost | 1352 |
| Alternative 6 | |
|---|---|
| Error | 34.4 |
| Cost | 976 |
| Alternative 7 | |
|---|---|
| Error | 19.3 |
| Cost | 968 |
| Alternative 8 | |
|---|---|
| Error | 43.8 |
| Cost | 584 |
| Alternative 9 | |
|---|---|
| Error | 43.4 |
| Cost | 320 |
herbie shell --seed 2023090
(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)))