sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.31k stars 449 forks source link

IndexedFreeMonoid element_constructor does not check if index is in index set #38398

Open Newtech66 opened 1 month ago

Newtech66 commented 1 month ago

Steps To Reproduce

sage: from sage.monoids.indexed_free_monoid import IndexedFreeMonoid
sage: L=['a','b','c']
sage: F=IndexedFreeMonoid(L)
sage: F
Free monoid indexed by {'a', 'b', 'c'}
sage: F([['d',3]])    # but 'd' is not part of the index set
F['d']^3
sage: F([['d',3]]) in F    # should return False
True

Expected Behavior

It should fail if I try to construct an element with an index not in the index_set.

Actual Behavior

It says the element exists.

Additional Information

No response

Environment

- **OS**: Windows 10 running WSL2 Ubuntu
- **Sage Version**: 10.4.beta6

Checklist

DaveWitteMorris commented 1 month ago

Please edit the "Steps to Reproduce". (I get an error: NameError: name 'IndexedFreeMonoid' is not defined.) I think you need another line at the start:

from sage.monoids.indexed_free_monoid import IndexedFreeMonoid
Newtech66 commented 1 month ago

Please edit the "Steps to Reproduce". (I get an error: NameError: name 'IndexedFreeMonoid' is not defined.) I think you need another line at the start:

from sage.monoids.indexed_free_monoid import IndexedFreeMonoid

Corrected.

tscrim commented 1 month ago

This is not a bug but a feature. This is done for speed reasons. It would be nice to have some checking, but we don't want to lose speed in internal code as this can be done in tight loops (e.g., algebra multiplication).