1

Back Story

I believe a quadratic polynomial, $ax^2+bx+c$, has only real solutions $\text{iff}$ the discriminant, $D \geq 0$, which occurs when:

$$ D = b^2 - 4ac \geq 0 \Rightarrow \begin{cases} b^2 \geq 4ac & \text{if } ac > 0, \\ \text{any } b & \text{if } ac \leq 0. \end{cases} $$

I want to create a software program that generates random quadratic polynomials with only real solutions without using any 'if-statements' because if it requires checking, then by this logic I would have to reject a lot of generated quadratic polynomials when simulating.

In Mathematica, I can use the code:

n = 10000; (* Number of random sets to generate *)
data = Table[
  a = RandomReal[{-2, 2}];
  b = RandomReal[{-2.5, 2.5}];
  c = RandomReal[{-3, 3}];
  discriminant = b^2 - 4*a*c;
  If[discriminant  >= 0, {a, b, c}, Nothing],
  {n}
];
chm = ConcaveHullMesh[data];
bdp = MeshCoordinates[RegionBoundary[chm]];
ListSurfacePlot3D[bdp, AxesLabel -> {"a", "b", "c"}, PlotLabel -> "Coefficients of Quadratics with D >= 0"]

To generate a shape like this:

This is a sample image using the coefficients of a quadratic polynomial as 3D points.

When I change the bounds for $a, b, \text{or } c$, I get a similar shape where it is partially flat on the top and bottom, then curves. And it seems to have a flip symmetry.

Question Repeated:

So then what shape is formed that contains all the points (a, b, c) given the maximum and minimum bounds for each of those 3 parameters?

Update:

Here is the code and images for different viewpoints for when $b^{2} = 4ac$:

n = 10000; (* Number of random sets to generate *)
data = Table[
    a = RandomReal[{-2, 2}];
    c = RandomReal[{-3, 3}];
    If[RandomChoice[{True, False}], 
        b = 2 * Sqrt[Abs[a * c]], (* Ensure b is real *)
        b = -2 * Sqrt[Abs[a * c]]
    ];
    If[a < 0, c = -Abs[c]]; (* Ensure c is negative if a is negative *)
    If[c < 0, a = -Abs[a]]; (* Ensure a is negative if c is negative *)
    {a, b, c},
    {n}
];

viewPoints = { {"Above", {0, 0, Infinity}}, {"Below", {0, 0, -Infinity}}, {"Front", {0, Infinity, 0}}, {"Behind", {0, -Infinity, 0}}, {"Left", {Infinity, 0, 0}}, {"Right", {-Infinity, 0, 0}}, {"Top Front Right", {Infinity, Infinity, Infinity}}, {"Bottom Back Left", {-Infinity, -Infinity, -Infinity}} };

plots = Table[ ListPlot3D[data, ViewPoint -> vp[[2]], ViewProjection -> "Orthographic", ImagePadding -> 5, PlotLabel -> Style[vp[[1]], 14, Bold, Background -> White], PlotRangePadding -> 0.2 ], {vp, viewPoints} ];

(* Adjust the size of the graphics grid as needed *) Rasterize[GraphicsGrid[Partition[plots, 2], Spacings -> {0, 0}, ImageSize -> Full]]

Which gave the example image:

This is a sample plot from 8 different orthographic view points.

KReiser
  • 65,137
  • 2
    suggest you get the best images you can of the (elliptical) cone $b^2 = 4ac$ Let me see if I have any way to show that...maybe not. Anyway, the positive definite forms are "inside" the (double-nappe) cone, the negative forms in the opposite piece, and the indefinite forms in the funny donut shape – Will Jagy Jan 10 '24 at 01:59
  • 1
    You haven't specified the distribution you want to draw your random polynomials from. In case that's because you don't particularly care about the distribution, this might be an XY problem – you could just generate random roots $x_1$, $x_2$ and form $(x-x_1)(x-x_2)$. – joriki Jan 10 '24 at 02:03
  • @joriki uniformly like in the code. Yes, you are correct that I could multiply those. But I was curious about the shape mentioned in the question. – Teg Louis Jan 10 '24 at 02:29
  • @WillJagy I try that tomorrow. I bet I can. How do we know that the double napped elliptical cone works for that part? – Teg Louis Jan 10 '24 at 02:34
  • 1
    An indefinite, but non-degenerate, quadratic form in three variables has a zero set that is an elliptical cone, or a circular cone, double napped and through the origin. You might ask for images of $z^2 - x^2 - y^2 = 0$ and then $z^2 - 2x^2 - y^2 = 0$ – Will Jagy Jan 10 '24 at 02:55
  • @WillJagy I updated it to show when $b^{2} = 4ac$ from different view points. – Teg Louis Jan 12 '24 at 03:48

1 Answers1

0

So, looking at your graphs and reading the requirement, it is not possible to generate that surface without using an 'if'-statement somewhere in the code (possibly only shown at the lower level.) I don't have a proof of this statement, but I think it is self-evident.

While you cannot perfectly describe the shape, I believe you can randomly generate a decent subspace that gives you only real roots and it appears to not use any if statements (even though absolute values require it).

Here is the Mathematica Code:

GenerateQuadraticCoefficients[n_Integer] := Module[
  {a, b, c, k, coefficientLists},

(* Function to generate a single set of coefficients ) generateSingleSet[] := Module[{a, b, c, k}, a = RandomReal[{-2, 2}]; c = -a RandomReal[{-3, 3}] / Max[Abs[a], 1^-6]; ( Avoid division by zero ) k = RandomReal[{1, 10}]; b = 2 Sqrt[Abs[a * c]] * k; {a, b, c} ];

(* Generate the list of coefficient lists *) coefficientLists = Table[generateSingleSet[], {n}];

coefficientLists ]

(* Example usage: generate 5 sets of coefficients *) GenerateQuadraticCoefficients[5]

and you can then test it out with:

data = GenerateQuadraticCoefficients[10000];
Solve[Dot[First[RandomSample[data,1]],{x^2,x,1}]==0,x]

While it is not possible with a digital computer, I guess that maybe it is possible with a hybrid digital-analog computer. So, for example, making a 3D Etch-a-Sketch like the first photo in the question. The position of the nobs/rods would give the coordinates of the point in the strangely-shaped box. But making that would most likely be just silly.