Repository navigation
Fix MapAt for parts that are lists, other heads and several positions - #2008
Open
tombouctou wants to merge 1 commit into
Open
tombouctou wants to merge 1 commit into
tombouctou wants to merge 1 commit into
Conversation
MapAt[f, {{1, 0}, {0, 1}}, {2}] gave {0, f[1]} instead of
{{1, 0}, f[{0, 1}]}: when the part at the position was itself a List,
it applied f inside that part and returned the part's elements as the
result. Also:
- the head of the expression was lost: MapAt[g, h[a, b], 2] gave
{a, g[b]} instead of h[a, g[b]];
- positions could not go into a part whose head is not List;
- a list of positions of different depths gave a wrong result.
Walk the position recursively, rebuilding each level with its own head.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MapAtgave wrong results whenever the part at the position was itself a list, which is common with matrices:With a one-index position, the code applied
finside the part at that position and returned that part's elements as the whole result. Also:This replaces the position handling in
eval_MapAtwith one recursive function that walks the position and rebuilds each level with its own head. Error messages (MapAt::partw,MapAt::psl), negative positions, associations, and the existing handling of rules are unchanged. The doc examples still pass.Tests: new cases in
test/builtin/functional/test_apply_fns_to_lists.py. pytest and the doctests pass.Found while running Strickland's
LambdaAlgebra.m, which builds a projection matrix withMapAt[0 # &, IdentityMatrix[n], {{i}, ...}].🤖 Generated with Claude Code