Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a series of symbolic manipulations (along with some coefficients).

As a sample, here is one of the intermediate forms

-1.00 (-0.707 (1.00+0.500 ax^2+0.375 ax^4+0.313 ax^6+0.273 ax^8) ay-0.0884 (1.00+0.500 ax^2+0.375 ax^4+0.313 ax^6+0.273 ax^8)^3 ay^3-0.0387 (1.00+0.500 ax^2+0.375 ax^4+0.313 ax^6+0.273 ax^8)^5 ay^5-0.0228 (1.00+0.500 ax^2+0.375 ax^4+0.313 ax^6+0.273 ax^8)^7 ay^7) Sign[(1.00+0.500 ax^2+0.375 ax^4+0.313 ax^6+0.273 ax^8) ay

As part of the calculations, Mathematica generates large expressions that can be further simplified by dropping higher order terms (such as powers > 10).

Is there someway to force Mathematic to drop high order terms in the evaluation?

Thoughts much appreciated.

share|improve this question
1  
You can use Series to do a series expansion. (Alternatively just append something like O[ax]^10 to the sum.) –  Szabolcs Apr 8 '13 at 14:50
    
Some of the intermediate forms don’t lend themselves to series expansion…. –  Pam Apr 8 '13 at 18:54

2 Answers 2

up vote 1 down vote accepted

Maybe I was a bit over cautious to not evaluate your expression, thats why I use all the Holds. Note that Simplify will change your expression, but normal evaluation wont. Anyway, any of the Holds can simply be cleared by applying ReleaseHold.

If you really want to drop such terms or make them 0, you can do something like this

Clear[expr]
expr := -1.00 (-0.707 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 0.313 ax^6 + 
        0.273 ax^8) ay - 
     0.0884 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 0.313 ax^6 + 
         0.273 ax^8)^3 ay^3 - 
     0.0387 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 0.313 ax^6 + 
         0.273 ax^8)^5 ay^5 - 
     0.0228 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 0.313 ax^6 + 
         0.273 ax^8)^7 ay^7) Sign[(1.00 + 0.500 ax^2 + 0.375 ax^4 + 
       0.313 ax^6 + 0.273 ax^8) ay];

axayPatt := ax | ay;

DeleteCases[Hold[expr] /. OwnValues[expr]
 ,
 (Times[_, axayPatt^n_] /; n > 5) | (axayPatt^n_ /; n > 5)
 ,
 Infinity
 ]

-> Hold[-1. (-0.707 (1. + 0.5 ax^2 + 0.375 ax^4) ay - 0.0884 (1. + 0.5 ax^2 + 0.375 ax^4)^3 ay^3 - 0.0387 (1. + 0.5 ax^2 + 0.375 ax^4)^5 ay^5 - 1) Sign[(1. + 0.5 ax^2 + 0.375 ax^4) ay]]

Or,

interExpr =
 ReplaceAll[
  Hold[expr] /. OwnValues[expr]
  ,
  axayPatt^n_ /; n > 5 :> 0 
  ]

-> Hold[-1. (-0.707 (1. + 0.5 ax^2 + 0.375 ax^4 + 0.313 0 + 0.273 0) ay - 0.0884 (1. + 0.5 ax^2 + 0.375 ax^4 + 0.313 0 + 0.273 0)^3 ay^3 - 0.0387 (1. + 0.5 ax^2 + 0.375 ax^4 + 0.313 0 + 0.273 0)^5 ay^5 - 0.0228 (1. + 0.5 ax^2 + 0.375 ax^4 + 0.313 0 + 0.273 0)^7 0) Sign[(1. + 0.5 ax^2 + 0.375 ax^4 + 0.313 0 + 0.273 0) ay]]

Or even, if you really want to do things manually and not use standard evaluation,

interExpr2 =
  ReplaceRepeated[
   interExpr
   ,
   {HoldPattern[___*0 | 0.*___] :> 0, 
    HoldPattern[a___ + 0 | 0. + b___] :> a + b}
   ];
interExpr2 // FullForm

-> Hold[Times[-1.,Plus[Times[-0.707,Plus[1.,Times[0.5,Power[ax,2]],Times[0.375,Power[ax,4]]],ay],Times[-1,Times[0.0884,Power[Plus[1.,Times[0.5,Power[ax,2]],Times[0.375,Power[ax,4]]],3],Power[ay,3]]],Times[-1,Times[0.0387,Power[Plus[1.,Times[0.5,Power[ax,2]],Times[0.375,Power[ax,4]]],5],Power[ay,5]]]],Sign[Times[Plus[1.,Times[0.5,Power[ax,2]],Times[0.375,Power[ax,4]]],ay]]]]

Which can be displayed as follows

HoldForm @@ interExpr2

-> -1. (-0.707 (1. +0.5 ax^2+0.375 ax^4) ay-0.0884 (1. +0.5 ax^2+0.375 ax^4)^3 ay^3-0.0387 (1. +0.5 ax^2+0.375 ax^4)^5 ay^5) Sign[(1. +0.5 ax^2+0.375 ax^4) ay]

share|improve this answer
    
Wow… thanks for taking the time… This gets me closer to what I want… still need to futz around to get around some funky non-Seriesable functions... –  Pam Apr 8 '13 at 18:53
    
@Pam no problem :), glad you're making progress. –  Jacob Akkerboom Apr 8 '13 at 19:21

I'll illustrate a fairly common way of clipping by total degree (which may or may not be what you wanted). To simplify I will replace your Sign[] by Sin[] as the former really does not have a series expansion and I am not sure how you wanted to handle it.

expr = -1.00 (-0.707 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 
        0.313 ax^6 + 0.273 ax^8) ay - 
     0.0884 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 0.313 ax^6 + 
         0.273 ax^8)^3 ay^3 - 
     0.0387 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 0.313 ax^6 + 
         0.273 ax^8)^5 ay^5 - 
     0.0228 (1.00 + 0.500 ax^2 + 0.375 ax^4 + 0.313 ax^6 + 
         0.273 ax^8)^7 ay^7) Sin[(1.00 + 0.500 ax^2 + 0.375 ax^4 + 
      0.313 ax^6 + 0.273 ax^8)] ay;
vars = {ax, ay};

vars = {ax, ay};

clipexpr = 
 Normal[Series[expr /. Thread[vars -> t*vars], {t, 0, 10}]] /. t -> 1

(* Out[32]= 0.594919986259 ay^2 + 0.488456858254 ax^2 ay^2 + 
 0.38747607797 ax^4 ay^2 + 0.292333442832 ax^6 ay^2 + 
 0.201047651375 ax^8 ay^2 + 0.074386035057 ay^4 + 
 0.135460414505 ax^2 ay^4 + 0.183908625668 ax^4 ay^4 + 
 0.220535029166 ax^6 ay^4 + 0.0325649271121 ay^6 + 
 0.0918671673987 ax^2 ay^6 + 0.172379201487 ax^4 ay^6 + 
 0.0191855384536 ay^8 + 0.0733088308746 ax^2 ay^8 *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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