Author Topic: Extension of the number range  (Read 2812 times)

mineiro

  • Member
  • ****
  • Posts: 958
Re: Extension of the number range
« Reply #15 on: March 16, 2022, 10:51:16 PM »
Hello sir Gunther, I'm testing a new version and will post after clean code.
Program now check's for overflow and remap memory, so, overflow will not occur anymore, well, only if machine don't have enough memory.
Program accepts console user input or redirection by a file.

time spend to calculate and show all iterations of number bellow: 11minutes 13 seconds
iterations: 49551 (or 49552 if given value N(0) is to be counted)
number below have 2098 digits
Code: [Select]
Your start value is: N(0) =
987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321987654321
It's an odd  number.
This leads to the following Collatz Sequence:
---------------------------------------------
N(1) = 2962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962965962962964
Instead of printing digit by digit I do conversion and printed value buffer.
time spend: 14 seconds

After optimization time spend = 8 seconds

So, I'm only cleaning and commenting the source code and will post today.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

Gunther

  • Member
  • *****
  • Posts: 4198
  • Forgive your enemies, but never forget their names
Re: Extension of the number range
« Reply #16 on: March 17, 2022, 12:21:06 AM »
Mineiro,

as I have already written: You are very diligent.

However, I have questions. Why do you calculate with BCD numbers? All values that can occur are positive. There is no fractional part, so these rounding
errors won't appear. Wouldn't it be more convenient and faster to calculate in binary? The test for even or odd would also be simplified etc.

You have to know the facts before you can distort them.

mineiro

  • Member
  • ****
  • Posts: 958
Re: Extension of the number range
« Reply #17 on: March 17, 2022, 01:19:49 AM »
Why do you calculate with BCD numbers?
To be easy to print iterations.

Quote
Wouldn't it be more convenient and faster to calculate in binary?
Yes, will be a lot faster if it's not necessary print all iterations value I suppose.
Well, convert decimal input string into binary number; do arithmetic on binary number, after each iteration convert binary number to decimal string and print. It's necessary check timings.

Follow a new attached version. For a reason that I don't understand it's not accepting input redirected files. I'm without win64 debug here.
If theres a file name "six.txt", and inside this file exist string "6",<enter> so it works. But when I try giant values I'm receiving an error (SEH I suppose).
collatz <six.txt >result.txt

To redirect output to a file it's working fine:
collatz >result.txt
« Last Edit: March 17, 2022, 02:29:00 AM by mineiro »
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

daydreamer

  • Member
  • *****
  • Posts: 2399
  • my kind of REAL10 Blonde
Re: Extension of the number range
« Reply #18 on: March 17, 2022, 03:22:20 AM »
Yes, will be a lot faster if it's not necessary print all iterations value I suppose.
I tried SIMT solution
one. Thread calculate and second thread converts/prints, while first thread continue calculate But fibonnaci
Bcd is just loop with SSE orps to ascii, while binary also need div loop

my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Gunther

  • Member
  • *****
  • Posts: 4198
  • Forgive your enemies, but never forget their names
Re: Extension of the number range
« Reply #19 on: March 17, 2022, 03:36:34 AM »
Mineiro,

Follow a new attached version. For a reason that I don't understand it's not accepting input redirected files. I'm without win64 debug here.
If theres a file name "six.txt", and inside this file exist string "6",<enter> so it works. But when I try giant values I'm receiving an error (SEH I suppose).
collatz <six.txt >result.txt

To redirect output to a file it's working fine:
collatz >result.txt

I'll test your program as soon as possible.
You have to know the facts before you can distort them.

Gunther

  • Member
  • *****
  • Posts: 4198
  • Forgive your enemies, but never forget their names
Re: Extension of the number range
« Reply #20 on: March 17, 2022, 03:42:51 AM »
Daydreamer,

I tried SIMT solution
one. Thread calculate and second thread converts/prints, while first thread continue calculate But fibonnaci
Bcd is just loop with SSE orps to ascii, while binary also need div loop

is this effort really necessary? The division by 2 can be done with a binary shift. Then only the multiplication by 3 and subsequent addition of 1 remains.
That's all it really is. We probably don't need to output every approximation either, just the starting value and the number of iterations at the end.
You have to know the facts before you can distort them.

daydreamer

  • Member
  • *****
  • Posts: 2399
  • my kind of REAL10 Blonde
Re: Extension of the number range
« Reply #21 on: March 17, 2022, 04:43:22 AM »
is this effort really necessary? The division by 2 can be done with a binary shift. Then only the multiplication by 3 and subsequent addition of 1 remains.
That's all it really is. We probably don't need to output every approximation either, just the starting value and the number of iterations at the end.
I used prints every few seconds interval,just like Cg programs shows 0-100% progress better than wait and know nothing about progress
anyway my progress is learn/practice SIMT skill or stay onethreaded which will utilize few % of modern 32 core cpu
my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding