Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Math-Complex/Number.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ Number >> asComplex [

{ #category : #'*Math-Complex' }
Number >> complexConjugate [
^ self.
"The complex conjugate of a complex number (a + bi) is another complex number (a - bi).
Copy link
Contributor

@hemalvarambhia hemalvarambhia Apr 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't have added the comment here and instead used tests to document this (Tests as Documentation). I would only comment on a design decision I made, the why, if you will. I suspect you did this because not all developers are familiar with concepts from mathematics. Is that right?

The part of about a real number being its own complex conjugate is a test already.

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
]

{ #category : #'*Math-Complex' }
Expand All @@ -37,13 +42,11 @@ Number >> i: aNumber [
{ #category : #'*Math-Complex' }
Number >> isComplexConjugateOf: aNumber [
"A complex conjugate of a real number is same real number"
^ self = aNumber
]
self
deprecated: 'This method is redundant. Just check the equality with complexConjugate'
transformWith: '`@rec isComplexConjugate: `@arg' -> '`@rec complexConjugate = `@arg'.

{ #category : #'*Math-Complex' }
Number >> isComplexConjugateOfAComplexNumber: aComplexNumber [
"A complex conjugate of a real number is same real number"
^ self isComplexConjugateOf: aComplexNumber
^ self complexConjugate = aNumber
]

{ #category : #'*Math-Complex' }
Expand Down
10 changes: 4 additions & 6 deletions src/Math-Complex/PMComplex.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,11 @@ PMComplex >> imaginary [
{ #category : #testing }
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."
^ aNumber isComplexConjugateOfAComplexNumber: self
]
self
deprecated: 'This method is redundant. Just check the equality with complexConjugate'
transformWith: '`@rec isComplexConjugate: `@arg' -> '`@rec complexConjugate = `@arg'.

{ #category : #testing }
PMComplex >> isComplexConjugateOfAComplexNumber: aComplexNumber [
"Answer true if self and aComplexNumber 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."
^ (aComplexNumber real = real) and: [ aComplexNumber imaginary = (-1 * imaginary) ]
^ self complexConjugate = aNumber
]

{ #category : #testing }
Expand Down
14 changes: 7 additions & 7 deletions src/Math-Complex/PMComplex.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ PMComplex >> productWithVector: aVector [
^ aVector collect: [ :each | each * self ]
]

{ #category : #'*Math-Complex' }
PMComplex class >> random [
"Answers a random number with abs between 0 and 1."

^ self abs: 1.0 random arg: 2 * Float pi random
]

{ #category : #'*Math-Complex' }
PMComplex >> random [
"analog to Number>>random. However, the only bound is that the abs of the produced complex is less than the length of the receive. The receiver effectively defines a disc within which the random element can be produced."
^ self class random * self

]

{ #category : #'*Math-Complex' }
PMComplex class >> random [
"Answers a random number with abs between 0 and 1."

^ self abs: 1.0 random arg: 2 * Float pi random
]

{ #category : #'*Math-Complex' }
PMComplex >> subtractToPolynomial: aPolynomial [
^ aPolynomial addNumber: self negated
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Matrix/PMMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ PMMatrix >> isHermitian [

1 to: self numberOfRows do: [ :i |
1 to: (i - 1) do: [ :j |
((self at: i at: j) isComplexConjugateOf: (self at: j at: i))
((self at: i at: j) complexConjugate = (self at: j at: i))
ifFalse: [ ^ false ] ] ].

^ true
Expand Down
7 changes: 7 additions & 0 deletions src/Math-Tests-Complex/NumberTest.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : #NumberTest }

{ #category : #'*Math-Tests-Complex' }
NumberTest >> testComplexConjugate [

self assert: 5 complexConjugate equals: 5
]
54 changes: 0 additions & 54 deletions src/Math-Tests-Complex/PMComplexTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -389,60 +389,6 @@ PMComplexTest >> testHash [
self assert: aComplex copy hash equals: aComplex hash
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfConjugateComplex [

self assert: ((3 + 2i) isComplexConjugateOf: (3 - 2i))
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfConjugateComplexAndReal [

self assert: ((5 + 0i) isComplexConjugateOf: 5)
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfConjugateRealAndComplex [

self assert: (5 isComplexConjugateOf: (5 - 0i))
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfDifferentReal [

self deny: (-5 isComplexConjugateOf: 5)
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfNonConjugateComplexAndReal [

self deny: ((5 + 3i) isComplexConjugateOf: 5)
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfNonConjugateDifferentComplex [

self deny: ((-0.5 - 1i) isComplexConjugateOf: (3 - 2i))
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfNonConjugateRealAndComplex [

self deny: (5 isComplexConjugateOf: (5 - 3i))
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfSameComplex [

self deny: ((3 - 2i) isComplexConjugateOf: (3 - 2i))
]

{ #category : #tests }
PMComplexTest >> testIsComplexConjugateOfSameReal [

self assert: (5 isComplexConjugateOf: 5)
]

{ #category : #tests }
PMComplexTest >> testIsComplexNumberOnComplex [

Expand Down
30 changes: 0 additions & 30 deletions src/Math-Tests-Complex/PMNumberTest.class.st

This file was deleted.