POV-Ray : Newsgroups : povray.programming : solving polynomials Server Time23 Jul 2024 07:11:01 EDT (-0400)
 solving polynomials (Message 1 to 5 of 5)
 From: robfi680 Subject: solving polynomials Date: 20 Oct 2016 03:40:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.580874a6f9e539ccf4af9d600%40news.povray.org",
"dateCreated": "2016-10-20T07:40:00+00:00",
"datePublished": "2016-10-20T07:40:00+00:00",
"author": {
"@type": "Person",
"name": "robfi680"
}
}
I was just looking at the source code for POVRay 3.7 for solving polynomials. In
the default case for Solve_Polynomial it looks to me like it solves the
polynomial twice for orders higher than four when a root is eliminated. I am
trying to understand the code for my own use. Could there be a break statement
missing ? Otherwise why does it solve for order n-1 and then n ?

The code looks like:
default:

if (epsilon > 0.0)
{
if ((c[n-1] != 0.0) && (fabs(c[n]/c[n-1]) < epsilon))
{

roots = polysolve(n-1, c, r);
}
}

/* Solve n-th order polynomial. */

roots = polysolve(n, c, r);

break;
```
 From: Le Forgeron Subject: Re: solving polynomials Date: 20 Oct 2016 14:02:44 Message: <580906c4@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#580906c4%40news.povray.org",
"dateCreated": "2016-10-20T18:02:44+00:00",
"datePublished": "2016-10-20T18:02:44+00:00",
"author": {
"@type": "Person",
"name": "Le Forgeron"
}
}
Le 20/10/2016 à 09:39, robfi680 a écrit :
> I was just looking at the source code for POVRay 3.7 for solving polynomials. In
> the default case for Solve_Polynomial it looks to me like it solves the
> polynomial twice for orders higher than four when a root is eliminated. I am
> trying to understand the code for my own use. Could there be a break statement
> missing ? Otherwise why does it solve for order n-1 and then n ?
>
> The code looks like:
>   default:
>
>    if (epsilon > 0.0)
>    {
>     if ((c[n-1] != 0.0) && (fabs(c[n]/c[n-1]) < epsilon))
>     {
>
>      roots = polysolve(n-1, c, r);
>     }
>    }
>
>    /* Solve n-th order polynomial. */
>
>    roots = polysolve(n, c, r);
>
>    break;
>
>
>

The interesting part is that master branch is already corrected : yes, a
break is/was missing.

Now, it only occurs for 5th and more order polynomial, something that is
rarely seen.

The correction was done on 8th September 2016, found by static code
analysis.
```
 From: Le Forgeron Subject: Re: solving polynomials Date: 20 Oct 2016 14:13:09 Message: <58090935\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#58090935%241%40news.povray.org",
"dateCreated": "2016-10-20T18:13:09+00:00",
"datePublished": "2016-10-20T18:13:09+00:00",
"author": {
"@type": "Person",
"name": "Le Forgeron"
}
}
Le 20/10/2016 à 20:02, Le_Forgeron a écrit :
> Le 20/10/2016 à 09:39, robfi680 a écrit :
>> I was just looking at the source code for POVRay 3.7 for solving polynomials. In
>> the default case for Solve_Polynomial it looks to me like it solves the
>> polynomial twice for orders higher than four when a root is eliminated. I am
>> trying to understand the code for my own use. Could there be a break statement
>> missing ? Otherwise why does it solve for order n-1 and then n ?
>>
>> The code looks like:
>>   default:
>>
>>    if (epsilon > 0.0)
>>    {
>>     if ((c[n-1] != 0.0) && (fabs(c[n]/c[n-1]) < epsilon))
>>     {
>>
>>      roots = polysolve(n-1, c, r);
>>     }
>>    }
>>
>>    /* Solve n-th order polynomial. */
>>
>>    roots = polysolve(n, c, r);
>>
>>    break;
>>
>>
>>
>
> The interesting part is that master branch is already corrected : yes, a
> break is/was missing.
>
> Now, it only occurs for 5th and more order polynomial, something that is
> rarely seen.
>
> The correction was done on 8th September 2016, found by static code
> analysis.
>

On second look, I'm not even sure the break is at the right place...
Christoph ?

if (epsilon > 0.0)
{
if ((c[n-1] != 0.0) && (fabs(c[n]/c[n-1]) < epsilon))
{
stats[Roots_Eliminated]++;

roots = polysolve(n-1, c, r);
}

break;
}

/* Solve n-th order polynomial. */

roots = polysolve(n, c, r);

break;
```
 From: clipka Subject: Re: solving polynomials Date: 20 Oct 2016 18:07:00 Message: <58094004@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#58094004%40news.povray.org",
"dateCreated": "2016-10-20T22:07:00+00:00",
"datePublished": "2016-10-20T22:07:00+00:00",
"author": {
"@type": "Person",
"name": "clipka"
}
}
Am 20.10.2016 um 20:13 schrieb Le_Forgeron:

> On second look, I'm not even sure the break is at the right place...
> Christoph ?

Dang. I think it indeed isn't.
```
 From: Cousin Ricky Subject: Re: solving polynomials Date: 22 Oct 2016 00:15:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"dateCreated": "2016-10-22T04:15:01+00:00",
"datePublished": "2016-10-22T04:15:01+00:00",
"author": {
"@type": "Person",
"name": "Cousin Ricky"
}
}
Le_Forgeron <jgr### [at] freefr> wrote:
> Now, it only occurs for 5th and more order polynomial, something that is
> rarely seen.

I've used 8th order in the past, and there's a significant chance that I will
again in the future.
```