(FPCore (x y z t a) :precision binary64 (- x (/ (* y (- z t)) a)))
↓
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) a)))
(if (<= t_1 -5e+307)
(+ x (/ (- t z) (/ a y)))
(if (<= t_1 1e+306) (- x t_1) (+ x (/ -1.0 (/ (/ a y) (- z t))))))))
double code(double x, double y, double z, double t, double a) {
return x - ((y * (z - t)) / a);
}
↓
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / a;
double tmp;
if (t_1 <= -5e+307) {
tmp = x + ((t - z) / (a / y));
} else if (t_1 <= 1e+306) {
tmp = x - t_1;
} else {
tmp = x + (-1.0 / ((a / y) / (z - t)));
}
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 * (z - t)) / a)
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) :: tmp
t_1 = (y * (z - t)) / a
if (t_1 <= (-5d+307)) then
tmp = x + ((t - z) / (a / y))
else if (t_1 <= 1d+306) then
tmp = x - t_1
else
tmp = x + ((-1.0d0) / ((a / y) / (z - t)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return x - ((y * (z - t)) / a);
}
↓
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / a;
double tmp;
if (t_1 <= -5e+307) {
tmp = x + ((t - z) / (a / y));
} else if (t_1 <= 1e+306) {
tmp = x - t_1;
} else {
tmp = x + (-1.0 / ((a / y) / (z - t)));
}
return tmp;
}
def code(x, y, z, t, a):
return x - ((y * (z - t)) / a)
↓
def code(x, y, z, t, a):
t_1 = (y * (z - t)) / a
tmp = 0
if t_1 <= -5e+307:
tmp = x + ((t - z) / (a / y))
elif t_1 <= 1e+306:
tmp = x - t_1
else:
tmp = x + (-1.0 / ((a / y) / (z - t)))
return tmp
function code(x, y, z, t, a)
return Float64(x - Float64(Float64(y * Float64(z - t)) / a))
end
↓
function code(x, y, z, t, a)
t_1 = Float64(Float64(y * Float64(z - t)) / a)
tmp = 0.0
if (t_1 <= -5e+307)
tmp = Float64(x + Float64(Float64(t - z) / Float64(a / y)));
elseif (t_1 <= 1e+306)
tmp = Float64(x - t_1);
else
tmp = Float64(x + Float64(-1.0 / Float64(Float64(a / y) / Float64(z - t))));
end
return tmp
end
function tmp = code(x, y, z, t, a)
tmp = x - ((y * (z - t)) / a);
end
↓
function tmp_2 = code(x, y, z, t, a)
t_1 = (y * (z - t)) / a;
tmp = 0.0;
if (t_1 <= -5e+307)
tmp = x + ((t - z) / (a / y));
elseif (t_1 <= 1e+306)
tmp = x - t_1;
else
tmp = x + (-1.0 / ((a / y) / (z - 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 16 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 2023263
(FPCore (x y z t a)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, F"
:precision binary64
:herbie-target
(if (< y -1.0761266216389975e-10) (- x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (- x (/ (* y (- z t)) a)) (- x (/ y (/ a (- z t))))))
(- x (/ (* y (- z t)) a)))