Optimization circuit calculus