-
-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
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"
^ selfStep 2: And a test:
NumberTest >> testComplexConjugate
self assert: 5 complexConjugate equals: 5Step 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 = aNumberAnd 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 = aNumberAnd 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:
testIsComplexConjugateOfConjugateComplextestIsComplexConjugateOfConjugateComplexAndRealtestIsComplexConjugateOfConjugateRealAndComplextestIsComplexConjugateOfDifferentRealtestIsComplexConjugateOfNonConjugateComplexAndRealtestIsComplexConjugateOfNonConjugateDifferentComplextestIsComplexConjugateOfNonConjugateRealAndComplextestIsComplexConjugateOfSameComplextestIsComplexConjugateOfSameReal