1
$\begingroup$

I am trying to learn how to make automatically from a list of polynomials (or an arbitrary collection of algebraic expression) a list of inequalities/equalities (those will later serve as constraints in some optimization program).

So suppose I have the list like

polynoms={ax^2+bx+c, cx+d, a^3-20x+d}

and I would like to end up with a list like

const={ax^2+bx+c>=0, cx+d>=0, a^3-20x+d==0}

or at least with the list

const2={ax^2+bx+c>=0, cx+d>=0, a^3-20x+d>= 0}

where to the entire list the same $\geq 0$ has been applied. It is not a problem to do it manually when there are 3 or 5 inequalities to be generated, but when I have a list of 30 it becomse a nightmare... I have been searching through a bunch of possibilities how to do it automatically, but all are failing.. Thanks for any hints!

$\endgroup$
2
$\begingroup$
polynoms = {ax^2 + bx + c, cx + d, a^3 - 20 x + d};

polynoms >= 0 // Thread

(*  {ax^2 + bx + c >= 0, cx + d >= 0, a^3 + d - 20 x >= 0}  *)

#[[1]][#[[2]], 0] & /@ Transpose[{
   {GreaterEqual, GreaterEqual, Equal},
   polynoms}]

(*  {ax^2 + bx + c >= 0, cx + d >= 0, a^3 + d - 20 x == 0}  *)

Or

Inner[#1[#2, 0] &,
 {GreaterEqual, GreaterEqual, Equal},
 polynoms, List]

(*  {ax^2 + bx + c >= 0, cx + d >= 0, a^3 + d - 20 x == 0}  *)
$\endgroup$
  • $\begingroup$ Thank you! It happened to be embarrassingly simple, I don't know how I failed to find "thread" command. $\endgroup$ – Kass Nov 20 '15 at 23:40
0
$\begingroup$

First, you may need to separate ax and bx into a * x and b * x if they are products with 'x'

Depending on your subsequent application (for example Solve) you can Apply Unequal to the list so that each variable is unique

  equations={a*b,b*c}

  notequal =Apply[Unequal, {a,b,c}]
  equationsnotequal = Apply[Unequal,equations]

and pass desired constraints simply by adding the bounds on the list e.g

Solve[{a,b,c}>0 && notequal && equations<42 && equationsnotequal, {a,b,c}, Integers] 
$\endgroup$
  • $\begingroup$ I need those constraints for NMaximize or FindFit, and those too sophisticated I guess to apply your idea... $\endgroup$ – Kass Nov 20 '15 at 23:42
  • $\begingroup$ OK, no worries. Even though it doesn't address your specific use I think I will leave the answer here in case its useful for others, especially re Solve. Was the comment about using a*x (or a_space_x) to represent the product of a and x in Mathematica useful? $\endgroup$ – PlaysDice Nov 21 '15 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.