(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y x) (- z t)) (- a t))))
↓
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ x (* (- z t) (/ (- y x) (- a t)))))
(t_2 (- x (/ (* (- y x) (- t z)) (- a t)))))
(if (<= t_2 -5e+307)
t_1
(if (<= t_2 -2e-227)
t_2
(if (<= t_2 5e-305)
(+ y (/ (* (- y x) (- a z)) t))
(if (<= t_2 5e+301) t_2 t_1))))))
double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (a - t));
}
↓
double code(double x, double y, double z, double t, double a) {
double t_1 = x + ((z - t) * ((y - x) / (a - t)));
double t_2 = x - (((y - x) * (t - z)) / (a - t));
double tmp;
if (t_2 <= -5e+307) {
tmp = t_1;
} else if (t_2 <= -2e-227) {
tmp = t_2;
} else if (t_2 <= 5e-305) {
tmp = y + (((y - x) * (a - z)) / t);
} else if (t_2 <= 5e+301) {
tmp = t_2;
} 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 - x) * (z - t)) / (a - t))
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 = x + ((z - t) * ((y - x) / (a - t)))
t_2 = x - (((y - x) * (t - z)) / (a - t))
if (t_2 <= (-5d+307)) then
tmp = t_1
else if (t_2 <= (-2d-227)) then
tmp = t_2
else if (t_2 <= 5d-305) then
tmp = y + (((y - x) * (a - z)) / t)
else if (t_2 <= 5d+301) then
tmp = t_2
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 - x) * (z - t)) / (a - t));
}
↓
public static double code(double x, double y, double z, double t, double a) {
double t_1 = x + ((z - t) * ((y - x) / (a - t)));
double t_2 = x - (((y - x) * (t - z)) / (a - t));
double tmp;
if (t_2 <= -5e+307) {
tmp = t_1;
} else if (t_2 <= -2e-227) {
tmp = t_2;
} else if (t_2 <= 5e-305) {
tmp = y + (((y - x) * (a - z)) / t);
} else if (t_2 <= 5e+301) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a):
return x + (((y - x) * (z - t)) / (a - t))
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 23 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.
if (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -5e307 or 5.0000000000000004e301 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t)))
if -5e307 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -1.99999999999999989e-227 or 4.99999999999999985e-305 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < 5.0000000000000004e301
herbie shell --seed 2023263
(FPCore (x y z t a)
:name "Graphics.Rendering.Chart.Axis.Types:linMap from Chart-1.5.3"
:precision binary64
:herbie-target
(if (< a -1.6153062845442575e-142) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t)))) (if (< a 3.774403170083174e-182) (- y (* (/ z t) (- y x))) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t))))))
(+ x (/ (* (- y x) (- z t)) (- a t))))