mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Programming (https://www.mersenneforum.org/forumdisplay.php?f=29)
-   -   Calculator that can factor and find exact roots of polynomials (https://www.mersenneforum.org/showthread.php?t=24932)

 alpertron 2019-11-12 20:32

Calculator that can factor and find exact roots of polynomials

Hello folks,

I have uploaded to [url]https://www.alpertron.com.ar/POLFACT.HTM[/url] a calculator that can factor polynomials over the integers or modulo a power of a prime. It also can find exact roots of polynomials expressed with radical expressions.

At this moment the roots are shown only if the degree of the irreducible factor of the input polynomial is <= 5. It also indicates when the quintic equation cannot be expressed as radical expressions.

Please let me know if there is any error.

 ewmayer 2019-11-12 21:22

I opened a new tab in my FF session, went to your page, enabled JS in NoScript, and, with a view toward poly-factoring x^4-1 as a little test, entered 4-1 and clicked 'factor'. I notice that whether I click 'evaluate' or 'factor', both those buttons go gray together, and "Factoring polynomial..." appears. Waited a full minute before killing it ... no result.

 alpertron 2019-11-12 21:31

I started Firefox 70.0.1 on Windows 10, entered .4-1 so it showed x^4-1 in the polynomial box, then I pressed the Factor button. The output with Pretty Print disabled is:

[CODE]
x^4 − 1

Irreducible polynomial factors:

x − 1
x + 1
x^2 + 1

Roots:

x1 = 1
x2 = -1
x3 = - 1 *i
x4 = 1 *i

Time elapsed: 0d 0h 0m 0.0s
[/CODE]

I do not have that NoScript plugin.

 ewmayer 2019-11-12 22:11

[QUOTE=alpertron;530400]I started Firefox 70.0.1 on Windows 10, entered .4-1 so it showed x^4-1 in the polynomial box, then I pressed the Factor button. The output with Pretty Print disabled is:

[CODE]
x^4 − 1

Irreducible polynomial factors:

x − 1
x + 1
x^2 + 1

Roots:

x1 = 1
x2 = -1
x3 = - 1 *i
x4 = 1 *i

Time elapsed: 0d 0h 0m 0.0s
[/CODE]

I do not have that NoScript plugin.[/QUOTE]

Part of it is that missing leading . in my input - suggest you add some kind of basic user-input parsing which indicates unrecognized input format, and only activates the buttons when the input is 'legal'. I retried with .4-1, it indeed auto-filled x^4-1 in the entry field, but clicking 'factor' still gives same as before, both 'evaluate' and 'factor' widgets go gray, and things hang until I click 'stop'. This is FF on Mac - I suspect you have some Windows-only stuff going on in your JS. Do you have ready access to a non-Win machine?

 alpertron 2019-11-12 22:16

[QUOTE=ewmayer;530403]Part of it is that missing leading . in my input - suggest you add some kind of basic user-input parsing which indicates unrecognized input format, and only activates the buttons when the input is 'legal'. I retried with .4-1, it indeed auto-filled x^4-1 in the entry field, but clicking 'factor' still gives same as before, both 'evaluate' and 'factor' widgets go gray, and things hang until I click 'stop'. This is FF on Mac - I suspect you have some Windows-only stuff going on in your JS. Do you have ready access to a non-Win machine?[/QUOTE]
The problem is that 4-1 is legal, because the parser converts that to 3. You can enter any polynomial expression, as explained in the help that you can read by expanding the "accordions". The trick using the dot (coefficient dot exponent) is optional and it makes a lot faster to enter the polynomials especially in mobile devices.

With respect to the second part, my code does not know what operating system is running. It uses Javascript and WebAssembly. Maybe you have not enabled WebAssembly in your plugin.

 alpertron 2019-11-13 11:32

I installed the NoScript extension to Firefox on Windows 10, and the Javascript was disabled when I loaded the calculator. After selecting "Temp TRUSTED" for my Web site, it worked OK and I could see the responses from the application.

 Dr Sardonicus 2019-11-13 17:02

I tried the minimum polynomial for $$2\cos(\frac{2\pi}{11})$$,

x^5 + x^4 - 4*x^3 - 3*x^2 + 3*x+ 1

and the answer was a bit hard to read. I'm not sure whether it was right.

 ewmayer 2019-11-13 20:13

[QUOTE=alpertron;530448]I installed the NoScript extension to Firefox on Windows 10, and the Javascript was disabled when I loaded the calculator. After selecting "Temp TRUSTED" for my Web site, it worked OK and I could see the responses from the application.[/QUOTE]

Exactly what I did using both FF and PaleMoon on my Mac. My next thought was that perhaps the versions of those browsers I'm running on that older legacy system (which has OS X frozen at 10.6.8 because my code-build flow is set up for that, and upgrading would break stuff) can't handle something in your JS, but retrying under Ubuntu 19 running on my Intel NUC, which is 4-5 years old gives the same failure. Oh, well.

 alpertron 2019-11-13 20:15

[QUOTE=Dr Sardonicus;530489]I tried the minimum polynomial for $$2\cos(\frac{2\pi}{11})$$,

x^5 + x^4 - 4*x^3 - 3*x^2 + 3*x+ 1

and the answer was a bit hard to read. I'm not sure whether it was right.[/QUOTE]

The answer shown by the application is wrong. I unchecked Pretty Print, copied the output to Notepad++, deleted all (xxx digits) and spaces, replaced i by I and finally copied that to gp. All five roots shown are non-real, so something is not good.

Another error is that the digits in group is not working. The program always shows groups of 6 digits.

I will work on that.

 alpertron 2019-11-13 20:17

[QUOTE=ewmayer;530508]Exactly what I did using both FF and PaleMoon on my Mac. My next thought was that perhaps the versions of those browsers I'm running on that older legacy system (which has OS X frozen at 10.6.8 because my code-build flow is set up for that, and upgrading would break stuff) can't handle something in your JS, but retrying under Ubuntu 19 running on my Intel NUC, which is 4-5 years old gives the same failure. Oh, well.[/QUOTE]
Those old browsers do not support WebAssembly. This was added on Firefox version 52, dated March 7, 2017.

 Dr Sardonicus 2019-11-13 22:48

[QUOTE=alpertron;530510]The answer shown by the application is wrong. I unchecked Pretty Print, copied the output to Notepad++, deleted all (xxx digits) and spaces, replaced i by I and finally copied that to gp. All five roots shown are non-real, so something is not good.

Another error is that the digits in group is not working. The program always shows groups of 6 digits.

I will work on that.[/QUOTE]I think that $$2\cos(\frac{2\pi}{11})$$ and its conjugates are about as good as it gets for expressing the roots of this polynomial. There is no expression in terms of "real radicals."

It is somewhat similar to the minimum polynomial x^3 - 3*x - 1 for $$2\cos(\frac{\pi}{3})$$, which the calculator expresses in terms of cosines. Obviously, it "knows" the trigonometric solution for the [i]casus irreducibilis[/i] of the cubic.

All times are UTC. The time now is 04:02.