Get mathematica to simplify expression with another equation

前端 未结 3 1087
囚心锁ツ
囚心锁ツ 2020-12-23 17:51

I have a very complicated mathematica expression that I\'d like to simplify by using a new, possibly dimensionless parameter.

An example of my expression is:

<
相关标签:
3条回答
  • 2020-12-23 18:17

    Have you tried this?

    K = a*b*t/((t + f) c*d);
    Solve[p == t/(t + f), t]
     -> {{t -> -((f p)/(-1 + p))}}
    
    Simplify[K /. %[[1]] ]
     -> (a b p)/(c d)
    

    EDIT: Oh, and are you aware of Eliminiate?

    Eliminate[{eq1, eq2}, {t,f}]
     -> a b p == c d K && c != 0 && d != 0
    
    Solve[%, K]
     -> {{K -> (a b p)/(c d)}}
    

    EDIT 2: Also, in this simple case, solving for K and t simultaneously seems to do the trick, too:

    Solve[{eq1, eq2}, {K, t}]
     -> {{K -> (a b p)/(c d), t -> -((f p)/(-1 + p))}}
    
    0 讨论(0)
  • Something along these lines is discussed in the MathGroup post at

    http://forums.wolfram.com/mathgroup/archive/2009/Oct/msg00023.html

    (I see it has an apocryphal note that is quite relevant, at least to the author of that post.)

    Here is how it might be applied in the example above. For purposes of keeping this self contained I'll repeat the replacement code.

    replacementFunction[expr_, rep_, vars_] := 
     Module[{num = Numerator[expr], den = Denominator[expr], 
       hed = Head[expr], base, expon}, 
      If[PolynomialQ[num, vars] && 
        PolynomialQ[den, vars] && ! NumberQ[den], 
       replacementFunction[num, rep, vars]/
        replacementFunction[den, rep, vars], 
       If[hed === Power && Length[expr] == 2, 
        base = replacementFunction[expr[[1]], rep, vars];
        expon = replacementFunction[expr[[2]], rep, vars];
        PolynomialReduce[base^expon, rep, vars][[2]], 
        If[Head[hed] === Symbol && 
          MemberQ[Attributes[hed], NumericFunction], 
         Map[replacementFunction[#, rep, vars] &, expr], 
         PolynomialReduce[expr, rep, vars][[2]]]]]]
    

    Your example is now as follows. We take the input, and also the replacement. For the latter we make an equivalent polynomial by clearing denominators.

    kK = a*b*t/((t + f) c*d);
    rep = Numerator[Together[p - t/(t + f)]];
    

    Now we can invoke the replacement. We list the variables we are interested in replacing, treating 'p' as a parameter. This way it will get ordered lower than the others, meaning the replacements will try to remove them in favor of 'p'.

    In[127]:= replacementFunction[kK, rep, {t, f}]
    Out[127]= (a b p)/(c d)
    

    This approach has a bit of magic in figuring out what should be the listed "variables". Possibly some further tweakage could be done to improve on that. But I believe that, generally, simply not listing the things we want to use as new replacements is the right way to go.

    Over the years there have been variants of this idea on MathGroup. It is possible that some others may be better suited to the specific expression(s) you wish to handle.

    --- edit ---

    The idea behind this is to use PolynomialReduce to do algebraic replacement. That is to say, we do not try for pattern matching but instead use polynomial "canonicalization" a method. But in general we're not working with polynomial inputs. So we apply this idea recursively on PolynomialQ arguments inside NumericQ functions.

    Earlier versions of this idea, along with some more explanation, can be found at the note referenced below, as well as in notes it references (how's that for explanatory recursion?).

    http://forums.wolfram.com/mathgroup/archive/2006/Aug/msg00283.html

    --- end edit ---

    --- edit 2 ---

    As observed in the wild, this approach is not always a simplifier. It does algebraic replacement, which involves, under the hood, a notion of "term ordering" (roughly, "which things get replaced by which others?") and thus simple variables may expand to longer expressions.

    Another form of term rewriting is syntactic replacement via pattern matching, and other responses discuss using that approach. It has a different drawback, insofar as the generality of patterns to consider might become overwhelming. For example, what does one do with k^2/(w + p^4)^3 when the rule is to replace k/(w + p^4) with q? (Specifically, how do we recognize this as being equivalent to (k/(w + p^4))^2*1/(w + p^4)?)

    The upshot is one needs to have an idea of what is desired and what methods might be feasible. This of course is generally problem specific.

    One thing that occurs is perhaps you want to find and replace all commonly occurring "complicated" expressions with simpler ones. This is referred to as common subexpression elimination (CSE). In Mathematica this can be done using a function called Experimental`OptimizeExpression[]. Here are several links to MathGroup posts that discuss this.

    http://forums.wolfram.com/mathgroup/archive/2009/Jul/msg00138.html

    http://forums.wolfram.com/mathgroup/archive/2007/Nov/msg00270.html

    http://forums.wolfram.com/mathgroup/archive/2006/Sep/msg00300.html

    http://forums.wolfram.com/mathgroup/archive/2005/Jan/msg00387.html

    http://forums.wolfram.com/mathgroup/archive/2002/Jan/msg00369.html

    Here is an example from one of those notes.

    InputForm[Experimental`OptimizeExpression[(3 + 3*a^2 + Sqrt[5 + 6*a + 5*a^2] +
          a*(4 + Sqrt[5 + 6*a + 5*a^2]))/6]]
    
    Out[206]//InputForm=
    Experimental`OptimizedExpression[Block[{Compile`$1, Compile`$3, Compile`$4, 
       Compile`$5, Compile`$6}, Compile`$1 = a^2; Compile`$3 = 6*a; 
       Compile`$4 = 5*Compile`$1; Compile`$5 = 5 + Compile`$3 + Compile`$4; 
       Compile`$6 = Sqrt[Compile`$5]; (3 + 3*Compile`$1 + Compile`$6 + 
         a*(4 + Compile`$6))/6]]
    

    --- end edit 2 ---

    Daniel Lichtblau

    0 讨论(0)
  • 2020-12-23 18:39
    K = a*b*t/((t+f)c*d);
    
    FullSimplify[ K, 
     TransformationFunctions -> {(# /. t/(t + f) -> p &), Automatic}]
    
    (a b p) / (c d)

    Corrected update to show another method:

    EQ1 = a1 == (ton (B ton^2 + A^2 B ton (toff + ton) + 
            A (ton^2 + B (toff + ton)^2)))/(toff + ton)^3;
    
    f = # /. ton + toff -> ton/p &;
    
    FullSimplify[f @ EQ1]
    
    a1 == p (A B + A^2 B p + (A + B) p^2)

    I don't know if this is of any value at this point, but hopefully at least it works.

    0 讨论(0)
提交回复
热议问题