Recent

Author Topic: Can /my/ AI help me with pascal coding?  (Read 7008 times)

440bx

  • Hero Member
  • *****
  • Posts: 6542
Re: Can /my/ AI help me with pascal coding?
« Reply #45 on: May 13, 2026, 07:28:37 pm »
fixing FPC bugs is definitely worth a vote, consider this mine for that too.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

microxa

  • New Member
  • *
  • Posts: 27
Re: Can /my/ AI help me with pascal coding?
« Reply #46 on: May 15, 2026, 10:21:48 pm »
A hello ANN made by gemini 1.5 Pro , just from briwser

Code: Pascal  [Select][+][-]
  1. program XOR_ANN;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   System.SysUtils, System.Math;
  7.  
  8. const
  9.   LEARNING_RATE = 0.5;
  10.   EPOCHS        = 20000;
  11.  
  12. type
  13.   TANN = record
  14.     // Веса: Индекс 1 -> Вход, Индекс 2 -> Нейрон
  15.     W_Input_Hidden: array[0..2, 0..1] of Double; // [Вход + Смещение, Нейрон]
  16.     W_Hidden_Output: array[0..2] of Double;      // [Нейрон + Смещение]
  17.    
  18.     // Выходы слоев
  19.     Hidden_Out: array[0..1] of Double;
  20.     Output_Out: Double;
  21.   end;
  22.  
  23. // Сигмоидная функция активации и ее производная
  24. function Sigmoid(X: Double): Double;
  25. begin
  26.   Result := 1.0 / (1.0 + Exp(-X));
  27. end;
  28.  
  29. function SigmoidDerivative(SigmoidVal: Double): Double;
  30. begin
  31.   Result := SigmoidVal * (1.0 - SigmoidVal);
  32. end;
  33.  
  34. // Инициализация случайными весами от -1.0 до 1.0
  35. procedure InitNetwork(var Net: TANN);
  36. var
  37.   i, j: Integer;
  38. begin
  39.   Randomize;
  40.   for i := 0 to 2 do
  41.     for j := 0 to 1 do
  42.       Net.W_Input_Hidden[i, j] := (Random * 2.0) - 1.0;
  43.  
  44.   for i := 0 to 2 do
  45.     Net.W_Hidden_Output[i] := (Random * 2.0) - 1.0;
  46. end;
  47.  
  48. // Прямой проход (Forward Pass)
  49. procedure ForwardPass(var Net: TANN; In1, In2: Double);
  50. var
  51.   j: Integer;
  52.   Sum: Double;
  53. begin
  54.   // Скрытый слой (включая смещение Bias как входной индекс 2 со значением 1.0)
  55.   for j := 0 to 1 do
  56.   begin
  57.     Sum := (In1 * Net.W_Input_Hidden[0, j]) +
  58.            (In2 * Net.W_Input_Hidden[1, j]) +
  59.            (1.0 * Net.W_Input_Hidden[2, j]);
  60.     Net.Hidden_Out[j] := Sigmoid(Sum);
  61.   end;
  62.  
  63.   // Выходной слой (включая смещение Bias скрытого слоя как индекс 2 со значением 1.0)
  64.   Sum := (Net.Hidden_Out[0] * Net.W_Hidden_Output[0]) +
  65.          (Net.Hidden_Out[1] * Net.W_Hidden_Output[1]) +
  66.          (1.0 * Net.W_Hidden_Output[2]);
  67.   Net.Output_Out := Sigmoid(Sum);
  68. end;
  69.  
  70. // Обратное распространение (Backpropagation)
  71. procedure Train(var Net: TANN; In1, In2, Target: Double);
  72. var
  73.   Out_Delta: Double;
  74.   Hidden_Delta: array[0..1] of Double;
  75.   j, i: Integer;
  76. begin
  77.   // 1. Расчет ошибки выходного слоя
  78.   Out_Delta := (Target - Net.Output_Out) * SigmoidDerivative(Net.Output_Out);
  79.  
  80.   // 2. Расчет ошибки скрытого слоя
  81.   for j := 0 to 1 do
  82.     Hidden_Delta[j] := (Out_Delta * Net.W_Hidden_Output[j]) * SigmoidDerivative(Net.Hidden_Out[j]);
  83.  
  84.   // 3. Корректировка весов выходного слоя
  85.   Net.W_Hidden_Output[0] := Net.W_Hidden_Output[0] + (LEARNING_RATE * Out_Delta * Net.Hidden_Out[0]);
  86.   Net.W_Hidden_Output[1] := Net.W_Hidden_Output[1] + (LEARNING_RATE * Out_Delta * Net.Hidden_Out[1]);
  87.   Net.W_Hidden_Output[2] := Net.W_Hidden_Output[2] + (LEARNING_RATE * Out_Delta * 1.0); // Смещение
  88.  
  89.   // 4. Корректировка весов скрытого слоя
  90.   for j := 0 to 1 do
  91.   begin
  92.     Net.W_Input_Hidden[0, j] := Net.W_Input_Hidden[0, j] + (LEARNING_RATE * Hidden_Delta[j] * In1);
  93.     Net.W_Input_Hidden[1, j] := Net.W_Input_Hidden[1, j] + (LEARNING_RATE * Hidden_Delta[j] * In2);
  94.     Net.W_Input_Hidden[2, j] := Net.W_Input_Hidden[2, j] + (LEARNING_RATE * Hidden_Delta[j] * 1.0); // Смещение
  95.   end;
  96. end;
  97.  
  98. var
  99.   Net: TANN;
  100.   Epoch, i: Integer;
  101.   // Набор данных XOR: Вход1, Вход2, Ожидаемый результат
  102.   XOR_Inputs: array[0..3, 0..1] of Double = ((0,0), (0,1), (1,0), (1,1));
  103.   XOR_Targets: array[0..3] of Double = (0, 1, 1, 0);
  104.  
  105. begin
  106.   try
  107.     InitNetwork(Net);
  108.     Writeln('Training...');
  109.  
  110.     // Цикл обучения
  111.     for Epoch := 1 to EPOCHS do
  112.     begin
  113.       for i := 0 to 3 do
  114.       begin
  115.         ForwardPass(Net, XOR_Inputs[i, 0], XOR_Inputs[i, 1]);
  116.         Train(Net, XOR_Inputs[i, 0], XOR_Inputs[i, 1], XOR_Targets[i]);
  117.       end;
  118.     end;
  119.  
  120.     Writeln('Testing results:');
  121.     for i := 0 to 3 do
  122.     begin
  123.       ForwardPass(Net, XOR_Inputs[i, 0], XOR_Inputs[i, 1]);
  124.       Writeln(Format('In: %.0f, %.0f -> Predicted: %.4f (Expected: %.0f)',
  125.         [XOR_Inputs[i, 0], XOR_Inputs[i, 1], Net.Output_Out, XOR_Targets[i]]));
  126.     end;
  127.  
  128.     Readln;
  129.   except
  130.     on E: Exception do
  131.       Writeln(E.ClassName, ': ', E.Message);
  132.   end;
  133. end.
  134.  

microxa

  • New Member
  • *
  • Posts: 27
Re: Can /my/ AI help me with pascal coding?
« Reply #47 on: May 16, 2026, 03:51:48 pm »

However, superb-high optimization still has to be done manually, something like this:
Code: Pascal  [Select][+][-]
  1. //Lucky ReLU
  2. function Act_ReLU_SSE(X: Single): Single;
  3. begin
  4.   if 0 < x then x := x else x := x * 0.01;
  5.   if 1 < x then x := 1;
  6.   result := x;
  7. end;
  8.  
  9. function Back_ReLU_SSE(X: Single): Single;
  10. begin
  11.   if x <= 0 then x := 1;
  12.   if 1 <= x then x := 0.01 else x := 1;
  13.   result := x;
  14. end;
  15.  

schuler

  • Sr. Member
  • ****
  • Posts: 351
Re: Can /my/ AI help me with pascal coding?
« Reply #48 on: May 18, 2026, 03:02:09 am »
Cool, quite a job right? Nice to see progress =^

Indeed!

This is to share an experiment with pas-sqlite:
Code: Pascal  [Select][+][-]
  1. pas-sqlite3/bin$ ./passqlite3
  2. sqlite> .mode box
  3. sqlite> create table tbl1(one text, two int);
  4. sqlite> insert into tbl1 values('hello!',10),('goodbye',20);
  5. sqlite> insert into tbl1 values('hello!',10),('goodbye',20);
  6. sqlite> select * from tbl1;
  7. ╭─────────┬─────╮
  8. │   one   │ two │
  9. ╞═════════╪═════╡
  10. │ hello!  │  10
  11. │ goodbye │  20
  12. │ hello!  │  10
  13. │ goodbye │  20
  14. ╰─────────┴─────╯
  15. sqlite> create table tbl3 as select * from tbl1;
  16. sqlite> select * from tbl3;
  17. ╭─────────┬─────╮
  18. │   one   │ two │
  19. ╞═════════╪═════╡
  20. │ hello!  │  10
  21. │ goodbye │  20
  22. │ hello!  │  10
  23. │ goodbye │  20
  24. ╰─────────┴─────╯
  25. sqlite> create table tbl2(one text, two int);
  26. sqlite> select * from tbl1, tbl2;
  27. sqlite> insert into tbl2 values ('nada',15);
  28. sqlite> select * from tbl1, tbl2;
  29. ╭─────────┬─────┬──────┬─────╮
  30. │   one   │ two │ one  │ two │
  31. ╞═════════╪═════╪══════╪═════╡
  32. │ hello!  │  10 │ nada │  15
  33. │ goodbye │  20 │ nada │  15
  34. │ hello!  │  10 │ nada │  15
  35. │ goodbye │  20 │ nada │  15
  36. ╰─────────┴─────┴──────┴─────╯
  37. sqlite> insert into tbl2 values ('nada',20);
  38. sqlite> select * from tbl1, tbl2 where tbl1.two = tbl2.two;
  39. ╭─────────┬─────┬──────┬─────╮
  40. │   one   │ two │ one  │ two │
  41. ╞═════════╪═════╪══════╪═════╡
  42. │ goodbye │  20 │ nada │  20
  43. │ goodbye │  20 │ nada │  20
  44. ╰─────────┴─────┴──────┴─────╯
  45. sqlite> select count(*) from (select * from tbl1) as tbx;
  46. ╭──────────╮
  47. │ count(*)
  48. ╞══════════╡
  49. │        4
  50. ╰──────────╯
  51. sqlite> create index x on tbl1 (two);
  52. sqlite> select one, sum(two) from tbl1 group by one;
  53. ╭─────────┬──────────╮
  54. │   one   │ sum(two)
  55. ╞═════════╪══════════╡
  56. │ goodbye │       40
  57. │ hello!  │       20
  58. ╰─────────┴──────────╯
  59. sqlite> select one, sum(two) from tbl1 group by two;
  60. ╭─────────┬──────────╮
  61. │   one   │ sum(two)
  62. ╞═════════╪══════════╡
  63. │ hello!  │       20
  64. │ goodbye │       40
  65. ╰─────────┴──────────╯
  66. sqlite> select one, sum(two) from tbl1 group by one order by one;
  67. ╭─────────┬──────────╮
  68. │   one   │ sum(two)
  69. ╞═════════╪══════════╡
  70. │ goodbye │       40
  71. │ hello!  │       20
  72. ╰─────────┴──────────╯
  73. sqlite> select one, sum(two) from tbl1 group by two order by one;
  74. ╭─────────┬──────────╮
  75. │   one   │ sum(two)
  76. ╞═════════╪══════════╡
  77. │ goodbye │       40
  78. │ hello!  │       20
  79. ╰─────────┴──────────╯
  80. sqlite> explain select * from tbl1;
  81. ╭──────┬─────────────┬────┬────┬─────┬───────────┬────┬─────────╮
  82. │ addr │   opcode    │ p1 │ p2 │ p3  │    p4     │ p5 │ comment │
  83. ╞══════╪═════════════╪════╪════╪═════╪═══════════╪════╪═════════╡
  84. │    0 │ Init        │  0 │  9 │   0 │           │  0 │         │
  85. │    1 │ OpenRead    │  0 │  2 │   02         │  0 │         │
  86. │    2 │ Explain     │  2 │  0216 │ SCAN tbl1 │  0 │         │
  87. │    3 │ Rewind      │  0 │  8 │   0 │           │  0 │         │
  88. │    4 │ Column      │  0 │  0 │   1 │           │  0 │         │
  89. │    5 │ Column      │  0 │  1 │   2 │           │  0 │         │
  90. │    6 │ ResultRow   │  1 │  2 │   0 │           │  0 │         │
  91. │    7 │ Next        │  0 │  4 │   0 │           │  1 │         │
  92. │    8 │ Halt        │  0 │  0 │   0 │           │  0 │         │
  93. │    9 │ Transaction │  0 │  0 │   40         │  1 │         │
  94. │   10Goto        │  0 │  1 │   0 │           │  0 │         │
  95. ╰──────┴─────────────┴────┴────┴─────┴───────────┴────┴─────────╯

:) I wish happy pascal coding to both human and artificial minds :)
« Last Edit: May 18, 2026, 03:18:37 am by schuler »

schuler

  • Sr. Member
  • ****
  • Posts: 351
Re: Can /my/ AI help me with pascal coding?
« Reply #49 on: May 18, 2026, 03:08:23 am »
A hello ANN made by gemini 1.5 Pro , just from briwser

@microxa, it is an interesting feeling to be able to see the magic with few lines of code - it isn't?

microxa

  • New Member
  • *
  • Posts: 27
Re: Can /my/ AI help me with pascal coding?
« Reply #50 on: May 18, 2026, 01:16:57 pm »
schuler
Oh yes, the magic of floating point...

For me, though, it's more of a game of squeezing computational performance out of old processors.

Gemini is quite adept at VCL coding as well (unlike me). But when refining the MNIST 'hello world' example with a simple Paint on TImage, I really had to work hard to extract the necessary solutions from it.

microxa

  • New Member
  • *
  • Posts: 27
Re: Can /my/ AI help me with pascal coding?
« Reply #51 on: May 20, 2026, 06:25:26 am »
> Another helloworld, from ai hell… 

> For testing the ann engine with momentum — I wanted a bit more than XOR — I wanted a single‑celled AMEBA from Life. Well, Gemini did its best… whoa...

Code: Pascal  [Select][+][-]
  1. 
  2. {$apptype console}
  3. program AnnLifeTrinity;
  4.  
  5. uses
  6.   SysUtils, Math, CRT;
  7.  
  8. const
  9.   nEpochs = 500;
  10.   Alpha = 0.9;  
  11.  
  12.   WIDTH  = 28;
  13.   HEIGHT = 28;
  14.   SIZE   = WIDTH * HEIGHT;
  15.  
  16.   nInp  = 9;
  17.   nHid  = 2;
  18.   nOut  = 1;  
  19.  
  20.   RULES_COUNT = 512;
  21.  
  22. type
  23.   TLifeField = array[1..SIZE] of Byte;
  24.  
  25.   TInputs     = array[1..nInp] of Single;
  26.   TDataSample = record
  27.     Inputs: TInputs;
  28.     Output: Single;
  29.   end;
  30.   TDataset    = array[0..RULES_COUNT - 1] of TDataSample;
  31.  
  32. var
  33.   CurrentField, NextField: TLifeField;
  34.  
  35.   InL: Array [1 .. nInp] of Single;
  36.   HL1: Array [1 .. nHid] of Single;
  37.   OutL: Array [1 .. nOut] of Single;
  38.  
  39.   // Веса связей (Минус один слой!)
  40.   W0: Array [1 .. nInp, 1 .. nHid] of Single;
  41.   W1: Array [1 .. nHid, 1 .. nOut] of Single;
  42.  
  43.   // Смещения (Bias) для двух слоев
  44.   B0: Array [1 .. nHid] of Single;
  45.   B1: Array [1 .. nOut] of Single;
  46.  
  47.   // Скорости моментума для весов
  48.   vW0: Array [1 .. nInp, 1 .. nHid] of Single;
  49.   vW1: Array [1 .. nHid, 1 .. nOut] of Single;
  50.  
  51.   // Скорости моментума для смещений
  52.   vB0: Array [1 .. nHid] of Single;
  53.   vB1: Array [1 .. nOut] of Single;
  54.  
  55.   ErrHL1: Array [1 .. nHid] of Single;
  56.   ErrOut: Array [1 .. nOut] of Single;
  57.  
  58.   Etalon: Array [1 .. nOut] of Single;
  59.  
  60.   Dataset : TDataset;
  61.  
  62. function Tanh(X: Single): Single;
  63. begin
  64.   if X > 15.0 then Exit(1.0);
  65.   if X < -15.0 then Exit(-1.0);
  66.   Result := (Exp(2 * X) - 1) / (Exp(2 * X) + 1);
  67. end;
  68.  
  69. function DifTanh(X: Single): Single;
  70. begin
  71.   Result := 1.0 - X * X;
  72. end;
  73.  
  74. procedure Calculate;
  75. var
  76.   i, j: Integer;
  77.   Sum: Single;
  78. begin
  79.   // Вход -> Скрытый слой (с учетом Bias B0)
  80.   for j := 1 to nHid do
  81.   begin
  82.     Sum := B0[j];
  83.     for i := 1 to nInp do
  84.       Sum := Sum + W0[i, j] * InL[i];
  85.     HL1[j] := Tanh(Sum);
  86.   end;
  87.  
  88.   // Скрытый слой -> Выход (с учетом Bias B1)
  89.   for j := 1 to nOut do
  90.   begin
  91.     Sum := B1[j];
  92.     for i := 1 to nHid do
  93.       Sum := Sum + W1[i, j] * HL1[i];
  94.     OutL[j] := Tanh(Sum);
  95.   end;
  96. end;
  97.  
  98. procedure FindError;
  99. var
  100.   i, j: Integer;
  101.   Sum: Single;
  102. end;
  103. begin
  104.   // Ошибка выходного слоя
  105.   for i := 1 to nOut do
  106.     ErrOut[i] := (Etalon[i] - OutL[i]) * DifTanh(OutL[i]);
  107.  
  108.   // Ошибка скрытого слоя (упрощенный проход назад)
  109.   for i := 1 to nHid do
  110.   begin
  111.     Sum := 0;
  112.     for j := 1 to nOut do
  113.       Sum := Sum + W1[i, j] * ErrOut[j];
  114.     ErrHL1[i] := Sum * DifTanh(HL1[i]);
  115.   end;
  116. end;
  117.  
  118. procedure Learn(Rate: Single);
  119. var
  120.   i, j: Integer;
  121. begin
  122.   // Обновление весов Скрытый -> Выход (с моментумом)
  123.   for i := 1 to nHid do
  124.     for j := 1 to nOut do
  125.     begin
  126.       vW1[i, j] := Alpha * vW1[i, j] + Rate * HL1[i] * ErrOut[j];
  127.       W1[i, j]  := W1[i, j] + vW1[i, j];
  128.     end;
  129.   for j := 1 to nOut do
  130.   begin
  131.     vB1[j] := Alpha * vB1[j] + Rate * 1.0 * ErrOut[j];
  132.     B1[j]  := B1[j] + vB1[j];
  133.   end;
  134.  
  135.   // Обновление весов Вход -> Скрытый (БЕЗ моментума для W0 по твоему методу!)
  136.   for i := 1 to nInp do
  137.     for j := 1 to nHid do
  138.     begin
  139.       W0[i, j] := W0[i, j] + Rate * InL[i] * ErrHL1[j];
  140.     end;
  141.   // Смещения первого слоя обновляем с моментумом для стабильности порогов
  142.   for j := 1 to nHid do
  143.   begin
  144.     vB0[j] := Alpha * vB0[j] + Rate * 1.0 * ErrHL1[j];
  145.     B0[j]  := B0[j] + vB0[j];
  146.   end;
  147. end;
  148.  
  149. procedure InitWeights;
  150. var
  151.   i, j: Integer;
  152. begin
  153.   // Зануляем скорости
  154.   FillChar(vW0, SizeOf(vW0), 0); FillChar(vW1, SizeOf(vW1), 0);
  155.   FillChar(vB0, SizeOf(vB0), 0); FillChar(vB1, SizeOf(vB1), 0);
  156.  
  157.   // Твой гениальный хак: Входной слой ЖЕСТКО ОБНУЛЯЕМ на старте!
  158.   for i := 1 to nInp do
  159.     for j := 1 to nHid do
  160.       W0[i, j] := 0.0;
  161.  
  162.   // Выходной слой инициализируем мелким Ксавьером
  163.   for i := 1 to nHid do
  164.     for j := 1 to nOut do
  165.       W1[i, j] := (Random(2001) - 1000) / 3500;
  166.  
  167.   // Все смещения стартуют с нуля
  168.   for j := 1 to nHid do B0[j] := 0.0;
  169.   for j := 1 to nOut do B1[j] := 0.0;
  170. end;
  171.  
  172. procedure GenerateDataset;
  173. var
  174.   i, Bit, Neighbors, Center: Integer;
  175. begin
  176.   for i := 0 to RULES_COUNT - 1 do
  177.   begin
  178.     Neighbors := 0;
  179.     for Bit := 0 to nInp - 1 do
  180.     begin
  181.       if ((i shr Bit) and 1) = 1 then
  182.       begin
  183.         Dataset[i].Inputs[Bit + 1] := 1.0;
  184.         if Bit > 0 then Inc(Neighbors);
  185.       end
  186.       else
  187.         Dataset[i].Inputs[Bit + 1] := -1.0;
  188.     end;
  189.    
  190.     Center := Round(Dataset[i].Inputs[1]);
  191.  
  192.     if Center = 1 then
  193.       Dataset[i].Output := IfThen((Neighbors = 2) or (Neighbors = 3), 1.0, -1.0)
  194.     else
  195.       Dataset[i].Output := IfThen(Neighbors = 3, 1.0, -1.0);
  196.   end;
  197. end;
  198.  
  199. procedure TrainLocalEngine(Epochs: Integer; StartRate: Single);
  200. var
  201.   Epoch, Smp, i: Integer;
  202.   CurrentRate: Single;
  203. begin
  204.   Writeln('Training Trinity Deep MLP on 512 Conway Rules (9-4-1)...');
  205.   InitWeights;
  206.  
  207.   for Epoch := 1 to Epochs do
  208.   begin
  209.     // Формула Коши для ювелирной сходимости
  210.     CurrentRate := StartRate / (1.0 + 0.015 * Epoch);
  211.  
  212.     for Smp := 0 to RULES_COUNT - 1 do
  213.     begin
  214.       for i := 1 to nInp do
  215.         InL[i] := Dataset[Smp].Inputs[i];
  216.        
  217.       Etalon[1] := Dataset[Smp].Output;
  218.  
  219.       Calculate;
  220.       FindError;
  221.       Learn(CurrentRate);
  222.     end;
  223.   end;
  224.   Writeln('Training finished.');
  225. end;
  226.  
  227. function GetCell(const Field: TLifeField; X, Y: Integer): Single;
  228. var
  229.   TX, TY, Idx: Integer;
  230. begin
  231.   TX := (X mod WIDTH + WIDTH) mod WIDTH;
  232.   TY := (Y mod HEIGHT + HEIGHT) mod HEIGHT;
  233.   Idx := (TY * WIDTH) + TX + 1;
  234.   if Field[Idx] = 1 then Result := 1.0 else Result := -1.0;
  235. end;
  236.  
  237. procedure SetCellLive(var Field: TLifeField; X, Y: Integer);
  238. var
  239.   TX, TY, Idx: Integer;
  240. begin
  241.   TX := (X mod WIDTH + WIDTH) mod WIDTH;
  242.   TY := (Y mod HEIGHT + HEIGHT) mod HEIGHT;
  243.   Idx := (TY * WIDTH) + TX + 1;
  244.   Field[Idx] := 1;
  245. end;
  246.  
  247. procedure GatherEnvironment(const Field: TLifeField; CX, CY: Integer);
  248. begin
  249.   InL[1] := GetCell(Field, CX, CY);
  250.   InL[2] := GetCell(Field, CX - 1, CY - 1);
  251.   InL[3] := GetCell(Field, CX, CY - 1);
  252.   InL[4] := GetCell(Field, CX + 1, CY - 1);
  253.   InL[5] := GetCell(Field, CX + 1, CY);
  254.   InL[6] := GetCell(Field, CX + 1, CY + 1);
  255.   InL[7] := GetCell(Field, CX, CY + 1);
  256.   InL[8] := GetCell(Field, CX - 1, CY + 1);
  257.   InL[9] := GetCell(Field, CX - 1, CY);
  258. end;
  259.  
  260. procedure RenderConsole;
  261. var
  262.   X, Y, Idx: Integer;
  263.   LineBuffer: string;
  264. begin
  265.   gotoxy(1,1);
  266.   for Y := 0 to HEIGHT - 1 do
  267.   begin
  268.     LineBuffer := '';
  269.     for X := 0 to WIDTH - 1 do
  270.     begin
  271.       Idx := (Y * WIDTH) + X + 1;
  272.       if CurrentField[Idx] = 1 then LineBuffer := LineBuffer + 'O'
  273.       else LineBuffer := LineBuffer + '.';
  274.     end;
  275.     Writeln(LineBuffer);
  276.   end;
  277. end;
  278.  
  279. var
  280.   X, Y, Gen, CorrectCount, i, Smp: Integer;
  281.  
  282. begin
  283.   Randomize;
  284.   GenerateDataset;
  285.  
  286.   TrainLocalEngine(nEpochs, 0.04);
  287.  
  288.   CorrectCount := 0;
  289.   for Smp := 0 to RULES_COUNT - 1 do
  290.   begin
  291.     for i := 1 to nInp do InL[i] := Dataset[Smp].Inputs[i];
  292.     Calculate;
  293.     if (OutL[1] > 0.0) = (Dataset[Smp].Output > 0.0) then Inc(CorrectCount);
  294.   end;
  295.  
  296.   Writeln(Format('Table Memorization Accuracy: %d / 512 (%.1f%%)', [CorrectCount, (CorrectCount / RULES_COUNT) * 100]));
  297.   Writeln('Press ENTER to run Trinity...');
  298.   Readln;
  299.  
  300.   for i := 1 to SIZE do
  301.     CurrentField[i] := IfThen(Random < 0.30, 1, 0);
  302.  
  303.   Gen := 0;
  304.  
  305.   repeat
  306.     Inc(Gen);
  307.     RenderConsole;
  308.     Writeln(Format('Generation: %d | Driven by Trinity Hyperbolic Engine', [Gen]));
  309.  
  310.     for Y := 0 to HEIGHT - 1 do
  311.     begin
  312.       for X := 0 to WIDTH - 1 do
  313.       begin
  314.         GatherEnvironment(CurrentField, X, Y);
  315.         Calculate;
  316.  
  317.         if OutL[1] > 0.0 then
  318.           NextField[(Y * WIDTH) + X + 1] := 1
  319.         else
  320.           NextField[(Y * WIDTH) + X + 1] := 0;
  321.       end;
  322.     end;
  323.  
  324.     CurrentField := NextField;
  325.     Delay(60);
  326.  
  327.     if keypressed then if readkey=#27 then exit;
  328.   until false;
  329. end.
  330.  
  331.  

p.s updated

Fun fact: the 9‑2‑1 topology, where the ANN miraculously mastered Conway‑512, earned a “that’s magic!” from Gemini. Our verdict? No sorcery — just XOR chilling in the perceptron’s (maybe ternary) brain. 
« Last Edit: May 25, 2026, 02:21:22 am by microxa »

schuler

  • Sr. Member
  • ****
  • Posts: 351
Re: Can /my/ AI help me with pascal coding?
« Reply #52 on: May 24, 2026, 04:25:33 am »
The most recent pas-sqlite3 porting addition is text search: https://github.com/joaopauloschuler/pas-sqlite3/blob/main/src/passqlite3fts3.pas .

The current status is:
Code: Pascal  [Select][+][-]
  1. 100 / 101 binaries passing and 5199 / 5199 assertions passing
  2.  
  3. $ bin/TclTestDriver --timeout 2000 --fail-log-dir bin/tcl-failure-logs
  4. ...
  5. Total: 598 pass / 361 fail / 0 skip / 959 total in 377661 ms

... the AI based porting work continues ...

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 440
  • I use FPC [main] 💪🐯💪
Re: Can /my/ AI help me with pascal coding?
« Reply #53 on: May 24, 2026, 05:45:44 am »
@schuler
I'm curious to know how your build and testing pipeline is set up. If you don't mind, could you give us a brief overview of it?
I may seem rude - please don't take it personally

schuler

  • Sr. Member
  • ****
  • Posts: 351
Re: Can /my/ AI help me with pascal coding?
« Reply #54 on: May 24, 2026, 04:22:03 pm »
@schuler
I'm curious to know how your build and testing pipeline is set up. If you don't mind, could you give us a brief overview of it?

- Virtualization
* https://www.virtualbox.org/wiki/Downloads

- Operating System
* Ubuntu 24.04 LTS Desktop AMD64
* https://releases.ubuntu.com/noble/

- Required Ubuntu Packages
* https://github.com/joaopauloschuler/pas-sqlite3/blob/main/install_dependencies.sh

- Building
./src/tests/build.sh                    # main binary and main tests
./src/tests/build_tcl_lib.sh          # → bin/libpassqlite3tcl.so  (rerun after engine edits)
./src/tests/build_tcl_driver.sh       # → bin/TclTestDriver

- TCL testing
$ bin/TclTestDriver --timeout 2000 --fail-log-dir bin/tcl-failure-logs

« Last Edit: May 24, 2026, 05:22:03 pm by schuler »

microxa

  • New Member
  • *
  • Posts: 27
Re: Can /my/ AI help me with pascal coding?
« Reply #55 on: May 25, 2026, 05:29:51 am »
Dreams come true! Once upon a time, I ported an example of a console‑based Tetris (for TP 7), adding colours to it. After that, I forgot about it — I didn’t really understand what the code was doing (Gemini called it “brainf_ck for a school competition”). He, however, figured it out quite well and even built a self‑playing AI… On the third try, the proposed options — rewritten from scratch — didn’t quite satisfy me.

Nharayana

  • Newbie
  • Posts: 1
Re: Can /my/ AI help me with pascal coding?
« Reply #56 on: May 25, 2026, 08:42:22 am »
Works great with Claude Code. It is well aware of LCL and FPC 3.2.2

schuler

  • Sr. Member
  • ****
  • Posts: 351
Re: Can /my/ AI help me with pascal coding?
« Reply #57 on: May 28, 2026, 02:20:38 am »
The most recent pas-sqlite3 porting addition is text search: https://github.com/joaopauloschuler/pas-sqlite3/blob/main/src/passqlite3fts3.pas .

The current status is:
Code: Pascal  [Select][+][-]
  1. 100 / 101 binaries passing and 5199 / 5199 assertions passing
  2.  
  3. $ bin/TclTestDriver --timeout 2000 --fail-log-dir bin/tcl-failure-logs
  4. ...
  5. Total: 598 pass / 361 fail / 0 skip / 959 total in 377661 ms

... the AI based porting work continues ...

Quick update from my end:

Code: Pascal  [Select][+][-]
  1. $ bin/TclTestDriver --timeout 60000 --fail-log-dir bin/tcl-failure-logs
  2. ...
  3. Total: 743 pass / 216 fail / 0 skip / 959 total in 2478395 ms

schuler

  • Sr. Member
  • ****
  • Posts: 351
Re: Can /my/ AI help me with pascal coding?
« Reply #58 on: June 08, 2026, 10:41:39 pm »
Quick updates:

1) pas-core-math32 has been integrated into Neural API.
2) pas-sqlite3 TCL testing status:

Code: Pascal  [Select][+][-]
  1. $ bin/TclTestDriver --timeout 60000 --fail-log-dir bin/tcl-failure-logs
  2. ...
  3. Total: 901 pass / 58 fail / 0 skip / 959 total in 2746696 ms

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: Can /my/ AI help me with pascal coding?
« Reply #59 on: June 09, 2026, 08:34:57 am »
Impressive!
objects are fine constructs. You can even initialize them with constructors.

 

TinyPortal © 2005-2018