Skip to content

Commit 7342d75

Browse files
committed
Fixed #247. Added complexConjugate to Number and removed isCompleConjugateOf:
1 parent 4b53cef commit 7342d75

File tree

7 files changed

+29
-105
lines changed

7 files changed

+29
-105
lines changed

src/Math-Complex/Number.extension.st

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ Number >> asComplex [
1515

1616
{ #category : #'*Math-Complex' }
1717
Number >> complexConjugate [
18-
^ self.
18+
"The complex conjugate of a complex number (a + bi) is another complex number (a - bi).
19+
Every real number x is also a complex number with imaginary part equal to 0.
20+
In other words, x = x + 0i and x = x - 0i.
21+
Therefore, the complex conjugate of a real number is the same real number"
22+
23+
^ self
1924
]
2025

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

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

4952
{ #category : #'*Math-Complex' }

src/Math-Complex/PMComplex.class.st

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,11 @@ PMComplex >> imaginary [
538538
{ #category : #testing }
539539
PMComplex >> isComplexConjugateOf: aNumber [
540540
"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."
541-
^ aNumber isComplexConjugateOfAComplexNumber: self
542-
]
541+
self
542+
deprecated: 'This method is redundant. Just check the equality with complexConjugate'
543+
transformWith: '`@rec isComplexConjugate: `@arg' -> '`@rec complexConjugate = `@arg'.
543544

544-
{ #category : #testing }
545-
PMComplex >> isComplexConjugateOfAComplexNumber: aComplexNumber [
546-
"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."
547-
^ (aComplexNumber real = real) and: [ aComplexNumber imaginary = (-1 * imaginary) ]
545+
^ self complexConjugate = aNumber
548546
]
549547

550548
{ #category : #testing }

src/Math-Complex/PMComplex.extension.st

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ PMComplex >> productWithVector: aVector [
1717
^ aVector collect: [ :each | each * self ]
1818
]
1919

20-
{ #category : #'*Math-Complex' }
21-
PMComplex class >> random [
22-
"Answers a random number with abs between 0 and 1."
23-
24-
^ self abs: 1.0 random arg: 2 * Float pi random
25-
]
26-
2720
{ #category : #'*Math-Complex' }
2821
PMComplex >> random [
2922
"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."
3023
^ self class random * self
3124

3225
]
3326

27+
{ #category : #'*Math-Complex' }
28+
PMComplex class >> random [
29+
"Answers a random number with abs between 0 and 1."
30+
31+
^ self abs: 1.0 random arg: 2 * Float pi random
32+
]
33+
3434
{ #category : #'*Math-Complex' }
3535
PMComplex >> subtractToPolynomial: aPolynomial [
3636
^ aPolynomial addNumber: self negated

src/Math-Matrix/PMMatrix.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ PMMatrix >> isHermitian [
567567

568568
1 to: self numberOfRows do: [ :i |
569569
1 to: (i - 1) do: [ :j |
570-
((self at: i at: j) isComplexConjugateOf: (self at: j at: i))
570+
((self at: i at: j) complexConjugate = (self at: j at: i))
571571
ifFalse: [ ^ false ] ] ].
572572

573573
^ true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Extension { #name : #NumberTest }
2+
3+
{ #category : #'*Math-Tests-Complex' }
4+
NumberTest >> testComplexConjugate [
5+
6+
self assert: 5 complexConjugate equals: 5
7+
]

src/Math-Tests-Complex/PMComplexTest.class.st

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -389,60 +389,6 @@ PMComplexTest >> testHash [
389389
self assert: aComplex copy hash equals: aComplex hash
390390
]
391391

392-
{ #category : #tests }
393-
PMComplexTest >> testIsComplexConjugateOfConjugateComplex [
394-
395-
self assert: ((3 + 2i) isComplexConjugateOf: (3 - 2i))
396-
]
397-
398-
{ #category : #tests }
399-
PMComplexTest >> testIsComplexConjugateOfConjugateComplexAndReal [
400-
401-
self assert: ((5 + 0i) isComplexConjugateOf: 5)
402-
]
403-
404-
{ #category : #tests }
405-
PMComplexTest >> testIsComplexConjugateOfConjugateRealAndComplex [
406-
407-
self assert: (5 isComplexConjugateOf: (5 - 0i))
408-
]
409-
410-
{ #category : #tests }
411-
PMComplexTest >> testIsComplexConjugateOfDifferentReal [
412-
413-
self deny: (-5 isComplexConjugateOf: 5)
414-
]
415-
416-
{ #category : #tests }
417-
PMComplexTest >> testIsComplexConjugateOfNonConjugateComplexAndReal [
418-
419-
self deny: ((5 + 3i) isComplexConjugateOf: 5)
420-
]
421-
422-
{ #category : #tests }
423-
PMComplexTest >> testIsComplexConjugateOfNonConjugateDifferentComplex [
424-
425-
self deny: ((-0.5 - 1i) isComplexConjugateOf: (3 - 2i))
426-
]
427-
428-
{ #category : #tests }
429-
PMComplexTest >> testIsComplexConjugateOfNonConjugateRealAndComplex [
430-
431-
self deny: (5 isComplexConjugateOf: (5 - 3i))
432-
]
433-
434-
{ #category : #tests }
435-
PMComplexTest >> testIsComplexConjugateOfSameComplex [
436-
437-
self deny: ((3 - 2i) isComplexConjugateOf: (3 - 2i))
438-
]
439-
440-
{ #category : #tests }
441-
PMComplexTest >> testIsComplexConjugateOfSameReal [
442-
443-
self assert: (5 isComplexConjugateOf: 5)
444-
]
445-
446392
{ #category : #tests }
447393
PMComplexTest >> testIsComplexNumberOnComplex [
448394

src/Math-Tests-Complex/PMNumberTest.class.st

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)