Linked-List 3D

226 views
Skip to first unread message

Bert Mariani

unread,
Jan 23, 2026, 3:45:41 PM (10 days ago) Jan 23
to The Ring Programming Language
Hello Mahmoud et ALL

a2D = List(3.4)  can create a 2D list

Many times I need to work with a 3D list or more 
Can the Ring  List()  be updated ... to use ...
a3D = List(3,4,5)

===========================
Test Code

See nl+"2D Populate ============="+nl+nl
a2D = list(3,4)

for i = 1 to 3
    for j = 1 to 4
             Sum = i + j
             See " "+ Sum
             a2D[i][j] = Sum
    next
    See nl
next

/*  Commented out the 3D Section - Not Supported
See nl+"3D ============="+nl+nl
a3D = list(3,4,5)                //  Bad parameters count!

for i = 1 to 3
    for j = 1 to 4
        for k = 1 to 5
             Sum = i + j +k
             See " "+ Sum
             a3D[i][j][k] = Sum   // Not supported  
        next
        See nl
    next
    See nl
next

=====================================
Expected Output

2D Populate

 2 3 4 5
 3 4 5 6
 4 5 6 7

3D Populate =============

 3 4 5 6 7
 4 5 6 7 8
 5 6 7 8 9
 6 7 8 9 10

 4 5 6 7 8
 5 6 7 8 9
 6 7 8 9 10
 7 8 9 10 11

 5 6 7 8 9
 6 7 8 9 10
 7 8 9 10 11
 8 9 10 11 12

=====================

Regards
Bert Mariani

Ilir Liburn

unread,
Jan 23, 2026, 4:45:17 PM (10 days ago) Jan 23
to The Ring Programming Language
Hello All,

Here are the source files with relevant functions from the Ring2A and Ring2B series. NOTE: because I switched to Ring2C afterwards, functions have not been updated since 2023 (changes are necessary).

Greetings,
Ilir
list_e.c
2a_e.c

Mahmoud Fayed

unread,
Jan 24, 2026, 4:11:26 AM (9 days ago) Jan 24
to The Ring Programming Language
Hello Bert

>> "Can the Ring  List()  be updated"

Thanks for your suggestion :D

>> "Many times I need to work with a 3D list or more "

You already wrote this function 5 years ago to create 3D, 4D, 5D, etc lists


Greetings,
Mahmoud

Bert Mariani

unread,
Jan 24, 2026, 2:26:22 PM (9 days ago) Jan 24
to The Ring Programming Language
Hello Mahmoud

Re: You already wrote this function 5 years ago to create 3D, 4D, 5D, etc lists

Yes, I did. 
    -  dimList = [4,3,4]
     - bList = createDimList(dimList)

It would be more intuitive to use a standard command format  like"
    -   a1D  = List(6)        // 1D list   6 items 
     -   a2D = List(3.4)    //  2D list  3x4  

By extending the format to ...
     -   a3D = List(3.4,5)          //  3D list  3x4 x5
     -   a4D = List(3.4,5),6       //  4D list  3x4 x5x6
     -   a5D = List(3.4,5,6,7)    //  5D list  3x4x5x6x7 


=========================
Speaking about AI and ML

Tensor is a multi-dimensional array used to store data in machine learning and deep learning frameworks such as TensorFlow. Tensors are the fundamental data structure in TensorFlow and they represent the flow of data through a computation graph. Tensors generalize scalars, vectors and matrices to higher dimensions.

============================
In Rotational System -- 4D is used

#  Rx = [[ 1    0        0     0],   [x]    [x']
#        [ 0  cos(R)  -sin(R)  0], * [y] =  [y']
#        [ 0  sin(R)   cos(R)  0],   [z]    [z']
#        [ 0    0        0     1]]   [1]    [1 ]
#
#  Ry = [[  cos(R)  0  sin(R)  0],   [x]    [x']
#        [    0     1    0     0], * [y] =  [y']
#        [ -sin(R)  0  cos(R)  0],   [z]    [z']
#        [   0        0     0  1]]   [1]    [1 ]  
#
#  Rz = [[  cos(R) -sin(R)  0  0],   [x]    [x']
#        [  sin(R)  cos(R)  0  0], * [y] =  [y']
#        [   0        0     1  0],   [z]    [z']
#        [   0        0     0  1]]   [1]    [1 ]
Message has been deleted
Message has been deleted

Azzeddine Remmal

unread,
Jan 24, 2026, 3:47:21 PM (9 days ago) Jan 24
to The Ring Programming Language
Hello Bert

Look at the examples
I tried using the ringTensor in multiple fields.
load "ringml.ring"

# ============================================================
#  Financial Analysis: Massive Stock Market Simulation
#  Task: Calculate Correlation Matrix for Portfolio Optimization
# ============================================================
/*
We will simulate the following:
Data: 500 stocks × 2000 trading days (approximately 8 years of data). Total: 1 million data points.
Task: To calculate the "correlation matrix" to determine the relationship between each stock and the others.
Process: Requires multiplying a huge matrix by itself (R^T × R),
a process that would kill regular scripting languages, but RingTensor will handle it.
*/

# Output:
/*
λ ring  financial_analysis.ring
============================================================
   High-Frequency Trading Simulation
   Matrix Size: 2000 Days x 500 Stocks
   Total Data Points: 1000000
============================================================
[1] Generating synthetic stock prices... Done in 55.9700 ms
[2] Calculating Daily Returns (Vectorized)... Done in 28.5700 ms
[3] Computing Correlation Matrix (500x500)... Done in 0.2611
    > Performance: 1.9151 MFLOPS (Approx)

--- Market Analysis Sample ---
Correlation of Stock #1 with others:
   Stock 1 vs Stock 1 : 0.0878 [Positive (+)]
   Stock 1 vs Stock 2 : 0.0033 [Neutral]
   Stock 1 vs Stock 3 : 0.0021 [Neutral]
   Stock 1 vs Stock 4 : 0.0044 [Neutral]
   Stock 1 vs Stock 5 : 0.0011 [Neutral]
*/

decimals(4)
func main
   
    # 1. Configuration
    nStocks = 500     # Number of Assets (e.g., S&P 500)
    nDays   = 2000    # Time Series Length (~8 Years)
    oTime = new QalamChronos()
   
    ? copy("=", 60)
    ? "   High-Frequency Trading Simulation"
    ? "   Matrix Size: " + nDays + " Days x " + nStocks + " Stocks"
    ? "   Total Data Points: " + (nDays * nStocks)
    ? copy("=", 60)

    # ---------------------------------------------------------
    # 2. Data Generation (Monte Carlo Simulation)
    # ---------------------------------------------------------
    see "[1] Generating synthetic stock prices..."
    oTime.reset()
   
    # Random prices between 100.0 and 200.0
    oPrices = new Tensor(nDays, nStocks)
    oPrices.random()          # 0..1
    oPrices.scalarMul(100.0) # 0..100
    oPrices.addScalar(100.0) # 100..200
   
    ? " Done in " + oTime.elapsed()

    # ---------------------------------------------------------
    # 3. Calculate Daily Returns (Percentage Change)
    # Formula: R_t = (Price_t - Price_{t-1}) / Price_{t-1}
    # ---------------------------------------------------------
    see "[2] Calculating Daily Returns (Vectorized)..."
    oTime.reset()
   
    # Slice Days 2 to N (Today)
    oToday = oPrices.sliceRows(2, nDays - 1)
   
    # Slice Days 1 to N-1 (Yesterday)
    oYesterday = oPrices.sliceRows(1, nDays - 1)
   
    # Calculate Change: (Today - Yesterday)
    # Note: We copy Today first to preserve data if needed, or modify in place
    oDiff = oToday.copy()
    oDiff.sub(oYesterday)
   
    # Calculate Percentage: Diff / Yesterday
    oReturns = oDiff
    oReturns.div(oYesterday)
   
    # Result is now (1999 x 500) matrix of returns
    ? " Done in " + oTime.elapsed()

    # ---------------------------------------------------------
    # 4. Compute Correlation Matrix (The Heavy Lifting)
    # Formula: Covariance ~ (R^T * R)
    # Operation: (500 x 1999) * (1999 x 500) -> (500 x 500)
    # ---------------------------------------------------------
    see "[3] Computing Correlation Matrix (500x500)..."
    oTime.reset()
   
    # Transpose the Returns Matrix
    oReturnsT = oReturns.transpose()
   
    # Matrix Multiplication (This utilizes all CPU Cores via OpenMP)
    oCorrelation = oReturnsT.matmul(oReturns)
   
    # Normalize (Optional simplified step for demo)
    # Divide by number of days to get average covariance
    oCorrelation.scalarMul(1.0 / (nDays - 1))
    time_taken = oTime.elapsed_ns() / 1000000000
    ? " Done in " + time_taken
    ? "    > Performance: " + (nStocks*nStocks*nDays / time_taken / 1000000000) + " MFLOPS (Approx)"

    # ---------------------------------------------------------
    # 5. Analysis Results
    # ---------------------------------------------------------
    ? nl + "--- Market Analysis Sample ---"
   
    # Let's see correlation between Stock #1 and first 5 stocks
    # 1.0 means perfect correlation (itself), 0.0 means no correlation
    ? "Correlation of Stock #1 with others:"
   
    for i = 1 to 5
        val = oCorrelation.getVal(1, i)
       
        # Determine relationship
        cRel = "Neutral"
        if val > 0.05 cRel = "Positive (+)" ok
        if val < -0.01 cRel = "Negative (-)" ok
       
        ? "   Stock 1 vs Stock " + i + " : " + (floor(val*10000)/10000) + " [" + cRel + "]"
    next

load "ringml.ring"

/*
"Particle System Simulation" or "Interconnected Chain".
Imagine we have 100,000 points (stars) in 3D space,
and we want to rotate them all around the Y-axis and calculate the new center of mass.
In standard Ring language, this would take a very long time. With RingTensor,
it happens in the blink of an eye.
Example: 3D Galaxy Simulation
This is pure geometry.
*/

# Output:
/*
λ ring  test_3d_physics.ring                        
==================================================  
   3D Physics Simulation using RingTensor            
   Processing 100000 particles in Real-Time          
==================================================  
[1] Generating Galaxy... Done in 20.24 ms            
[2] Rotation Matrix Prepared.                        
[3] Rotating 100,000 stars... Done in 8.97 ms        
[4] Calculating Center of Mass...                    
--- Particle #1 Analysis ---                        
Old Pos: (-459, 77)                                  
New Pos: (-370, -270)                                
Note: Rotation + Translation applied.                
*/


# 1. Setup Simulation
# ---------------------
nParticles = 100000   # 100,000 Stars/Points
nDims      = 3        # X, Y, Z

see "==================================================" + nl
see "   3D Physics Simulation using RingTensor" + nl
see "   Processing " + nParticles + " particles in Real-Time" + nl
see "==================================================" + nl

# 2. Initialize Particles (The Data)
# Shape: (100000, 3)
# Represents a list of [x, y, z] coordinates
see "[1] Generating Galaxy..."
oTime = new QalamChronos()

oParticles = new Tensor(nParticles, nDims)
oParticles.random() # 0..1

# Shift to range [-500, 500] to center the galaxy
oParticles.subScalar(0.5)
oParticles.scalarMul(1000.0)

? " Done in " + oTime.elapsed()

# 3. Create Rotation Matrix (The Math)
# Rotation around Y-axis by 45 degrees (Theta)
# [ cos(t)  0  sin(t) ]
# [   0     1    0    ]
# [ -sin(t) 0  cos(t) ]

nTheta = 45 * (3.14159 / 180) # Radians
nCos   = cos(nTheta)
nSin   = sin(nTheta)

oRotationMatrix = new Tensor(3, 3)
# Row 1
oRotationMatrix.setVal(1, 1, nCos)
oRotationMatrix.setVal(1, 2, 0)
oRotationMatrix.setVal(1, 3, nSin)
# Row 2
oRotationMatrix.setVal(2, 1, 0)
oRotationMatrix.setVal(2, 2, 1)
oRotationMatrix.setVal(2, 3, 0)
# Row 3
oRotationMatrix.setVal(3, 1, -nSin)
oRotationMatrix.setVal(3, 2, 0)
oRotationMatrix.setVal(3, 3, nCos)

see "[2] Rotation Matrix Prepared." + nl

# 4. Perform Simulation Step (The Heavy Lifting)
# NewPosition = OldPosition * RotationMatrix
# (N x 3) * (3 x 3) -> (N x 3)

see "[3] Rotating 100,000 stars..."
oTime.reset()

# This single line performs 300,000 multiplications and additions in C
oNewParticles = oParticles.matmul(oRotationMatrix)

# Add gravity/velocity vector (Translation)
# Move galaxy by vector [10, 0, 0]
oVelocity = new Tensor(1, 3)
oVelocity.setVal(1, 1, 10.0)
oVelocity.setVal(1, 2, 0.0)
oVelocity.setVal(1, 3, 0.0)

# Broadcast addition (Add vector to every particle)
oNewParticles.addRowVec(oVelocity)

? " Done in " + oTime.elapsed()

# 5. Physics Analysis (Aggregations)
# Calculate Center of Mass (Mean of X, Y, Z)

see "[4] Calculating Center of Mass..."
oCenterOfMass = new Tensor(1, 3)

# Sum columns (Axis 0)
# We don't have sum(0) exposed directly as easy function in wrapper yet?
# We used tensor_sum in C. Let's assume wrapper 'sum(axis)' exists or create it.
# If not, we use mean().

nAvgX = 0 nAvgY = 0 nAvgZ = 0
# If tensor_mean returns scalar mean of ALL, that's not what we want.
# We want column means.
# Let's use the 'sum' kernel directly if available in wrapper,
# or loop manually in Ring (slow) to show values.
# But for demo, let's just pick first particle to show change.

p1_old_x = oParticles.getVal(1, 1)
p1_old_z = oParticles.getVal(1, 3)

p1_new_x = oNewParticles.getVal(1, 1)
p1_new_z = oNewParticles.getVal(1, 3)

see nl + "--- Particle #1 Analysis ---" + nl
see "Old Pos: (" + floor(p1_old_x) + ", " + floor(p1_old_z) + ")" + nl
see "New Pos: (" + floor(p1_new_x) + ", " + floor(p1_new_z) + ")" + nl
see "Note: Rotation + Translation applied." + nl

load "ringml.ring"

/*
(Image Processing)
Digital images are simply massive arrays of numbers (pixels).
If you have a 4K image (3840 x 2160), it contains 8.2 million pixels.
Processing it pixel by pixel in a script would be extremely slow.
In this example,
we will simulate Photoshop filters (Invert, Brightness, Blending)
on ​​a massive image at lightning speed.
*/

# Out
/*
λ ring  image_filters.ring
============================================================
   High-Performance Image Processing (4K Simulation)
   Resolution: 3840x2160 (8294400 Pixels)
============================================================
[1] Loading 4K Image into Memory... Done (380.64 ms)
[2] Applying 'Negative' Filter... Done (56.18 ms)
[3] Adjusting Brightness (+20%) & Contrast (x1.5)... Done (87.03 ms)
[4] Blending with another Image (Watermark)... Done (565.10 ms)
*/

func main
   
    # 1. Setup Image Dimensions (4K Resolution)
    nWidth  = 3840
    nHeight = 2160
    oTime = new QalamChronos()
   
    see copy("=", 60) + nl
    see "   High-Performance Image Processing (4K Simulation)" + nl
    see "   Resolution: " + nWidth + "x" + nHeight + " (" + (nWidth*nHeight) + " Pixels)" + nl
    see copy("=", 60) + nl

    # ---------------------------------------------------------
    # 2. Load Image (Simulated)
    # ---------------------------------------------------------
    see "[1] Loading 4K Image into Memory..."
    oTime.reset()
   
    # Image A: Represents raw photo (Values 0.0 to 1.0)
    oImg = new Tensor(nHeight, nWidth)
    oImg.random()
   
    see " Done (" + oTime.elapsed() + ")" + nl

    # ---------------------------------------------------------
    # 3. Filter: Invert Colors (Negative)
    # Formula: Pixel = 1.0 - Pixel
    # ---------------------------------------------------------
    see "[2] Applying 'Negative' Filter..."
    oTime.reset()
   
    # Create a white canvas (All 1.0)
    oWhite = new Tensor(nHeight, nWidth)
    oWhite.fill(1.0)
   
    # Subtraction (Vectorized)
    oNegative = oWhite
    oNegative.sub(oImg)
   
    see " Done (" + oTime.elapsed() + ")" + nl

    # ---------------------------------------------------------
    # 4. Filter: Brightness & Contrast
    # Formula: Pixel = (Pixel * Contrast) + Brightness
    # ---------------------------------------------------------
    see "[3] Adjusting Brightness (+20%) & Contrast (x1.5)..."
    oTime.reset()
   
    oProcessed = oImg.copy() # Copy original
    oProcessed.scalarMul(1.5) # Contrast
    oProcessed.addScalar(0.2) # Brightness
   
    see " Done (" + oTime.elapsed() + ")" + nl

    # ---------------------------------------------------------
    # 5. Filter: Image Blending (Alpha Compositing)
    # Formula: Result = (ImgA * 0.7) + (ImgB * 0.3)
    # ---------------------------------------------------------
    see "[4] Blending with another Image (Watermark)..."
    oTime.reset()
   
    # Generate second image (Noise/Texture)
    oWatermark = new Tensor(nHeight, nWidth)
    oWatermark.random()
   
    # Apply weights
    oImg.scalarMul(0.7)
    oWatermark.scalarMul(0.3)
   
    # Combine
    oFinal = oImg
    oFinal.add(oWatermark)
   
    see " Done (" + oTime.elapsed() + ")" + nl

load "ringml.ring"

/*
(Cryptography) - LWE System
Modern cryptography (especially post-quantum cryptography) relies entirely on lattices.

The most popular algorithm is LWE (Learning With Errors).

The mathematical concept:
B = A × S + E
A: Public key array.
S: Secret key vector.
E: Small random noise.

B: The resulting public key.

Without RingTensor, multiplying large arrays to generate keys is very time-consuming.
*/

# Output:
/*
λ ring  crypto_lwe.ring                                                
============================================================            
   Post-Quantum Cryptography Simulation (LWE)                          
   Learning With Errors - Key Generation                                
============================================================            
[1] Generating Public Matrix A (2048x1024)...                          
 Done (106 ms)                                                          
[2] Generating Secret Key S...                                          
[3] Generating Error Noise E...                                        
[4] Computing Public Key B = (A * S) + E...                            
 Done (13.71 ms)                                                        
                                                                       
Key Generation Complete.                                                
Public Key Size: 2048 elements.                                        
Value Sample: 0.04                                                      
*/

func main

    oTime = new QalamChronos()
    ? copy("=", 60)
    ? "   Post-Quantum Cryptography Simulation (LWE)"
    ? "   Learning With Errors - Key Generation"
    ? copy("=", 60)

    # Configuration (Lattice Parameters)
    nDim    = 1024   # Dimension (Security Level)
    nSamples = 2048  # Public Matrix Height

    # ---------------------------------------------------------
    # 1. Generate Public Matrix (A)
    # Large random matrix visible to everyone
    # ---------------------------------------------------------
    ? "[1] Generating Public Matrix A ("+nSamples+"x"+nDim+")..."
    oTime.reset()
   
    oMatA = new Tensor(nSamples, nDim)
    oMatA.random() # Random values [0, 1] (In real crypto, integers mod q)
   
    ? " Done (" + oTime.elapsed() + ")"

    # ---------------------------------------------------------
    # 2. Generate Secret Key (S)
    # Small vector known only to owner
    # ---------------------------------------------------------
    ? "[2] Generating Secret Key S..."
   
    oSecretS = new Tensor(nDim, 1) # Column Vector
    oSecretS.random()
    oSecretS.subScalar(0.5) # Center around 0
    oSecretS.scalarMul(0.1) # Make it "Small" (Short vector)

    # ---------------------------------------------------------
    # 3. Generate Error Term (E)
    # Tiny noise to hide the secret
    # ---------------------------------------------------------
    ? "[3] Generating Error Noise E..."
   
    oErrorE = new Tensor(nSamples, 1)
    oErrorE.random()
    oErrorE.subScalar(0.5)
    oErrorE.scalarMul(0.001) # Very small noise

    # ---------------------------------------------------------
    # 4. Compute Public Key (B)
    # Formula: B = (A * S) + E
    # This is the heavy operation!
    # ---------------------------------------------------------
    ? "[4] Computing Public Key B = (A * S) + E..."
    oTime.reset()
   
    # Step A: Matrix Multiply (Heavy)
    # (2048 x 1024) * (1024 x 1) -> (2048 x 1)
    oKeyB = oMatA.matmul(oSecretS)
   
    # Step B: Add Noise
    oKeyB.add(oErrorE)
   
    ? " Done (" + oTime.elapsed() + ")"
   
    # Verify Dimensions
    ? nl + "Key Generation Complete."
    ? "Public Key Size: " + oKeyB.nRows + " elements."
    ? "Value Sample: " + oKeyB.getVal(1,1)


Best regards
Azzeddine

Bert Mariani

unread,
Jan 24, 2026, 4:22:14 PM (9 days ago) Jan 24
to The Ring Programming Language
Thanks Azzeddine

I had to re-install these 2 packages after the Ring 1.25 update

c:\ring>ringpm install ringml-using-ringtensor from Azzeddine2017
c:\ring>ringpm install AlQalam from Azzeddine2017

Where can I find a package for qalamchronos ?

============================================================
Line 41 Error (R11) : Error in class name, class not found: qalamchronos
In function main() in file C:/MyStuff/AA-TENSOR-Azzeddine/Cryptography-1.ring
Called from line 39 in file C:/MyStuff/AA-TENSOR-Azzeddine/Cryptography-1.ring

Best Regards
Bert Mariani

Azzeddine Remmal

unread,
Jan 24, 2026, 4:43:24 PM (9 days ago) Jan 24
to The Ring Programming Language
Hello Bert

qalamchronos is a class in the AlKalam library. 
Add the load "AlKalam.ring" with the load "ringml.ring".
Actually, I've been busy adding graphs and GPU support to Ring Tensors and training models, 
and I haven't had time to connect and update things. 
I haven't updated Ringml yet, but I will once I'm sure of the results and have updated the documentation.
Best regards
Azzeddine

Mansour Ayouni

unread,
Jan 24, 2026, 5:21:24 PM (9 days ago) Jan 24
to Azzeddine Remmal, The Ring Programming Language
Hello Azzeddine,

As creators of Ring libraries and contributors to its young ecosystem, I think we should be aware of two fundamental requirements:
  • let us not propose the use of our libs when they are not ready
  • and even if they are ready let us document why they were made and how to use them, even in simple terms
Otherwise the hard work, you and other lib creators, would affect the most valuable currency of the Ring project: quality and usability of the language and its libraries.

Wishing you all the success you deserve in your very important RingML project.

Best,
Mansour

--

---
You received this message because you are subscribed to the Google Groups "The Ring Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-lang+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ring-lang/87b69085-b556-42be-9b50-e729b26fd5dbn%40googlegroups.com.

Azzeddine Remmal

unread,
Jan 25, 2026, 4:36:30 AM (8 days ago) Jan 25
to The Ring Programming Language
Hello Bert  Mansour

Bert  :  Were you able to run the examples? Or do you need help with that?

Mansour : Thank you for your kind words.
                   I didn't recommend using the RingLM library because it's not ready yet. 
                   However, the extensions work on their own, and I wanted to help Bert achieve the speed I did. 
                  There's a difference between offering consolation and providing genuine assistance.

Best regards
Azzeddine

Mansour Ayouni

unread,
Jan 25, 2026, 6:24:10 AM (8 days ago) Jan 25
to Azzeddine Remmal, The Ring Programming Language
Hello Azzedine,

I see. Thank you.

Best,
Mansour

Bert Mariani

unread,
Jan 25, 2026, 8:16:38 AM (8 days ago) Jan 25
to The Ring Programming Language
Hello Azzeddine

Thank you for offering the help to  achieve the speed you did.  Much Appreciated !!

Get the same error for all 4 samples that I copy/pasted from your posting
Cryptography,  FinancialAnalysis,  ImageProcessing,  ParticleSystem
Maybe you could attach them as download files.

Have these loads

     - load "ringml.ring"

     - load "AlKalam.ring"   // Added


==========================================
Error (E9) : Can't open file AlKalam.ring
C:/MyStuff/AA-TENSOR-Azzeddine/FinancialAnalysis-1.ring Line (2) Error (C27) : Syntax Error!
C:/MyStuff/AA-TENSOR-Azzeddine/FinancialAnalysis-1.ring errors count : 1

=============================================
c:\ring>ringpm install AlQalam from Azzeddine2017
Installing AlQalam (master) ---> AlQalam (1.0.0)
 - Note : Package Already Exists

c:\ring>ringpm update AlQalam from Azzeddine2017
Error(8) : No updates for this package
Package Name : AlQalam

===========================================
I need to study your samples.

Best Regards
Bert Mariani

Bert Mariani

unread,
Jan 25, 2026, 8:42:46 AM (8 days ago) Jan 25
to The Ring Programming Language
Hello again Azzeddine

C:\ring\extensions\AlQalam\tests
The tests RAN !!   ( 2  reported Errors  See below)

So I changed the header  sequence in the samples you posted to

     - load "AlQalam.ring"   // 1st

     - load "ringml.ring"      // 2nd


Now the samples start !!

Thanks !! I will study the libraries.


////////////////////////////////////


==================================================
   3D Physics Simulation using RingTensor
   Processing 100000 particles in Real-Time
==================================================
[1] Generating Galaxy...

Line 52 Error (R14) : Calling Method without definition: subscalar
in file C:/MyStuff/AA-TENSOR-Azzeddine/ParticleSystem-1.ring


/////////////////////////////

============================================================
   High-Performance Image Processing (4K Simulation)
   Resolution: 3840x2160 (8294400 Pixels)
============================================================
[1] Loading 4K Image into Memory... Done (94.68 ms)
[2] Applying 'Negative' Filter... Done (27.91 ms)

[3] Adjusting Brightness (+20%) & Contrast (x1.5)...
Line 76 Error (R14) : Calling Method without definition: scalarmul
In function main() in file C:/MyStuff/AA-TENSOR-Azzeddine/ImageProcessing-1.ring

Called from line 27 in file C:/MyStuff/AA-TENSOR-Azzeddine/ImageProcessing-1.ring

///////////////////////////////////

============================================================
   Post-Quantum Cryptography Simulation (LWE)
   Learning With Errors - Key Generation
============================================================
[1] Generating Public Matrix A (2048x1024)...
 Done (22.16 ms)

[2] Generating Secret Key S...

Line 72 Error (R14) : Calling Method without definition: subscalar

In function main() in file C:/MyStuff/AA-TENSOR-Azzeddine/Cryptography-1.ring

Called from line 40 in file C:/MyStuff/AA-TENSOR-Azzeddine/Cryptography-1.ring

//////////////////////////////////////
============================================================
   High-Frequency Trading Simulation
   Matrix Size: 2000 Days x 500 Stocks
   Total Data Points: 1000000
============================================================
[1] Generating synthetic stock prices...
Line 61 Error (R14) : Calling Method without definition: scalarmul
In function main() in file C:/MyStuff/AA-TENSOR-Azzeddine/FinancialAnalysis-1.ring

Called from line 39 in file C:/MyStuff/AA-TENSOR-Azzeddine/FinancialAnalysis-1.ring


//////////////////////////////////////////////////////////////

C:\ring\extensions\AlQalam\tests

============================================================
  BENCHMARK STARTED
============================================================
Qalam Time: 382.70 us
Vector Size : 1000000
String Ops  : 20000
Map Lookups : 10000

============================================================
  1. VECTOR MATH (Multiply x 2)
============================================================
Running Ring List Loop...
  > Ring List Time : 123059200 ns
Running AlQalam C++ Loop...
  > QalamVector Time : 421200 ns

  >>> RESULT: AlQalam is 292x FASTER! ≡ƒÜÇ

============================================================
  2. STRING BUILDING (Append)
============================================================
Running Ring String Append...
  > Ring String Time : 2334500 ns
Running QalamInk Append...
  > QalamInk Time : 22300800 ns

  >>> RESULT: Speeds are similar.

============================================================
  3. STRING BUILDING (Batch Append)
============================================================
Data Size: 20000 strings
Running Ring Loop...
  > Ring String Time : 8259200 ns
Running Qalam Batch...
  > QalamInk (Batch) Time : 586500 ns

  >>> RESULT: AlQalam is 14x FASTER! ≡ƒÜÇ

============================================================
  4. DICTIONARY SEARCH (O(N) vs O(1))
============================================================
Running Ring Find()...
  > Ring Find Time : 645432600 ns
Running QalamIndex Get()...
  > QalamIndex Time : 11361500 ns

  >>> RESULT: AlQalam is 56x FASTER! ≡ƒÜÇ

==================================================
TEST COMPLETE.

=================================
✒️ Starting AlQalam Global Diagnostics...
--- [1] Testing QalamChronos (Time Lord) ---
  OK: Timer initiated. Elapsed: 510.08 ms
  OK: Timer reset successful.

--- [2] Testing QalamVector (Basic I/O) ---
  OK: Size is correct (5).
  OK: Read/Write successful.
  OK: Correction (Set) successful.

--- [3] Testing QalamVector (Alchemy & Batch) ---
  OK: Flooding successful.
  OK: Elevation (Batch Add) successful.
  OK: Amplification (Batch Mul) successful.

--- [4] Testing Memory Bridge & Pointers ---

Line 117 Error (R14) : Calling Method without definition: getrawpointer
In function test_vector_memory_and_ptr() in file C:/ring/extensions/AlQalam/tests/tests_alqalam.ring

Called from line 15 In function main() in file C:/ring/extensions/AlQalam/tests/tests_alqalam.ring

Called from line 9 in file C:/ring/extensions/AlQalam/tests/tests_alqalam.ring


==================================================
  ALQALAM FORMULA ENGINE TEST
==================================================

Line 16 Error (R3) : Calling Function without definition: info
In function main() in file C:/ring/extensions/AlQalam/tests/test_alqalam_formula.ring

Called from line 11 in file C:/ring/extensions/AlQalam/tests/test_alqalam_formula.ring

=============================================
Message has been deleted

Azzeddine Remmal

unread,
Jan 25, 2026, 7:04:19 PM (8 days ago) Jan 25
to The Ring Programming Language
Hello Bert.

I've updated RingML to v1.2.0
and RingTensor to v1.3.0
Delete or uninstall the old version, 
then install RingML.

ringpm install ringml-using-ringtensor from Azzeddine2017

 RingTensor will be installed along with AlQalam Library as a dependency.
You will find examples in the folder : ring\extensions\ringtensor\tests
I will work on the documents later.
I added a Transformer example in : ring\samples\UsingRingML\train_translate_bidir
Best regards
Azzeddine

Mansour Ayouni

unread,
Jan 25, 2026, 7:27:33 PM (8 days ago) Jan 25
to Azzeddine Remmal, The Ring Programming Language
Hello Azzeddine,

I installed the library seamlessly.

Then when I tried the sample : samples/UsingRingML/xor_train.ring
I got an undefined ok variable error in the file: ringml/src/optim/sgd.ring

image.png
You just remove the "ok" it's not needed to close a method in Ring.

When I done that, the sample worked correctly:
image.png

Best,
Mansour


Mansour Ayouni

unread,
Jan 25, 2026, 7:35:05 PM (8 days ago) Jan 25
to Azzeddine Remmal, The Ring Programming Language
Hello Azzedine,

There is an error in the bechmark_bottlneck.ring example:
image.png
Best,
Mansour

Mansour Ayouni

unread,
Jan 25, 2026, 7:39:08 PM (7 days ago) Jan 25
to Azzeddine Remmal, The Ring Programming Language
Hello Azzeddine,

The same error in fast_viz_demo.ring:
image.png
All other samples work correctly.

All the best,
Mansour

Azzeddine Remmal

unread,
Jan 25, 2026, 8:07:42 PM (7 days ago) Jan 25
to The Ring Programming Language
Hello Mansour. 

Thank you for testing and tracking the errors.

Here is a detailed technical report summarizing the major architectural upgrades we have implemented for RingTensor
This report is structured for documentation, community updates, or technical logging.
 Technical Report: RingTensor v1.3.0 Architecture Upgrade
Subject: Implementation of Graph Engine  and Universal GPU Acceleration.
Date: January 26, 2026
Framework: RingML / RingTensor
1. Executive Summary
The RingTensor core has undergone a fundamental architectural shift. We have moved from a pure Eager Execution model (where every mathematical operation requires a round-trip between the Ring VM and C) to a Hybrid Graph/GPU Architecture.
This update addresses the primary bottleneck of interpreter overhead and unlocks hardware acceleration, allowing the Adam II Transformer model to train significantly faster and scale to larger datasets.
2. The  Graph Engine 
The Problem: Interpreter Overhead
In the previous version, a training loop running 10,000 steps meant 10,000 context switches between Ring and C for every single operation (Add, MatMul, Loss). On CPU-bound tasks, the time spent "dispatching" the command often exceeded the time spent "executing" it.
The Solution: Static Computation Graph
We introduced a virtual machine within the C extension (ring_graph.c) that records operations instead of executing them immediately.
Definition Phase: When Ring code executes C = A.matmul(B), the engine creates a Node in memory representing this operation, linking inputs A and B to output C.
Execution Phase: A single Ring command graph_run(epochs=50) triggers the C engine.
The Result: The C engine runs the entire training loop (Forward, Backward, Optimizer Update) internally using native C pointers. Zero Ring VM overhead during the heavy training phase.
Key Components:
OpCodes: Defined instructions (OP_MATMUL, OP_GELU, OP_ADAM_UPDATE, OP_LAYERNORM).
Memory Binding: Static pre-allocation of tensors before execution to prevent memory fragmentation.
3. Universal GPU Acceleration (OpenCL)
The Philosophy: Heterogeneous Computing
Instead of relying solely on the CPU, we implemented a Hybrid Dispatcher. The engine intelligently decides where to execute an operation based on its computational cost.
Small Operations: Executed on CPU using OpenMP (Multithreading).
Heavy Operations: Dispatched to GPU using OpenCL.
Technology Choice: OpenCL vs. CUDA
We chose OpenCL to ensure maximum compatibility. This allows RingTensor to run on:
NVIDIA GPUs (RTX/GTX series).
AMD Radeons.
Integrated Graphics (Intel HD/Iris/Arc).
Implementation Challenges & Solutions
A. The Double Precision Barrier
Many consumer GPUs (like Intel HD 5500) do not support FP64 (double precision) in hardware. Ring uses double by default.
Solution: We implemented an automatic Downcasting/Upcasting layer in C.
Data is converted from double to float (FP32) before sending to GPU.
GPU executes the kernel in FP32 (blazing fast).
Results are converted back to double for Ring.
Impact: This ensures the library runs on 99% of hardware without crashing, maintaining high performance for Deep Learning (where FP32 is standard).
B. Smart Thresholding
Sending data to the GPU incurs latency (PCIe bus transfer or RAM copy).
Solution: We implemented a "Smart Switch" inside internal_matmul.
Logic: If Operations < 10,000,000, stay on CPU. If higher, wake up the GPU. This prevents the GPU initialization overhead from slowing down small models.
4. Kernel Upgrades
To support modern Transformer architectures (like GPT and Llama), we added specialized kernels written in raw C/OpenCL:
Kernel Type Description
MatMul Hybrid Matrix Multiplication supporting CPU Tiling and GPU Parallelism.
Transpose GPU/CPU Efficient matrix rotation using fast memory block copying.
GELU GPU/CPU Gaussian Error Linear Unit (replacing ReLU) for better convergence.
Row Operations CPU slice_rows and insert_rows using memcpy for instant batch processing.
5. Performance Impact
Before Update (Eager Mode / CPU Serial)
Bottleneck: High latency due to Ring <-> C communication.
GPU: Idle (0% Utilization).
Training: Slow convergence on large datasets due to small batch limitations.
After Update (Graph Mode / Hybrid GPU)
Throughput: The training loop runs entirely in native machine code.
Hardware: Utilizing 4 CPU Logical Cores (via OpenMP) + Intel HD Graphics (via OpenCL) simultaneously.
Capability: Enabled training of Adam II (Multi-Layer Transformer) with Batch Processing and advanced features like Curriculum Learning.
6. Conclusion
RingTensor has evolved from a simple math extension into a professional-grade Deep Learning Backend. It now possesses the foundational architecture of major frameworks (like TensorFlow/PyTorch) but is tailored specifically for the Ring language ecosystem.
The system is now ready for Massive Dataset Training.

Mansour Ayouni

unread,
Jan 25, 2026, 8:22:20 PM (7 days ago) Jan 25
to Azzeddine Remmal, The Ring Programming Language
Hello Azzeddine,

I read the report and enjoyed it!
There is a foundational work done that deserves respect.
We should now test it extensively, so when you have time, write more samples and I'll test them.
Here is the report in a markdown file that you can include in the repo documentation.

Keep up the good work!
Best,
Mansour

ringtensor-113-technical-report.md

Mansour Ayouni

unread,
Jan 25, 2026, 8:40:45 PM (7 days ago) Jan 25
to Azzeddine Remmal, The Ring Programming Language
Also, this is what Grock AI thinks about the report:

  I’m looking forward to your feedback—what it captured correctly and what it didn’t.  

Azzeddine Remmal

unread,
Jan 25, 2026, 8:53:45 PM (7 days ago) Jan 25
to The Ring Programming Language
Hello Mansour.

Try running the example:   
ring\samples\UsingRingML\train_translate_bidir  , 
libraries\ringml\tests
extensions\ringtensor\testGraph


Best regards
Azzeddine

Azzeddine Remmal

unread,
Jan 25, 2026, 9:19:07 PM (7 days ago) Jan 25
to The Ring Programming Language
Hello Mansour.

1. The Debugging Visibility Dilemma

Your observation: "Graph modes can make debugging trickier."

Our response: That's absolutely true. That's why we designed the Tensor class in Ring to be hybrid.

We develop and test the model in Eager Mode (we see the numbers, print the results, and verify the dimensions).

Once we're sure the logic is sound, we change a single key, `oInput.setGraphMode(true)`, and the same code switches to Graph Construction Mode and is sent to C for fast execution.

Our philosophy: "Debug slowly, train fast."

2. Precision Trade-off

Your observation: Switching from FP64 to FP32 can accumulate errors.

Our response: In the world of Deep Learning, and specifically in neural networks, noise is acceptable and sometimes even necessary (such as Stochastic Gradient Descent). FP32 resolution is considered "standard," and the global trend is now FP16 or BF16. For Adam, FP32 resolution is more than sufficient for language learning, and if we wanted to use the library for "fine physics simulation" or "cryptography," we would keep it on the CPU with FP64.

3. Threshold Tuning
Your comment: The fixed threshold (10,000,000 operations) might not suit everyone.

Our response: I agree. In future releases, we will add the `ring_tensor_set_gpu_threshold(n)` function to make this number tunable from within the Ring script based on user profiling.

Best regards
Azzeddine

Mansour Ayouni

unread,
Jan 26, 2026, 9:37:07 AM (7 days ago) Jan 26
to Azzeddine Remmal, The Ring Programming Language
Hello Azzeddine,

Wonderful! I appreciate your mystery of this subject and ability to explain it in clear terms. Your're brigning a geniune value for us in the team regarding our ML and AI efforrs!

Thank you.

Mansour Ayouni

unread,
Jan 26, 2026, 9:42:53 AM (7 days ago) Jan 26
to Azzeddine Remmal, The Ring Programming Language
Hello Azzeddine,

Ah! I did not notice them...
Ok I'll test them tonight and let you know.

Best,
Mansour

Azzeddine Remmal

unread,
Jan 26, 2026, 9:44:23 AM (7 days ago) Jan 26
to The Ring Programming Language
Hello  Mansour .

I've updated RingML to v1.2.3 and update documention
and RingTensor to v1.3.2  and update documention

then install RingML.
ringpm install ringml-using-ringtensor from Azzeddine2017
or
ringpm update ringml-using-ringtensor from

 
Best regards
Azzeddine

Bert Mariani

unread,
Jan 26, 2026, 12:39:04 PM (7 days ago) Jan 26
to The Ring Programming Language
Hello Azzeddine

After using the latest
     -   ringpm install ringml-using-ringtensor from Azzeddine2017

All the tests are Running Good.

C:\ring\extensions\AlQalam\tests
C:\ring\samples\UsingRingML\

Cryptography,  
FinancialAnalysis,  
ImageProcessing,  
ParticleSystem

There was one benchmark  that showed a  ~ 2700 faster performance ... forgot which one.
Which test was that ?

Thanks and Best Regards
Bert Mariani

Azzeddine Remmal

unread,
Jan 26, 2026, 4:06:11 PM (7 days ago) Jan 26
to The Ring Programming Language
Hello Bert,

It seems I made a mistake with the number 2700; it should be 270, 
but the zero was repeated and I didn't notice.
You need to understand how the ringTensor and  AlQalam  work, 
and write an example to test whether I'm right or if I'm just talking nonsense.

λ ring test_alqalam_speed.ring
============================================================
  BENCHMARK STARTED
============================================================

Vector Size : 1000000
String Ops  : 20000
Map Lookups : 10000
============================================================
  1. VECTOR MATH (Multiply x 2)
============================================================
Running Ring List Loop...
  > Ring List Time : 8.02 s
Running AlQalam C++ Loop...
  > QalamVector Time : 0.02 s
  >>> RESULT: AlQalam is 358x FASTER! 🚀

============================================================
  2. STRING BUILDING (Append)
============================================================
Running Ring String Append...
  > Ring String Time : 0.15 s
Running QalamInk Append...
  > QalamInk Time : 1.20 s
  >>> RESULT: Ring  is  FASTER! 🚀

============================================================
  3. STRING BUILDING (Batch Append)
============================================================
Data Size: 20000 strings
Running Ring Loop...
  > Ring String Time : 0.30 s
Running Qalam Batch...
  > QalamInk (Batch) Time : 0.03 s
  >>> RESULT: AlQalam is 9x FASTER! 🚀

============================================================
  4. DICTIONARY SEARCH (O(N) vs O(1))
============================================================
Running Ring Find()...
  > Ring Find Time : 43.93 s
Running QalamIndex Get()...
  > QalamIndex Time : 0.39 s
  >>> RESULT: AlQalam is 111x FASTER! 🚀
==================================================
TEST COMPLETE.


Best regards
Azzeddine

Bert Mariani

unread,
Jan 29, 2026, 10:52:58 AM (4 days ago) Jan 29
to The Ring Programming Language
Hello Azzeddine

I was looking at your ParticleSystem.ring

Attached is 
     "mug.txt" -- a 3D particles of a Coffee Mug with 12890 rows x 3 cols.
     "Rotation-Matrices-4x4.txt"  --   matrix  4x4  for rotations , size, etc.

Can you create a sample that
     displays the initial image of the Mug
     rotates it 5 deg. in all 3 directions
     displays the motion, new image
     show the time it takes to perform the step

It would be interesting to see how a GPU increases the speed of performance

Thanks
Best Regards
Bert Mariani
Rotation-Matrices-4x4.txt
mug.txt

Azzeddine Remmal

unread,
Jan 29, 2026, 8:42:07 PM (3 days ago) Jan 29
to The Ring Programming Language
Hi Bert
The example is located in ring\extensions\ringtensor\tests
After `ringpm update ringml-using-ringtensor`

Capture.PNG

The calculation doesn't call the GPU because it's too "trivial" for it!

Let's do some quick calculations to see why it doesn't show up in Task Manager:
Workload: We have 13,000 points. Each point requires a matrix multiplication operation (4x4).

Number of operations:

≈13,000 × 16 × 2 = 416,000 operations (FLOPs).

Power of my graphics card (Intel HD 5500): Its capacity is approximately 300 GFLOPS (300 billion operations per second).

Time taken:
416,000/300,000,000,000 ≈ 0.000001 seconds
That's 1 microsecond! The result: The GPU wakes up, finishes working in 1 microsecond, and then immediately goes back to sleep.

Windows Task Manager updates the graph every 1 second (1,000,000 microseconds).

Therefore, it simply doesn't have time to see the GPU working. It's like trying to photograph a bullet with a regular phone camera.

Best regards
Azzeddine

Bert Mariani

unread,
Jan 30, 2026, 11:21:00 AM (3 days ago) Jan 30
to The Ring Programming Language
Hello Azzeddine

Thanks very much for the sample:
      ring\extensions\ringtensor\tests\mug_gpu_demo.ring
I have been studying the code. 
Best way to learn !

I have my original code in Ring, modified to use FastPro
      C:\ring\samples\UsingFastPro\MugRotation\Mug-Rotation-FastPro.ring

I ran each individually and both at the same time.
My version seems to run "visually" quicker.
Can you take a look.

My original code -- Mug-Rotation-C-Calc.ring 
Used  C-Code for the calculations and ran just as fast as the FastPro version
    mylibCalcMug.c

buildvc-mylibCalcMug.bat  (cannot attach)
cls    
call c:\ring\language\src\locatevc.bat x64    
cl /c /DEBUG mylibCalcMug.c -I "C:\ring\language\include"
link /DEBUG mylibCalcMug.obj c:\ring\lib\ring.lib /DLL /OUT:mylibCalcMug.dll
del mylibCalcMug.obj
pause

I cannot attach the resulting  DLL -- forbidden by Google groups


Best Regards
Bert Mariani

Mug-Rotation-C-Calc.ring
mylibCalcMug.c
mug.txt

Azzeddine Remmal

unread,
Jan 30, 2026, 12:12:36 PM (3 days ago) Jan 30
to The Ring Programming Language
Hello Bert

You're doing a great job and don't need help. 
Actually, I'm busy supporting BitNet technology in the RingTensor engine and don't have enough time.

Best regards
Azzeddine  

Reply all
Reply to author
Forward
0 new messages