• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PolyMathOrg / PolyMath / 4385132063

pending completion
4385132063

push

github

GitHub
Merge pull request #316 from jecisc/divers-cleanings

2977 of 2977 new or added lines in 214 files covered. (100.0%)

19725 of 24212 relevant lines covered (81.47%)

2.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.39
/src/Math-Core-Process/PMFixpoint.class.st
1
"
2
`PMFixpoint` is just a little utility. It calculates the fixpoint of a block with one variable. A starting value for the variable is necessary. The variable does not need to be numerical, it can be anything the block can eat and spit out.
3

4
Example:
5

6
```
7
| a |
8
a := PMFixpoint block: [:x| 1/(1+x)] value: 20.0.
9
a evaluate
10
```
11
"
12
Class {
13
        #name : #PMFixpoint,
14
        #superclass : #PMIterativeProcess,
15
        #instVars : [
16
                'cycleFlag',
17
                'result2',
18
                'result1',
19
                'results',
20
                'block',
21
                'verbose',
22
                'equalityTest'
23
        ],
24
        #category : #'Math-Core-Process'
25
}
26

27
{ #category : #'instance creation' }
28
PMFixpoint class >> block: aBlock value: anObject [
3✔
29
^self new block: aBlock ;value: anObject; yourself
3✔
30
]
3✔
31

32
{ #category : #information }
33
PMFixpoint class >> defaultMaximumIterations [
3✔
34
        ^200
3✔
35
]
3✔
36

37
{ #category : #information }
38
PMFixpoint class >> defaultVerbose [
3✔
39
        ^true
3✔
40
]
3✔
41

42
{ #category : #private }
43
PMFixpoint >> adjustIteratorFor: aCycleLength [
3✔
44
1 to: results size do:[:i| |last| last:=i + aCycleLength.
3✔
45
        (equalityTest
3✔
46
                ifNil: [(results at:i)literalEqual:(results at:last)]
3✔
47
                ifNotNil:[:t|(t value: (results at:i) value: (results at:last))])
3✔
48
                        ifTrue: [        result1 :=result.
3✔
49
                                                ^iterations :=last - 1]]
3✔
50
]
3✔
51

52
{ #category : #accessing }
53
PMFixpoint >> block: aBlock [
3✔
54
^block := aBlock
3✔
55
]
3✔
56

57
{ #category : #accessing }
58
PMFixpoint >> cycle [
3✔
59
        | length |
3✔
60
        length := self cycleLength ifNil: [ ^ #() ].
3✔
61
        ^ (results copyFrom: iterations + 1 - length to: iterations) asArray
3✔
62
]
3✔
63

64
{ #category : #printing }
65
PMFixpoint >> cycleInfo: cycleLength [
3✔
66
verbose ifFalse: [ ^self ].
3✔
67
GrowlMorph
3✔
68
                        openWithLabel: 'Info'
3✔
69
                        contents: ('{1} iterations used.
3✔
70
warning: {2}-cycle detected' format: (Array with: iterations with: cycleLength))
3✔
71
                        color: Color gray muchDarker
3✔
72
]
3✔
73

74
{ #category : #private }
75
PMFixpoint >> cycleLength [
3✔
76
"returns nil - not zero -, if no cycle exists"
3✔
77
|c|
3✔
78
results ifNil:[^nil].
3✔
79
c:=(results copyFrom: 1 to: results size -1)reversed.
3✔
80
c withIndexDo:[:r :i|(equalityTest
3✔
81
        ifNil: [(result literalEqual: r)]
3✔
82
        ifNotNil:[:t|(t value: result value: r)])
3✔
83
                ifTrue:[^i]].
3✔
84
^nil
3✔
85
]
3✔
86

3✔
87
{ #category : #accessing }
3✔
88
PMFixpoint >> equalityTest: aBlock [
3✔
89
"you can set your own equality test to decide when the fixpoint is reached"
3✔
90
self assert: aBlock argumentCount=2.
3✔
91
^equalityTest:=aBlock
3✔
92
]
3✔
93

94
{ #category : #operation }
95
PMFixpoint >> evaluateIteration [
3✔
96
cycleFlag         ifTrue: [result1:=result]
3✔
97
                                ifFalse:[result2:=result].
3✔
98
cycleFlag :=cycleFlag not.
3✔
99
result := block value: result copy .
3✔
100
^results add:result
3✔
101
]
3✔
102

103
{ #category : #operation }
104
PMFixpoint >> finalizeIterations [
3✔
105
        self hasConverged
3✔
106
                ifTrue: [ (cycleFlag
3✔
107
                                ifTrue: [ result = result1 and: [ result ~= result2 ] ]
3✔
108
                                ifFalse: [ result = result2 and: [ result ~= result1 ] ])
3✔
109
                                ifTrue: [ self cycleInfo: 2 ]
3✔
110
                                ifFalse: [ self simpleInfo ] ]
3✔
111
                ifFalse: [ self cycleLength
3✔
112
                                ifNil: [ self unfinishedInfo ]
3✔
113
                                ifNotNil: [ :x |
3✔
114
                                        self adjustIteratorFor: x.
3✔
115
                                        self cycleInfo: x ] ]
3✔
116
]
3✔
117

118
{ #category : #information }
119
PMFixpoint >> hasConverged [
3✔
120
^equalityTest
3✔
121
        ifNil: [(result literalEqual: result1) or: [result literalEqual: result2]]
3✔
122
        ifNotNil: [:t|(t value: result value: result1)or:[t value: result value: result2]]
3✔
123
]
3✔
124

125
{ #category : #initialization }
126
PMFixpoint >> initialize [
3✔
127
verbose := self class defaultVerbose .
3✔
128
^super initialize
3✔
129
]
3✔
130

131
{ #category : #operation }
132
PMFixpoint >> initializeIterations [
3✔
133
        "cycleFlag & result1 & result2 are used, so that 2-cycles are immediately found (with correct iteration number!)"
3✔
134

3✔
135
        cycleFlag := true.
3✔
136
        result1 := result.
3✔
137
        result2 := result.
3✔
138
        (results := OrderedCollection new: maximumIterations + 1) add: result
3✔
139
]
3✔
140

141
{ #category : #printing }
142
PMFixpoint >> printOn: aStream [
×
143
        super printOn: aStream .
×
144
        aStream nextPut: $(.
×
145
        block printOn: aStream .
×
146
        aStream nextPutAll: ' value: ' .
×
147
        result printOn: aStream.
×
148
        aStream nextPut: $)
×
149
]
×
150

151
{ #category : #printing }
152
PMFixpoint >> simpleInfo [
3✔
153
verbose ifFalse: [ ^self ].
3✔
154
GrowlMorph
3✔
155
                        openWithLabel: 'Info'
3✔
156
                        contents: ('{1} iterations needed.' format: (Array with: iterations))
3✔
157
                        color: Color green muchDarker
3✔
158
]
3✔
159

160
{ #category : #printing }
161
PMFixpoint >> unfinishedInfo [
3✔
162
verbose ifFalse: [ ^self ].
3✔
163
GrowlMorph
3✔
164
                        openWithLabel: 'Warning'
3✔
165
                        contents: ('maximumIterations ({1}) reached.
3✔
166
you can run evaluate a second time' format: (Array with: maximumIterations))
3✔
167
                        color: Color orange darker
3✔
168
]
3✔
169

170
{ #category : #accessing }
171
PMFixpoint >> value: aStartingValue [
3✔
172
"the value, that will be fed at first to the block when evaluating"
3✔
173
^result:=aStartingValue
3✔
174
]
3✔
175

3✔
176
{ #category : #accessing }
3✔
177
PMFixpoint >> verbose: aBoolean [
3✔
178
"decides whether info should be delivered via GrowlMorphs. by default true"
3✔
179
^verbose:=aBoolean
3✔
180
]
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc