HP Forums
Constant Vector as Argument in PPL - 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: Constant Vector as Argument in PPL (/thread-21904.html)



Constant Vector as Argument in PPL - NumericDavid - 06-17-2024 07:53 PM

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


RE: Constant Vector as Argument in PPL - BruceH - 06-18-2024 10:00 AM

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'?


RE: Constant Vector as Argument in PPL - ftneek - 06-18-2024 06:39 PM

(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.


RE: Constant Vector as Argument in PPL - NumericDavid - 06-18-2024 08:09 PM

(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...


RE: Constant Vector as Argument in PPL - ftneek - 06-18-2024 09:05 PM

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?


RE: Constant Vector as Argument in PPL - NumericDavid - 06-18-2024 10:01 PM

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.


RE: Constant Vector as Argument in PPL - ftneek - 06-19-2024 12:10 AM

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.


RE: Constant Vector as Argument in PPL - NumericDavid - 06-22-2024 07:10 PM

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.


RE: Constant Vector as Argument in PPL - NumericDavid - 06-22-2024 07:23 PM

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.


RE: Constant Vector as Argument in PPL - komame - 06-22-2024 08:34 PM

(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.