delcols bug
|
01-02-2024, 07:08 PM
(This post was last modified: 01-02-2024 08:29 PM by Albert Chan.)
Post: #1
|
|||
|
|||
delcols bug
Below produce permanent of square matrix.
delcols does not work (tested on both HP emulators 2018/10/16, 2023/4/13) I had to add mydelcols := delcols, and use mydelcols to make it work. Code: #cas Lets debug with print(m); right after LOCAL r > per([[0,1,2],[3,4,5],[6,7,8]]) → 144 Terminal: m:[[0,1,2],[3,4,5],[6,7,8]] m:[[3,5],[6,8]] m:[[8]] m:[[6]] m:[[3,4],[6,7]] m:[[7]] m:[[6]] This is using delcols directly inside sum: Terminal: m:[[0,1,2],[3,4,5],[6,7,8]] m:[[4],[7]] m:Error: Bad Argument Type m:Error: Invalid Dimension |
|||
01-02-2024, 09:20 PM
Post: #2
|
|||
|
|||
RE: delcols bug
Albert, thanks for bringing this up. I’ve filed a ticket for this in the bug tracker I’ve set up to help organize development. The programs given in the ticket are a bit shorter, namely
Code: #cas Code: #cas |
|||
01-05-2024, 09:49 PM
(This post was last modified: 01-05-2024 10:01 PM by jte.)
Post: #3
|
|||
|
|||
RE: delcols bug
Prof. Parisse has clarified what is going on here: delcols(-) is modifying its first argument (the matrix) inside the sum(-). For delcols(-)’ modification to its matrix argument to be observed from the outside, the matrix must be passed as a variable (not evaluated to a temporary).
One way of passing the matrix argument as a variable is to quote it (another is to use delcols(-) inside sum(-)…). A screenshot showing how quoting the matrix argument makes the modification visible afterwards follows: If a temporary is passed, the change is not made to variables that contributed to the construction of the temporary, as shown by the following screenshot: |
|||
01-06-2024, 10:45 AM
Post: #4
|
|||
|
|||
RE: delcols bug
delcols does not auto-quote it's argument, sum does. If the first argument of delcols is an identifier of a variable containing a matrix, then the modified matrix is stored in the variable.
That should explain the issue. |
|||
01-06-2024, 11:55 AM
Post: #5
|
|||
|
|||
RE: delcols bug
(01-06-2024 10:45 AM)parisse Wrote: delcols does not auto-quote it's argument, sum does. Thanks! OP sum line should avoid matrix to be modified, like this: > sum(when(r[k],r[k]*per(delcols(m+0,k)),0), k=1..len(r)); Although this does not explain why OP hack work too. I would have expected mydelcols := delcols line have no effect. > mydelcols := delcols; > sum(when(r[k],r[k]*per(mydelcols(m,k)),0), k=1..len(r)); Quote: If the first argument of delcols is an identifier of a variable containing a matrix, Perhaps delcols/delrows possibly modify matrix behavior should be in documentation? m2 := delcols(m,k) // m unchanged m2 := delcols('m',k) // m changed to m2 If this is not yet in documentation (i.e. undefined behavior), perhaps we can change it? I think m should not be modified, unless explicitly asked, say m := delcols('m',k) |
|||
01-08-2024, 04:24 PM
Post: #6
|
|||
|
|||
RE: delcols bug
If I decide to change something, then I'll certainly simplify, delrows/delcols shoud not modify the matrix.
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)