Skip to content

Add complexConjugate to Number and remove isComplexConjugateOf: #247

@olekscode

Description

@olekscode

Step 1: We can add a complexConjugate method to the Number class that would return self

Number >> complexConjugate
    "The complex conjugate of a complex number (a + bi) is another complex number (a - bi).
    Every real number x is also a complex number with imaginary part equal to 0.
    In other words, x = x + 0i and x = x - 0i.
    Therefore, the complex conjugate of a real number is the same real number"
    
    ^ self

Step 2: And a test:

NumberTest >> testComplexConjugate

    self assert: 5 complexConjugate equals: 5

Step 3: Then inside PMMatrix >> isHermitian, instead of checking this condition

(self at: i at: j) isComplexConjugateOf: (self at: j at: i)

We simply write this:

(self at: i at: j) complexConjugate = (self at: j at: i)

Step 4: Then we deprecate the isComplexConjugateOf: because it is redundant:

PMComplex >> isComplexConjugateOf: aNumber
    "Answer true if self and aNumber are complex conjugates of each other. The complex conjugate of a complex number is the number with an equal real part and an imaginary part equal in magnitude but opposite in sign."
    self
        deprecated: 'This method is redundant. Just check the equality with complexConjugate'
        transformWith: '`@rec isComplexConjugate: `@arg' -> '`@rec complexConjugate = `@arg'.
        
    ^ self complexConjugate = aNumber

And the same for Number

Number >> isComplexConjugateOf: aNumber
    "A complex conjugate of a real number is same real number"
    self
        deprecated: 'This method is redundant. Just check the equality with complexConjugate'
        transformWith: '`@rec isComplexConjugate: `@arg' -> '`@rec complexConjugate = `@arg'.
        
    ^ self complexConjugate = aNumber

And we directly remove those two methods because they were only meant for double dispatch:

  • PMComplex >> isComplexConjugateOfAComplexNumber:
  • Number >> isComplexConjugateOfAComplexNumber:

Step 5: Finally, we remove the tests of isComplexConjugateOf: from PMComplexTest class. Those tests are not needed anymore and their job will be done by three tests: PMComlexTest >> testComplexConjugate, NumberTest >> testComplexConjugate and PMComplexTest >> testEquality.

Those are the tests to be removed:

  • testIsComplexConjugateOfConjugateComplex
  • testIsComplexConjugateOfConjugateComplexAndReal
  • testIsComplexConjugateOfConjugateRealAndComplex
  • testIsComplexConjugateOfDifferentReal
  • testIsComplexConjugateOfNonConjugateComplexAndReal
  • testIsComplexConjugateOfNonConjugateDifferentComplex
  • testIsComplexConjugateOfNonConjugateRealAndComplex
  • testIsComplexConjugateOfSameComplex
  • testIsComplexConjugateOfSameReal

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions