Trace formulas and their applications