Home / Case Studies / sympy__sympy-19783

Case Study: sympy-Issues-19747

Space compression success: retrieved tests induce a small trace-covered subspace that fully contains the ground-truth edits, yielding a large positive entropy gain.

k_test=5 k_ret=10 N=28222 N_cov=626 ext_failure=false ΔH=15.462

One-screen takeaway

Why this is a “good case”: Test retrieval finds multiple effective tests ($n=4/5$), whose union coverage subspace is ~45× smaller than the global space while still containing all ground-truth edits ($g_{\text{excl}}=0$). The indirect pipeline therefore recovers both GT locations in the trace-constrained top-10, producing a very large positive gain.

Issue summary

Title: Dagger() * IdentityOperator() is not simplified
Symptom: multiplying Dagger(A) by IdentityOperator() fails to simplify, returning an expression like A^\dagger I instead of A^\dagger.

Problem statement snippet
from sympy.physics.quantum.dagger import Dagger
from sympy.physics.quantum import IdentityOperator
A = Operators('A')
Identity = IdentityOperator()
A * Identity  # gives A, correctly
B = Dagger(A)
B * Identity  # returns A^\dagger I

Outcome

MetricValueNotes
Direct entropy$H_{\text{direct}}=18.1059$Issue→code top-10 contains only 1/2 GT.
Indirect entropy$H_{\text{indirect}}=2.6439$Stage1 + Stage2 after test-driven routing.
Entropy gain$\Delta H=15.4621$Huge positive uncertainty reduction.
External failurefalse$g_{\text{excl}}=0$, no coverage gap penalty.

Key quantities (inspectable)

ItemValueNotes
Instance sympy__sympy-19783 Good case (compression success).
Budgets $k_{\text{test}}=5$, $k_{\text{ret}}=10$ Same as default empirical setting.
Global space $N=28222$ #candidate functions/methods.
Trace subspace $N_{\text{cov}}=626$ Union coverage size (L_sub_size). Compression $\approx 28222/626 \approx 45.1\times$.
Ground truth $|G|=2$ Two GT edit locations.
Direct hits $g_{\text{ret}}=1$ Direct top-10 contains 1/2 GT.
Indirect hits $g_{\text{ret}}=2$ Indirect top-10 contains 2/2 GT.
Effective tests $n=4$ (out of 5) Stage1 entropy $H_{\text{stage1}}=-\log_2(4/5)=0.3219$.
Coverage gap $g_{\text{excl}}=0$ No GT lies outside trace coverage.
Compression alone is not enough in general—but here it is paired with full GT coverage and high effective-test ratio, so Stage2 uncertainty collapses.

Evidence (lists used in the computation)

Ground-truth edit locations (|G|=2)
sympy/physics/quantum/dagger.py::Dagger.__new__
sympy/physics/quantum/operator.py::IdentityOperator.__mul__
Selected tests (k_test=5) and effective tests (n=4)
Selected tests:
- sympy/physics/quantum/tests/test_operator.py::test_operator_dagger   (effective)
- sympy/core/tests/test_args.py::test_sympy__physics__quantum__operator__IdentityOperator
- sympy/physics/quantum/tests/test_operator.py::test_identity          (effective)
- sympy/core/tests/test_args.py::test_sympy__physics__quantum__dagger__Dagger (effective)
- sympy/physics/quantum/tests/test_dagger.py::test_scalars             (effective)

Effective tests (cover at least one GT):
- sympy/physics/quantum/tests/test_operator.py::test_operator_dagger
- sympy/physics/quantum/tests/test_operator.py::test_identity
- sympy/core/tests/test_args.py::test_sympy__physics__quantum__dagger__Dagger
- sympy/physics/quantum/tests/test_dagger.py::test_scalars
Direct vs Indirect top-k returned functions (k_ret=10)
Direct top-10:
1. sympy/physics/quantum/operator.py::IdentityOperator.__init__
2. sympy/physics/quantum/operator.py::IdentityOperator.__mul__               [GT ✓]
3. sympy/physics/quantum/operator.py::IdentityOperator._print_contents
4. sympy/physics/quantum/operator.py::IdentityOperator._eval_commutator
5. sympy/physics/quantum/operator.py::IdentityOperator._print_contents_latex
6. sympy/physics/quantum/operator.py::IdentityOperator._apply_operator
7. sympy/physics/quantum/operator.py::IdentityOperator.default_args
8. sympy/physics/quantum/operator.py::IdentityOperator._print_contents_pretty
9. sympy/physics/quantum/operator.py::IdentityOperator._eval_adjoint
10. sympy/physics/quantum/operator.py::IdentityOperator.dimension

Indirect (trace-constrained) top-10:
1. sympy/physics/quantum/operator.py::IdentityOperator.__init__
2. sympy/physics/quantum/operator.py::IdentityOperator.__mul__               [GT ✓]
3. sympy/physics/quantum/operator.py::IdentityOperator._eval_adjoint
4. sympy/physics/quantum/operator.py::IdentityOperator._eval_inverse
5. sympy/physics/quantum/dagger.py::Dagger.__new__                            [GT ✓]
6. sympy/physics/quantum/operator.py::IdentityOperator._represent_default_basis
7. sympy/physics/quantum/operator.py::Operator.inverse
8. sympy/physics/quantum/operator.py::Operator.__mul__
9. sympy/functions/elementary/miscellaneous.py::IdentityFunction.__new__
10. sympy/physics/quantum/hilbert.py::ComplexSpace.eval

Computed uncertainty terms (numbers for this case)

TermValueHow it was obtained
$H_{\text{direct}}$18.105949From $(N=28222, k_{\text{ret}}=10, |G|=2, g_{\text{ret}}=1)$.
$H_{\text{stage1}}$0.321928$-\log_2(n/k_{\text{test}})=-\log_2(4/5)$.
$H_{\text{stage2}}$2.321928No external penalty ($g_{\text{excl}}=0$); GT concentrated in $S_{\text{ret}}$.
$H_{\text{indirect}}$2.643856$H_{\text{stage1}} + H_{\text{stage2}}$.
$\Delta H$15.462093$H_{\text{direct}} - H_{\text{indirect}}$.
Raw parameter slice (for reproducibility)
{
  "instance_id": "sympy__sympy-19783",
  "k_test": 5,
  "k_ret": 10,
  "gt_threshold": 1.0,
  "N": 28222,
  "L_sub_size": 626,
  "total_gt": 2,
  "gt_covered_by_tests": 2,
  "g_ret_direct": 1,
  "g_ret_indirect": 2,
  "g_ext": 0,
  "n_effective": 4,
  "H_direct": 18.105949419261542,
  "H_stage1": 0.3219280948873623,
  "H_stage2": 2.321928094887362,
  "H_indirect": 2.6438561897747244,
  "delta_H": 15.462093229486818
}
Takeaway: A small set of relevant tests shrinks the search space by ~45× while still covering all GT edits. This enables trace-constrained ranking to recover both GT locations in top-10, yielding a very large positive $\Delta H$.