## ChatGPT

General discussion for topics related to the FreeBASIC project or its community.
deltarho
Posts: 4158
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

### ChatGPT

I had a random integral range returning values in [a,b]. I wanted the minimum and maximum returned.

That seemed simple enough, but I couldn't get any code to work.

I haven't used ChatGPT for months and thought: “What have I a got to lose?”

My logic was wrong.

I initialized min as 0 and max as 500.

What I should have done was to initialize min as 500 and max as 0; the opposite of what I was doing.

That worked.

Fairly obvious really, but as is often the case, the obvious seems to evade us.

Well done ChatGPT. deltarho
Posts: 4158
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

### Re: ChatGPT

Here is my test code:

Code: Select all

``````Function rnd_range (first As Double, last As Double) As Double
Function = Rnd * (last - first) + first
End Function

Randomize
Dim As Ulong x, min=500, max=0
For i as Ulong = 1 to 100
x = Int(rnd_range(1, 101)) ' [1,100]
If x > max Then max = x
If x < min Then min = x
Next
Print min, max
Sleep``````
On six separate runs I got:

Code: Select all

``````6,99
1,100
1,99
2,100
1,98
1,100``````
BasicCoder2
Posts: 3879
Joined: Jan 01, 2009 7:03
Location: Australia

### Re: ChatGPT

You might also say well done to those professional programmers who put the code online that chatGPT is trained on.

A common function returning the max and min that would have been written correctly many times in the thousands(?) of lines of code I assume were used to train ChatGPT?

It may also have been trained on the written explanations on how commonly used code works?

An amazing piece of software but I have a niggling feeling that over time it will be no more amazing then how computers have perfect recall and can search, process and print data using programmed rules faster and more accurately than we can. The main difference as I understand it is ChatGPT uses RNNs and other techniques to learn the rules for transforming inputs into given outputs by trial and error using hill climbing (using back propagation) rather than have a programmer try and figure out how to hard code the rules themselves. They don't figure out the outputs, they predict them based on all the online examples.

At least that is how I understand it from what I have read so far.
deltarho
Posts: 4158
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

### Re: ChatGPT

From what I have read lately about AI there are some very disturbing predictions and many advocates are back tracking at pace. If regulation is not pursued directly, we may find ourselves in very deep water.
BasicCoder2
Posts: 3879
Joined: Jan 01, 2009 7:03
Location: Australia

### Re: ChatGPT

I see they are working out how to use chatGPT to control the real world!
https://www.microsoft.com/en-us/researc ... -robotics/
deltarho
Posts: 4158
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

### Re: ChatGPT

"Have you ever wanted to tell a robot what to do using your own words, like you would to a human? Wouldn’t it be amazing to just tell your home assistant robot: “Please warm up my lunch“, and have it find the microwave by itself?"

It would be amazing in my kitchen – I haven't got a microwave. deltarho
Posts: 4158
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

### Re: ChatGPT

BasicCoder2
Posts: 3879
Joined: Jan 01, 2009 7:03
Location: Australia

### Re: ChatGPT

You have used chatGPT to check your code. That is no different to someone using a spelling or grammar checker. Someone just told me how they used it to improve their job resume. It seems to me to be a useful tool but like any tool AI can be misused. AI might be used to develop a new life saving drug or a deadly virus. It might be used to generate fake news and video to "confirm" the fake news. However at this stage I have seen no evidence of malicious intent or otherwise in such software. If it says humans should be eliminated that is just the internet text written by humans talking. It is the human intelligence that I fear with good historic and current reasons for doing so. That is where I see the danger in AI, its misuse by malicious human beings.
dafhi
Posts: 1623
Joined: Jun 04, 2005 9:51

### Re: ChatGPT

i asked Perplexity.ai (chatgpt backend) to help me factor something and i actually understood : D

Code: Select all

``````Regarding the question about how to simplify n^1 - n^(phys_fps+1), we can factor out n
and simplify the expression as follows:

n^1 - n^(phys_fps+1) = n * (n^0 - n^phys_fps) = n * (1 - n^phys_fps)
``````
though in retrospect i prefer n - n^(fps+1)

but, chatgpt befudged a more complicated equation which i stared at for at least 40 minutes totally confused. i also checked it in fb and indeed the provided solution was incorrect.

beans
Luxan
Posts: 206
Joined: Feb 18, 2009 12:47
Location: New Zealand

### Re: ChatGPT

I've been trying numerous sources to find the integral of sin(sin(x)), including Wolfram Alpha.

ChatGPT suggested the use of Elliptical Integrals as part of the output; after explicitly requesting
this of ChatGPT it returned :

∫sin(sin(x))dx = x - sin(x) + ∑((-1)^(n+1) * (2*n-1)!! / (2^n * n!) * E(sin(x)/2)) + C

Where E() is likely the Elliptical_f() function.

This seems like progress; however I haven't been able to confirm the validity of this result.

As for using AI to translate a large Python file to FreeBasic; for now this is a remote possibility.
Dr_D
Posts: 2448
Joined: May 27, 2005 4:59
Contact:

### Re: ChatGPT

Here's a thing chatgpt made. I had to modify a few things to get it to work, and I added the code to give it a practical test, but it does work "somewhat." Code: Select all

``````#include "fbgfx.bi"

declare sub Rotozoom(src As Any Ptr, dst As Any Ptr, src_width As Integer, src_height As Integer, dst_width As Integer, dst_height As Integer, angle As Double, zoom As Double)

screenres 640,480,32

dim as fb.image ptr temp1 = imagecreate(640,480)
dim as fb.image ptr temp2 = imagecreate(640,480)

for y as integer = 0 to 480

for x as integer = 0 to 640

pset temp1, (x,y), rgb(rnd*255,rnd*255,rnd*255)

next
next

dim as double ang

do

ang+=.1

Rotozoom( temp1, temp2, 640,480,640,480,ang,.1)

screenlock
cls
put(0,0),temp2

screensync
screenunlock

sleep 3,1

loop until multikey(FB.SC_ESCAPE)

Sub Rotozoom(src As Any Ptr, dst As Any Ptr, src_width As Integer, src_height As Integer, dst_width As Integer, dst_height As Integer, angle As Double, zoom As Double)

Dim cx As Double = src_width / 2.0
Dim cy As Double = src_height / 2.0
Dim dst_cx As Double = dst_width / 2.0
Dim dst_cy As Double = dst_height / 2.0
Dim cos_angle As Double = Cos(angle)
Dim sin_angle As Double = Sin(angle)

For dst_y As Integer = 0 To dst_height - 1
For dst_x As Integer = 0 To dst_width - 1
Dim src_x As Double = ((dst_x - dst_cx) / zoom) * cos_angle - ((dst_y - dst_cy) / zoom) * sin_angle + cx
Dim src_y As Double = ((dst_y - dst_cy) / zoom) * cos_angle + ((dst_x - dst_cx) / zoom) * sin_angle + cy

Dim x1 As Integer = Int(src_x)
Dim y1 As Integer = Int(src_y)
Dim x2 As Integer = x1 + 1
Dim y2 As Integer = y1 + 1

Dim x_frac As Double = src_x - x1
Dim y_frac As Double = src_y - y1

If x1 >= 0 And x2 < src_width And y1 >= 0 And y2 < src_height Then
Dim src_ptr1 As Any Ptr = src + (y1 * src_width + x1) * 4
Dim src_ptr2 As Any Ptr = src + (y1 * src_width + x2) * 4
Dim src_ptr3 As Any Ptr = src + (y2 * src_width + x1) * 4
Dim src_ptr4 As Any Ptr = src + (y2 * src_width + x2) * 4

Dim r1 As Byte = peek(src_ptr1)
Dim g1 As Byte = peek(src_ptr1+1)
Dim b1 As Byte = peek(src_ptr1+2)
Dim a1 As Byte = Peek(src_ptr1+3)

Dim r2 As Byte = Peek(src_ptr2)
Dim g2 As Byte = Peek(src_ptr2+1)
Dim b2 As Byte = Peek(src_ptr2+2)
Dim a2 As Byte = Peek(src_ptr2+3)

Dim r3 As Byte = Peek(src_ptr3+0)
Dim g3 As Byte = Peek(src_ptr3+1)
Dim b3 As Byte = Peek(src_ptr3+2)
Dim a3 As Byte = Peek(src_ptr3+3)

Dim r4 As Byte = Peek(src_ptr4)
Dim g4 As Byte = Peek(src_ptr4+1)
Dim b4 As Byte = Peek(src_ptr4+2)
Dim a4 As Byte = Peek(src_ptr4+3)

Dim r As Byte = (1.0 - y_frac) * ((1.0 - x_frac) * r1 + x_frac * r2) + y_frac * ((1.0 - x_frac) * r3 + x_frac * r4)
Dim g As Byte = (1.0 - y_frac) * ((1.0 - x_frac) * g1 + x_frac * g2) + y_frac * ((1.0 - x_frac) * g3 + x_frac * g4)
Dim b As Byte = (1.0 - y_frac) * ((1.0 - x_frac) * b1 + x_frac * b2) + y_frac * ((1.0 - x_frac) * b3 + x_frac * b4)
Dim a As Byte = (1.0 - y_frac) * ((1.0 - x_frac) * a1 + x_frac * a2) + y_frac * ((1.0 - x_frac) * a3 + x_frac * a4)

Dim dst_ptr As Any Ptr = dst + (dst_y * dst_width + dst_x) * 4
poke dst_ptr, r
poke dst_ptr+1, g
poke dst_ptr+2, b
poke dst_ptr+3, a
End If
Next
Next

End sub``````
dafhi
Posts: 1623
Joined: Jun 04, 2005 9:51

### Re: ChatGPT

reminds me of a Game of Life entity
BasicCoder2
Posts: 3879
Joined: Jan 01, 2009 7:03
Location: Australia

### Re: ChatGPT

Dr_D

What was the actual wording of the text question (request?) you gave to chatGPT for it to generate the code?

I modified this section to make it clear what the code was doing.

Code: Select all

``````' ...
line temp1,(280,180)-(380,340),rgb(255,255,0),bf  'draw a rectangle

dim as double ang

do
ang+=.1
Rotozoom( temp1, temp2, 640,480,640,480,ang,.1)
screenlock
cls
put(0,0),temp2,trans
line temp2,(0,0)-(640,480),rgb(255,0,255),bf    'clear destination bitmap
screensync
screenunlock
sleep 30,1
loop until multikey(FB.SC_ESCAPE)

'...
``````
Dr_D
Posts: 2448
Joined: May 27, 2005 4:59
Contact:

### Re: ChatGPT

This was my input, "Write an optimized rotozoom function with sub-pixel accuracy in freebasic that work on 32 bit images only"
And yeah... that was a good idea to make it clear that output image. BasicCoder2 wrote: Aug 01, 2023 4:25 Dr_D

What was the actual wording of the text question (request?) you gave to chatGPT for it to generate the code?

I modified this section to make it clear what the code was doing.

Code: Select all

``````' ...
line temp1,(280,180)-(380,340),rgb(255,255,0),bf  'draw a rectangle

dim as double ang

do
ang+=.1
Rotozoom( temp1, temp2, 640,480,640,480,ang,.1)
screenlock
cls
put(0,0),temp2,trans
line temp2,(0,0)-(640,480),rgb(255,0,255),bf    'clear destination bitmap
screensync
screenunlock
sleep 30,1
loop until multikey(FB.SC_ESCAPE)

'...
``````
dafhi
Posts: 1623
Joined: Jun 04, 2005 9:51

### Re: ChatGPT

i'll probs have a go at this roto