ワンクリックで
overload-operators-dsl
For domain-specific languages: operator overloading, make Python look like math/domain notation, expression builders.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
For domain-specific languages: operator overloading, make Python look like math/domain notation, expression builders.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | overload-operators-dsl |
| description | For domain-specific languages: operator overloading, make Python look like math/domain notation, expression builders. |
Implement __add__, __mul__, etc. to make operators build structure.
class Vector:
def __init__(self, *components):
self.components = components
def __add__(self, other):
return Vector(*(a + b for a, b in zip(self.components, other.components)))
def __mul__(self, scalar):
return Vector(*(c * scalar for c in self.components))
def __rmul__(self, scalar):
return self * scalar # Handle 2 * v
v = Vector(1, 2, 3)
w = Vector(4, 5, 6)
result = 2 * v + w # Vector math with natural syntax
class Expression:
"""DSL for symbolic math."""
def __init__(self, op, *args):
self.op, self.args = op, args
# Arithmetic operators build expressions
def __add__(self, other): return Expression('+', self, other)
def __radd__(self, other): return Expression('+', other, self)
def __sub__(self, other): return Expression('-', self, other)
def __rsub__(self, other): return Expression('-', other, self)
def __mul__(self, other): return Expression('*', self, other)
def __rmul__(self, other): return Expression('*', other, self)
def __truediv__(self, other): return Expression('/', self, other)
def __pow__(self, other): return Expression('**', self, other)
def __neg__(self): return Expression('-', self)
# Equality and hashing for use in dicts
def __eq__(self, other):
return (isinstance(other, Expression) and
self.op == other.op and self.args == other.args)
def __hash__(self):
return hash((self.op, self.args))
# Create symbols
x, y, z = Expression('x'), Expression('y'), Expression('z')
# Natural mathematical syntax
polynomial = 3*x**2 + 2*x + 1
derivative = D(polynomial, x) # 6*x + 2
# Simplification table uses expressions as keys
simp_table = {
sin(0): 0,
cos(0): 1,
ln(1): 0,
}
__r*__ methods: Handle 2 + x not just x + 2__eq__ and __hash__: For use in sets/dicts__repr__: Show expression structure clearlyConducts iterative deep research on any topic using web search, progressive exploration, and structured synthesis. Use when asked for comprehensive research, deep investigation, thorough analysis, or multi-source exploration of any topic. Triggers: research, investigate, deep dive, comprehensive analysis, explore thoroughly, find everything about.
For cross-cutting concerns: add behavior without modifying functions, caching, timing, logging, validation wrappers.
For performance work: measure before changing, profile to find bottlenecks, compare before and after.
For symbolic computation: ASTs, mathematical expressions, code that manipulates code structure, expression transformations.
For ordered processing: A* search, Dijkstra, event simulation, task scheduling. Efficient min/max extraction with heap-based queue.
For dynamic programming: overlapping subproblems, recursive solutions with repeated computations, memoization to avoid redundant work.