How to neglect specific terms in an expression?

Click For Summary
SUMMARY

This discussion focuses on using Mathematica for neglecting specific terms in expressions based on explicit time dependence. The user inquired about tools or methods to automate this process, specifically referencing the function Select with FreeQ[t] to filter terms. It was concluded that while Select can remove terms without explicit time dependence, it may not always yield the expected results due to Mathematica's structural pattern matching approach. Users must be cautious with pattern matching to ensure accurate term elimination.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of structural pattern matching in programming
  • Knowledge of explicit time dependence in mathematical expressions
  • Basic experience with functional programming concepts
NEXT STEPS
  • Explore advanced pattern matching techniques in Mathematica
  • Learn about the ReplaceAll function for term manipulation
  • Investigate the use of Cases for filtering expressions
  • Study the implications of semantic versus structural pattern matching
USEFUL FOR

Mathematica users, physicists working with time-dependent systems, and anyone interested in advanced expression manipulation techniques in computational mathematics.

Robin04
Messages
259
Reaction score
16
I've just started using Mathematica and I'm still trying to get used to how things are properly done with it. I tried to do a calculation (this one: https://www.physicsforums.com/threads/lagrangian-of-a-driven-pendulum-landau-problem.965714/) and I had to neglect some terms in an expression.

Is there any tool in Mathematica where I can specify some condition like 'term has explicit time dependence' and it automatically throws out the terms that meet that condition? Or how is this done with these calculations? For now, I just subtracted it from the variable manually but I suppose there's some more elegant way of doing this.

EDIT: As the problem above has been solved I must add that I actually don't need to neglect terms there, because they fall out on their own, but I'm still curious if there are such tools in Mathematica.
 
Last edited:
Physics news on Phys.org
Will something like this

Select[a*t*Cos+c*Sin[t]+E^(t-1)+d*Cos+f-1,FreeQ[t]]

which returns this

-1 + f + d*Cos

correctly handle all the cases that you are considering?

You must be very careful with pattern matching methods like this and check that they correctly do exactly what you are expecting in every single case.

Notice for example

Select[a*t*Cos+(c+t)*Sin[g]+E^(t-1)+d*Cos+f-1,FreeQ[t]]

"incorrectly" returns

-1 + f + d*Cos

instead of

-1 + f + d*Cos + c*Sin[g]

if you are expecting this to understand that you intend to eliminate all and only those terms which do not have explicit time dependence.

What is happening, but not shown, is that Plus has a list of arguments, Select is going through that list of arguments at a time, if there is no t in an argument then Select is returning that, otherwise it is discarding that. (c+t)*Sin[g] is one of the arguments in that list. c*Sin[g]+t*Sin[g] is not one of the arguments in that list.

Mathematica does "structural pattern matching", it is simply trying to match the literal structure of expressions, not "semantic pattern matching" or trying to match the meaning of the expression.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
346