delcols bug - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: delcols bug (/thread-21096.html) |
delcols bug - Albert Chan - 01-02-2024 07:08 PM 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 RE: delcols bug - jte - 01-02-2024 09:20 PM 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 RE: delcols bug - jte - 01-05-2024 09:49 PM 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: RE: delcols bug - parisse - 01-06-2024 10:45 AM 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. RE: delcols bug - Albert Chan - 01-06-2024 11:55 AM (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) RE: delcols bug - parisse - 01-08-2024 04:24 PM If I decide to change something, then I'll certainly simplify, delrows/delcols shoud not modify the matrix. |