real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + (((y - x) * z) / t)
end function
↓
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= (-4d+166)) then
tmp = x + ((z / t) * y)
else
tmp = x + ((z * (y - x)) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return x + (((y - x) * z) / t);
}
↓
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -4e+166) {
tmp = x + ((z / t) * y);
} else {
tmp = x + ((z * (y - x)) / t);
}
return tmp;
}
def code(x, y, z, t):
return x + (((y - x) * z) / t)
↓
def code(x, y, z, t):
tmp = 0
if y <= -4e+166:
tmp = x + ((z / t) * y)
else:
tmp = x + ((z * (y - x)) / t)
return tmp
function code(x, y, z, t)
return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
↓
function code(x, y, z, t)
tmp = 0.0
if (y <= -4e+166)
tmp = Float64(x + Float64(Float64(z / t) * y));
else
tmp = Float64(x + Float64(Float64(z * Float64(y - x)) / t));
end
return tmp
end
function tmp = code(x, y, z, t)
tmp = x + (((y - x) * z) / t);
end
↓
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (y <= -4e+166)
tmp = x + ((z / t) * y);
else
tmp = x + ((z * (y - x)) / t);
end
tmp_2 = tmp;
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 11 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 2023272
(FPCore (x y z t)
:name "Numeric.Histogram:binBounds from Chart-1.5.3"
:precision binary64
:herbie-target
(if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))
(+ x (/ (* (- y x) z) t)))