
(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 3 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 (fma x y (* y (* x 2.0)))))
double code(double x, double y) {
return x * fma(x, y, (y * (x * 2.0)));
}
function code(x, y) return Float64(x * fma(x, y, Float64(y * Float64(x * 2.0)))) end
code[x_, y_] := N[(x * N[(x * y + N[(y * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, y, y \cdot \left(x \cdot 2\right)\right)
\end{array}
Initial program 86.1%
associate-*l*99.7%
associate-*l*99.7%
Simplified99.7%
associate-*r*99.7%
*-commutative99.7%
associate-*r*99.7%
add-log-exp56.0%
add-cube-cbrt55.9%
log-prod55.9%
pow255.9%
associate-*r*55.9%
*-commutative55.9%
associate-*r*55.9%
*-commutative55.9%
exp-prod55.9%
pow355.9%
add-cbrt-cube55.9%
exp-prod54.1%
associate-*r*54.1%
Applied egg-rr56.8%
+-commutative56.8%
fma-define56.8%
exp-prod58.8%
unpow258.8%
prod-exp58.9%
rem-log-exp99.8%
distribute-rgt-out99.8%
count-299.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (* 3.0 (* x (* x y))))
double code(double x, double y) {
return 3.0 * (x * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 3.0d0 * (x * (x * y))
end function
public static double code(double x, double y) {
return 3.0 * (x * (x * y));
}
def code(x, y): return 3.0 * (x * (x * y))
function code(x, y) return Float64(3.0 * Float64(x * Float64(x * y))) end
function tmp = code(x, y) tmp = 3.0 * (x * (x * y)); end
code[x_, y_] := N[(3.0 * N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(x \cdot \left(x \cdot y\right)\right)
\end{array}
Initial program 86.1%
associate-*l*99.7%
associate-*l*99.7%
Simplified99.7%
add-sqr-sqrt68.9%
pow268.9%
associate-*r*68.9%
*-commutative68.9%
associate-*r*68.8%
associate-*r*61.1%
sqrt-prod48.5%
sqrt-unprod31.8%
add-sqr-sqrt56.3%
Applied egg-rr56.3%
unpow256.3%
swap-sqr48.5%
add-sqr-sqrt86.0%
associate-*l*99.7%
associate-*l*99.7%
*-commutative99.7%
*-commutative99.7%
associate-*l*99.7%
associate-*l*99.7%
Applied egg-rr99.7%
Final simplification99.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(x * Float64(y * Float64(x * 3.0))) end
function tmp = code(x, y) tmp = x * (y * (x * 3.0)); end
code[x_, y_] := N[(x * N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y \cdot \left(x \cdot 3\right)\right)
\end{array}
Initial program 86.1%
*-commutative86.1%
associate-*l*99.7%
associate-*r*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
associate-*r*99.7%
Simplified99.7%
Final simplification99.7%
(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 2024044
(FPCore (x y)
:name "Diagrams.Segment:$catParam from diagrams-lib-1.3.0.3, A"
:precision binary64
:herbie-target
(* (* x 3.0) (* x y))
(* (* (* x 3.0) x) y))