A Survey on Mathematical Reasoning and Optimization with Large Language Models