----------------------------------------------------------------------------
::  Notes for "DFactors2"
----------------------------------------------------------------------------
by Klaus Q. Fischer, Windhoek, Namibia, Africa, 27.10.2012


----------------------------------------------------------------------------
::  Copyright
----------------------------------------------------------------------------
Michael M. Ross
http://www.naturalnumbers.org
http://wordwisesolutions.com/
michaelmross@gmail.com


----------------------------------------------------------------------------
::  SOURCE
----------------------------------------------------------------------------
Visual Basic 6 with SP6  (Visual Studio, German)
\dfactors2
Compilation by "Project2.vbp"
Cerated result "DistinctFactors2.exe"      public name "DFactors2.exe"


============================================================================
MODIFIED: DFactors2.exe output: DPF2-{From_N-To_N}.txt    up to 10^15   2012
============================================================================

----------------------------------------------------------------------------
::  Summary of changes
----------------------------------------------------------------------------
A)  Extended content with "Power" for Prime factor
B)  Changed order of content, count of factors as 2nd data
C)  New Header for content to reflect above changes

D)  Accept entry number range "From" "To" ("From" was ignored)
E)  Filename reflects entered number range "From" "To"
    Now it's possible to calculate e.g. just a few or only one Prime_Factor
----------------------------------------------------------------------------


----------------------------------------------------------------------------
::  Changes
----------------------------------------------------------------------------
File: Form1.frm

0.  Some comments added see '  kqf: 

0.1 Version
from 1.0
to   2.0


in => Command1_Click()
----------------------
1.  Filename range from - to vs. lines per file
    If fs > txTo Then fs = txTo       ' kqf shorter content 1 file only

1.1 If "range from" doesnt start with "1" it generated a wrong Filename
from "(fs + nn - 1)"
to   "(fs)"
e.g. from 4 to 16 generate a DPF2-4-16.txt

1.2 Special case for one factor only
    If (txTo = txN) Then fs = 1
e.g. from 162514264337593543950331 to "same n" will generate
   a DPF2-162514264337593543950331-1.txt

2.  Name of text-output {at 2 places}
from "DPF-"
to   "DPF2-"

3.  Header of text-output
from "N : Unique Prime Factors : W(N)"
to   "N: W(N) = Unique Prime Factors P,x {* P,x }"


in => tdx(nn As Variant)
------------------------
4.  Static output only for number "1"
from "1: 0 : 0"
to   "1: 0 = 0,0"

5.  Dynamic output only for primes
from Trim$(nn) + ": " + Trim$(nn) + " : 1"
to   Trim$(nn) + ": " + "1 = " + Trim$(nn) + ",1"

6.  Dynamic output only for composite
from Trim$(nn) + ": " + fns + " : " + Trim$(dp)
to   Trim$(nn) + ": " + Trim$(dp) + " = " + fns

7.  Separator output between prime factors
from ","
to   " * "

7.1 add 2 spaces and change (len) 1 => 3 {at 2 places}


in => PrimeFactors(comp As Variant) As String
---------------------------------------------
8.  replaced RemoveDups()
    with a simplified conversion from X to comparr to strStr
----------------------------------------------------------------------------


----------------------------------------------------------------------------
::  MAY BE MORE
----------------------------------------------------------------------------
1.  ESC key doesn't work on large numbers.
    Because only every 100.number the key will be checked.

2.  Unknown LAN activity see => ICMP_DPF2.png

3.  On larger numbers show current factors found: prime and power
    Just to see that some something is going on...

4.  Error? or Limitation? at 25 digit number!
    It show E+17. Should be full number without colon.
8162514264337593543950331: 4 = 3,1 * 337,1 * 37861,1 * 2,13245913355603E+17,1

5.  Sometimes activity display stops but program is still running fine.
    Freeze e.g. "Press Esc to stop... N = 32200"
5.1 For unknown reason it may re-start again...

6.  Is there a better way for memory allocation?
    e.g. "ReDim Preserve comparr()"

7.  Add a header for each file .txt (currently header only in the 1st)

8.  Add columne with the sum of power of all the prime factors
----------------------------------------------------------------------------


----------------------------------------------------------------------------
::  CONVERSION from .txt into .csv into spreadsheet .ods
----------------------------------------------------------------------------

1.  The text output looks similar like this
1.1 Header
N: W(N) = Unique Prime Factors P,x {* P,x }
1.2 Content e.g.
5: 1 = 5,1
6: 2 = 2,1 * 3,1

2.  Make a copy of all .txt files from a TXT-folder into a CSV-folder
2.1 Rename each filename to improve readablity and to serve this expectation
    To find a number higher than the filename indicate.
    At first the number range is unknown but indicated by the next filename.
e.g. "DPF2-1-100000.txt"      into "DPF2-1.txt"
e.g. "DPF2-100001-200000.txt" into "DPF2-100k.txt"

3.  Replace some content of .txt file to change into a .csv :
    Choose separator e.g. ";"
3.1  ": " to ";"
3.2  " = " to ";"
3.3  " * " to ";"
3.4  "," to ";"
3.5  Check row 1 to be the CSV-Header: N;W(N);P,x;{ * P,x }
3.6  Save this .txt file and ...
3.7  Rename this "*.txt" file to "*.csv"
e.g. "DPF2-1.txt"    into "DPF2-1.csv"
e.g. "DPF2-100k.txt" into "DPF2-100k.csv"

4.  Open the .csv file with a spreadsheet, e.g. for LibreOffice
4.1 Within the 'Textimport csv' select correct separator ";"
4.2 Font size 9
4.3 Color first unused column 'salmon'
4.4 Color header row 'yellow' center + bold
4.5 Extend header with # for each pair "2;2;3;3;4;4 ..."
4.6 Cell format content as number "-1.234"
4.7 Save as a spreadsheet change from *.csv to *.ods for LibreOffice

5.  Extend the spreadsheet
5.1 Define a bottom row header as a copy of header e.g. '=A1'
5.2 Name 3 bottom rows: Count, MAX, MIN
5.3 Enter formula e.g. 'COUNT(B$2:B$50001)' 'MAX()' 'MIN()' for each column
5.4 Select content and optimize column width
5.5 Save as a spreadsheet change from *.csv to *.ods for LibreOffice

6.  Add column(s) with a formula(s) to double check the content
    Column "%" just to separate dynamic results from static input
6.1 Calculate the prime and power for each row
    Column "Calculate" Power(C2;D2)* (2.) * (3.) * (4.) * (5.) ...
6.2 Compare the dynamic calculation with the static indicated number
    Column "Check" If (A2=x2;" ";1)
6.3 Build a sum of any difference discovered
6.4 If there is no difference: Fine!
6.5 If there is a  difference: Find out why! Correct source of error!
6.6 Calculate the sum of all powers for each number
    Columne "x(N)"
6.7 Classification of "W(N)" and "x(N)"
    Columne "P_class"
6.7 In any way: Don't forget to save the extended spreadsheet now...

7.  Create a template of the 1st spreadsheet (covering 5. and 6.)
7.1 Open prepared template rename & save for all other spreadsheets
7.2 Open selected .csv details like 4. & 4.1
7.3 Compare .csv range to fit into .ods or extend .ods range
7.4 Just mark, copy static content of .csv and paste into .ods
7.5 Close .csv without saving!
7.6 Save intermediate result of template as .ods
7.7 Continue with details given in 4.2 to 4.6
7.8 If 7.3 has extended the range, also extend all formulas!
    extend "Calculate" so that "Check" doesn't show any "Error"
    extend "x(N)" to calculate extend results
7.9 Save final result as .ods

8.  Create one spreadsheet that contains all statistic data
e.g. "DPF2-Statistics.ods"
8.1 Copy content of "Count", "MAX", "MIN", +++ as static data
8.2 Check that the current range fit otherwise first extend the range!

9.  Create one spreadsheet that contains all static content data
9.1 Open each 100k spreadsheet and just mark, copy and paste static content


Column Header Spreadsheet
A) "N:"              Number 1 to max.
B) "W(N)"            count of factors
C) "P"               Prime and
D) "x"               Power for Prime
+) pairs C,D repeat as often as B) indicate

.  Add color for the header, extend header for as many pairs exist
.  Optional add some statistics like SUM or MAX and MIN of columns

Examples: for LibreOffice 3.5.7
Input:  DPF2-1-100000.txt	2.821 MB
Output: DPF2-1.csv		2.203 MB
Result: DPF2-1.ods		2.172 MB
                                2.350 MB with 4. + 5.
----------------------------------------------------------------------------


----------------------------------------------------------------------------
::  Analysis of "Form1"
----------------------------------------------------------------------------
::  Sub-Functions
----------------------------------------------------------------------------
Command1_Click()

Form_KeyDown(KeyCode As Integer, Shift As Integer)
tdx(nn As Variant)

PrimeFactors(comp As Variant) As String
  Factorize(dNumber As Variant, i As Variant) As Factor()
  RemoveDups(strings() As String) As String                  *** removed ***

RealMod(a As Variant, b As Variant) As Variant
IsPrime(pt As Variant) As Boolean

ModOp(Value1 As Variant, Value2 As Variant) As Double
Form_Load()
Form_Unload(Cancel As Integer)
GetFS()
fMax(pt As Variant) As Variant
----------------------------------------------------------------------------


----------------------------------------------------------------------------
::  TEST
----------------------------------------------------------------------------
0.  Program "DistinctFactors2.exe"         public name "DFactors2.exe"
0.1 Has  about 20 kB of Program-Code
0.2 Needs about 5 MB of RAM
0.3 Limitation VB 6  to "79228162514264337593543950335"
                         987654321_987654321_987654321  = 29 digit limit
0.4 Safe range limit to  "9999999999999999999999999999" = 28 digit maximum

1.  Usually from "1" to                       "1000000" =  7 digit  10 files
1.1 Timing AMILO XP SP3 1.8 GHz  750 MB		00:--:--
1.2 Timing ACER W7 HP   1.4 GHz 4000 MB		00:29:00   last-1st filetime

2.  Timing  from "1" to                        "100000" =  6 digit   1 file
2.1 Timing AMILO XP SP3 1.8 GHz  750 MB		00:01:18
2.2 Timing ACER W7 HP   1.4 GHz 4000 MB		00:00:58

3.  Timing for 1 # only      "162514264337593543950331" = 24 digit   1 value
3.1 Timing AMILO XP SP3 1.8 GHz  750 MB		00:01:13
3.2 Timing ACER W7 HP   1.4 GHz 4000 MB		00:00:35

4.  Timing for 1 # only     "8162514264337593543950331" = 25 digit   1 value
4.1 Timing AMILO XP SP3 1.8 GHz  750 MB		00:0-:--
4.2 Timing ACER W7 HP   1.4 GHz 4000 MB		00:10:55

5.  Timing for 1 # only    "28162514264337593543950331" = 26 digit   1 value
5.1 Timing AMILO XP SP3 1.8 GHz  750 MB		00:0-:--
5.2 Timing ACER W7 HP   1.4 GHz 4000 MB		00:0-:--

6.  Timing for 1 # only   "228162514264337593543950331" = 27 digit   1 value
6.1 Timing AMILO XP SP3 1.8 GHz  750 MB		00:0-:--
6.2 Timing ACER W7 HP   1.4 GHz 4000 MB		00:0-:--

7.  Timing for 1 # only  "9228162514264337593543950331" = 28 digit   1 value
7.1 Timing AMILO XP SP3 1.8 GHz  750 MB	16:03-	00:0-:--
7.2 Timing ACER W7 HP   1.4 GHz 4000 MB	17:01-	00:0-:--
----------------------------------------------------------------------------
----------------------------------------------------------------------------

----------------------------------------------------------------------------
EOF