(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 (- (* y (* x 9.0)) (* a (* t (* z 4.0))))) (* z c)))
(t_2 (* x (* 9.0 y))))
(if (<= t_1 -1e+134)
(/ (+ b (- t_2 (* (* z 4.0) (* t a)))) (* z c))
(if (<= t_1 0.0002)
(* (/ 1.0 c) (/ (+ b (- t_2 (* z (* 4.0 (* t a))))) z))
(if (<= t_1 INFINITY) t_1 (* -4.0 (/ a (/ c t))))))))
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 + ((y * (x * 9.0)) - (a * (t * (z * 4.0))))) / (z * c);
double t_2 = x * (9.0 * y);
double tmp;
if (t_1 <= -1e+134) {
tmp = (b + (t_2 - ((z * 4.0) * (t * a)))) / (z * c);
} else if (t_1 <= 0.0002) {
tmp = (1.0 / c) * ((b + (t_2 - (z * (4.0 * (t * a))))) / z);
} else if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = -4.0 * (a / (c / t));
}
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 + ((y * (x * 9.0)) - (a * (t * (z * 4.0))))) / (z * c);
double t_2 = x * (9.0 * y);
double tmp;
if (t_1 <= -1e+134) {
tmp = (b + (t_2 - ((z * 4.0) * (t * a)))) / (z * c);
} else if (t_1 <= 0.0002) {
tmp = (1.0 / c) * ((b + (t_2 - (z * (4.0 * (t * a))))) / z);
} else if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = -4.0 * (a / (c / t));
}
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 + ((y * (x * 9.0)) - (a * (t * (z * 4.0))))) / (z * c)
t_2 = x * (9.0 * y)
tmp = 0
if t_1 <= -1e+134:
tmp = (b + (t_2 - ((z * 4.0) * (t * a)))) / (z * c)
elif t_1 <= 0.0002:
tmp = (1.0 / c) * ((b + (t_2 - (z * (4.0 * (t * a))))) / z)
elif t_1 <= math.inf:
tmp = t_1
else:
tmp = -4.0 * (a / (c / t))
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
The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.
Herbie found 19 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.
herbie shell --seed 2023258
(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)))