Skip to content

_algebra._check_compatible: tuple-vs-list domain comparison fails spuriously #22

@0xC000005

Description

@0xC000005

Summary

_algebra._check_compatible compares two interpolants' domain attributes with Python !=. When one was constructed with domain=[(-1, 1)] (tuple-of-tuples) and the other with domain=[[-1, 1]] (list-of-lists), the comparison fails even though the bounds are numerically identical. This raises a spurious Domain mismatch from algebra ops.

Trigger

Surfaced during v0.21.0 development (Task 5 — Slider cross-feature tests). The natural `+`/`*` algebra of two ChebyshevSliders with mixed domain syntax triggers it:

```python
s_f = ChebyshevSlider(f, num_dimensions=1, domain=[(-1, 1)], ...) # tuple
s_g = ChebyshevSlider(g, num_dimensions=1, domain=[(-1, 1)], ...) # tuple

After scalar mul, _from_slides normalizes domain to [list(b) for b in domain]

so 2.0 * s_g now has domain=[[-1, 1]]

h = s_f + 2.0 * s_g # raises ValueError: Domain mismatch
```

The internal normalization in scalar-mul (`[list(bounds) for bounds in source.domain]` in `_algebra.py`) makes one operand a list-of-lists, then `add` calls `_check_compatible` which uses `!=` and fails.

Workaround

Pass `domain=[[-1, 1]]` (list-of-lists) consistently. All existing test fixtures already do this, which is why the bug hasn't surfaced before.

Suggested fix

In `src/pychebyshev/_algebra.py::_check_compatible`, replace the bare `a.domain != b.domain` with a numerical comparison that treats nested tuples and lists as equal — e.g. `np.allclose(np.array(a.domain), np.array(b.domain))` or per-bound `(lo_a, hi_a) == (lo_b, hi_b)` after coercion to tuples.

Priority

Minor UX bug — only triggers in algebra paths with mixed-syntax domains. Tracked from v0.21.0 PR #21 review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions