Skip to main content
added 317 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
selector =  Module[{selcoeffsNotBothZero = Select[NotNot @* FreeQ[x | y]] @ #},y]; 
 
coeffsNotBothNonNegative = FreeQ[{__?NonNegative}]]@
 @  Outer[Coefficient, selSelect[coeffsNotBothZero] @ #, {x, y}]]] &; 

Select[selector]Select[coeffsNotBothNonNegative] @ list 
{{1, 0, x - y}, {1, 0, 0}, {-1, x - y, 0}, {1, -2 x + y, 0}, 
 {0, -x - y, -1}, {-x + 3 y, 0, 0}, {2 x - 3 y, 0, 1}}

You can also do:

coeffsNotBothNonNegative2 = FreeQ[_?Positive][
    Select[coeffsNotBothZero][#] /. {i_Integer :> Sign[i], x | y -> 1}] &;

Select[coeffsNotBothNonNegative2] @ list == Select[coeffsNotBothNonNegative] @ list

True

selector =  Module[{sel = Select[Not @* FreeQ[x | y]] @ #}, 
   FreeQ[{__?NonNegative}] @ Outer[Coefficient, sel, {x, y}]] &; 

Select[selector] @ list 
{{1, 0, x - y}, {1, 0, 0}, {-1, x - y, 0}, {1, -2 x + y, 0}, 
 {0, -x - y, -1}, {-x + 3 y, 0, 0}, {2 x - 3 y, 0, 1}}
coeffsNotBothZero = Not @* FreeQ[x | y]; 

coeffsNotBothNonNegative = FreeQ[{__?NonNegative}]@
   Outer[Coefficient, Select[coeffsNotBothZero] @ #, {x, y}] &;

Select[coeffsNotBothNonNegative] @ list
{{1, 0, x - y}, {1, 0, 0}, {-1, x - y, 0}, {1, -2 x + y, 0}, 
 {0, -x - y, -1}, {-x + 3 y, 0, 0}, {2 x - 3 y, 0, 1}}

You can also do:

coeffsNotBothNonNegative2 = FreeQ[_?Positive][
    Select[coeffsNotBothZero][#] /. {i_Integer :> Sign[i], x | y -> 1}] &;

Select[coeffsNotBothNonNegative2] @ list == Select[coeffsNotBothNonNegative] @ list

True

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

selector =  Module[{sel = Select[Not @* FreeQ[x | y]] @ #}, 
   FreeQ[{__?NonNegative}] @ Outer[Coefficient, sel, {x, y}]] &; 

Select[selector] @ list 
{{1, 0, x - y}, {1, 0, 0}, {-1, x - y, 0}, {1, -2 x + y, 0}, 
 {0, -x - y, -1}, {-x + 3 y, 0, 0}, {2 x - 3 y, 0, 1}}