Post Reply 
Write a GCD program for the HP-41C with chatGPT
12-28-2022, 12:35 PM
Post: #1
Write a GCD program for the HP-41C with chatGPT
The first answer was a bit disappointing.
At least it looks like a program for the HP-41C.
But it's nice that when I asked to replace the labels, the goto commands were also replaced.
This was my first try, so be kind to me.

[Image: tZ62pRm.png]
Find all posts by this user
Quote this message in a reply
12-28-2022, 02:10 PM
Post: #2
RE: Write a GCD program for the HP-41C with chatGPT
I find quite impressive the way chatGPT answers look so human.

However I find also quite puzzling how the answers look so authoritative, as from an expert on the topic, while clearly chatGPT has no understanding at all of how a 41C program is working, and you had to instruct it exactly how to modify the program to make it work.

It's clear for us that the program provided initially is not a working HP-41 program, but on other more complex topics it could be easy for people to take answers from such IA programs as answers from experts and take them as expression of the truth.

This will become a problem when people will not be able to differentiate information and data coming from a human expert or from such IA programs.

Another problem is that these IA programs are fed with huge loads of data from the internet and their outputs is now part of internet content, thus polluting the reference used to build them.
Find all posts by this user
Quote this message in a reply
12-28-2022, 02:28 PM (This post was last modified: 12-28-2022 02:31 PM by pier4r.)
Post: #3
RE: Write a GCD program for the HP-41C with chatGPT
Oh ChatGPT arrived also here. It is a really interesting development. As Didier pointed out, the model is often "confidently incorrect", especially on topics where the initial training data does not have many data points.

I am surprised it knows the 41C as the datapoints in the training data (they used Common Crawl as the main dataset) surely are minimal.

Other languages fails as well. For example if one asks about RPL, it tries with Lisp. Puppet is mixed with Ruby. Terraform is mixed with other programs too.

In other words, it tries, and it shows confidence (that more often than not is enough for a human to accept the answer), but it can be subtly wrong.

Instead of small code snippets in the most common languages (python, java, what have you, but also awk or bash) it works well. I find it neat to ask for pointers and directions rather than full solutions, a sort of "quick search engine". In that case it works really well.

Much better is to work with human languages (again, the most common ones at least). I use it for German, English and Italian and it is pretty neat. Like checking the grammar, building example sentences with words or providing meaning of the words. I often double check with vocabularies and grammar books but in human languages it is really helpful.

There are also many other usages. For example it could be an helper for the outline of an article or book, given some initial pointers. It also helps for recommendations, like "I liked this list of movies or books or places or what have you, what should I check next?". The recommendations weren't bad!


The important part to keep in mind is though: it picks the next words based on statistics "what will likely be here given my training dataset", so it can be subtly wrong in all possible cases if one lowers the guard. Also because in the internet people like me write with broken grammar (or code or what have you) all the time and the training data comes from the net.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
12-28-2022, 02:39 PM
Post: #4
RE: Write a GCD program for the HP-41C with chatGPT
(12-28-2022 02:10 PM)Didier Lachieze Wrote:  However I find also quite puzzling how the answers look so authoritative

On the other hand also very submissive:
Quote:I apologize for the oversight.

A colleague asked the bot to rewrite some savage insults using Nonviolent Communication.
The result was interesting and hilarious at the same time.

This could be the future of all internet forums: no locked threads, but automatic moderation.
Find all posts by this user
Quote this message in a reply
12-29-2022, 09:50 AM
Post: #5
RE: Write a GCD program for the HP-41C with chatGPT
I've seen two or three spam posts on the anycpu forum recently which have the feel of being automatically generated: broadly coherent with the existing thread but actually not useful contributions - and, as a giveaway, one punctuation character acts as a spam link.

I suspect those of us who moderate are more likely to encounter this technology as a nuisance than as an assist.

But those of us who don't moderate may not even see those problematic posts, and conclude that all is well...
Find all posts by this user
Quote this message in a reply
12-29-2022, 12:43 PM
Post: #6
RE: Write a GCD program for the HP-41C with chatGPT
(12-29-2022 09:50 AM)EdS2 Wrote:  I suspect those of us who moderate are more likely to encounter this technology as a nuisance than as an assist.

This is in response to a request to rewrite a recent post using Nonviolent Communication:
Quote:I understand that it can be frustrating to encounter what may seem like irrational or baseless ideas. I'm curious if there might be a way to express your perspective without using derogatory language or suggesting that someone seek mental health treatment as a solution. Could you perhaps rephrase your comment to say something like: "I appreciate that people may have different perspectives, but I'm having a hard time understanding how this particular theory fits into the conversation. Could you perhaps explain your perspective further or provide some supporting evidence for your viewpoint?" This approach focuses on expressing your own feelings and needs, rather than attacking or belittling someone else's thoughts or experiences.

This sounds pretty reasonable, doesn't it?
Find all posts by this user
Quote this message in a reply
12-29-2022, 03:36 PM
Post: #7
RE: Write a GCD program for the HP-41C with chatGPT
Interesting, but it definitively need to be trained on the HP-41.
Nit-picking here, data registers on the HP-41 are numerical. (00 ... 99) → Ex.: STO 00 ; RCL 01 ; ST+ 02
Find all posts by this user
Quote this message in a reply
12-30-2022, 07:04 AM
Post: #8
RE: Write a GCD program for the HP-41C with chatGPT
Definitely spooky.
Find all posts by this user
Quote this message in a reply
12-30-2022, 04:57 PM (This post was last modified: 12-30-2022 05:04 PM by Allen.)
Post: #9
RE: Write a GCD program for the HP-41C with chatGPT
During the holidays I've also been experimenting with the OpenAI Chatbots.. with not as impressive or promising results. When asked what the prime factors of 8633 (answer: 89 and 97), it produced a long paragraph of "correct sounding" drivel.. The other (non math) questions were pretty good, but I'm not prepared to spend much time even considering AI-generated software it can reliably answer some more 7th/8th grade math things correctly.

Me: what are the prime factors of 8633?

Quote:The prime factors of 8633 are 3, 3, 3, 3, 3, and 11.

To find the prime factors of a composite number, one approach is to use a method such as trial division, which involves dividing the composite number by each prime number less than its square root until a divisor is found. In this case, 8633 can be divided by 3 to get 2877, which is still composite. Dividing this number by 3 again gives 959, which can be divided by 3 again to get 319. This process can be repeated until the number has been fully factored into its prime components.
(ChatGPT Dec 15 Version.)

In a separate question, the chatbot insisted that
1024-4 = 1000.

Me: Using only addition, add eight 8s to get the number 1,000.

Quote:To add eight 8s to get the number 1,000 using only addition, you can use the following calculation:

8 + 8 + 8 + 8 + 8 + 8 + 8 + 8 = 64
64 + 64 + 64 + 64 + 64 + 64 + 64 + 64 = 512
512 + 512 = 1,024

The result of this calculation is 1,024, which is slightly larger than 1,000. However, if you subtract 4 from 1,024, you get 1,000.

Here is the calculation with the subtraction:

1,024 - 4 = 1,000

Using only addition, you can add eight 8s to get the number 1,000 by starting with 8 and adding it to itself seven more times to get 64, then adding 64 to itself seven more times to get 512, and finally adding 512 to itself once to get 1,024. You can then subtract 4 from 1,024 to get 1,000.
(ChatGPT Dec 15 Version.)

Other than a simple addition problem and "how many sides does a square have", few of the math questions were correct.

The problem in using these for math/computer science isn't going to be when it's blatantly WRONG in the examples above. The challenge will be figuring out when it's nearly right- which is analogous to debugging intern code that works most of the time.
I think if combined with a SAT-solver or similar, the code COULD work, but I'm not betting on it anytime soon.


Me: how many edges does a 6 dimensional hyper-cube have?
( correct answer is 192)
Quote:A 6-dimensional hypercube, also known as a tesseract, has 32 edges.

A hypercube is a multi-dimensional extension of a cube, and it is defined as a geometric shape with an equal number of dimensions and vertices. A 6-dimensional hypercube has 6 dimensions and 8 vertices, and it can be thought of as a cube in 6-dimensional space.

The edges of a hypercube are the lines that connect its vertices, and a 6-dimensional hypercube has a total of 32 edges. Each of the 8 vertices of a tesseract is connected to 7 other vertices by an edge, and there are a total of 8 vertices, so the number of edges in a tesseract is 8 * 7 = 56 edges. However, since each edge is counted twice (once for each of the two vertices it connects), the total number of edges in a tesseract is 32.

It is worth noting that hypercubes with more than 3 dimensions are difficult to visualize and are often represented using diagrams or other visual aids.

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
12-30-2022, 11:36 PM (This post was last modified: 12-30-2022 11:36 PM by pier4r.)
Post: #10
RE: Write a GCD program for the HP-41C with chatGPT
Nice ones Allen. Yes if asked about basic checkmates (on lichess.org there are chapters to train those), chatGPT is not even getting the position most of the time.

I think that the current iteration is mostly tuned for natural languages (try translations or explanation of words) and most common code snippets. For the rest they need better training or data.

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
06-21-2024, 07:35 PM
Post: #11
RE: Write a GCD program for the HP-41C with chatGPT
I thought to give it another try using copilot:

Quote:Use the Euclidian algorithm to write a program for the old calculator HP-41C from Hewlett Packard that calculates the greatest common divisor of two numbers.

To write a program for the HP-41C calculator that calculates the greatest common divisor (GCD) of two numbers using the Euclidean algorithm, follow these steps in pseudocode:
  1. Start: Begin the program.
  2. Input A and B: Prompt the user to enter two numbers, A and B.
  3. Check if B is 0: If B is 0, then the GCD is A. Go to step 7.
  4. Compute Remainder: Calculate the remainder of A divided by B.
  5. Set A to B and B to Remainder: Replace the value of A with B and the value of B with the remainder calculated in step 4.
  6. Repeat: Go back to step 3.
  7. Display GCD: The value of A is now the GCD. Display this value.
  8. End: End the program.

Now, translating this pseudocode into a program for the HP-41C, which uses RPN (Reverse Polish Notation) and has a specific set of instructions:
Code:
01 LBL "GCD"       ; Label the program GCD
02 PROMPT          ; Prompt for first number, stores in X
03 STO 00          ; Store first number in register 00
04 PROMPT          ; Prompt for second number, stores in X
05 STO 01          ; Store second number in register 01
06 LBL 01          ; Loop label
07 RCL 01          ; Recall second number
08 X=0?            ; Check if second number is 0
09 GTO 02          ; If 0, go to label 02
10 RCL 00          ; Recall first number
11 RCL 01          ; Recall second number
12 MOD             ; Calculate remainder of first number divided by second
13 STO 00          ; Store result in register 00 (new A)
14 RCL 01          ; Recall second number
15 STO 01          ; Store previous A in register 01 (new B)
16 RCL 00          ; Recall new A to check in next iteration
17 GTO 01          ; Go back to start of loop
18 LBL 02          ; Label for GCD result
19 RCL 00          ; Recall the GCD result
20 PSE             ; Pause to display the GCD
21 RTN             ; Return from the program

This program uses the HP-41C's capabilities to calculate the GCD of two numbers entered by the user. It utilizes registers for storing intermediate values and loops until the second number becomes 0, at which point the first number is the GCD.

Quote:Do not prompt for the numbers but assume that the two numbers are already on the stack.

To modify the program so it assumes the two numbers are already on the stack instead of prompting the user to enter them, we'll remove the PROMPT instructions and adjust the storage instructions accordingly. Here's the updated program:
Code:
01 LBL "GCD"       ; Label the program GCD
02 STO 01          ; Store second number (already on stack) in register 01
03 STO 00          ; Store first number (now on stack) in register 00
04 LBL 01          ; Loop label
05 RCL 01          ; Recall second number
06 X=0?            ; Check if second number is 0
07 GTO 02          ; If 0, go to label 02
08 RCL 00          ; Recall first number
09 RCL 01          ; Recall second number
10 MOD             ; Calculate remainder of first number divided by second
11 STO 00          ; Store result in register 00 (new A)
12 RCL 01          ; Recall second number
13 STO 01          ; Store previous A in register 01 (new B)
14 RCL 00          ; Recall new A to check in next iteration
15 GTO 01          ; Go back to start of loop
16 LBL 02          ; Label for GCD result
17 RCL 00          ; Recall the GCD result
18 PSE             ; Pause to display the GCD
19 RTN             ; Return from the program

This version assumes the user has already placed the two numbers on the stack with the first number entered being on the bottom (first to be stored in register 00) and the second number on top (to be stored in register 01).

Quote:There's a problem with step 5: Set A to B and B to Remainder. The remainder has to be stored in register 01 (new B). The second number has to be stored in register 00 (new A). To do so, use the RDN (roll down) command.

To correct the issue with step 5, where the remainder needs to be stored in register 01 (new B) and the second number in register 00 (new A), we can use the RDN (roll down) command to adjust the values accordingly. Here's the revised section of the program:
Code:
01 LBL "GCD"       ; Label the program GCD
02 STO 01          ; Store second number (already on stack) in register 01
03 STO 00          ; Store first number (now on stack) in register 00
04 LBL 01          ; Loop label
05 RCL 01          ; Recall second number
06 X=0?            ; Check if second number is 0
07 GTO 02          ; If 0, go to label 02
08 RCL 00          ; Recall first number
09 RCL 01          ; Recall second number
10 MOD             ; Calculate remainder of first number divided by second
11 X<>Y            ; Swap X and Y registers
12 STO 01          ; Store the remainder (now in Y after swap) in register 01 (new B)
13 RDN             ; Roll down the stack
14 STO 00          ; Store the original second number (now on X after RDN) in register 00 (new A)
15 GTO 01          ; Go back to start of loop
16 LBL 02          ; Label for GCD result
17 RCL 00          ; Recall the GCD result
18 PSE             ; Pause to display the GCD
19 RTN             ; Return from the program

This adjustment ensures that after calculating the remainder (step 10), we swap the X and Y registers so that the remainder can be stored in register 01 as the new B (step 12). Then, we use the RDN command to roll down the stack, bringing the original second number into the X register, which is then stored as the new A in register 00 (step 14). This corrects the logic to match the intended algorithm steps.

Quote:We're close. The swap command (X<>Y) in line 11 has the be removed. And thus the comment in line 12 has to be adjusted.

Based on the feedback, here's the corrected excerpt without the swap command (X<>Y) in line 11, and with the adjusted comment in line 12:
Code:
01 LBL "GCD"       ; Label the program GCD
02 STO 01          ; Store second number (already on stack) in register 01
03 STO 00          ; Store first number (now on stack) in register 00
04 LBL 01          ; Loop label
05 RCL 01          ; Recall second number
06 X=0?            ; Check if second number is 0
07 GTO 02          ; If 0, go to label 02
08 RCL 00          ; Recall first number
09 RCL 01          ; Recall second number
10 MOD             ; Calculate remainder of first number divided by second
11 STO 01          ; Store the remainder in register 01 (new B)
12 RDN             ; Roll down the stack
13 STO 00          ; Store the original second number (now on X after RDN) in register 00 (new A)
14 GTO 01          ; Go back to start of loop
15 LBL 02          ; Label for GCD result
16 RCL 00          ; Recall the GCD result
17 PSE             ; Pause to display the GCD
18 RTN             ; Return from the program

Quote:Almost there: we need another RDN command after line 02. Otherwise the second number is also stored in register 00 in line 03.

To ensure the correct order of storing the numbers in the registers and to avoid the second number being stored in both registers, an additional RDN command is needed after line 02. Here's the corrected code:
Code:
01 LBL "GCD"       ; Label the program GCD
02 STO 01          ; Store second number (already on stack) in register 01
03 RDN             ; Roll down the stack
04 STO 00          ; Store first number (now on stack) in register 00
05 LBL 01          ; Loop label
06 RCL 01          ; Recall second number
07 X=0?            ; Check if second number is 0
08 GTO 02          ; If 0, go to label 02
09 RCL 00          ; Recall first number
10 RCL 01          ; Recall second number
11 MOD             ; Calculate remainder of first number divided by second
12 STO 01          ; Store the remainder in register 01 (new B)
13 RDN             ; Roll down the stack
14 STO 00          ; Store the original second number (now on X after RDN) in register 00 (new A)
15 GTO 01          ; Go back to start of loop
16 LBL 02          ; Label for GCD result
17 RCL 00          ; Recall the GCD result
18 PSE             ; Pause to display the GCD
19 RTN             ; Return from the program

Quote:Drop the PSE command in line 18. Replace the RTN command in line 19 by the END command.

Code:
01 LBL "GCD"       ; Label the program GCD
02 STO 01          ; Store second number (already on stack) in register 01
03 RDN             ; Roll down the stack
04 STO 00          ; Store first number (now on stack) in register 00
05 LBL 01          ; Loop label
06 RCL 01          ; Recall second number
07 X=0?            ; Check if second number is 0
08 GTO 02          ; If 0, go to label 02
09 RCL 00          ; Recall first number
10 RCL 01          ; Recall second number
11 MOD             ; Calculate remainder of first number divided by second
12 STO 01          ; Store the remainder in register 01 (new B)
13 RDN             ; Roll down the stack
14 STO 00          ; Store the original second number (now on X after RDN) in register 00 (new A)
15 GTO 01          ; Go back to start of loop
16 LBL 02          ; Label for GCD result
17 RCL 00          ; Recall the GCD result
18 END             ; End of the program

Quote:Perfect. Now I want to test the program. Can you give me two numbers that I could use? And what is the expected result?

You can use the numbers 48 and 18.
The expected result for the Greatest Common Divisor (GCD) of 48 and 18 is 6.
Find all posts by this user
Quote this message in a reply
Post Reply 




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