Domain-specific languages for convex and non-convex optimization