Finding roots of a Polynomial with real coefficients



Table of Contents


1. Executable File Size (Memory Consumption) Comparison
2. Readability of Source Code
3. Accuracy of the Original and the Translated Version
4. Internal Memory Comparison of C# Compliers
5. References
6. The Output followed by Translated Programs (Test1.cs, Complex.cs, Cpolyroot.cs)


1. Executable File Size (Memory Consumption) Comparison


Executable file size is not the best way to identify an efficiency of compilers because every compiler is built in a different environment. From the resulting table, I can guess that g77 compiler has a biggest executable file size because of the overhead data to bypass to the gcc compiler.

So, we cannot simply conclude the efficiency of the compiler because of such reasons. I can think that some operating system provides some library with default.

During this experiment, I’ve noticed that if I use IDE, Visual Studio 2005, I get the extra file size. So, for the consistency of this experiment, I’ve decided to use executive files (mcs.exe, csc.exe) to compile the translated program without using any IDE.

The resulting table shows Visual C# and mono compilers give the almost same file size under any operating systems.


Executable File Size Comparison Table

#

OS

Compiler

Debug Mode

File Size (KB)

Debug File (KB)

1

Win2000

Mono C# 1.1.18.0 for Win

debug

8.50

5.32

2

Win2000

Mono C# 1.1.18.0 for Win

no debug

8.50

-

3

Win2000

Visual C# 2005 Compiler 8.00.50727.42 for
.Net 2.0.50727

debug

9.50

27.50

4

Win2000

Visual C# 2005 Compiler 8.00.50727.42 for
.Net 2.0.50727

no debug

9.00

-

5

Win2000

Visual C# 2005 Compiler version 8.00.50727.42 for
.Net 2.0.50727

no debug / optimize

8.50

-

6

Mac OSX 10.4

Mono C# 1.1.18.0 for OSX

debug

8.50

5.36

7

Mac OSX 10.4

Mono C# 1.1.18.0 for OSX

no debug

8.50

-

8

Ubuntu 6.06

Mono C# 1.1.13.6 for Linux

denug

8.50

6.20

9

Ubuntu 6.06

Mono C# 1.1.13.6 for Linux

no debug

8.50

-

10

Win2000

Cygwin GNU Fortran (GCC) 3.4.4

-

85.12

-

* Note All CPU architectures above are x86 including OSX.


2. Readability of Source Code


It is almost needless to say that the original source code is hard to read because of lack of control structures and jumps by “go to” statements. Moreover, Implicit variables makes it much harder because we don't have any clue of what the author indicates which data type is if we don't know anything about the rule for real to be prefix a-h and so on.

I believe that the translated version in C# is much easier to read because I've translated the original with controlled structures, thanks to the C#, and I've eliminated labels into minimum number of three with same functions.


3. Accuracy of the Original and the Translated Version

Surprisingly, the original program is very accurate in computing as much to 36 polynomials.

However in some sense, the original is inferior to the translated version. The original shows inaccuracy in complex values after computing polynomials. I can guess that the inaccuracy comes from the implementation of complex addition in the FORTRAN compiler. The maximum inaccuracy in a value is 0.00001048 which should be close to 0.


On contrary, the translated version in C# gives much accurate results for complex addition, which all seems to be exact zero.


4. Internal Memory Comparison of C# Compliers with Test1.cs


Internal memory comparison is a good way to investigate the efficiency of compilers.

So, I have tested the translated C# source code with the mono compiler under several operating systems such as Windows, Mac and Linux.

The test was a measurement of internal memory consumption within an instance of a class Test1 in a file, Test1.cs, which is almost identical to the original FORTRAN test function.

From the resulting table, Visual C# is slightly better than the mono compiler because I guess that Visual C# knows better implementation in Windows.

Surprisingly in Windows, there is no difference in efficiency between debug and release mode or with “optimize” or without “optimize”. On the other hand, OSX and Linux show the improvement with the release mode.


Internal Memory Comparison Table of C# Compliers

#

OS

Compiler

Internal Memory used in Test (KB)

1

Win2000

Mono C# 1.1.18.0 for Win

128.00

2

Win2000

Visual C# 2005 Compiler 8.00.50727.42 for
.Net 2.0.50727

119.97

3

Mac OSX 10.4

Mono C# 1.1.18.0 for OSX

160.00

4

Mac OSX 10.4

Mono C# 1.1.18.0 for OSX

156.00

5

Ubuntu 6.06

Mono C# 1.1.13.6 for Linux

148.00

6

Ubuntu 6.06

Mono C# 1.1.13.6 for Linux

144.00


5. References


Cygwin (g77.exe) http://www.cygwin.com/

Mono (mcs.exe) http://www.mono-project.com/Main_Page

Visual C# (csc.exe) http://msdn.microsoft.com/vstudio/


































6. Output with the program compiled by Visual C#


(x-1)(x+2)=

-2 + 1x^1 + 1x^2

(x-1)(x+2)(x-3)=

6 - 5x^1 - 2x^2 + 1x^3

(x-1)(x+2)(x-3)(x+4)=

24 - 14x^1 - 13x^2 + 2x^3 + 1x^4

(x-1)(x+2)(x-3)(x+4)(x-5)=

-120 + 94x^1 + 51x^2 - 23x^3 - 3x^4 + 1x^5


Roots of polynomial


-120 + 94x^1 + 51x^2 - 23x^3 - 3x^4 + 1x^5 = 0


Error code = 0


Real roots = 1.00 -4.00 3.00 -2.00 5.00


Imaginary roots = 0.00 0.00 0.00 0.00 0.00


Test of roots: all 5 values must be (close to) zero

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)


Test with coefficients a(i)=i, i=1,M


Roots of polynomial


1 + 2x^1 + 3x^2 + 4x^3 + 5x^4 + 6x^5 + 7x^6 + 8x^7 + 9x^8 +

10x^9 + 11x^10 + 12x^11 + 13x^12 + 14x^13 + 15x^14 + 16x^15 + 17x^16 + 1

8x^17 + 19x^18 + 20x^19 + 21x^20 + 22x^21 + 23x^22 + 24x^23 + 25x^24 + 2

6x^25 + 27x^26 + 28x^27 + 29x^28 + 30x^29 + 31x^30 + 32x^31 + 33x^32 + 3

4x^33 + 35x^34 + 36x^35 + 37x^36 = 0

Error code = 0


Real roots = -0.89 -0.89 0.87 0.87 -0.86 -0.86 0.32 0.32 0.58 0.58 -0.81 -0

.81 -0.28 -0.28 0.02 0.02 -0.74 -0.74 0.46 0.46 0.93 0.93 0.17 0.17 -0.65 -0.65

0.70 0.70 -0.54 -0.54 0.79 0.79 -0.41 -0.41 -0.13 -0.13

Imaginary roots = -0.07 0.07 -0.34 0.34 -0.22 0.22 -0.85 0.85 -0.70 0.70 -0.36 0

.36 -0.85 0.85 -0.90 0.90 -0.49 0.49 -0.78 0.78 -0.19 0.19 -0.89 0.89 -0.61 0.61

-0.60 0.60 -0.71 0.71 -0.47 0.47 -0.79 0.79 -0.89 0.89

Test of roots: all 36 values must be (close to) zero

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

(0.0000000, 0.0000000)

Internal Memory Used: 122852 bytes