<commit_before>package org.purview.core.data

import scala.math.Numeric._
import scala.math._

object Complex {
  trait ComplexIsConflicted[A] extends Numeric[Complex[A]] {
    implicit protected def arithmetic: Numeric[A]
    def plus(x: Complex[A], y: Complex[A]) = x + y
    def minus(x: Complex[A], y: Complex[A]) = x - y
    def times(x: Complex[A], y: Complex[A]) = x * y
    def negate(x: Complex[A]) = -x
    def fromInt(x: Int) = Complex(arithmetic.fromInt(x), arithmetic.fromInt(0))
    def toInt(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real).toInt
    }
    def toLong(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real).toLong
    }
    def toFloat(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real).toFloat
    }
    def toDouble(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real)
    }

    def compare(x: Complex[A], y: Complex[A]) = toDouble(x) compare toDouble(y)
  }

  implicit def numeric[A: Numeric] = new ComplexIsConflicted[A] {
    protected def arithmetic = implicitly
  }

  implicit def fromTuple[A: Numeric](aa: (A, A)) = Complex(aa._1, aa._2)

  implicit def fromAnyReal[A: Numeric](n: A) = Complex(n, (implicitly: Numeric[A]).fromInt(0))
  implicit def fromAnyImaginary[A: Numeric](n: A) = new {
    def i = Complex((implicitly: Numeric[A]).fromInt(0), n)
  }
}

case class Complex[A: Numeric](val real: A, val imag: A) {
  protected def arithmetic: Numeric[A] = implicitly

  def +(that: Complex[A]): Complex[A] =
    new Complex(arithmetic.plus(this.real, that.real), arithmetic.plus(this.imag, that.imag))

  def -(that: Complex[A]): Complex[A] =
    new Complex(arithmetic.minus(this.real, that.real), arithmetic.minus(this.imag, that.imag))

  def *(that: Complex[A]): Complex[A] =
    new Complex(arithmetic.minus(arithmetic.times(this.real, that.real), arithmetic.times(this.imag, that.imag)),
                arithmetic.plus(arithmetic.times(this.real, that.imag), arithmetic.times(this.imag, that.real)))

  def +(that: A): Complex[A] = new Complex(arithmetic.plus(this.real, that), this.imag)
  def -(that: A): Complex[A] = new Complex(arithmetic.minus(this.real, that), this.imag)
  def *(that: A): Complex[A] = new Complex(arithmetic.times(this.real, that), arithmetic.times(this.imag, that))
}
<commit_msg>Added magnitude property to complex numbers.<commit_after>package org.purview.core.data

import scala.math.Numeric._
import scala.math._

object Complex {
  trait ComplexIsConflicted[A] extends Numeric[Complex[A]] {
    implicit protected def arithmetic: Numeric[A]
    def plus(x: Complex[A], y: Complex[A]) = x + y
    def minus(x: Complex[A], y: Complex[A]) = x - y
    def times(x: Complex[A], y: Complex[A]) = x * y
    def negate(x: Complex[A]) = -x
    def fromInt(x: Int) = Complex(arithmetic.fromInt(x), arithmetic.fromInt(0))
    def toInt(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real).toInt
    }
    def toLong(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real).toLong
    }
    def toFloat(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real).toFloat
    }
    def toDouble(x: Complex[A]) = {
      val imag = arithmetic.toDouble(x.real)
      val real = arithmetic.toDouble(x.imag)
      sqrt(imag * imag + real * real)
    }

    def compare(x: Complex[A], y: Complex[A]) = toDouble(x) compare toDouble(y)
  }

  implicit def numeric[A: Numeric] = new ComplexIsConflicted[A] {
    protected def arithmetic = implicitly
  }

  implicit def fromTuple[A: Numeric](aa: (A, A)) = Complex(aa._1, aa._2)

  implicit def fromAnyReal[A: Numeric](n: A) = Complex(n, (implicitly: Numeric[A]).fromInt(0))
  implicit def fromAnyImaginary[A: Numeric](n: A) = new {
    def i = Complex((implicitly: Numeric[A]).fromInt(0), n)
  }
}

case class Complex[A: Numeric](val real: A, val imag: A) {
  protected def arithmetic: Numeric[A] = implicitly

  def toInt = Complex.numeric[A].toInt(this)
  def toLong = Complex.numeric[A].toLong(this)
  def toFloat = Complex.numeric[A].toFloat(this)
  def toDouble = Complex.numeric[A].toDouble(this)

  def +(that: Complex[A]): Complex[A] =
    new Complex(arithmetic.plus(this.real, that.real), arithmetic.plus(this.imag, that.imag))

  def -(that: Complex[A]): Complex[A] =
    new Complex(arithmetic.minus(this.real, that.real), arithmetic.minus(this.imag, that.imag))

  def *(that: Complex[A]): Complex[A] =
    new Complex(arithmetic.minus(arithmetic.times(this.real, that.real), arithmetic.times(this.imag, that.imag)),
                arithmetic.plus(arithmetic.times(this.real, that.imag), arithmetic.times(this.imag, that.real)))

  def +(that: A): Complex[A] = new Complex(arithmetic.plus(this.real, that), this.imag)
  def -(that: A): Complex[A] = new Complex(arithmetic.minus(this.real, that), this.imag)
  def *(that: A): Complex[A] = new Complex(arithmetic.times(this.real, that), arithmetic.times(this.imag, that))
}

{'fraction_non_alphanumeric': 0.15551109494361587, 'fraction_numerical': 0.0018188432157148053, 'mean_word_length': 3.7405172413793104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6271438', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1889, 'n_words': 445}