norm() accepts a matrix and builds (list(0, 0)^2 + list(3, 4)^2)^(1/2) instead of computing the Frobenius norm or rejecting the rank

Open
#359 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
67/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r, rust
Domain
backend

Research direction

Start at the implementation of norm() and its tests; the issue gives reproductions for rank-1 and rank-2 inputs but names no source files or test paths. Trace how the argument rank is checked and how reduction sets reduced and value. Add coverage showing that matrix input either computes the Frobenius norm or returns a clear rank error, while vector cases remain correct.

Written by the indexing model from the issue text.

Description

area/linear-algebra good first issue help wanted kind/contract severity/4-minor

norm(v) is documented as "Euclidean (L2) norm ||v||_2 of vector v". Given a matrix it does not reject the argument: it squares each row as a number and builds an expression that contains list(...)^2, which is not a well-formed quantity and has no value.

library(rssn)
compute(parse_term("norm(list(list(3,4),list(0,0)))"))$text
# "(list(0, 0)^2 + list(3, 4)^2)^(1/2)"
compute(parse_term("norm(list(list(1,2),list(3,4)))"))$text
# "(list(1, 2)^2 + list(3, 4)^2)^(1/2)"
compute(parse_term("norm(list(list(1,0),list(0,1)))"))$text
# "(list(0, 1)^2 + list(1, 0)^2)^(1/2)"

Each of these reports reduced = TRUE with value = NA, so the caller gets a confidently-reduced expression that no further rule can use. Note the rows come out in reverse order (list(0,0) before list(3,4) for the first matrix), which is a second sign that the arguments were never checked.

The vector case is correct (norm(list(3,4)) is 5), and so is norm(list(1,2,3)) (14^(1/2)), so the defect is specifically that a rank-2 argument is accepted and reduced elementwise-ish instead of being rejected.

Expected: either the Frobenius norm (norm(list(list(3,4),list(0,0))) = 5) or an error naming the argument and the rank it wanted — the same way value_tensor() refuses a non-tensor with "the value is not a tensor". Producing list(0, 0)^2 is the one outcome that cannot be used.

rssn 0.3.0, R 4.6.2 binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
14h 51m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.