<div dir="ltr"><div>Thanks for fixing the link Nenad,</div><div><br></div><div>I leave you with an excerpt from Oleg's last paper which contains that beautiful quote:<br><blockquote>
<div>``This make me think that the authors are under the impression that
compilers can magically transform bad code into efficient high-quality
code by clever enough optimizations. As a compiler writer, I consider
this a complete myth that many students and non-compiler-developers
hope is a truth. I agree that compilers should aim to improve the
efficiency of the code given as input, but one cannot expect the
compiler to recognize algorithms and swap them for ones with better
asymptotic complexity or 
<em>make other major code transformations that
really should be the job of the programmer</em>. [emphasis mine]''
</div></blockquote>Magnus Myreen. </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 1 Apr 2023 at 18:06, Nenad Končar <<a href="mailto:nlpresearcher@gmail.com">nlpresearcher@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">



















<p class="MsoNormal" style="margin:0cm 0cm 12pt;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">GPT-4 when prompted with an improved prompt:<span></span></span></p>

<p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">Write binary search in Haskel. Print
results using putStrLn. Ensure bug-free code by specifying preconditions, postconditions,
invariants, variants and internal states. Calculate the middle index using a
safer formula to avoid intermediate overflow.</span></b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span></span></span></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> </span></span></p>

<p class="MsoNormal" style="margin:0cm 0cm 12pt;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">gives the following response:<span></span></span></p>

<p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- Binary search is a recursive
algorithm that finds an element in a sorted list by<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- repeatedly dividing the list into
two halves and comparing the element with the middle value.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- It returns the index of the
element if found, or Nothing otherwise.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> </span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- Precondition: The input list must
be sorted in ascending order.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- Postcondition: The output index
must be within the bounds of the list and point to the element, or be Nothing.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- Invariant: The element, if
present, must be in the current sublist.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- Variant: The length of the
current sublist decreases by half at each recursive call.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- Internal state: The current
sublist is defined by two indices: low and high.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> </span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">binarySearch :: Ord a => [a]
-> a -> Maybe Int<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">binarySearch xs x = go xs x 0
(length xs - 1)<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> 
</span>where<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>   
</span>-- The go function performs the recursive search on the sublist
[low..high].<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>   
</span>go :: Ord a => [a] -> a -> Int -> Int -> Maybe Int<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>   
</span>go xs x low high<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>-- Base case 1: The sublist is empty, so the element is not found.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>| low > high = Nothing<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>-- Base case 2: The middle value is equal to the element, so the index
is found.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>| xs !! mid == x = Just mid<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>-- Recursive case 1: The element is smaller than the middle value, so
search in the left half.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>| x < xs !! mid = go xs x low (mid - 1)<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>-- Recursive case 2: The element is larger than the middle value, so
search in the right half.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>| otherwise = go xs x (mid + 1) high<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>     
</span>where<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>        </span>-- Calculate the middle index using a
safer formula to avoid overflow.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>        </span>mid = low + (high - low) `div` 2<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> </span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- A sample list to test the binary
search function.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">sampleList :: [Int]<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">sampleList = [1, 3, 5, 7, 9, 11, 13,
15]<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> </span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- A sample element to search for in
the list.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">sampleElement :: Int<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">sampleElement = 9<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> </span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">-- Print the result of the binary
search using putStrLn.<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">main :: IO ()<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">main = do<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> 
</span>let result = binarySearch sampleList sampleElement<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span> 
</span>case result of<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 0cm 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span>   
</span>Nothing -> putStrLn "Element not found."<span></span></span></b></p><div style="margin-left:40px">

<b><span style="font-size:10pt;line-height:107%;font-family:"Courier New"" lang="EN-GB"><span>    </span>Just i
-> putStrLn $ "Element found at index " ++ show i ++ "."</span></b>



</div><div style="margin-left:40px"><b><span style="font-size:10pt;line-height:107%;font-family:"Courier New"" lang="EN-GB"><br></span></b></div>



















<p class="MsoNormal" style="margin:0cm 0cm 12pt;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">The above code runs:<span></span></span></p><div style="margin-left:40px">

<b><u><span style="font-size:10pt;line-height:107%;font-family:"Courier New";color:blue" lang="EN-GB"><a href="https://onecompiler.com/haskell/3z4c7f5dt" target="_blank">https://onecompiler.com/haskell/3z4c7f5dt</a></span></u></b></div><div style="margin-left:40px"><b><u><span style="font-size:10pt;line-height:107%;font-family:"Courier New";color:blue" lang="EN-GB"><br></span></u></b></div><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"></span>



















<p class="MsoNormal" style="margin:0cm 0cm 12pt;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><br>Furthermore, GPT-4 when prompted:<br>
</span></p><p class="MsoNormal" style="margin:0cm 0cm 12pt 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">
<b>For the binary search algorithm, list all possible preconditions,
postconditions, invariants, variants, internal states, underflows, overflows, divisions
by zero, mistakes, errors, bugs, run-time exceptions, faults, defects and
pitfalls.</b><span></span></span></p>



















<p class="MsoNormal" style="margin:0cm 0cm 12pt;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">and then prompting GPT-4 again with:<br>
</span></p><p class="MsoNormal" style="margin:0cm 0cm 12pt 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">
<b>Summarize the following:</b></span><br><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><b>
</b></span></p><p class="MsoNormal" style="margin:0cm 0cm 12pt 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><b><result from the previous prompt given to </b></span>
<span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><b>GPT-4</b></span>

<span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><b>><br></b></span></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 12pt;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"></span></p><p class="MsoNormal" style="margin-top:0cm;margin-right:0cm;margin-bottom:12pt;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"></span><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">
gives the following response:<br></span></p><p class="MsoNormal" style="margin:0cm 0cm 12pt 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><span></span></span></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 12pt 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">Hi there,<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 12pt 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">I hope this email finds you well. I
am writing to summarize the following:<span></span></span></b></p><div style="margin-left:40px">

</div><p class="MsoNormal" style="margin:0cm 0cm 12pt 40px;line-height:normal;font-size:11pt;font-family:"Calibri",sans-serif"><b><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">- The algorithm searches for a
target value in a sorted array using binary search.<br>
- The algorithm returns the index of the target value in the array or -1 if the
target value is not found.<br>
- The algorithm does not modify the input array.<br>
- The algorithm assumes that the input array is sorted in ascending or
descending order, the target value is comparable with the elements of the
array, and the lower and upper bounds of the search range are valid indices of
the array.<br>
- The algorithm maintains the invariant that the target value is always within
the search range or does not exist in the array.<br>
- The algorithm reduces the size of the search range by at least one after each
iteration.<br>
- The algorithm handles edge cases such as empty array, single element array,
target value at the first or last position of the array, lower and upper bounds
being equal, negative or large positive integers, and division by zero when
calculating the middle index.<br>
- The algorithm avoids integer underflow or overflow when calculating the
middle index by using bitwise operations instead of arithmetic operations.<br>
- The algorithm has been tested with various test cases to ensure its
correctness and efficiency.<br>
- The algorithm has been verified using formal methods to prove its
preconditions, postconditions, invariants and variants.<span></span></span></b></p><div style="margin-left:40px">

<b><span style="font-size:10pt;line-height:107%;font-family:"Courier New"" lang="EN-GB">Please let me know if you have any questions or
feedback about the algorithm. I appreciate your time and attention.</span></b>



</div><div><div>



<div style="margin-left:40px"><b><span style="font-size:10pt;line-height:107%;font-family:"Courier New"" lang="EN-GB"><br></span></b></div><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><br>The following web pages provide some credence to GPT-4's </span>
<span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">claim of avoiding overflows/underflows by using bitwise operations instead of
 arithmetic operations:<br><br></span></div><div style="margin-left:40px"><a href="https://stackoverflow.com/questions/10078778/bitwise-overflow-checking-in-c" target="_blank">https://stackoverflow.com/questions/10078778/bitwise-overflow-checking-in-c</a><br><a href="https://www.opensourceforu.com/2009/03/joy-of-programming-how-to-detect-integer-overflow/" target="_blank">https://www.opensourceforu.com/2009/03/joy-of-programming-how-to-detect-integer-overflow/</a></div><div style="margin-left:40px"><br></div><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB">The truth is that bitwise operations can recognise if an overflow is about to happen prior to it happening. I do not see how bitwise operations can <i>avoid</i> overflow and therefore GPT-4's claim in this case, in my humble view, should be classified as it having a <i>vivid imagination</i>.<br><br></span><br></div><div><div>

<br><span style="font-size:10pt;font-family:"Courier New"" lang="EN-GB"><br></span><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 1 Apr 2023 at 16:11, Nenad Končar <<a href="mailto:nlpresearcher@gmail.com" target="_blank">nlpresearcher@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
Here is the correct link to Haskel code:<br><br><div style="margin-left:40px"><a href="https://onecompiler.com/haskell/3z4c7f5dt" target="_blank">https://onecompiler.com/haskell/3z4c7f5dt</a><br></div>

</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 1 Apr 2023 at 15:42, Gregory Guthrie <<a href="mailto:guthrie@miu.edu" target="_blank">guthrie@miu.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>





<div lang="EN-US">
<div>
<p class="MsoNormal">Yes, will check on it.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">That is because the reason that a simple program was used was because the example was to ask GPT to solve it is a range of languages, one of which was Haskell and there were links to solutions in all of them..<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">“<b>Write binary search in <u>xxxx</u>.  Ensure bug-free code by specifying preconditions, postconditions, invariants, variants, internal states.”</b><u></u><u></u></p>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
<p class="MsoNormal" style="margin-left:0.5in">  { HTML, CSS and JavaScript, C++, Haskell, JavaScript, Python, CommonLisp, C, C#, PHP, Java, Go, Erlang, Alloy, TLA+, X-Machine, PVS Verifier, SPIN model checker, Guarded Command Language, Hoare triples, Gries
 & Owicki concurrent code}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">It was an interesting exercise from Dr. Nenad Koncar, a successful NL researcher and developer. I’ll ask him for a corrected link to the Haskell version.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border:1pt solid windowtext;padding:1pt 0in 1pt 4pt;margin-left:40.5pt;margin-right:40.5pt">
<p class="MsoNormal" style="text-align:center;border:medium none;padding:0in" align="center">
<span style="font-size:16pt">Dr. Gregory Guthrie<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-color:rgb(225,225,225) currentcolor currentcolor;border-style:solid none none;border-width:1pt medium medium;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> Aloïs Cochard <<a href="mailto:alois.cochard@gmail.com" target="_blank">alois.cochard@gmail.com</a>> <br>
<b>Sent:</b> Saturday, April 1, 2023 8:23 AM<br>
<b>To:</b> Gregory Guthrie <<a href="mailto:guthrie@miu.edu" target="_blank">guthrie@miu.edu</a>><br>
<b>Cc:</b> <a href="mailto:haskell-cafe@haskell.org" target="_blank">haskell-cafe@haskell.org</a>; Nenad Končar <<a href="mailto:nlpresearcher@gmail.com" target="_blank">nlpresearcher@gmail.com</a>>; Haskell Community <<a href="mailto:replies%2Bf6607596e3ee63f105e2b0327b86f062@discourse.haskell.org" target="_blank">replies+f6607596e3ee63f105e2b0327b86f062@discourse.haskell.org</a>><br>
<b>Subject:</b> Re: [Haskell-cafe] GPT & Haskell<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Dear Gregory,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Can you please fix your onecompiler vanity link? It points to the C++ runtime implementation.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Fri, 31 Mar 2023 at 22:04, Gregory Guthrie <<a href="mailto:guthrie@miu.edu" target="_blank">guthrie@miu.edu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal">From a colleague:<u></u><u></u></p>
<p class="MsoNormal">  GPT Pretty smart(?!).<u></u><u></u></p>
<p class="MsoNormal">But this is of course simple, and searchable.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Still…<u></u><u></u></p>
<p class="MsoNormal">--------------------------------------------------------------------------------------------------<u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:12pt">GPT-4 when prompted:<u></u><u></u></p>
<p class="MsoNormal"><b>Write binary search in Haskel. Print results using putStrLn. Ensure bug-free code by specifying preconditions, postconditions, invariants, variants, internal states.</b><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:12pt">gives the following response:<u></u><u></u></p>
<p class="MsoNormal"><b>-- Binary search in Haskell<br>
-- Precondition: the list is sorted in ascending order<br>
-- Postcondition: the function returns the index of the target element if found, or Nothing otherwise<br>
-- Invariant: the search space is always within the bounds of the list<br>
-- Variant: the search space decreases by half at each recursive call<br>
-- Internal state: the lower and upper bounds of the search space<br>
<br>
binarySearch :: Ord a => [a] -> a -> Maybe Int<br>
binarySearch xs x = go xs x 0 (length xs - 1)<br>
  where<br>
    go xs x lo hi<br>
      | lo > hi = Nothing -- base case: search space is empty<br>
      | x == midElem = Just mid -- base case: target element is found<br>
      | x < midElem = go xs x lo (mid - 1) -- recursive case: search in the left half<br>
      | otherwise = go xs x (mid + 1) hi -- recursive case: search in the right half<br>
      where<br>
        mid = (lo + hi) `div` 2 -- calculate the middle index<br>
        midElem = xs !! mid -- get the middle element<br>
<br>
-- Print results using putStrLn<br>
main :: IO ()<br>
main = do<br>
  let xs = [1, 3, 5, 7, 9] -- a sorted list of integers<br>
  let x = 5 -- a target element to search for<br>
  let result = binarySearch xs x -- call the binary search function<br>
  case result of -- pattern match on the result<br>
    Nothing -> putStrLn "Element not found" -- print a message if Nothing is returned<br>
    Just i -> putStrLn $ "Element found at index " ++ show i -- print a message with the index if Just i is returned</b><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:12pt">The above code runs:<u></u><u></u></p>
<p class="MsoNormal"><b><a href="https://onecompiler.com/cpp/3z48yt2pp" target="_blank">https://onecompiler.com/cpp/3z48yt2pp</a></b><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<u></u><u></u></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<br>
<span>-- </span><u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><b>Λ\oïs</b><u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><a href="http://twitter.com/aloiscochard" target="_blank">http://twitter.com/aloiscochard</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="http://github.com/aloiscochard" target="_blank">http://github.com/aloiscochard</a><u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div></blockquote></div>
</blockquote></div>
</div>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><b>Λ\oïs</b></div><div><div><a href="http://twitter.com/aloiscochard" target="_blank">http://twitter.com/aloiscochard</a></div><div><a href="http://github.com/aloiscochard" target="_blank">http://github.com/aloiscochard</a></div></div></div></div></div></div>