Factorization algorithm for some special matrix functions