Post Reply 
Constant Vector as Argument in PPL
06-17-2024, 07:53 PM
Post: #1
Constant Vector as Argument in PPL
Hello Prime Friends,

I see a strange difference between the two PPL functions

export bla()
begin
return normalize([0,0,-1]);
end;
export blu()
begin
return normalize([0,0,1]);
end;

SIZE(bla) equals 6 and the numbers don't seem to make a sense. I'd expect bla = [0,0,-1] since normalize(v) should be v/abs(v).

blu and SIZE(blu) are [0,0,1] and 3 as expected.

Do you know what's going on?

Best Wishes,
David
Find all posts by this user
Quote this message in a reply
06-18-2024, 10:00 AM
Post: #2
RE: Constant Vector as Argument in PPL
No but I've had problems in the past passing vectors/matrices directly as arguments to functions causing syntax errors. The work-around was to assign them to variables and then use those as the function arguments.

Maybe this is linked to that same general 'bugginess'?
Find all posts by this user
Quote this message in a reply
06-18-2024, 06:39 PM (This post was last modified: 06-18-2024 07:14 PM by ftneek.)
Post: #3
RE: Constant Vector as Argument in PPL
(06-17-2024 07:53 PM)NumericDavid Wrote:  Hello Prime Friends,
...
SIZE(bla) equals 6 and the numbers don't seem to make a sense. I'd expect bla = [0,0,-1] since normalize(v) should be v/abs(v).

Are you using the physical calculator or Virtual Calculator, and which revision number?

In macOS VC revision 14425 SIZE(bla()) returns {3} in Home and 3 in CAS view, and bla() returns [0,0,-1] in both views.

(06-18-2024 10:00 AM)BruceH Wrote:  No but I've had problems in the past passing vectors/matrices directly as arguments to functions causing syntax errors. The work-around was to assign them to variables and then use those as the function arguments.

Maybe this is linked to that same general 'bugginess'?

Such as the issue described in this thread? I wonder if anything can be done to improve this behavior on the Prime.

- neek
Find all posts by this user
Quote this message in a reply
06-18-2024, 08:09 PM (This post was last modified: 06-18-2024 08:21 PM by NumericDavid.)
Post: #4
RE: Constant Vector as Argument in PPL
(06-18-2024 06:39 PM)ftneek Wrote:  Are you using the physical calculator or Virtual Calculator, and which revision number?

Both physical Prime G2 2.1.14730 and same Version on Windows 11 virtual calculator. Both, Device and virtual answer correctly on normalize([0,0,-1]) in their Home Screen.

Also, storing [0,0,-1] in some variable first and applying the function then works perfectly. I'm trying to understand why...
Find all posts by this user
Quote this message in a reply
06-18-2024, 09:05 PM
Post: #5
RE: Constant Vector as Argument in PPL
I could not make SIZE(bla()) return 6 on my VC, even from another PPL program. Can you share exactly the steps you take to reproduce a result of 6?

- neek
Find all posts by this user
Quote this message in a reply
06-18-2024, 10:01 PM
Post: #6
RE: Constant Vector as Argument in PPL
May we concentrate on the actual calculator? Differences between Mac or Windows VC are less important to me.

I just entered into a physical HP Prime G2 the program:
verbatim"
EXPORT BLA()
BEGIN
normalize([0,0,-1])
END;
"
By tapping the "Run" virtual button in the Program Catalog view, i obtain the answer:
verbatim"
BLA [0,0.31511344578,
0.904534033733,0,0,
-0.301511344578]
"
Which is unexpected to me.

On contrast, if i omit the "-" symbol in the program above, i obtain, by "Run" the answer:
verbatim"
BLA [0,0,1]
"
Which is what i'd expect.
Find all posts by this user
Quote this message in a reply
06-19-2024, 12:10 AM (This post was last modified: 06-19-2024 12:14 AM by ftneek.)
Post: #7
RE: Constant Vector as Argument in PPL
Mentioning the behavior of the Prime across hardware versions/firmware revisions can help the developers pinpoint when a bug is introduced, making it easier to track down and fix.

Indeed, on a physical calculator the program behaves as you describe while normalize([0,0,-1]) correctly returns [0,0,-1] in Home view. I will file a ticket on the bug tracker, let's hope it can be resolved.

- neek
Find all posts by this user
Quote this message in a reply
06-22-2024, 07:10 PM (This post was last modified: 06-22-2024 07:36 PM by NumericDavid.)
Post: #8
RE: Constant Vector as Argument in PPL
OK, that's a valid point. The problem occurs on our Prime G2 Hardware and my Windows 11 64bit VC, both on 2023 04 13 (14730) but not on your VC (Mac).

I have a feeling that issue might be related to a CAS/ not CAS irritation. My application is purely numeric but normalize() seems to try to return an expression instead of numeric vector.
Find all posts by this user
Quote this message in a reply
06-22-2024, 07:23 PM
Post: #9
RE: Constant Vector as Argument in PPL
Update:
nrm([5 10 -1])
translates to nrm(ListToMat({0,1,3,5,10,-1}))
first, and then things go wrong. This might be where the "6" comes from.
Find all posts by this user
Quote this message in a reply
06-22-2024, 08:34 PM
Post: #10
RE: Constant Vector as Argument in PPL
(06-22-2024 07:10 PM)NumericDavid Wrote:  I have a feeling that issue might be related to a CAS/ not CAS irritation. My application is purely numeric but normalize() seems to try to return an expression instead of numeric vector.

I think you are on the right track. It appears that normalize() is a command dedicated to CAS, and passing a parameter inside a PPL program might not be handled correctly. Therefore, when you enter the program not as pure PPL, but as a CAS region, everything works correctly:
Code:
#cas
bla:=
normalize([0,0,-1]);
#end

However, a simpler solution is to substitute individual elements of the vector one by one, e.g., normalize[0,0,-1] instead of normalize([0,0,-1]).
Then your program will look like this:
Code:
export bla()
begin
  return normalize(0,0,-1);
end;

This should solve your problem.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)