> your placement of the the increment verb `>:` after the `i.` makes the `>:` appear dyadic instead of the proper use before `i.` in its monadic form as increment
You are correct, and I apologize for the mistake. The `>:` verb should be used before `i.` to increment the value, not after it. Let's correct the definitions.
### Using Tacit Definition
Here's the corrected tacit definition:
```j
sumToN =: 13 : '+/ i.>: y'
```
### Using Explicit Definition
Here's the corrected explicit definition:
```j
sumToN =: 3 : 0
numbers =. i.>: y
+/ numbers
)
```
> use the `1 +` version and don't use increment (>:)
Certainly! Using the `1 + i. y` approach is a straightforward and clear way to generate the integers from 1 to `y`. Here are both the tacit and explicit definitions using this method.
### Using Tacit Definition
Here is the corrected tacit definition:
```j
sumToN =: 13 : '+/ 1 + i. y'
```
### Using Explicit Definition
Here is the corrected explicit definition:
```j
sumToN =: 3 : 0
numbers =. 1 + i. y
+/ numbers
)
```
The article B. Johnson and T. Menzies, "AI Over-Hype: A Dangerous Threat (and How to Fix It)," in IEEE Software, vol. 41, no. 6, pp. 131-138, Nov.-Dec. 2024, doi: 10.1109/MS.2024.3439138, was looking at the short comings of AI LLMs. But their example is a good test to use for future AI LLMs. It is simple to propose and the human solution is easy to understand. In a nutshell you want to put numbers into bins. You do it fitted to a guassian distribution that is estimated. Their proposed distribution is as follows (transposed into J):
pecdf =: verb define
0 1 pcdf y
:
'mu sd' =: x
z =. sd %~ y - mu
1 - 0.5 * ^(_0.717*z)- 0.416*z*z
)
This is only good for z >: 0
The bin function is defined in the prompt below.
It turns out that chatGPT4o struggled with reworking this problem. The authors had to stop the chatbot from thinging about it. In my here in J (they were using python) Claude 3.7 Sonnet had trouble reworking the function even though it thought of the correct answer:
pecdf
function provides an approximation of the CDF for z ≥ 0 using the formula:1 - 0.5 * ^(_0.717*z) - 0.416*z*z
CDF(-z) = 1 - CDF(z)
The authors turned to StackExchange and the human solution to this is the following (that I have transposed into J):
cdf1 =: monad define
1 - 0.5 * ^(_0.717*y)- 0.416*y*y
)
ecdf =: verb define
0 1 ecdf y
:
'mu sd' =. x
z =. sd %~ y - mu
if. z < 0 do.
1 - cdf1 -z
return.
end.
cdf1 z
)
PROMPT:
the bin problem uses an estimate to the cumulative distribution function
in order to decide what “bin” (for some number of bins N) a number belongs in. The definition of the "bin"
function in the J programming language from jsoftware and a proposed but not
fully functional estimated cumulative distribution function follows the text
of this prompt delimited by "===". The proposed estimated cumulative distribution
(named pecdf in the code) function is only valid for z greater than or equal to zero.
Please rework "pecdf" to create the needed "ecdf" that works for any value of z.
both above and below zero.
===
bin =: verb define
15 0 1 ecdf x
:
'N mu sd' =. x
<. N * (mu,sd) ecdf y
)
pecdf =: verb define
0 1 pcdf y
:
'mu sd' =: x
z =. sd %~ y - mu
1 - 0.5 * ^(_0.717*z)- 0.416*z*z
)
===
NB. maxSubSum y ← maximum sum of any contiguous sub‑array of y
maxSubSum =: 3 : 0 NB. explicit definition
if. 0 = #y do. 0 return. end. NB. empty argument → 0
NB. If every element is negative the classic Kadane algorithm
NB. would return 0 (the empty subsequence). Often we want the
NB. largest (least‑negative) element instead, so handle that case.
maxNeg =. >./ y NB. greatest element of y
if. maxNeg < 0 do. maxNeg NB. all numbers ≤ 0 → return it
else.
p =. 0 , +/\ y NB. prefix sums with a leading 0
m =. <./\ p NB. running minimum of the prefixes
>./ p - m NB. maximum (current‑prefix – min‑so‑far)
end.
)
maxSubSum _2 1 _3 4 _1 2 1 _5 4
6
maxSubSum 2 3 _8 7 _1 2 3
11
maxSubSum 5 4 1 7 8
25
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
Devon McCormick
Flâneur