pattern function