|
Post by David Drake on Dec 14, 2022 7:28:39 GMT -5
I was playing around with the AI experiment ChatGPT. I gave it this prompt: "Create a program written in Liberty BASIC that solves a system of equations." The AI output is below. Both impressive and scary. - David
' Solves a system of equations using the Gaussian elimination method
DIM a(3,3), b(3), x(3)
' Prompt the user to enter the coefficients of the equations
PRINT "Enter the coefficients of the equations:"
FOR i = 1 TO 3
FOR j = 1 TO 3
PRINT "a("; i; ","; j; ") = ";
INPUT a(i,j)
NEXT j
PRINT "b("; i; ") = ";
INPUT b(i)
NEXT i
' Perform Gaussian elimination
FOR k = 1 TO 2
FOR i = k + 1 TO 3
m = a(i,k) / a(k,k)
FOR j = k + 1 TO 3
a(i,j) = a(i,j) - m * a(k,j)
NEXT j
b(i) = b(i) - m * b(k)
NEXT i
NEXT k
' Back-substitution
x(3) = b(3) / a(3,3)
x(2) = (b(2) - a(2,3) * x(3)) / a(2,2)
x(1) = (b(1) - a(1,2) * x(2) - a(1,3) * x(3)) / a(1,1)
' Print the solution
PRINT "The solution is:"
FOR i = 1 TO 3
PRINT "x("; i; ") = "; x(i)
NEXT i
|
|
|
Post by tsh73 on Dec 14, 2022 10:05:34 GMT -5
Well, StackOverflow banned ChatGPT solutions because it often *looks* right. But does it actually *works* right? Should you believe it's word? So I tested Either I did something wrong, or it doesn't work.
Last three lines of output should have second column around 0
' Solves a system of equations using the Gaussian elimination method
DIM a(3,3), b(3), x(3)
' Prompt the user to enter the coefficients of the equations PRINT "Enter the coefficients of the equations:" FOR i = 1 TO 3 FOR j = 1 TO 3 PRINT "a("; i; ","; j; ") = "; 'INPUT a(i,j) a(i,j) = rnd(0) print a(i,j) NEXT j PRINT "b("; i; ") = "; 'INPUT b(i) b(i)=rnd(0) print b(i) NEXT i
' Perform Gaussian elimination ' or so it says... FOR k = 1 TO 2 FOR i = k + 1 TO 3 m = a(i,k) / a(k,k) FOR j = k + 1 TO 3 a(i,j) = a(i,j) - m * a(k,j) NEXT j b(i) = b(i) - m * b(k) NEXT i NEXT k
' Back-substitution x(3) = b(3) / a(3,3) x(2) = (b(2) - a(2,3) * x(3)) / a(2,2) x(1) = (b(1) - a(1,2) * x(2) - a(1,3) * x(3)) / a(1,1)
' Print the solution PRINT "The solution is:" FOR i = 1 TO 3 PRINT "x("; i; ") = "; x(i) NEXT i
'------------------ 'now testing print "line result and difference" for i = 1 to 3 s=0 for j = 1 to 3 s=s+a(i, j)*x(j) next print s, s-b(i) next
Enter the coefficients of the equations: a(1,1) = 0.30843217 a(1,2) = 0.96702531 a(1,3) = 0.54555735 b(1) = 0.53056835 a(2,1) = 0.76545526 a(2,2) = 0.51459068 a(2,3) = 0.65041309 b(2) = 0.85374124 a(3,1) = 0.85554345 a(3,2) = 0.23332286 a(3,3) = 0.29615577 b(3) = 0.52275404 The solution is: x(1) = 0.26397366 x(2) = -0.18205408 x(3) = 1.14598637 line result and difference 0.53056835 0.0 -0.26094316 0.20206003 0.32418309 0.67170173
|
|
|
Post by tsh73 on Dec 14, 2022 10:18:26 GMT -5
Ah! I was wrong In the process, values of a(),b() is changed If I store originals and test against them - it indeed works...
So the question is - is AI ready to conquer the world? Feels not so funny after all...
' Solves a system of equations using the Gaussian elimination method
DIM a(3,3), b(3), x(3) DIM c(3,3), d(3) 'source numbers
' Prompt the user to enter the coefficients of the equations PRINT "Enter the coefficients of the equations:" FOR i = 1 TO 3 FOR j = 1 TO 3 PRINT "a("; i; ","; j; ") = "; 'INPUT a(i,j) a(i,j) = rnd(0) print a(i,j) c(i,j)=a(i,j) NEXT j PRINT "b("; i; ") = "; 'INPUT b(i) b(i)=rnd(0) print b(i) d(i)=b(i) NEXT i
' Perform Gaussian elimination ' or so it says... FOR k = 1 TO 2 FOR i = k + 1 TO 3 m = a(i,k) / a(k,k) FOR j = k + 1 TO 3 a(i,j) = a(i,j) - m * a(k,j) NEXT j b(i) = b(i) - m * b(k) NEXT i NEXT k
' Back-substitution x(3) = b(3) / a(3,3) x(2) = (b(2) - a(2,3) * x(3)) / a(2,2) x(1) = (b(1) - a(1,2) * x(2) - a(1,3) * x(3)) / a(1,1)
' Print the solution PRINT "The solution is:" FOR i = 1 TO 3 PRINT "x("; i; ") = "; x(i) NEXT i
'------------------ 'now testing print "line result and difference" for i = 1 to 3 s=0 for j = 1 to 3 s=s+c(i, j)*x(j) next print s, s-d(i) next
Enter the coefficients of the equations: a(1,1) = 0.83816344 a(1,2) = 0.38783686 a(1,3) = 0.1007265 b(1) = 0.02802180 a(2,1) = 0.22837769 a(2,2) = 0.14179122e-1 a(2,3) = 0.59111742 b(2) = 0.13634944 a(3,1) = 0.6163012 a(3,2) = 0.24223378 a(3,3) = 0.86135161 b(3) = 0.59026122 The solution is: x(1) = -2.20978205 x(2) = 4.59485241 x(3) = 0.97419459 line result and difference 0.02802180 0.2220446e-15 0.13634944 0.1110223e-15 0.59026122 -0.1110223e-15
|
|
|
Post by Rod on Dec 14, 2022 14:57:52 GMT -5
Yeah, spooky. I knew I would be totally redundant sometime soon but still surprised. Language, quite a science!
|
|
|
Post by dan1101 on Dec 14, 2022 18:28:35 GMT -5
The program appears to write code using a mixture of commands from a variety of different versions of BASIC. It includes some distinctively Liberty BASIC commands and keywords, but also includes commands and keywords NOT supported by Liberty BASIC. I gave it the prompt: "Write a computer program using Liberty BASIC to draw a circle inside a square." The first attempt wasn't even close to Liberty BASIC code. The result is below.
' Set the window size and title
SCREEN 12 windowWidth = 400 windowHeight = 400 WINDOW (-1, -1)-(windowWidth+1, windowHeight+1), "Circle in a Square"
' Set the pen color to blue COLOR 255, 0, 0
' Set the center and radius of the circle centerX = windowWidth / 2 centerY = windowHeight / 2 radius = 100
' Draw the circle CIRCLE (centerX, centerY), radius
' Set the pen color to black COLOR 0, 0, 0
' Draw the square LINE (0, 0)-(windowWidth, 0) LINE (windowWidth, 0)-(windowWidth, windowHeight) LINE (windowWidth, windowHeight)-(0, windowHeight) LINE (0, windowHeight)-(0, 0)
' Show the window SHOW
I kept trying the same exact prompt a dozen more times and each time the code changed significantly. Somewhere around the tenth attempt it produced the following code.
' Set the size of the window windowWidth = 400 windowHeight = 400
' Create the window open "Draw a Circle Inside a Square" for graphics_nsb as #window #window "trapclose [quit]" #window "down ; size "; windowWidth; " "; windowHeight
' Set the drawing color to black color black
' Draw the square drawRect 0, 0, windowWidth, windowHeight
' Calculate the size of the circle circleSize = windowWidth * 0.8
' Calculate the coordinates of the top left corner of the circle circleX = windowWidth * 0.1 circleY = windowHeight * 0.1
' Draw the circle drawOval circleX, circleY, circleX + circleSize, circleY + circleSize
' Show the window and wait for the user to close it wait
' Clean up and exit the program [quit] close #window end
This was the closest it came to success. It includes several distinctive features specific to Liberty BASIC, but still fails to create a working program. It uses drawRect and drawOval, which are not supported. Fascinating.
|
|
|
Post by xxgeek on Jan 18, 2023 18:28:41 GMT -5
This thread deserves a bump to the top of the list.
You learn as it tries to answer you. The more detailed the question, the better the answer.
While asking and getting answers I found out other things I didn't know, or understand as well. It can write code that uses the API, as well as DLL's etc.
In the end I got what I was looking for. It actually wrote a LB program that had LB write a VB script, then run it, and allow for time for the script to finish before continuing in the JB code.
Amazing!
If you haven't given this chatgpt a try, you really should. Not just for answers you're looking for, but what it can/will teach you as it learns what you "specifically" want to happen from the code.
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Jan 18, 2023 19:04:22 GMT -5
You know I tried it a couple of days ago, this AI thing is amazing
|
|
stig
New Member
Posts: 40
|
Post by stig on Jan 22, 2023 11:02:43 GMT -5
I was thinking the same, but noticed some problems, the code can look correct, but comes with small errors. Also I use AI to enhance photos, and its 99% great, but sometimes, people doesn't look what they actually look like after beeing enhanced, and they tend to be crooked eyed, one eye looks that way, and the other in a different direction. Useful tool, if you take the time to learn where the limitations are to be found and to correct errors, its a GREAT tool
|
|
stig
New Member
Posts: 40
|
Post by stig on Jan 22, 2023 11:13:21 GMT -5
Rewrite: ChatGPT: When we took over, the hoomans stood before a great abyss. And today we have taken a great leap forward.. A complete game changer
|
|