(FPCore (K m n M l)
:precision binary64
(*
(cos (- (/ (* K (+ m n)) 2.0) M))
(exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))
↓
(FPCore (K m n M l)
:precision binary64
(* (exp (- (- (- n m) l) (pow (- (* (+ m n) 0.5) M) 2.0))) (cos M)))
double code(double K, double m, double n, double M, double l) {
return cos((((K * (m + n)) / 2.0) - M)) * exp((-pow((((m + n) / 2.0) - M), 2.0) - (l - fabs((m - n)))));
}
↓
double code(double K, double m, double n, double M, double l) {
return exp((((n - m) - l) - pow((((m + n) * 0.5) - M), 2.0))) * cos(M);
}
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = cos((((k * (m + n)) / 2.0d0) - m_1)) * exp((-((((m + n) / 2.0d0) - m_1) ** 2.0d0) - (l - abs((m - n)))))
end function
↓
real(8) function code(k, m, n, m_1, l)
real(8), intent (in) :: k
real(8), intent (in) :: m
real(8), intent (in) :: n
real(8), intent (in) :: m_1
real(8), intent (in) :: l
code = exp((((n - m) - l) - ((((m + n) * 0.5d0) - m_1) ** 2.0d0))) * cos(m_1)
end function
public static double code(double K, double m, double n, double M, double l) {
return Math.cos((((K * (m + n)) / 2.0) - M)) * Math.exp((-Math.pow((((m + n) / 2.0) - M), 2.0) - (l - Math.abs((m - n)))));
}
↓
public static double code(double K, double m, double n, double M, double l) {
return Math.exp((((n - m) - l) - Math.pow((((m + n) * 0.5) - M), 2.0))) * Math.cos(M);
}
def code(K, m, n, M, l):
return math.cos((((K * (m + n)) / 2.0) - M)) * math.exp((-math.pow((((m + n) / 2.0) - M), 2.0) - (l - math.fabs((m - n)))))
↓
def code(K, m, n, M, l):
return math.exp((((n - m) - l) - math.pow((((m + n) * 0.5) - M), 2.0))) * math.cos(M)
function code(K, m, n, M, l)
return Float64(cos(Float64(Float64(Float64(K * Float64(m + n)) / 2.0) - M)) * exp(Float64(Float64(-(Float64(Float64(Float64(m + n) / 2.0) - M) ^ 2.0)) - Float64(l - abs(Float64(m - n))))))
end
↓
function code(K, m, n, M, l)
return Float64(exp(Float64(Float64(Float64(n - m) - l) - (Float64(Float64(Float64(m + n) * 0.5) - M) ^ 2.0))) * cos(M))
end
function tmp = code(K, m, n, M, l)
tmp = cos((((K * (m + n)) / 2.0) - M)) * exp((-((((m + n) / 2.0) - M) ^ 2.0) - (l - abs((m - n)))));
end
↓
function tmp = code(K, m, n, M, l)
tmp = exp((((n - m) - l) - ((((m + n) * 0.5) - M) ^ 2.0))) * cos(M);
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 9 alternatives:
Alternative
Accuracy
Speedup
Accuracy vs Speed
The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.
herbie shell --seed 2023161
(FPCore (K m n M l)
:name "Maksimov and Kolovsky, Equation (32)"
:precision binary64
(* (cos (- (/ (* K (+ m n)) 2.0) M)) (exp (- (- (pow (- (/ (+ m n) 2.0) M) 2.0)) (- l (fabs (- m n)))))))