<commit_before>import Foundation

class MLinearEquationsSolutionStrategyRowAddition:MLinearEquationsSolutionStrategy
{
    class func samePivot(step:MLinearEquationsSolutionStep) -> MLinearEquationsSolutionStrategyRowAddition?
    {
        var indexEquation:Int = 0
        let countEquations:Int = step.equations.count
        let maxEquation:Int = countEquations - 1
        
        for equation:MLinearEquationsSolutionEquation in step.equations
        {
            if indexEquation < maxEquation
            {
                if equation.nonZero()
                {
                    let nextIndex:Int = indexEquation + 1
                    let equationBelow:MLinearEquationsSolutionEquation = step.equations[nextIndex]
                    
                    if equationBelow.nonZero()
                    {
                        let pivotIndex:Int = equation.pivotIndex()
                        let pivotIndexBelow:Int = equationBelow.pivotIndex()
                        
                        if pivotIndex == pivotIndexBelow
                        {
                            guard
                                
                                let topPolynomial:MLinearEquationsSolutionEquationItemPolynomial = equation.items[pivotIndex] as? MLinearEquationsSolutionEquationItemPolynomial,
                                let bottomPolynomial:MLinearEquationsSolutionEquationItemPolynomial = equationBelow.items[pivotIndex] as? MLinearEquationsSolutionEquationItemPolynomial
                            
                            else
                            {
                                return nil
                            }
                            
                            let topCoefficient:Double = topPolynomial.coefficient
                            let bottomCoefficient:Double = bottomPolynomial.coefficient
                            var scalar:Double = abs(bottomCoefficient / topCoefficient)
                            
                            if topCoefficient > 0
                            {
                                if bottomCoefficient > 0
                                {
                                    scalar = -scalar
                                }
                            }
                            else
                            {
                                if bottomCoefficient < 0
                                {
                                    scalar = -scalar
                                }
                            }
                            
                            print("row addition: \(nextIndex) scalar \(scalar). Top: \(topCoefficient), bottom: \(bottomCoefficient)")
                            
                            let strategy:MLinearEquationsSolutionStrategyRowAddition = MLinearEquationsSolutionStrategyRowAddition(
                                step:step,
                                indexRow:nextIndex,
                                scalar:scalar)
                            
                            return strategy
                        }
                    }
                }
            }
            
            indexEquation += 1
        }
        
        return nil
    }
    
    private let indexRow:Int
    private let scalar:Double
    
    private init(
        step:MLinearEquationsSolutionStep,
        indexRow:Int,
        scalar:Double)
    {
        self.indexRow = indexRow
        self.scalar = scalar
        super.init(step:step)
    }
    
    override func process(delegate:MLinearEquationsSolutionStrategyDelegate)
    {
        super.process(delegate:delegate)
        
        addRows()
    }
    
    //MARK: private
    
    private func addRows()
    {
        var equations:[MLinearEquationsSolutionEquation] = []
        let scalarString:String = MSession.sharedInstance.stringFrom(number:scalar)
        let descr:String = String(
            format:NSLocalizedString("MLinearEquationsSolutionStrategyRowAddition_descr", comment:""),
            "\(indexRow)",
            "\(indexRow)",
            "\((indexRow - 1))",
            scalarString)
        
        var indexEquation:Int = 0
        
        for equation:MLinearEquationsSolutionEquation in self.step.equations
        {
            let newEquation:MLinearEquationsSolutionEquation
            
            if indexEquation == indexRow
            {
                let previousEquation:MLinearEquationsSolutionEquation = self.step.equations[indexEquation - 1]
                let scaledPrevious:MLinearEquationsSolutionEquation = previousEquation.multiplyScalar(
                    scalar:scalar)
                
                newEquation = equation.addEquation(
                    equation:scaledPrevious)
            }
            else
            {
                newEquation = equation
            }
            
            equations.append(newEquation)
            
            indexEquation += 1
        }
        
        let step:MLinearEquationsSolutionStepProcess = MLinearEquationsSolutionStepProcess(
            equations:equations,
            descr:descr)
        completed(step:step)
    }
}
<commit_msg>typo row index description<commit_after>import Foundation

class MLinearEquationsSolutionStrategyRowAddition:MLinearEquationsSolutionStrategy
{
    class func samePivot(step:MLinearEquationsSolutionStep) -> MLinearEquationsSolutionStrategyRowAddition?
    {
        var indexEquation:Int = 0
        let countEquations:Int = step.equations.count
        let maxEquation:Int = countEquations - 1
        
        for equation:MLinearEquationsSolutionEquation in step.equations
        {
            if indexEquation < maxEquation
            {
                if equation.nonZero()
                {
                    let nextIndex:Int = indexEquation + 1
                    let equationBelow:MLinearEquationsSolutionEquation = step.equations[nextIndex]
                    
                    if equationBelow.nonZero()
                    {
                        let pivotIndex:Int = equation.pivotIndex()
                        let pivotIndexBelow:Int = equationBelow.pivotIndex()
                        
                        if pivotIndex == pivotIndexBelow
                        {
                            guard
                                
                                let topPolynomial:MLinearEquationsSolutionEquationItemPolynomial = equation.items[pivotIndex] as? MLinearEquationsSolutionEquationItemPolynomial,
                                let bottomPolynomial:MLinearEquationsSolutionEquationItemPolynomial = equationBelow.items[pivotIndex] as? MLinearEquationsSolutionEquationItemPolynomial
                            
                            else
                            {
                                return nil
                            }
                            
                            let topCoefficient:Double = topPolynomial.coefficient
                            let bottomCoefficient:Double = bottomPolynomial.coefficient
                            var scalar:Double = abs(bottomCoefficient / topCoefficient)
                            
                            if topCoefficient > 0
                            {
                                if bottomCoefficient > 0
                                {
                                    scalar = -scalar
                                }
                            }
                            else
                            {
                                if bottomCoefficient < 0
                                {
                                    scalar = -scalar
                                }
                            }
                            
                            print("row addition: \(nextIndex) scalar \(scalar). Top: \(topCoefficient), bottom: \(bottomCoefficient)")
                            
                            let strategy:MLinearEquationsSolutionStrategyRowAddition = MLinearEquationsSolutionStrategyRowAddition(
                                step:step,
                                indexRow:nextIndex,
                                scalar:scalar)
                            
                            return strategy
                        }
                    }
                }
            }
            
            indexEquation += 1
        }
        
        return nil
    }
    
    private let indexRow:Int
    private let scalar:Double
    
    private init(
        step:MLinearEquationsSolutionStep,
        indexRow:Int,
        scalar:Double)
    {
        self.indexRow = indexRow
        self.scalar = scalar
        super.init(step:step)
    }
    
    override func process(delegate:MLinearEquationsSolutionStrategyDelegate)
    {
        super.process(delegate:delegate)
        
        addRows()
    }
    
    //MARK: private
    
    private func addRows()
    {
        var equations:[MLinearEquationsSolutionEquation] = []
        let scalarString:String = MSession.sharedInstance.stringFrom(number:scalar)
        let descr:String = String(
            format:NSLocalizedString("MLinearEquationsSolutionStrategyRowAddition_descr", comment:""),
            "\(indexRow + 1)",
            "\(indexRow + 1)",
            "\((indexRow))",
            scalarString)
        
        var indexEquation:Int = 0
        
        for equation:MLinearEquationsSolutionEquation in self.step.equations
        {
            let newEquation:MLinearEquationsSolutionEquation
            
            if indexEquation == indexRow
            {
                let previousEquation:MLinearEquationsSolutionEquation = self.step.equations[indexEquation - 1]
                let scaledPrevious:MLinearEquationsSolutionEquation = previousEquation.multiplyScalar(
                    scalar:scalar)
                
                newEquation = equation.addEquation(
                    equation:scaledPrevious)
            }
            else
            {
                newEquation = equation
            }
            
            equations.append(newEquation)
            
            indexEquation += 1
        }
        
        let step:MLinearEquationsSolutionStepProcess = MLinearEquationsSolutionStepProcess(
            equations:equations,
            descr:descr)
        completed(step:step)
    }
}

{'fraction_non_alphanumeric': 0.0515701526937482, 'fraction_numerical': 0.002208777489676366, 'mean_word_length': 1.1068177220311552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3026420', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2148, 'n_words': 364}