Optimization and probabilistic satisfiability on nested and co-nested formulas