Group Abstract Group Abstract

Message Boards Message Boards

How to make Sum work with the error Sum::vexdep with dependencies

Attachments:
POSTED BY: Peter Burbery
7 Replies

Ok, _?IntegerQ and _Integer are not totally equivalent, but they show their difference only in fringe cases such as Integer[3]. But are you really afraid that your code will meet such constructs?

POSTED BY: Gianluca Gorni

I want the code to be as robust as possible. There's a lot of helpful functions for this like GraphQ, IntegerQ, RealValuedNumericQ and RealValuedNumberQ coming in 13.3, PolynomialQ, etc.

POSTED BY: Peter Burbery

Your pattern test accepts List[Red]:

In[36]:= MatchQ[List[Red], l_?(Function[{x}, ListQ[x], {}])]

Out[36]= True
POSTED BY: Gianluca Gorni

Yes I know, I can't really think of an example where List isn't accepted. The point stands, though.

POSTED BY: Peter Burbery

I am trying to understand your function ReplacePlusMinus. First question: what is the purpose of the complicated pattern test l_?(Function[{x}, ListQ[x], {}])? Why not this simpler form:

myReplacePlusMinus[l_List] := 
 SequenceReplace[l, {x_, -x_} :> PlusMinus[x]]

Have you tried ReplacePlusMinus in these examples?

ReplacePlusMinus[{1, -1}]
ReplacePlusMinus[{-a, a}]

Are you ok with the output?

POSTED BY: Gianluca Gorni

If I use _List, the function will match something that I don't want it to match such as List[Red]. Maybe that's not a good example. Instead of using _Integer, for example, I use IntegerQ. Or instead of using _Graph I use GraphQ. _Integer would match Integer[Red] but IntegerQ[Integer[Red]]] would return False. _Graph would match Graph[Red] but GraphQ[Graph[Red]] would return False, which is what I want. PatternTest with the shorthand form ? has high precedence. I am using the three argument form of function so I can an attribute such as HoldAll like Function[{x},x^2,{HoldAll}] if need be. I think there's an example of this in the documentation.

POSTED BY: Peter Burbery

I wonder if you have tried the following:

In[53]:= ReplacePlusMinus[{1, -1}]
ReplacePlusMinus[{-a, a}]
ReplacePlusMinus[{-1 + Sqrt[2], 1 - Sqrt[2]}]

Out[53]= {1, -1}

Out[54]= {-a, a}

Out[55]= {-1 + Sqrt[2], 1 - Sqrt[2]}
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard