Recent posts

#71
Next on the #WEFAgenda2030 is a food-crisis.
They also destroy all companies making "vertical farming".

#72
Bitcoin by today is somewhere between 60000 and 70000 US$.
"Plan B" sees the value of 1 BITCOIN at 500.000 in 2025 so get in if you can!
Even if you buy just 0.1 Bitcoin.

⏰ Timestamps
0:16 Bitcoin Stock-to-Flow Model (S2F)
4:27 Bitcoin Market Cycle
5:54 Bitcoin Relative Strength Index (RSI)
8:03 Bitcoin 200 Week Moving Average (200WMA)
9:04 Bitcoin Realized Price
11:47 Bitcoin Realized Return
12:40 Bitcoin in Profit

#73
Source Code and Discussions / Re: Pattern-Matcher for Wildca...
Last post by Theo Gottwald - April 02, 2024, 08:18:56 AM
Patternmatcher Simple Variant.
This function takes the following parameters:
' Input:
- `text`: The string to search for patterns.
- `pattern`: The pattern to match against the text.
- `occurrence`: The x'th occurrence of the pattern to find (1-based index).
Output:
- `position`: ByRef parameter to store the starting position of the found pattern.
- `length`: ByRef

Function PatternMatch(ByVal text As String, ByVal pattern As String, ByVal occurrence As Long, ByRef position As Long, ByRef length As Long) As Long
    Dim i As Long, j As Long, k As Long
    Dim found As Long, match As Long
    Dim patternLength As Long, textLength As Long
   
    patternLength = Len(pattern)
    textLength = Len(text)
   
    found = 0
    i = 1
    j = 1
   
    Do While i <= textLength
        Select Case Mid$(pattern, j, 1)
            Case "+"
                If j = patternLength Then
                    found = found + 1
                    If found = occurrence Then
                        position = i - patternLength + 1
                        length = patternLength
                        PatternMatch = -1
                        Exit Function
                    End If
                    j = 1
                Else
                    j = j + 1
                End If
                i = i + 1
           
            Case "*"
                If j = patternLength Then
                    found = found + 1
                    If found = occurrence Then
                        position = i - patternLength + 1
                        length = textLength - i + 1
                        PatternMatch = -1
                        Exit Function
                    End If
                    j = 1
                Else
                    j = j + 1
                End If
           
            Case "?"
                If j = patternLength Then
                    found = found + 1
                    If found = occurrence Then
                        position = i - patternLength + 1
                        length = patternLength
                        PatternMatch = -1
                        Exit Function
                    End If
                    j = 1
                Else
                    j = j + 1
                End If
                i = i + 1
           
            Case "["
                match = 0
                j = j + 1
                Do While Mid$(pattern, j, 1) <> "]"
                    If Mid$(pattern, j, 1) = Mid$(text, i, 1) Then
                        match = -1
                        Exit Do
                    End If
                    j = j + 1
                Loop
                If match Then
                    If j = patternLength Then
                        found = found + 1
                        If found = occurrence Then
                            position = i - patternLength + 1
                            length = patternLength
                            PatternMatch = -1
                            Exit Function
                        End If
                        j = 1
                    Else
                        j = j + 1
                    End If
                    i = i + 1
                Else
                    i = i + 1
                    j = 1
                End If
           
            Case Else
                If Mid$(pattern, j, 1) = Mid$(text, i, 1) Then
                    If j = patternLength Then
                        found = found + 1
                        If found = occurrence Then
                            position = i - patternLength + 1
                            length = patternLength
                            PatternMatch = -1
                            Exit Function
                        End If
                        j = 1
                    Else
                        j = j + 1
                    End If
                    i = i + 1
                Else
                    i = i + 1
                    j = 1
                End If
        End Select
    Loop
   
    PatternMatch = 0
End Function
' Coded by MISTRAL LARGE
#74
Source Code and Discussions / Pattern-Matcher for Wildcards
Last post by Theo Gottwald - April 02, 2024, 08:16:11 AM
Version 1: using Glushkov's algorithm implementation in PowerBasic that handles the wildcard characters and the cases where a character class is empty and a wildcard character needs to be escaped.

' Global variables for the DFA
Dim dfaStates() As DFAState
Dim dfaInitialState As Long
Dim dfaAcceptingStates As String ' Bitset representing the accepting states

Type DFAState
    isAccepting As Boolean
    transitions(0 To 255) As Long ' Assuming ASCII characters
End Type

Function PatternMatch(ByVal text As String, ByVal pattern As String, ByVal occurrence As Long, ByRef position As Long, ByRef length As Long) As Long
    ' Preprocess the pattern to build a DFA
    BuildDFA(pattern)

    ' Match the text against the DFA
    Dim state As Long
    state = dfaInitialState
    Dim found As Long
    found = 0
    Dim i As Long
    i = 1
    Do While i <= Len(text)
        state = DFATransition(state, Mid$(text, i, 1))
        If DFAIsAccepting(state) Then
            found = found + 1
            If found = occurrence Then
                position = i - Len(pattern) + 1
                length = Len(pattern)
                PatternMatch = -1
                Exit Function
            End If
        End If
        i = i + 1
    Loop

    PatternMatch = 0
End Function

Sub BuildDFA(ByVal pattern As String)
    ' Implement Glushkov's algorithm to build a DFA from the pattern

    Dim numStates As Long
    numStates = Len(pattern) + 1
    ReDim dfaStates(0 To numStates - 1)

    Dim i As Long
    For i = 0 To numStates - 1
        Dim state As DFAState
        state.isAccepting = (i = numStates - 1)
        For j = 0 To 255
            state.transitions(j) = -1 ' -1 represents an invalid transition
        Next j
        dfaStates(i) = state
    Next i

    Dim currentState As Long
    currentState = 0
    For i = 1 To Len(pattern)
        Dim c As String
        c = Mid$(pattern, i, 1)
        Dim charCode As Long
        charCode = Asc(c)
        Select Case c
            Case "+"
                ' Handle the "+" wildcard character
                ' This is equivalent to the previous character being optional
                ' We add a transition from the previous state to the current state for the previous character
                Dim prevCharCode As Long
                prevCharCode = Asc(Mid$(pattern, i - 1, 1))
                dfaStates(currentState - 1).transitions(prevCharCode) = currentState

            Case "*"
                ' Handle the "*" wildcard character
                ' This is equivalent to the previous character being repeated zero or more times
                ' We add a transition from the previous state to itself for the previous character
                ' We also add a transition from the previous state to the current state for any character
                prevCharCode = Asc(Mid$(pattern, i - 1, 1))
                dfaStates(currentState - 1).transitions(prevCharCode) = currentState - 1
                For j = 0 To 255
                    dfaStates(currentState - 1).transitions(j) = currentState
                Next j

            Case "?"
                ' Handle the "?" wildcard character
                ' This is equivalent to the previous character being optional
                ' We add a transition from the previous state to the current state for any character
                For j = 0 To 255
                    dfaStates(currentState - 1).transitions(j) = currentState
                Next j

            Case "["
                ' Handle the "[" wildcard character
                ' We start a new character class
                ' We also handle the case where the character class is empty
                Dim charClassStart As Long
                charClassStart = i
                If i = Len(pattern) Or Mid$(pattern, i + 1, 1) = "]" Then
                    ' The character class is empty, so we add a transition for any character
                    For j = 0 To 255
                        dfaStates(currentState - 1).transitions(j) = currentState
                    Next j
                End If

            Case "]"
                ' Handle the "]" wildcard character
                ' We end a character class
                ' We add a transition from the previous state to the current state for any character in the class
                Dim charClassEnd As Long
                charClassEnd = i
                For j = charClassStart + 1 To charClassEnd - 1
                    Dim charClassChar As String
                    charClassChar = Mid$(pattern, j, 1)
                    Dim charClassCharCode As Long
                    charClassCharCode = Asc(charClassChar)
                    dfaStates(currentState - 1).transitions(charClassCharCode) = currentState
                Next j

            Case Else
                ' Handle a regular character or an escaped wildcard character
                If c = "\" Then
                    ' The next character is escaped
                    Dim nextChar As String
                    nextChar = Mid$(pattern, i + 1, 1)
                    Dim nextCharCode As Long
                    nextCharCode = Asc(nextChar)
                    dfaStates(currentState).transitions(nextCharCode) = currentState + 1
                    currentState = currentState + 1
                    i = i + 1 ' Skip the next character
                Else
                    dfaStates(currentState).transitions(charCode) = currentState + 1
                    currentState = currentState + 1
                End If
        End Select
    Next i

    ' Set the accepting states
    dfaAcceptingStates = Str$(2 ^ (numStates - 1)) ' Only the last state is accepting
    dfaInitialState = 0
End Sub

Function DFAIsAccepting(ByVal state As Long) As Boolean
    Dim acceptingStates As String
    acceptingStates = Str$(dfaAcceptingStates)
    Dim stateBit As Long
    stateBit = (state Mod 10)
    Return (stateBit = 1)
End Function

Function DFATransition(ByVal state As Long, ByVal c As String) As Long
    Dim charCode As Long
    charCode = Asc(c)
    Dim transition As Long
    transition = dfaStates(state).transitions(charCode)
    If transition = -1 Then
        ' If there's no valid transition, stay in the same state
        transition = state
    End If
    Return transition
End Function
' using MISTRAL LARGE


#75
Following the tracks of Germany, Netherlands and France

Is this the end of British Farming? Tractors storm Parliament.

PoliticsJOE
28 mar 2024

#76
General Discussion / "Clean" Code, Horrible Perform...
Last post by Charles Pegge - March 30, 2024, 12:57:42 AM
OOP abstractions come at a high cost for both man and machine. Where appropriate use case blocks instead, or better still ,  lookup tables!


Molly Rocket

28 feb 2023

#77
OxygenBasic / Re: Tools for 4 Dimensional Ge...
Last post by Charles Pegge - March 29, 2024, 12:57:24 PM
Note that AVX support is quite patchy. For instance my PC has an AMD Ryzen-3 processor pre 2020, and this does not support AVX.

https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
#78
OxygenBasic / Re: dll for HTTPS that uses th...
Last post by Theo Gottwald - March 29, 2024, 09:11:31 AM
Quote from: Eduardo Jorge on March 27, 2024, 04:21:02 PMTheo, with tls1.2 it works normally on win7, the problem is tls1.3

I seem not to understand the problem.
Why don't you just hop over to Claude3 and ask for a solution?
#79
OxygenBasic / Re: Tools for 4 Dimensional Ge...
Last post by Theo Gottwald - March 28, 2024, 11:12:05 AM
Here's the implementation of the interpolate function in O2 Basic, along with variants in x86 and x64 SIMD assembler:

O2 Basic:

method interpolate(Transform4D other, float t)
    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    for i = 0 to 24
        r[i] = a[i] + (b[i] - a[i]) * t
    next

    idx += 25 ; Update the matrix index
end method

x86 SIMD Assembler (SSE):

method interpolate_SSE(Transform4D other, float t)
    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    ; Load the interpolation factor into an SSE register
    movss xmm7, t
    shufps xmm7, xmm7, 0

    ; Perform interpolation using SSE instructions
    mov ecx, 6 ; Loop counter (6 iterations for 24 elements)
    mov esi, a
    mov edi, b
    mov edx, r

    .loop:
        movaps xmm0, [esi]
        movaps xmm1, [edi]
        subps xmm1, xmm0
        mulps xmm1, xmm7
        addps xmm0, xmm1
        movaps [edx], xmm0

        add esi, 16
        add edi, 16
        add edx, 16

        dec ecx
        jnz .loop

    idx += 25 ; Update the matrix index
end method

x64 SIMD Assembler (AVX):

method interpolate_AVX(Transform4D other, float t)
    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    ; Load the interpolation factor into an AVX register
    vbroadcastss ymm7, t

    ; Perform interpolation using AVX instructions
    mov rcx, 3 ; Loop counter (3 iterations for 24 elements)
    mov rsi, a
    mov rdi, b
    mov rdx, r

    .loop:
        vmovaps ymm0, [rsi]
        vmovaps ymm1, [rdi]
        vsubps ymm1, ymm1, ymm0
        vmulps ymm1, ymm1, ymm7
        vaddps ymm0, ymm0, ymm1
        vmovaps [rdx], ymm0

        add rsi, 32
        add rdi, 32
        add rdx, 32

        dec rcx
        jnz .loop

    idx += 25 ; Update the matrix index
end method

In the O2 Basic implementation, the interpolation is performed element-wise using a loop.

The x86 SIMD assembler variant uses SSE instructions to perform the interpolation. It loads the interpolation factor into an SSE register and uses movaps, subps, mulps, and addps instructions to perform the interpolation on four elements at a time. The loop is unrolled to process 24 elements (6 iterations).

The x64 SIMD assembler variant uses AVX instructions, which can process eight elements at a time. It loads the interpolation factor into an AVX register using vbroadcastss and uses vmovaps, vsubps, vmulps, and vaddps instructions for the interpolation. The loop is unrolled to process 24 elements (3 iterations).

Note that the SIMD assembler code assumes the availability of SSE (x86) or AVX (x64) instructions on the target platform. Make sure to adapt the code to match the specific assembler syntax and conventions of your assembler and platform.


method interpolate(Transform4D other, float t)
    if t < 0.0 or t > 1.0
        print "Error: Interpolation factor t must be between 0 and 1."
        return
    endif

    float* a = @f + idx * 4
    float* b = @other.f + other.idx * 4
    float* r = @f + (idx + 25) * 4

    int i
    for i = 0 to 24
        r[i] = a[i] + (b[i] - a[i]) * t
    next

    idx += 25 ; Update the matrix index
end method

@Charles tell me if you need anything else. As you can see i have mutated to a 4D- ASM Expert "Over night" :-)

#80
OxygenBasic / Re: Tools for 4 Dimensional Ge...
Last post by Charles Pegge - March 28, 2024, 10:03:23 AM
Thanks Theo,

We don't need the full set of 3D matrix operations, but interpolation would be potentially very useful for taking 3D sections of a 4D object. For instance: slicing a 4D hypersphere along the w axis would produce 3D spheres of different sizes.