
(FPCore (x1 x2 x3 x4) :precision binary64 (* (* (* x1 x2) x3) x4))
double code(double x1, double x2, double x3, double x4) {
return ((x1 * x2) * x3) * x4;
}
real(8) function code(x1, x2, x3, x4)
real(8), intent (in) :: x1
real(8), intent (in) :: x2
real(8), intent (in) :: x3
real(8), intent (in) :: x4
code = ((x1 * x2) * x3) * x4
end function
public static double code(double x1, double x2, double x3, double x4) {
return ((x1 * x2) * x3) * x4;
}
def code(x1, x2, x3, x4): return ((x1 * x2) * x3) * x4
function code(x1, x2, x3, x4) return Float64(Float64(Float64(x1 * x2) * x3) * x4) end
function tmp = code(x1, x2, x3, x4) tmp = ((x1 * x2) * x3) * x4; end
code[x1_, x2_, x3_, x4_] := N[(N[(N[(x1 * x2), $MachinePrecision] * x3), $MachinePrecision] * x4), $MachinePrecision]
\left(\left(x1 \cdot x2\right) \cdot x3\right) \cdot x4
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x1 x2 x3 x4) :precision binary64 (* (* (* x1 x2) x3) x4))
double code(double x1, double x2, double x3, double x4) {
return ((x1 * x2) * x3) * x4;
}
real(8) function code(x1, x2, x3, x4)
real(8), intent (in) :: x1
real(8), intent (in) :: x2
real(8), intent (in) :: x3
real(8), intent (in) :: x4
code = ((x1 * x2) * x3) * x4
end function
public static double code(double x1, double x2, double x3, double x4) {
return ((x1 * x2) * x3) * x4;
}
def code(x1, x2, x3, x4): return ((x1 * x2) * x3) * x4
function code(x1, x2, x3, x4) return Float64(Float64(Float64(x1 * x2) * x3) * x4) end
function tmp = code(x1, x2, x3, x4) tmp = ((x1 * x2) * x3) * x4; end
code[x1_, x2_, x3_, x4_] := N[(N[(N[(x1 * x2), $MachinePrecision] * x3), $MachinePrecision] * x4), $MachinePrecision]
\left(\left(x1 \cdot x2\right) \cdot x3\right) \cdot x4
(FPCore (x1 x2 x3 x4) :precision binary64 (* (* (fmax x3 x4) (fmax x1 x2)) (* (fmin x3 x4) (fmin x1 x2))))
double code(double x1, double x2, double x3, double x4) {
return (fmax(x3, x4) * fmax(x1, x2)) * (fmin(x3, x4) * fmin(x1, x2));
}
real(8) function code(x1, x2, x3, x4)
real(8), intent (in) :: x1
real(8), intent (in) :: x2
real(8), intent (in) :: x3
real(8), intent (in) :: x4
code = (merge(x4, merge(x3, max(x3, x4), x4 /= x4), x3 /= x3) * merge(x2, merge(x1, max(x1, x2), x2 /= x2), x1 /= x1)) * (merge(x4, merge(x3, min(x3, x4), x4 /= x4), x3 /= x3) * merge(x2, merge(x1, min(x1, x2), x2 /= x2), x1 /= x1))
end function
public static double code(double x1, double x2, double x3, double x4) {
return (fmax(x3, x4) * fmax(x1, x2)) * (fmin(x3, x4) * fmin(x1, x2));
}
def code(x1, x2, x3, x4): return (fmax(x3, x4) * fmax(x1, x2)) * (fmin(x3, x4) * fmin(x1, x2))
function code(x1, x2, x3, x4) return Float64(Float64(((x3 != x3) ? x4 : ((x4 != x4) ? x3 : max(x3, x4))) * ((x1 != x1) ? x2 : ((x2 != x2) ? x1 : max(x1, x2)))) * Float64(((x3 != x3) ? x4 : ((x4 != x4) ? x3 : min(x3, x4))) * ((x1 != x1) ? x2 : ((x2 != x2) ? x1 : min(x1, x2))))) end
function tmp = code(x1, x2, x3, x4) tmp = (max(x3, x4) * max(x1, x2)) * (min(x3, x4) * min(x1, x2)); end
code[x1_, x2_, x3_, x4_] := N[(N[(N[Max[x3, x4], $MachinePrecision] * N[Max[x1, x2], $MachinePrecision]), $MachinePrecision] * N[(N[Min[x3, x4], $MachinePrecision] * N[Min[x1, x2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\mathsf{max}\left(x3, x4\right) \cdot \mathsf{max}\left(x1, x2\right)\right) \cdot \left(\mathsf{min}\left(x3, x4\right) \cdot \mathsf{min}\left(x1, x2\right)\right)
Initial program 99.5%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.5%
Applied rewrites99.5%
(FPCore (x1 x2 x3 x4) :precision binary64 (* (* (fmax x3 x4) x1) (* (fmin x3 x4) x2)))
double code(double x1, double x2, double x3, double x4) {
return (fmax(x3, x4) * x1) * (fmin(x3, x4) * x2);
}
real(8) function code(x1, x2, x3, x4)
real(8), intent (in) :: x1
real(8), intent (in) :: x2
real(8), intent (in) :: x3
real(8), intent (in) :: x4
code = (merge(x4, merge(x3, max(x3, x4), x4 /= x4), x3 /= x3) * x1) * (merge(x4, merge(x3, min(x3, x4), x4 /= x4), x3 /= x3) * x2)
end function
public static double code(double x1, double x2, double x3, double x4) {
return (fmax(x3, x4) * x1) * (fmin(x3, x4) * x2);
}
def code(x1, x2, x3, x4): return (fmax(x3, x4) * x1) * (fmin(x3, x4) * x2)
function code(x1, x2, x3, x4) return Float64(Float64(((x3 != x3) ? x4 : ((x4 != x4) ? x3 : max(x3, x4))) * x1) * Float64(((x3 != x3) ? x4 : ((x4 != x4) ? x3 : min(x3, x4))) * x2)) end
function tmp = code(x1, x2, x3, x4) tmp = (max(x3, x4) * x1) * (min(x3, x4) * x2); end
code[x1_, x2_, x3_, x4_] := N[(N[(N[Max[x3, x4], $MachinePrecision] * x1), $MachinePrecision] * N[(N[Min[x3, x4], $MachinePrecision] * x2), $MachinePrecision]), $MachinePrecision]
\left(\mathsf{max}\left(x3, x4\right) \cdot x1\right) \cdot \left(\mathsf{min}\left(x3, x4\right) \cdot x2\right)
Initial program 99.5%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6499.4%
Applied rewrites99.4%
herbie shell --seed 1
(FPCore (x1 x2 x3 x4)
:name "x1 * x2 * x3 * x4"
:precision binary64
:pre (and (and (and (and (<= 1e-20 x1) (<= x1 2e-20)) (and (<= 1e-20 x2) (<= x2 2e-20))) (and (<= 1e+15 x3) (<= x3 2e+15))) (and (<= 1e+15 x4) (<= x4 2e+15)))
(* (* (* x1 x2) x3) x4))