Symbolic Variable Elimination for Discrete and Continuous Graphical Models