<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ascend4.org/index.php?action=history&amp;feed=atom&amp;title=Solving_cubic_polynomials</id>
	<title>Solving cubic polynomials - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ascend4.org/index.php?action=history&amp;feed=atom&amp;title=Solving_cubic_polynomials"/>
	<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;action=history"/>
	<updated>2026-05-03T19:51:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6275&amp;oldid=prev</id>
		<title>Jpye: /* Calculation checking */</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6275&amp;oldid=prev"/>
		<updated>2022-07-07T02:50:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Calculation checking&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:50, 7 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l183&quot;&gt;Line 183:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 183:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The following [https://docs.sympy.org/latest/tutorial/simplification.html sympy] code can be used to confirm the algebra of the &amp;#039;general solution&amp;#039; above. Note that this page uses the depressed form &amp;lt;math&amp;gt;y^3-3Py-2Q=0&amp;lt;/math&amp;gt;, while most other sources use &amp;lt;math&amp;gt;y^3+py +q=0&amp;lt;/math&amp;gt;, with results that are equivalent but have more constants lying around.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The following [https://docs.sympy.org/latest/tutorial/simplification.html sympy] code can be used to confirm the algebra of the &amp;#039;general solution&amp;#039; above. Note that this page uses the depressed form &amp;lt;math&amp;gt;y^3-3Py-2Q=0&amp;lt;/math&amp;gt;, while most other sources use &amp;lt;math&amp;gt;y^3+py +q=0&amp;lt;/math&amp;gt;, with results that are equivalent but have more constants lying around.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To determine the expressions for &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; in the depressed cubic. This &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;expression with &lt;/del&gt;&amp;lt;math&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;a_3 &lt;/del&gt;= a/3&amp;lt;/math&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;aims &lt;/del&gt;at &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;improved &lt;/del&gt;numerical precision.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To determine the expressions for &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; in the depressed cubic. This &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;unnecessary replacement &amp;lt;code&amp;gt;a3&amp;lt;/code&amp;gt;&lt;/ins&gt;&amp;lt;math&amp;gt;= a/3&amp;lt;/math&amp;gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;is aimed &lt;/ins&gt;at &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;increasing &lt;/ins&gt;numerical precision.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sympy import *&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sympy import *&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6274:rev-6275:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6274&amp;oldid=prev</id>
		<title>Jpye: /* Implementation in C */</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6274&amp;oldid=prev"/>
		<updated>2022-07-07T02:47:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Implementation in C&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:47, 7 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l168&quot;&gt;Line 168:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 168:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=py&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=py&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sympy import *; x,a,b,c,F = symbols(&#039;x,a,b,c,F&#039;) &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;                                 &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;from sympy import *; x,a,b,c&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;,w&lt;/ins&gt;,F = symbols(&#039;x,a,b,c&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;,w&lt;/ins&gt;,F&#039;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;cubic = x**3 + a*x**2 + b*x + c &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;                                  &lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;cubic = x**3 + a*x**2 + b*x + c&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(cubic.subs(x,w*F)/F^3).expand()&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(cubic.subs(x,w*F)/F^3).expand()&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6273:rev-6274:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6273&amp;oldid=prev</id>
		<title>Jpye: /* Implementation in C */</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6273&amp;oldid=prev"/>
		<updated>2022-07-07T02:46:38Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Implementation in C&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:46, 7 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l154&quot;&gt;Line 154:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 154:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This approach has been implemented in plain C code as {{srcbranch|python3|models/johnpye/fprops/cubicroots.c}}, licensed under the GPL. The code includes debugging output that be turned off by disabling &amp;lt;code&amp;gt;CUBICROOTS_DEBUG&amp;lt;/code&amp;gt;. The routine can be compiled to calculate using standard &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt; precision, or with the switches &amp;lt;code&amp;gt;CUBICROOTS_EXTRA_PRECISION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CUBICROOTS_LOW_PRECISION&amp;lt;/code&amp;gt;, calculation with &amp;lt;code&amp;gt;long double&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;, respectively, can be selected. This selection is done at compile time only, and only affects the internal precision of the calculation, not the API. Currently this code is embedded within [[FPROPS]] build (which uses [https://scons.org SCons]), but it is trivial to convert it to a standalone code. The dependencies on &amp;lt;code&amp;gt;color.h&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;common.h&amp;lt;/code&amp;gt; can very easily be removed.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This approach has been implemented in plain C code as {{srcbranch|python3|models/johnpye/fprops/cubicroots.c}}, licensed under the GPL. The code includes debugging output that be turned off by disabling &amp;lt;code&amp;gt;CUBICROOTS_DEBUG&amp;lt;/code&amp;gt;. The routine can be compiled to calculate using standard &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt; precision, or with the switches &amp;lt;code&amp;gt;CUBICROOTS_EXTRA_PRECISION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CUBICROOTS_LOW_PRECISION&amp;lt;/code&amp;gt;, calculation with &amp;lt;code&amp;gt;long double&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;, respectively, can be selected. This selection is done at compile time only, and only affects the internal precision of the calculation, not the API. Currently this code is embedded within [[FPROPS]] build (which uses [https://scons.org SCons]), but it is trivial to convert it to a standalone code. The dependencies on &amp;lt;code&amp;gt;color.h&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;common.h&amp;lt;/code&amp;gt; can very easily be removed.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is also a test suite that can be compiled by passing &amp;lt;code&amp;gt;-DTEST&amp;lt;/code&amp;gt; to the compiler. The various test cases are implemented via the &amp;lt;code&amp;gt;RTEST(a,b,c,nr,x0,x1,x2)&amp;lt;/code&amp;gt; macro, which checks the that the roots of the polynomial &amp;lt;math&amp;gt;x^3 + a x^2 + b x + c = 0&amp;lt;/math&amp;gt; solve to the expected &amp;lt;code&amp;gt;nr&amp;lt;/code&amp;gt; roots, 1 or 3, with values &amp;lt;math&amp;gt;\left\lbrace x_0\right\rbrace&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\lbrace x_0, x_1, x_2\right\rbrace&amp;lt;/math&amp;gt;, respectively. The solved roots are checked to be correct with relative tolerance of &amp;lt;code&amp;gt;TESTTOL&amp;lt;/code&amp;gt;, which is nominally &amp;lt;code&amp;gt;1-e13&amp;lt;/code&amp;gt; (at &amp;lt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;math&lt;/del&gt;&amp;gt;double&amp;lt;/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;math&lt;/del&gt;&amp;gt; precision). Further testing may reveal that this tolerance is overly optimistic, but it works so far.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is also a test suite that can be compiled by passing &amp;lt;code&amp;gt;-DTEST&amp;lt;/code&amp;gt; to the compiler. The various test cases are implemented via the &amp;lt;code&amp;gt;RTEST(a,b,c,nr,x0,x1,x2)&amp;lt;/code&amp;gt; macro, which checks the that the roots of the polynomial &amp;lt;math&amp;gt;x^3 + a x^2 + b x + c = 0&amp;lt;/math&amp;gt; solve to the expected &amp;lt;code&amp;gt;nr&amp;lt;/code&amp;gt; roots, 1 or 3, with values &amp;lt;math&amp;gt;\left\lbrace x_0\right\rbrace&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\lbrace x_0, x_1, x_2\right\rbrace&amp;lt;/math&amp;gt;, respectively. The solved roots are checked to be correct with relative tolerance of &amp;lt;code&amp;gt;TESTTOL&amp;lt;/code&amp;gt;, which is nominally &amp;lt;code&amp;gt;1-e13&amp;lt;/code&amp;gt; (at &amp;lt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;code&lt;/ins&gt;&amp;gt;double&amp;lt;/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;code&lt;/ins&gt;&amp;gt; precision). Further testing may reveal that this tolerance is overly optimistic, but it works so far.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some challenging cases were found during testing, such as  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some challenging cases were found during testing, such as  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6272:rev-6273:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6272&amp;oldid=prev</id>
		<title>Jpye at 02:45, 7 July 2022</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6272&amp;oldid=prev"/>
		<updated>2022-07-07T02:45:39Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:45, 7 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l152&quot;&gt;Line 152:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 152:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Implementation in C ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Implementation in C ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This approach has been implemented in plain C code as {{srcbranch|python3|models/johnpye/fprops/cubicroots.c}}, licensed under the GPL. The code includes debugging output that be turned off by disabling &amp;lt;code&amp;gt;CUBICROOTS_DEBUG&amp;lt;/code&amp;gt;. The routine can be compiled to calculate using standard &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt; precision, or with the switches &amp;lt;code&amp;gt;CUBICROOTS_EXTRA_PRECISION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CUBICROOTS_LOW_PRECISION&amp;lt;/code&amp;gt;, calculation with &amp;lt;code&amp;gt;long double&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;, respectively, can be selected. This selection is done at compile time only, and only affects the internal precision of the calculation, not the API. Currently this code is embedded within [[FPROPS]] build (which uses [https://scons.org&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;] &lt;/del&gt;SCons]), but it is trivial to convert it to a standalone code. The dependencies on &amp;lt;code&amp;gt;color.h&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;common.h&amp;lt;/code&amp;gt; can very easily be removed.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This approach has been implemented in plain C code as {{srcbranch|python3|models/johnpye/fprops/cubicroots.c}}, licensed under the GPL. The code includes debugging output that be turned off by disabling &amp;lt;code&amp;gt;CUBICROOTS_DEBUG&amp;lt;/code&amp;gt;. The routine can be compiled to calculate using standard &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt; precision, or with the switches &amp;lt;code&amp;gt;CUBICROOTS_EXTRA_PRECISION&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CUBICROOTS_LOW_PRECISION&amp;lt;/code&amp;gt;, calculation with &amp;lt;code&amp;gt;long double&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;, respectively, can be selected. This selection is done at compile time only, and only affects the internal precision of the calculation, not the API. Currently this code is embedded within [[FPROPS]] build (which uses [https://scons.org SCons]), but it is trivial to convert it to a standalone code. The dependencies on &amp;lt;code&amp;gt;color.h&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;common.h&amp;lt;/code&amp;gt; can very easily be removed.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is also a test suite that can be compiled by passing &amp;lt;code&amp;gt;-DTEST&amp;lt;/code&amp;gt; to the compiler. The various test cases are implemented via the &amp;lt;code&amp;gt;RTEST(a,b,c,nr,x0,x1,x2)&amp;lt;/code&amp;gt; macro, which checks the that the roots of the polynomial &amp;lt;math&amp;gt;x^3 + a x^2 + b x + c = 0&amp;lt;/math&amp;gt; solve to the expected &amp;lt;code&amp;gt;nr&amp;lt;/code&amp;gt; roots, 1 or 3, with values &amp;lt;math&amp;gt;\left\lbrace x_0\right\rbrace&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\lbrace x_0, x_1, x_2\right\rbrace&amp;lt;/math&amp;gt;, respectively. The solved roots are checked to be correct with relative tolerance of &amp;lt;code&amp;gt;TESTTOL&amp;lt;/code&amp;gt;, which is nominally &amp;lt;code&amp;gt;1-e13&amp;lt;/code&amp;gt; (at &amp;lt;math&amp;gt;double&amp;lt;/math&amp;gt; precision). Further testing may reveal that this tolerance is overly optimistic, but it works so far.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is also a test suite that can be compiled by passing &amp;lt;code&amp;gt;-DTEST&amp;lt;/code&amp;gt; to the compiler. The various test cases are implemented via the &amp;lt;code&amp;gt;RTEST(a,b,c,nr,x0,x1,x2)&amp;lt;/code&amp;gt; macro, which checks the that the roots of the polynomial &amp;lt;math&amp;gt;x^3 + a x^2 + b x + c = 0&amp;lt;/math&amp;gt; solve to the expected &amp;lt;code&amp;gt;nr&amp;lt;/code&amp;gt; roots, 1 or 3, with values &amp;lt;math&amp;gt;\left\lbrace x_0\right\rbrace&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;\left\lbrace x_0, x_1, x_2\right\rbrace&amp;lt;/math&amp;gt;, respectively. The solved roots are checked to be correct with relative tolerance of &amp;lt;code&amp;gt;TESTTOL&amp;lt;/code&amp;gt;, which is nominally &amp;lt;code&amp;gt;1-e13&amp;lt;/code&amp;gt; (at &amp;lt;math&amp;gt;double&amp;lt;/math&amp;gt; precision). Further testing may reveal that this tolerance is overly optimistic, but it works so far.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6271:rev-6272:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6271&amp;oldid=prev</id>
		<title>Jpye at 02:38, 7 July 2022</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6271&amp;oldid=prev"/>
		<updated>2022-07-07T02:38:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:38, 7 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The purpose of this page is to describe a robust process, in software, for finding real roots of a real cubic polynomial, something that is essential for dealing with cubic equations of state in chemical process modelling. It turns out that this is one of the great problems in the history of mathematics, and not that simple, as [https://youtu.be/N-KXStupwsc this video] helpfully explains. This page attempts to stick to the essential details and describe how to implement a solution suitable for coding.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The purpose of this page is to describe a robust process, in software, for finding real roots of a real cubic polynomial, something that is essential for dealing with cubic equations of state in chemical process modelling. It turns out that this is one of the great problems in the history of mathematics, and not that simple, as [https://youtu.be/N-KXStupwsc this video &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;from Burkard Polster&lt;/ins&gt;] helpfully explains. This page attempts to stick to the essential details and describe how to implement a solution suitable for coding.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== General solution ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== General solution ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6270:rev-6271:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6270&amp;oldid=prev</id>
		<title>Jpye at 02:37, 7 July 2022</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6270&amp;oldid=prev"/>
		<updated>2022-07-07T02:37:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:37, 7 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The purpose of this page is to describe a robust process, in software, for finding real roots of a real cubic polynomial, something that is essential for dealing with cubic equations of state in chemical process modelling. It turns out that this is one of the great problems in the history of mathematics, and not &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;at all &lt;/del&gt;simple, as [https://youtu.be/N-KXStupwsc this video] helpfully explains. This page attempts to stick to the essential details and describe how to implement a solution suitable for coding.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The purpose of this page is to describe a robust process, in software, for finding real roots of a real cubic polynomial, something that is essential for dealing with cubic equations of state in chemical process modelling. It turns out that this is one of the great problems in the history of mathematics, and not &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;that &lt;/ins&gt;simple, as [https://youtu.be/N-KXStupwsc this video] helpfully explains. This page attempts to stick to the essential details and describe how to implement a solution suitable for coding.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== General solution ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== General solution ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6269:rev-6270:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6269&amp;oldid=prev</id>
		<title>Jpye at 02:37, 7 July 2022</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6269&amp;oldid=prev"/>
		<updated>2022-07-07T02:37:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:37, 7 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The purpose of this page is to describe a robust process, in software, for finding real roots of a real cubic polynomial. It turns out that this is one of the great problems in the history of mathematics, and not at all simple, as [https://youtu.be/N-KXStupwsc this video] helpfully explains. This page attempts to stick to the essential details and describe how to implement a solution suitable for coding.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The purpose of this page is to describe a robust process, in software, for finding real roots of a real cubic polynomial&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, something that is essential for dealing with cubic equations of state in chemical process modelling&lt;/ins&gt;. It turns out that this is one of the great problems in the history of mathematics, and not at all simple, as [https://youtu.be/N-KXStupwsc this video] helpfully explains. This page attempts to stick to the essential details and describe how to implement a solution suitable for coding.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== General solution ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== General solution ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6268:rev-6269:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6268&amp;oldid=prev</id>
		<title>Jpye: /* Implementation in C */</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6268&amp;oldid=prev"/>
		<updated>2022-07-06T11:27:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Implementation in C&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:27, 6 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l173&quot;&gt;Line 173:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 173:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some subtle logic was also needed for cases where &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; are close to zero. The variable &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; is used to check how small &amp;lt;math&amp;gt;\left|D\right|&amp;lt;/math&amp;gt; can be before it is assumed to be zero, yielding double and single real roots, as opposed to a single or three different real roots. It is not clear yet whether this value of &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; has been wisely chosen; for now it works with the test suite provided. The tolerances &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;TOLQ&amp;lt;/code&amp;gt; (&lt;/del&gt;for &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;) and &lt;/del&gt;&amp;lt;code&amp;gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;TOLP&lt;/del&gt;&amp;lt;/code&amp;gt; &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(&lt;/del&gt;for &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;) work similarly.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some subtle logic was also needed for cases where &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; are close to zero. The variable &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; is used to check how small &amp;lt;math&amp;gt;\left|D\right|&amp;lt;/math&amp;gt; can be before it is assumed to be zero, yielding double and single real roots, as opposed to a single or three different real roots. It is not clear yet whether this value of &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; has been wisely chosen; for now it works with the test suite provided&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, which includes all of the test cases used in GSL as well as quite a few more&lt;/ins&gt;. The tolerances for &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(&lt;/ins&gt;&amp;lt;code&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;TOLQ&lt;/ins&gt;&amp;lt;/code&amp;gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;) and &lt;/ins&gt;for &amp;lt;math&amp;gt;P&amp;lt;/math&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;gt; (&amp;lt;code&amp;gt;TOLP&amp;lt;/code&lt;/ins&gt;&amp;gt;) work similarly&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Again, the values have not yet been carefully tuned&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The logic for specifically handling the cases of &amp;lt;math&amp;gt;P=0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; adds a bit of code, but would reduce computation cost in cases where a lot of such polynomials are being solved. Perhaps it could be removed to make the code simpler.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The logic for specifically handling the cases of &amp;lt;math&amp;gt;P=0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; adds a bit of code, but would &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;presumably &lt;/ins&gt;reduce computation cost in cases where a lot of such polynomials are being solved. Perhaps it could be removed to make the code simpler.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A current limitation of the code is that it has no way of passing back the nature of the roots, for example if the value of &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; is close to zero, or whether there were multiple roots or not. Only the number of roots is returned. It is not yet know if users of this function could benefit from that information or not. Note that the root are sorted so as to be returned in increasing order. Double roots could be the first two or the second two roots.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A current limitation of the code is that it has no way of passing back the nature of the roots, for example if the value of &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; is close to zero, or whether there were multiple roots or not. Only the number of roots is returned. It is not yet know if users of this function could benefit from that information or not. Note that the root are sorted so as to be returned in increasing order. Double roots could be the first two or the second two roots.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6267:rev-6268:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6267&amp;oldid=prev</id>
		<title>Jpye: /* Implementation in C */</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6267&amp;oldid=prev"/>
		<updated>2022-07-05T04:37:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Implementation in C&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:37, 5 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l166&quot;&gt;Line 166:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 166:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Both of these cases were improved by adding some additional logic for re-scaling &amp;lt;math&amp;gt;w = \frac{x}{F}&amp;lt;/math&amp;gt;, and then also dividing the parameters &amp;lt;math&amp;gt;a,b,c&amp;lt;/math&amp;gt; in order to keep the polynomial monic.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Both of these cases were improved by adding some additional logic for re-scaling &amp;lt;math&amp;gt;w = \frac{x}{F}&amp;lt;/math&amp;gt;, and then also dividing the parameters &amp;lt;math&amp;gt;a,b,c&amp;lt;/math&amp;gt; in order to keep the polynomial monic.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;source lang=py&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;from sympy import *; x,a,b,c,F = symbols(&#039;x,a,b,c,F&#039;)                                  &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;cubic = x**3 + a*x**2 + b*x + c                                   &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(cubic.subs(x,w*F)/F^3).expand()&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/source&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some subtle logic was also needed for cases where &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; are close to zero. The variable &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; is used to check how small &amp;lt;math&amp;gt;\left|D\right|&amp;lt;/math&amp;gt; can be before it is assumed to be zero, yielding double and single real roots, as opposed to a single or three different real roots. It is not clear yet whether this value of &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; has been wisely chosen; for now it works with the test suite provided. The tolerances &amp;lt;code&amp;gt;TOLQ&amp;lt;/code&amp;gt; (for &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;) and &amp;lt;code&amp;gt;TOLP&amp;lt;/code&amp;gt; (for &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;) work similarly.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Some subtle logic was also needed for cases where &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; are close to zero. The variable &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; is used to check how small &amp;lt;math&amp;gt;\left|D\right|&amp;lt;/math&amp;gt; can be before it is assumed to be zero, yielding double and single real roots, as opposed to a single or three different real roots. It is not clear yet whether this value of &amp;lt;code&amp;gt;TOLD&amp;lt;/code&amp;gt; has been wisely chosen; for now it works with the test suite provided. The tolerances &amp;lt;code&amp;gt;TOLQ&amp;lt;/code&amp;gt; (for &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;) and &amp;lt;code&amp;gt;TOLP&amp;lt;/code&amp;gt; (for &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;) work similarly.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6264:rev-6267:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
	<entry>
		<id>https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6264&amp;oldid=prev</id>
		<title>Jpye: /* Implementation in C */</title>
		<link rel="alternate" type="text/html" href="https://ascend4.org/index.php?title=Solving_cubic_polynomials&amp;diff=6264&amp;oldid=prev"/>
		<updated>2022-07-03T11:53:24Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Implementation in C&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:53, 3 July 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l171&quot;&gt;Line 171:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 171:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The logic for specifically handling the cases of &amp;lt;math&amp;gt;P=0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; adds a bit of code, but would reduce computation cost in cases where a lot of such polynomials are being solved. Perhaps it could be removed to make the code simpler.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The logic for specifically handling the cases of &amp;lt;math&amp;gt;P=0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; adds a bit of code, but would reduce computation cost in cases where a lot of such polynomials are being solved. Perhaps it could be removed to make the code simpler.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A current limitation of the code is that it has no way of passing back the nature of the roots, for example if the value of &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; is close to zero, or whether there were multiple roots or not. Only the number of roots is returned. It is not yet know if users of this function could benefit from that information or not.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;A current limitation of the code is that it has no way of passing back the nature of the roots, for example if the value of &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; is close to zero, or whether there were multiple roots or not. Only the number of roots is returned. It is not yet know if users of this function could benefit from that information or not&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Note that the root are sorted so as to be returned in increasing order. Double roots could be the first two or the second two roots&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Calculation checking ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Calculation checking ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key mediawiki:diff:1.41:old-6263:rev-6264:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jpye</name></author>
	</entry>
</feed>