Skip to main content
skill CX Codex

constrained-optimization — Claude Code skill: setup and usage

Guides Claude Code through constrained optimization problems. It classifies constraints, formulates Lagrangians, and checks KKT optimality conditions.

MIT ★ 3,951 updated 2026-01-26

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add parcadei/Continuous-Claude-v3 --skill constrained-optimization -a claude-code
Open on GitHub

What constrained-optimization does

The skill provides a structured decision tree for optimization subject to equalities, inequalities, and box bounds. When handling equality constraints, it sets up the Lagrangian system for symbolic solving. For inequality bounds, it switches to Karush-Kuhn-Tucker conditions with complementary slackness or applies penalty and barrier formulations.

Numerical solving is handled via scipy.optimize.minimize using the SLSQP method. Tool commands inside the skill rely on uv run python to execute one-liners or pass symbolic tasks to sympy_compute.py and z3_solve.py through runtime.harness.

Execution will fail if Python dependencies like scipy, sympy, and z3 are missing from your environment.

What it helps with

  • Classify constraints into equalities, inequalities, and variable bounds
  • Solve Lagrangian systems analytically using SymPy
  • Prove KKT complementary slackness conditions with Z3
  • Configure SciPy SLSQP optimization with custom constraint dictionaries

Example prompts for the agent

  • Formulate the Lagrangian and find the minimum of x^2 + y^2 subject to x + y = 1
  • Verify KKT optimality conditions for my inequality constraints using Z3
  • Run SciPy SLSQP minimization with equality constraints via uv

How to install constrained-optimization

1Skills CLI (Vercel)

npx skills add parcadei/Continuous-Claude-v3 --skill constrained-optimization -a claude-code

2Manually: put the files in place

~/.claude/skills/constrained-optimization/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/constrained-optimization/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about constrained-optimization

How do I install constrained-optimization in Claude Code?

Run npx skills add parcadei/Continuous-Claude-v3 --skill constrained-optimization -a claude-code. Alternatively, copy the file to ~/.claude/skills/constrained-optimization/SKILL.md.

What does the constrained-optimization skill do?

It guides Claude Code through problem-solving strategies for optimization with constraints. It covers constraint classification, KKT conditions, penalty methods, and numerical optimization with SciPy.

Which dependencies are required to run the optimization scripts?

The skill uses uv to execute Python commands and requires scipy, sympy, and z3. It also references internal project scripts sympy_compute.py and z3_solve.py.

Source text

SKILL.md · MIT
---
name: constrained-optimization
description: "Problem-solving strategies for constrained optimization in optimization"
allowed-tools: [Bash, Read]
---

# Constrained Optimization

## When to Use

Use this skill when working on constrained-optimization problems in optimization.

## Decision Tree


1. **Constraint Classification**
   - Equality: h(x) = 0
   - Inequality: g(x) <= 0
   - Bounds: l <= x <= u

2. **Lagrangian Method (Equality Constraints)**
   - L(x, lambda) = f(x) + sum lambda_j * h_j(x)
   - Solve: grad_x L = 0 and h(x) = 0
   - `sympy_compute.py solve "grad_L_system"`

3. **KKT Conditions (Inequality Constraints)**
   - Extend Lagrangian with mu_i for g_i(x) <= 0
   - Complementary slackness: mu_i * g_i(x) = 0
   - `z3_solve.py prove "kkt_satisfied"`

4. **Penalty and Barrier Methods**
   - Penalty: add P(x) = rho * sum max(0, g_i(x))^2
   - Barrier: add B(x) = -sum log(-g_i(x)) for interior point
   - Increase penalty/decrease barrier parameter iteratively

5. **SciPy Constrained Optimization**
   - `scipy.optimize.minimize(f, x0, method='SLSQP', constraints=cons)`
   - constraints = [{'type': 'eq', 'fun': h}, {'type': 'ineq', 'fun': lambda x: -g(x)}]
   - bounds = [(l1, u1), (l2, u2), ...]


## Tool Commands

### Scipy_Slsqp
```bash
uv run python -c "from scipy.optimize import minimize; cons = dict(type='eq', fun=lambda x: x[0] + x[1] - 1); res = minimize(lambda x: x[0]**2 + x[1]**2, [1, 1], method='SLSQP', constraints=cons); print('Min at', res.x)"
```

### Sympy_Lagrangian
```bash
uv run python -m runtime.harness scripts/sympy_compute.py solve "[2*x - lam, 2*y - lam, x + y - 1]" --vars "[x, y, lam]"
```

### Z3_Kkt_Satisfied
```bash
uv run python -m runtime.harness scripts/z3_solve.py prove "complementary_slackness"
```

## Key Techniques

*From indexed textbooks:*

- [nonlinear programming_tif] Conjugate Direction Methods** - Methods involving directions conjugate to each other with respect to a certain quadratic form, enhancing efficiency in finding minima. Quasi-Newton Methods** - Variants of Newton’s method that approximate the Hessian matrix. Nonderivative Methods** - Address optimization methods that don’t require derivative information.
- [nonlinear programming_tif] Optimization Over a Convex Set** - Focuses on optimization problems constrained within a convex set. Optimality Conditions:** Similar to unconstrained optimization, but within the context of convex sets. Feasible Directions and Conditional Gradient** - Explores methods that ensure feasibility within constraints.
- [nonlinear programming_tif] In this chapter we consider the constrained optimization problem minimize f(z) subject to z € X, where we assume throughout that: (a) X is a nonempty and convex subset of 2. When dealing with algo- rithms, we assume in addition that X is closed. The function f: %™ — R is continuously differentiable over X.
- [nonlinear programming_tif] The methods for obtaining lower bounds are elaborated on in Section 5. Lagrangian relaxation method is discussed in detail. This method requires the optimization of nondifferentiable functions, and some of the major relevant algorithms, subgradient and cutting plane methods, will be discussed in Chapter 6.
- [nonlinear programming_tif] The image depicts a three-dimensional graphical representation, likely related to linear algebra or optimization. Key elements include: - **Axes**: Three intersecting axes are shown, suggesting a three-dimensional coordinate system. Equation and Constraints**: A linear equation `{x | Ax = b, x ≥ 0}` is noted, indicating a system or set of constraints.

## Cognitive Tools Reference

See `.claude/skills/math-mode/SKILL.md` for full tool documentation.

© parcadei · MIT · parcadei/Continuous-Claude-v3

Similar skills

All skills for Science and research →

From the same set161

The whole set →
convex-optimization Skill for tackling convex optimization problems. Includes convexity verification, problem classification, and solution methods based on KKT conditions. CX Codex +1 ★ 3,951repo stars connectedness A skill for Claude Code with strategies for connectedness problems in topology. CX Codex +1 ★ 3,951repo stars analytic-functions analytic-functions is a Claude Code skill for checking analyticity, verifying Cauchy-Riemann equations, and computing power series and analytic continuations. It activates for theory of functions questions. CX Codex +1 ★ 3,951repo stars math-intuition-builder math-intuition-builder develops mathematical understanding by guiding you through concrete examples, diagrams, and analogies before diving into calculation. Useful when you need solid intuition before solving a problem. CX Codex +1 ★ 3,951repo stars integration-theory integration-theory — a Claude Code skill for solving measure-theoretic integration problems. Covers simple functions, monotone and dominated convergence, Fatou's lemma, and Fubini—Tonelli via sympy_compute.py and z3_solve.py commands. CX Codex +1 ★ 3,951repo stars math-progress-monitor math-progress-monitor — a skill that evaluates whether you're on the right track while solving a math problem and helps decide whether to keep going or switch strategies. Activates on phrases like "I'm stuck" or "is this approach working". CX Codex +1 ★ 3,951repo stars rings A Claude Code skill with decision trees and tools for abstract algebra problems on rings. Verifies ring axioms, analyzes properties, and manipulates ideals using Z3 and SymPy. CX Codex +1 ★ 3,951repo stars critic critic reviews features and implementations for logic issues, test gaps, and mismatches with repository patterns, then saves its findings to a Markdown file. CX Codex ★ 3,951repo stars

Project sponsors

Companies that keep this analytics open