Skip to content

Commit 33bfd2c

Browse files
Merge pull request #231 from PolyMathOrg/refactor-to-deeper-insight
Refactor: Introduce complexConjugate Message, Deprecate conjugated
2 parents d70167c + 83860b8 commit 33bfd2c

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

src/Math-AutomaticDifferenciation/PMDualNumber.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ PMDualNumber >> asInteger [
137137
PMDualNumber >> conjugated [
138138
^ self class
139139
value: self value conjugated
140-
eps: self eps asComplex conjugated
140+
eps: self eps asComplex complexConjugate
141141
]
142142

143143
{ #category : #'mathematical functions' }

src/Math-Complex/PMComplex.class.st

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,18 @@ PMComplex >> - anObject [
169169
]
170170

171171
{ #category : #arithmetic }
172-
PMComplex >> / anObject [
172+
PMComplex >> / aNumber [
173173
"Answer the result of dividing receiver by aNumber"
174174
| a b c d newReal newImaginary |
175-
anObject isComplexNumber ifTrue:
175+
aNumber isComplexNumber ifTrue:
176176
[a := self real.
177177
b := self imaginary.
178-
c := anObject real.
179-
d := anObject imaginary.
178+
c := aNumber real.
179+
d := aNumber imaginary.
180180
newReal := ((a * c) + (b * d)) / ((c * c) + (d * d)).
181181
newImaginary := ((b * c) - (a * d)) / ((c * c) + (d * d)).
182-
^ PMComplex real: newReal imaginary: newImaginary].
183-
^ anObject adaptToComplex: self andSend: #/.
182+
^ self class real: newReal imaginary: newImaginary].
183+
^ aNumber adaptToComplex: self andSend: #/.
184184
]
185185

186186
{ #category : #comparing }
@@ -403,11 +403,24 @@ PMComplex >> asComplex [
403403
^self
404404
]
405405

406+
{ #category : #arithmetic }
407+
PMComplex >> complexConjugate [
408+
409+
^ self class real: real imaginary: imaginary negated
410+
]
411+
406412
{ #category : #arithmetic }
407413
PMComplex >> conjugated [
414+
408415
"Return the complex conjugate of this complex number."
409416

410-
^self class real: real imaginary: imaginary negated
417+
self
418+
deprecated: 'Use #complexConjugate instead'
419+
on: '3 April 2022'
420+
in:
421+
'Pharo-9.0.0+build.1575.sha.9bb5f998e8a6d016ec7abde3ed09c4a60c0b4551 (64 Bit)'.
422+
423+
^ self complexConjugate
411424
]
412425

413426
{ #category : #'mathematical functions' }
@@ -694,14 +707,15 @@ PMComplex >> sinh [
694707

695708
{ #category : #'mathematical functions' }
696709
PMComplex >> sqrt [
710+
697711
"Return the square root of the receiver with a positive imaginary part."
698712

699713
| u v |
700-
(imaginary = 0 and: [real >= 0])
701-
ifTrue: [^self class real: real sqrt imaginary: 0].
714+
(imaginary = 0 and: [ real >= 0 ]) ifTrue: [
715+
^ self class real: real sqrt imaginary: 0 ].
702716
v := (self abs - real / 2) sqrt.
703717
u := imaginary / 2 / v.
704-
^self class real: u imaginary: v
718+
^ self class real: u imaginary: v
705719
]
706720

707721
{ #category : #'mathematical functions' }

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

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

27+
{ #category : #'*Math-Complex' }
28+
PMComplex >> random [
29+
"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."
30+
^ self class random * self
31+
32+
]
33+
3434
{ #category : #'*Math-Complex' }
3535
PMComplex >> subtractToPolynomial: aPolynomial [
3636
^ aPolynomial addNumber: self negated

src/Math-Tests-AutomaticDifferenciation/PMDualNumberTest.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ PMDualNumberTest >> testConjugated [
8989
self assert: a value equals: z value absSquared.
9090
self
9191
assert: a eps
92-
equals: z eps asComplex conjugated * z value + (z value asComplex conjugated * z eps)
92+
equals: z eps asComplex complexConjugate * z value + (z value asComplex conjugated * z eps)
9393
]
9494

9595
{ #category : #tests }

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ PMComplexTest >> testComplexCollection [
194194
]
195195

196196
{ #category : #tests }
197-
PMComplexTest >> testConjugated [
198-
| c cc |
199-
c := 5 - 6 i.
200-
cc := c conjugated.
201-
self assert: cc real equals: c real.
202-
self assert: cc imaginary equals: c imaginary negated
197+
PMComplexTest >> testComplexConjugate [
198+
| z complexConjugateOfZ expected |
199+
z := 5 - 6 i.
200+
201+
complexConjugateOfZ := z complexConjugate .
202+
203+
expected := 5 + 6 i.
204+
self assert: complexConjugateOfZ equals: expected.
203205
]
204206

205207
{ #category : #tests }
@@ -486,7 +488,7 @@ PMComplexTest >> testNumberAsComplex [
486488
minusOne := -1 asComplex.
487489
self assert: minusOne real equals: -1.
488490
self assert: minusOne imaginary equals: 0.
489-
self assert: minusOne conjugated equals: minusOne.
491+
self assert: minusOne complexConjugate equals: minusOne.
490492
self assert: minusOne sqrt equals: 1 i
491493
]
492494

0 commit comments

Comments
 (0)