> 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
First evaluate 2 - 3 → -1.Then evaluate 1 - (-1) → 2.
Grok 4.1 Thinking
In the J language, what is -/ 1 2 3?
2
In J, -/ is the insert (reduce) adverb applied to the subtraction verb -. It folds right-to-left over the list: 1 - (2 - 3) = 1 - (-1) = 2. For confirmation, -/ 1 2 3 4 yields -2, matching 1 - (2 - (3 - 4)).
NB. ====================================================================
NB. csv_loader.ijs
NB. A script to load a comma-separated value file into a J boxed table.
NB.
NB. Usage:
NB. load 'csv_loader.ijs'
NB. table =: read_csv 'c:/path/to/mydata.csv'
NB. ====================================================================
NB. Define strictly necessary constants if simpler profile isn't loaded
CR =: 13 { a.
LF =: 10 { a.
NB. --------------------------------------------------------------------
NB. Verb: read_csv
NB. Purpose: Reads a file, splits by lines, then by commas.
NB. Arguments: y = file path (string)
NB. Returns: A rank-2 array of boxes (Result). Data remains strings.
NB. --------------------------------------------------------------------
read_csv =: 3 : 0
NB. 1. Read the file from disk (Chapter 28: Data Files)
NB. fread returns _1 if the file cannot be read.
raw_text =. 1!:1 < y
NB. Check for read errors
if. raw_text -: _1 do.
'Error: Could not read file.' return.
end.
NB. 2. Normalize broken line endings (Chapter 28.3.2: Text Files)
NB. Remove Carriage Returns (CR) to handle Windows format.
clean_text =. raw_text -. CR
NB. Ensure the text ends with a Line Feed (LF) so the Cut command works
NB. on the last line. {: takes the tail (last item).
clean_text =. clean_text , (LF ~: {: clean_text) # LF
NB. 3. Cut text into rows (Chapter 17: Cutting)
NB. <;._2 cuts y based on the last character of y (which is now LF).
NB. It boxes the result and removes the delimiter.
rows =. <;._2 clean_text
NB. 4. Define a local verb to split a single string by comma
NB. We append a comma to the end of the row so ;._2 works properly.
split_by_comma =. 3 : '<;._2 y , '','''
NB. 5. Apply the split verb to Every row (Chapter 25: Each)
NB. &.> is the 'Each' adverb (derived from Under Open).
NB. It applies split_by_comma to the contents of each box in 'rows'.
table_of_lists =. split_by_comma &.> rows
NB. 6. Convert list of lists into a Matrix (Chapter 26: Open)
NB. Monadic > (Open/Mix) turns a list of boxed lists into a table.
NB. If rows have different lengths, J automatically pads with empty boxes.
> table_of_lists
)
NB. A brief demo function (Optional: Usage example)
demo_csv =: 3 : 0
smoutput 'To use this script, type:'
smoutput ' data =: read_csv ''your_file.csv'''
''
)
This cut and pasted into JQt without a problem. It loaded without error. I ran it on a csv file in one of the labs in J:
data =: read_csv '/Applications/j9.7/addons/labs/labs/examples/data/tdata.csv’
it runs and produces a J boxed table with the only problem being the double quote delimiters have been left in place.
I asked the Gemini 3 pro to fix that and got back this:
NB. ====================================================================
NB. csv_loader_v2.ijs
NB. Loads a CSV file into a boxed table and strips enclosing quotes.
NB.
NB. Usage:
NB. load 'csv_loader_v2.ijs'
NB. data =: read_csv 'c:/data/test.csv'
NB. ====================================================================
CR =: 13 { a.
LF =: 10 { a.
Q =: '"' NB. Define the double quote constant
NB. --------------------------------------------------------------------
NB. Verb: strip_quotes
NB. Purpose: Removes the first and last character if they are double quotes.
NB. Used as a helper for read_csv.
NB. --------------------------------------------------------------------
strip_quotes =: 3 : 0
NB. If string is too short (0 or 1 char), return it as is
if. 1 >: #y do. y return. end.
NB. Check if first ({.) and last ({:) characters are quotes
is_quoted =. (Q = {. y) *. (Q = {: y)
if. is_quoted do.
}. }: y NB. }. (Behead/Drop First) and }: (Curtail/Drop Last)
else.
y NB. Return original if not quoted
end.
)
NB. --------------------------------------------------------------------
NB. Verb: read_csv
NB. Purpose: Reads file, splits by LF then comma, then strips quotes.
NB. --------------------------------------------------------------------
read_csv =: 3 : 0
NB. 1. Read file
raw_text =. 1!:1 < y
if. raw_text -: _1 do. 'Error: File not found' return. end.
NB. 2. Normalize line endings (remove CR, ensure final LF)
clean_text =. raw_text -. CR
clean_text =. clean_text , (LF ~: {: clean_text) # LF
NB. 3. Cut into rows
rows =. <;._2 clean_text
NB. 4. Define split verb: split by comma, then apply strip_quotes
NB. We use Each (&.>) so strip_quotes applies to every cell.
NB. Note how we compose operations:
NB. a. Append comma (y,',')
NB. b. Cut (<;._2)
NB. c. Apply strip_quotes to each resulting box (strip_quotes&.>)
split_and_clean =. 3 : 'strip_quotes &.> <;._2 y , '','''
NB. 5. Apply to all rows
table_of_lists =. split_and_clean &.> rows
NB. 6. Open into matrix (handles ragged rows by padding with empty boxes)
> table_of_lists
)
This now runs as you would expect.
Not too bad but probably not a tough J program to complete. But it does show that “context stuffing” may be a way to provide enough information on the J language for the LLM to have a chance at producing correct J code.
Tom McGuire
For gpt-oss you could look for ways to RAG such as
https://github.com/sureshram/gpt-oss-rag because
1. fine-tuning is not necessary, and even with LoRA your hardware is
at most only capable of fine tuning the 20b model. fine-tuning the
120b model need a cluster.
2. there probably isn't enough text material about J for get good result
with fine-tuning.