
(FPCore (x y) :precision binary64 (* (* (* x 3.0) x) y))
double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 3.0d0) * x) * y
end function
public static double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
def code(x, y): return ((x * 3.0) * x) * y
function code(x, y) return Float64(Float64(Float64(x * 3.0) * x) * y) end
function tmp = code(x, y) tmp = ((x * 3.0) * x) * y; end
code[x_, y_] := N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 3\right) \cdot x\right) \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (* (* x 3.0) x) y))
double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 3.0d0) * x) * y
end function
public static double code(double x, double y) {
return ((x * 3.0) * x) * y;
}
def code(x, y): return ((x * 3.0) * x) * y
function code(x, y) return Float64(Float64(Float64(x * 3.0) * x) * y) end
function tmp = code(x, y) tmp = ((x * 3.0) * x) * y; end
code[x_, y_] := N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot 3\right) \cdot x\right) \cdot y
\end{array}
(FPCore (x y) :precision binary64 (* (* x (* x y)) 3.0))
double code(double x, double y) {
return (x * (x * y)) * 3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * (x * y)) * 3.0d0
end function
public static double code(double x, double y) {
return (x * (x * y)) * 3.0;
}
def code(x, y): return (x * (x * y)) * 3.0
function code(x, y) return Float64(Float64(x * Float64(x * y)) * 3.0) end
function tmp = code(x, y) tmp = (x * (x * y)) * 3.0; end
code[x_, y_] := N[(N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision] * 3.0), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(x \cdot y\right)\right) \cdot 3
\end{array}
Initial program 89.4%
associate-*l*99.7%
associate-*l*99.6%
Simplified99.6%
add-sqr-sqrt60.7%
pow260.7%
associate-*r*60.7%
*-commutative60.7%
associate-*r*60.7%
associate-*r*57.6%
sqrt-prod43.3%
sqrt-unprod24.0%
add-sqr-sqrt46.6%
Applied egg-rr46.6%
unpow246.6%
swap-sqr43.3%
add-sqr-sqrt89.4%
associate-*l*99.7%
*-commutative99.7%
associate-*l*99.6%
associate-*r*99.7%
Applied egg-rr99.7%
(FPCore (x y) :precision binary64 (* (* x y) (* x 3.0)))
double code(double x, double y) {
return (x * y) * (x * 3.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * y) * (x * 3.0d0)
end function
public static double code(double x, double y) {
return (x * y) * (x * 3.0);
}
def code(x, y): return (x * y) * (x * 3.0)
function code(x, y) return Float64(Float64(x * y) * Float64(x * 3.0)) end
function tmp = code(x, y) tmp = (x * y) * (x * 3.0); end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y\right) \cdot \left(x \cdot 3\right)
\end{array}
Initial program 89.4%
associate-*l*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (* x (* x (* y 3.0))))
double code(double x, double y) {
return x * (x * (y * 3.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (x * (y * 3.0d0))
end function
public static double code(double x, double y) {
return x * (x * (y * 3.0));
}
def code(x, y): return x * (x * (y * 3.0))
function code(x, y) return Float64(x * Float64(x * Float64(y * 3.0))) end
function tmp = code(x, y) tmp = x * (x * (y * 3.0)); end
code[x_, y_] := N[(x * N[(x * N[(y * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(y \cdot 3\right)\right)
\end{array}
Initial program 89.4%
*-commutative89.4%
associate-*l*99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (* x (* (* x y) 3.0)))
double code(double x, double y) {
return x * ((x * y) * 3.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * ((x * y) * 3.0d0)
end function
public static double code(double x, double y) {
return x * ((x * y) * 3.0);
}
def code(x, y): return x * ((x * y) * 3.0)
function code(x, y) return Float64(x * Float64(Float64(x * y) * 3.0)) end
function tmp = code(x, y) tmp = x * ((x * y) * 3.0); end
code[x_, y_] := N[(x * N[(N[(x * y), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\left(x \cdot y\right) \cdot 3\right)
\end{array}
Initial program 89.4%
associate-*l*99.7%
associate-*l*99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y) :precision binary64 (* (* x 3.0) (* x y)))
double code(double x, double y) {
return (x * 3.0) * (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 3.0d0) * (x * y)
end function
public static double code(double x, double y) {
return (x * 3.0) * (x * y);
}
def code(x, y): return (x * 3.0) * (x * y)
function code(x, y) return Float64(Float64(x * 3.0) * Float64(x * y)) end
function tmp = code(x, y) tmp = (x * 3.0) * (x * y); end
code[x_, y_] := N[(N[(x * 3.0), $MachinePrecision] * N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot \left(x \cdot y\right)
\end{array}
herbie shell --seed 2024098
(FPCore (x y)
:name "Diagrams.Segment:$catParam from diagrams-lib-1.3.0.3, A"
:precision binary64
:alt
(* (* x 3.0) (* x y))
(* (* (* x 3.0) x) y))