2

I would like to transform rules algebraically. A very simple example would be: -

k^2 - 2 k x + x^2 /. {2*k -> 1}

This transforms to: -

$$k^2-2 k x+x^2$$

However, I would like it to return something more like: -

$$\frac{1}{4}- x+x^2$$

In fact, I am more interested in solving quadratic, cubic and quartic polynomials. For example, I am able to set the discriminant of a quadratic to zero as a rule since the solution of a quadratic is already in an expanded form: -

quadratic = a*x^2 + b*x + c
Solve[quadratic == 0, x]  /. { Discriminant[quadratic, x] -> 0 }

This yields the correct results: -

$$\left\{\left\{x\to -\frac{b}{2 a}\right\},\left\{x\to -\frac{b}{2 a}\right\}\right\}$$

To achieve something similar for the cubic one must expand the solution while also transforming the discriminant.

cubic := a*x^3 + b*x^2 + c*x + d;
ExpandAll[Solve[cubic == 0 , x]] /. { Expand[-27*a^2*Discriminant[cubic, x]] -> 0 }

This process requires some forward thinking and doesn't easily apply to a quartic.

I am hoping Mathematica has some built in transformation rules for substituting expressions algebraically (obviously assuming certain criteria, i.e field/ring etc..) Does anyone have any suggestions?

Blair Azzopardi
  • 473
  • 1
  • 4
  • 10

1 Answers1

2

I understand you want to transform the solution to an equation by imposing that it's solutions also satisfy another equation (discriminant = 0).

This is for the quadratic case : all output are equivalent, though the first one is the most familiar.

Solve[{quadratic == 0, Discriminant[quadratic, x] == 0}, {x, c}]
(* {{x -> -(b/(2 a)), c -> b^2/(4 a)}} *)

Solve[{quadratic == 0, Discriminant[quadratic, x] == 0}, {x, b}]
(* {{x -> -(Sqrt[c]/Sqrt[a]), b -> 2 Sqrt[a] Sqrt[c]}, 
   {x -> Sqrt[c]/Sqrt[a], b -> -2 Sqrt[a] Sqrt[c]}} *)

Solve[{quadratic == 0, Discriminant[quadratic, x] == 0}, {x, a}]
(* {{x -> -((2 c)/b), a -> b^2/(4 c)}} *)
b.gates.you.know.what
  • 20,103
  • 2
  • 43
  • 84