Object subclass: #Tarai instanceVariableNames: 'x y z ' classVariableNames: '' poolDictionaries: '' category: 'Tarai-Benchmark'! !Tarai methodsFor: 'arithmetic' stamp: 'sumim 4/26/2003 02:36'! - anInteger ^ self asNumber - anInteger! ! !Tarai methodsFor: 'private' stamp: 'sumim 4/28/2003 16:12'! setX: xTaraiOrInteger y: yTaraiOrInteger z: zTaraiOrInteger x _ xTaraiOrInteger. y _ yTaraiOrInteger. z _ zTaraiOrInteger! ! !Tarai methodsFor: 'converting' stamp: 'sumim 4/26/2003 02:55'! asNumber ^ (x <= y ifTrue: [y] ifFalse: [ (self class x: (self class x: x - 1 y: y z: z) y: (self class x: y - 1 y: z z: x) z: (self class x: z - 1 y: x z: y))]) asNumber! ! !Tarai methodsFor: 'comparing' stamp: 'sumim 4/26/2003 02:50'! <= aTaraiOrInteger ^ self asNumber <= aTaraiOrInteger asNumber! ! !Tarai methodsFor: 'adapting' stamp: 'sumim 4/28/2003 19:38'! adaptToNumber: rcvr andSend: selector ^ rcvr perform: selector with: self asNumber! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! Tarai class instanceVariableNames: ''! !Tarai class methodsFor: 'example' stamp: 'sumim 4/26/2003 02:36'! example "Tarai example" ^ Time millisecondsToRun: [(Tarai x: 192 y: 96 z: 0) asNumber]! ! !Tarai class methodsFor: 'instance creation' stamp: 'sumim 4/28/2003 16:14'! x: xTaraiOrInteger y: yTaraiOrInteger z: zTaraiOrInteger ^ self new setX: xTaraiOrInteger y: yTaraiOrInteger z: zTaraiOrInteger; yourself! ! Tarai subclass: #NuTarai instanceVariableNames: 'value ' classVariableNames: '' poolDictionaries: '' category: 'Tarai-Benchmark'! !NuTarai methodsFor: 'converting' stamp: 'sumim 4/26/2003 16:24'! asNumber ^ value ifNil: [value _ super asNumber]! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! NuTarai class instanceVariableNames: ''! !NuTarai class methodsFor: 'example' stamp: 'sumim 4/26/2003 03:19'! example "NuTarai example" ^ Time millisecondsToRun: [(NuTarai x: 192 y: 96 z: 0) asNumber]! ! Object subclass: #TaraiBlock instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tarai-Benchmark'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! TaraiBlock class instanceVariableNames: ''! !TaraiBlock class methodsFor: 'mathematical functions' stamp: 'sumim 4/28/2003 16:52'! x: xBlockContext y: yBlockContext z: zBlockContext ^ xBlockContext value <= yBlockContext value ifTrue: [yBlockContext value] ifFalse: [ self x: [(self x: [xBlockContext value - 1] y: yBlockContext z: zBlockContext)] y: [(self x: [yBlockContext value - 1] y: zBlockContext z: xBlockContext)] z: [(self x: [zBlockContext value - 1] y: xBlockContext z: yBlockContext)]]! ! !TaraiBlock class methodsFor: 'example' stamp: 'sumim 4/28/2003 16:40'! example "TaraiBlock example" ^ Time millisecondsToRun: [TaraiBlock x: [192] y: [96] z: [0]]! ! TaraiBlock subclass: #NuTaraiBlock instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tarai-Benchmark'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! NuTaraiBlock class instanceVariableNames: ''! !NuTaraiBlock class methodsFor: 'example' stamp: 'sumim 4/28/2003 19:43'! example "NuTaraiBlock example" ^ Time millisecondsToRun: [NuTaraiBlock x: [192] y: [96] z: [0]]! ! !NuTaraiBlock class methodsFor: 'mathematical functions' stamp: 'sumim 4/28/2003 16:59'! x: xBlockContext y: yBlockContext z: zBlockContext | xvalue yvalue | xvalue _ xBlockContext value. yvalue _ yBlockContext value. ^ xvalue <= yvalue ifTrue: [yvalue] ifFalse: [ self x: [(self x: [xvalue - 1] y: yBlockContext z: zBlockContext)] y: [(self x: [yvalue - 1] y: zBlockContext z: xBlockContext)] z: [(self x: [zBlockContext value - 1] y: xBlockContext z: yBlockContext)]]! ! Object subclass: #TaraiMemo instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tarai-Benchmark'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! TaraiMemo class instanceVariableNames: 'tarais '! !TaraiMemo class methodsFor: 'class initialization' stamp: 'sumim 4/27/2003 16:54'! initialize tarais _ nil! ! !TaraiMemo class methodsFor: 'accessing' stamp: 'sumim 4/26/2003 00:25'! tarais ^ tarais! ! !TaraiMemo class methodsFor: 'example' stamp: 'sumim 4/27/2003 17:35'! example "TaraiMemo example" ^ Time millisecondsToRun: [TaraiMemo initialize; x: 192 y: 96 z: 0]! ! !TaraiMemo class methodsFor: 'mathematical functions' stamp: 'sumim 4/26/2003 00:31'! x: x y: y z: z ^ x <= y ifTrue: [y] ifFalse: [ (tarais ifNil: [tarais _ Dictionary new]) at: {x. y. z} ifAbsent: [ tarais at: {x. y. z} put: ( self x: (self x: x - 1 y: y z: z) y: (self x: y - 1 y: z z: x) z: (self x: z - 1 y: x z: y))]]! ! TaraiMemo subclass: #NuTaraiMemo instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Tarai-Benchmark'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! NuTaraiMemo class instanceVariableNames: ''! !NuTaraiMemo class methodsFor: 'class initialization' stamp: 'sumim 4/28/2003 16:15'! initializeX: xInteger y: yInteger z: zInteger | max | max _ {xInteger. yInteger. zInteger} max + 1. tarais _ Array new: max + 1 * max * max + 1. tarais at: 1 put: max! ! !NuTaraiMemo class methodsFor: 'example' stamp: 'sumim 4/28/2003 16:36'! example "NuTaraiMemo example" | time | time _ Time millisecondsToRun: [NuTaraiMemo initialize; x: 192 y: 96 z: 0]. Smalltalk garbageCollect. ^ time! ! !NuTaraiMemo class methodsFor: 'mathematical functions' stamp: 'sumim 4/28/2003 16:16'! x: xInteger y: yInteger z: zInteger ^ xInteger <= yInteger ifTrue: [yInteger] ifFalse: [ | idx | ((tarais ifNil: [self initializeX: xInteger y: yInteger z: zInteger. tarais]) at: (idx _ (tarais first + 1 * tarais first) * xInteger + (tarais first * yInteger - 1) + zInteger - 1) + 1) ifNil: [ tarais at: idx + 1 put: ( self x: (self x: xInteger - 1 y: yInteger z: zInteger) y: (self x: yInteger - 1 y: zInteger z: xInteger) z: (self x: zInteger - 1 y: xInteger z: yInteger))]]! ! TaraiMemo initialize!