You can get a reasonable approximation by dividing the 50% base quality by the number of mats and then multiplying by the number of HQ mats. There are times when mats are weighted unequally, but I don't think you'll be able to have a general purpose equation to help with that.