Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.1226.mcz
==================== Summary ====================
Name: Kernel-nice.1226
Author: nice
Time: 5 May 2019, 10:12:56.491163 am
UUID: b48136e7-9c94-45b5-b5f9-b2d73396097a
Ancestors: Kernel-nice.1225
Fix un-intentional leak of ternaryBinaryExponentationOf:
This is an experiment not ready for consumption.
Sorry for the extra commit.
=============== Diff against Kernel-nice.1225 ===============
Item was removed:
- ----- Method: Integer>>raisedToInteger: (in category 'mathematical functions') -----
- raisedToInteger: n
- (n < 3 or: [self highBitOfMagnitude * n < 2048]) ifTrue: [^super raisedToInteger: n].
- ^n ternaryBinaryExponentationOf: self!
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.1225.mcz
==================== Summary ====================
Name: Kernel-nice.1225
Author: nice
Time: 4 May 2019, 11:50:07.297369 pm
UUID: 02906432-5829-436e-92de-4f1fd552397c
Ancestors: Kernel-nice.1224
Fix nthRootRounded:
How does it work?
To have short notation, say we have the truncated nth root x of y such that:
x^n <= y
(x+1)^n > y
The true root r is somewhere in between
r^n = y
x <= r < x+1
But is r closer to x or x+1?
Let's just check the mid point (x+0.5)^n
(x+0.5)^n < y ==> (x+0.5 < r) we must answer x+1
(x+0.5)^n > y ==> (r < x+0.5) we must answer x
(x+0.5)^n = y is impossible, the left member of inequality is an irreducible Fraction (odd numerator, even denominator), the right member is an Integer.
We eliminate the Fraction denominator to stick with Integer arithmetic and test:
(x*2+1)^n < (y << n)
It seems like ancient code was testing
(x^n + (x+1)^n)/2 < y
Gasp, did I write this?
=============== Diff against Kernel-nice.1224 ===============
Item was changed:
----- Method: Integer>>nthRootRounded: (in category 'mathematical functions') -----
nthRootRounded: aPositiveInteger
"Answer the integer nearest the nth root of the receiver."
| guess |
self = 0 ifTrue: [^0].
self negative
ifTrue:
[aPositiveInteger even ifTrue: [ ArithmeticError signal: 'Negative numbers don''t have even roots.' ].
^(self negated nthRootRounded: aPositiveInteger) negated].
guess := self nthRootTruncated: aPositiveInteger.
+ ^(2 * guess + 1 raisedToInteger: aPositiveInteger) < (self bitShift: aPositiveInteger)
- ^self * 2 > ((guess + 1 raisedTo: aPositiveInteger) + (guess raisedTo: aPositiveInteger))
ifTrue: [guess + 1]
ifFalse: [guess]!
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.829.mcz
==================== Summary ====================
Name: Collections-nice.829
Author: nice
Time: 3 May 2019, 11:06:11.65639 pm
UUID: 695419ed-754d-41ff-8b51-b8715934b1f5
Ancestors: Collections-fn.828
Remove unused digitShiftSum: (since Kernel-nice.1224)
=============== Diff against Collections-fn.828 ===============
Item was removed:
- ----- Method: Interval>>digitShiftSum: (in category 'enumerating') -----
- digitShiftSum: aBlock
- "Reconstruct an Integer that has been split in chunks by using shift and add.
- Each of my element represent a digitShift, an my step size repreent the digit length of chunks.
- The block is evaluated with each digitShift to produce the chunks.
-
- Algorithm insights:
- Let d0,d1,d2,... be the chunks, and s be the bit shift (8*step because digitLength is 8bits)
- The naive loop does shift each chunk and accumulate into a sum:
- ((d0 + (d1<<s)) + (d2<<s)) + (d3<<s) + ...
- The length of accumulator increase at each iteration (1+2+3...) resulting in a cost (size+1)*size/2, or O(size^2)
- Note that Horner scheme would be of about same cost
- (((... + d3) << s + d2) << s + d1) << s + d0
- (a bit like so called Shlemiel the painter)
- If we instead divide and conquer, we add smaller parts (1+1+2+...) resulting into a cost of O(size*log2(size))
- (d0 + (d1<<s)) + ((d2 + (d3<<s)) << s) + ...
- However, the divide and conquer split comes with an additionnal cost, so do it only if worth it."
-
- | sz half offset |
- "Naive loop in O(size^2)/2 is best for small size"
- (sz := self size) <= 8 ifTrue: [^self inject: 0 into: [:sum :shift | ((aBlock value: shift) bitShift: 8 * shift) + sum]].
- half := sz // 2.
- offset := half * step + start.
- ^((start to: half - 1 * step + start by: step) digitShiftSum: aBlock)
- + (((0 to: self last - offset by: step) digitShiftSum: [:k | aBlock value: offset + k]) bitShift: 8 * offset)!
Nicolas Cellier uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-nice.361.mcz
==================== Summary ====================
Name: KernelTests-nice.361
Author: nice
Time: 3 May 2019, 10:46:16.703499 pm
UUID: 8630d99a-ddab-4914-96bf-7f06d1899cee
Ancestors: KernelTests-pre.360
Apply refactorings of Kernel-nice.1224
=============== Diff against KernelTests-pre.360 ===============
Item was changed:
----- Method: LargePositiveIntegerTest>>testDigitDiv (in category 'tests') -----
testDigitDiv
| a b q r qr ap bp |
ap := self x23kbits.
bp := self x13kbits.
+ self assert: (ap digitDivSplit: bp) = ((ap digitDiv: bp neg: false) collect: #normalize).
- self assert: (ap recursiveDigitDiv: bp) = ((ap primDigitDiv: bp neg: false) collect: #normalize).
#(#yourself #negated) do: [:opa |
#(#yourself #negated) do: [:opb |
a := ap perform: opa.
b := bp perform: opb.
qr := a digitDiv: b neg: opa ~~ opb.
q := qr first normalize.
r := qr last normalize.
self assert: q * b + r = a.
self assert: r abs < b abs.
self assert: a positive ==> r positive.
self assert: a negative ==> (r negative | r isZero)]]
!
Item was changed:
----- Method: LargePositiveIntegerTest>>testFastMultiply (in category 'tests') -----
testFastMultiply
| a b ab ap bp |
ap := self x92kbits.
bp := self x106kbits.
#(#yourself #negated) do: [:opa |
#(#yourself #negated) do: [:opb |
a := ap perform: opa.
b := bp perform: opb.
ab := a * b.
+ self assert: (a multiplyByInteger: b) = ab.
+ self assert: (a digitMultiply: b neg: a negative ~~ b negative) = ab.
+ self assert: (a digitMul22: b) = ab.
+ self assert: (a digitMul23: b) = ab.
+ self assert: (a digitMul33: b) = ab]]!
- self assert: (a fastMultiply: b) = ab.
- self assert: (a karatsubaTimes: b) = ab.
- self assert: (a toom3Times: b) = ab]]!
Item was changed:
----- Method: LargePositiveIntegerTest>>testSquared (in category 'tests') -----
testSquared
| large ref |
large := self x23kbits.
ref := large * large.
self assert: ref = large squared.
+ self assert: ref = large squaredByHalf.
+ self assert: ref = large squaredByThird.
+ self assert: ref = large squaredByFourth.!
- self assert: ref = large squaredKaratsuba.
- self assert: ref = large squaredToom3.
- self assert: ref = large squaredToom4.!
David T. Lewis uploaded a new version of Chronology-Core to project The Trunk:
http://source.squeak.org/trunk/Chronology-Core-cbc.41.mcz
==================== Summary ====================
Name: Chronology-Core-cbc.41
Author: cbc
Time: 22 April 2019, 8:58:13.835953 am
UUID: 3d8013b6-d58f-004e-8e6b-5a59ed5841e7
Ancestors: Chronology-Core-dtl.40
We have the ability to change the starting day of the week (Week>>startDay:).
This change adds #dayOfLocalWeek to DateAndTime and Timespan to return the indexed day of the week based on the altered starting day.
Original #dayOfWeek is left as-is along with all other working code.
=============== Diff against Chronology-Core-dtl.40 ===============
Item was added:
+ ----- Method: DateAndTime>>dayOfLocalWeek (in category 'ansi protocol') -----
+ dayOfLocalWeek
+
+ "Sunday=1, ... , Saturday=7"
+
+ ^ (self julianDayNumber + 2 - Week weekdayStartIndex rem: 7) + 1
+ !
Item was added:
+ ----- Method: Timespan>>dayOfLocalWeek (in category 'ansi protocol') -----
+ dayOfLocalWeek
+ "Answer the day of the week represented by the receiver."
+
+ ^ start dayOfLocalWeek!
Item was added:
+ ----- Method: Week class>>weekdayStartIndex (in category 'squeak protocol') -----
+ weekdayStartIndex
+ ^self indexOfDay: self startDay!