Menu

Substituting a lengthy sub-expression in a more lengthier expression.

Help
videohead
2022-08-24
2022-08-26
  • videohead

    videohead - 2022-08-24

    I have a complicated expression

    !E := (!Y1*eta**2*y1 - !Y1*eta**2*y2 + !Y1*eta**2*y3 - !Y1*eta**2*y4 - !Y1*eta*x1*xi + !Y1*eta*x1 + !Y1*eta*x2*xi - !Y1*eta*x2 - !Y1*eta*x3*xi + !Y1*eta*x3 + !Y1*eta*x4*xi - !Y1*eta*x4 - 2*!Y1*eta*y1 + 2*!Y1*eta*y2 + !Y1*x1*xi - !Y1*x1 - !Y1*x2*xi + !Y1*x2 - !Y1*x3*xi + !Y1*x3 + !Y1*x4*xi - !Y1*x4 + !Y1*y1 - !Y1*y2 - !Y1*y3 + !Y1*y4 - !Y2*eta**2*y1 + !Y2*eta**2*y2 - !Y2*eta**2*y3 + !Y2*eta**2*y4 + !Y2*eta*x1*xi + !Y2*eta*x1 - !Y2*eta*x2*xi - !Y2*eta*x2 + !Y2*eta*x3*xi + !Y2*eta*x3 - !Y2*eta*x4*xi - !Y2*eta*x4 + 2*!Y2*eta*y1 - 2*!Y2*eta*y2 - !Y2*x1*xi - !Y2*x1 + !Y2*x2*xi + !Y2*x2 + !Y2*x3*xi + !Y2*x3 - !Y2*x4*xi - !Y2*x4 - !Y2*y1 + !Y2*y2 + !Y2*y3 - !Y2*y4 + !Y3*eta**2*y1 - !Y3*eta**2*y2 + !Y3*eta**2*y3 - !Y3*eta**2*y4 - !Y3*eta*x1*xi - !Y3*eta*x1 + !Y3*eta*x2*xi + !Y3*eta*x2 - !Y3*eta*x3*xi - !Y3*eta*x3 + !Y3*eta*x4*xi + !Y3*eta*x4 + 2*!Y3*eta*y3 - 2*!Y3*eta*y4 + !Y3*x1*xi + !Y3*x1 - !Y3*x2*xi - !Y3*x2 - !Y3*x3*xi - !Y3*x3 + !Y3*x4*xi + !Y3*x4 - !Y3*y1 + !Y3*y2 + !Y3*y3 - !Y3*y4 - !Y4*eta**2*y1 + !Y4*eta**2*y2 - !Y4*eta**2*y3 + !Y4*eta**2*y4 + !Y4*eta*x1*xi - !Y4*eta*x1 - !Y4*eta*x2*xi + !Y4*eta*x2 + !Y4*eta*x3*xi - !Y4*eta*x3 - !Y4*eta*x4*xi + !Y4*eta*x4 - 2*!Y4*eta*y3 + 2*!Y4*eta*y4 - !Y4*x1*xi + !Y4*x1 + !Y4*x2*xi - !Y4*x2 + !Y4*x3*xi - !Y4*x3 - !Y4*x4*xi + !Y4*x4 + !Y4*y1 - !Y4*y2 - !Y4*y3 + !Y4*y4 - eta**2*y1**2 + 2*eta**2*y1*y2 - 2*eta**2*y1*y3 + 2*eta**2*y1*y4 - eta**2*y2**2 + 2*eta**2*y2*y3 - 2*eta**2*y2*y4 - eta**2*y3**2 + 2*eta**2*y3*y4 - eta**2*y4**2 + eta*x1*xi*y1 - eta*x1*xi*y2 + eta*x1*xi*y3 - eta*x1*xi*y4 - eta*x1*y1 - eta*x1*y2 + eta*x1*y3 + eta*x1*y4 - eta*x2*xi*y1 + eta*x2*xi*y2 - eta*x2*xi*y3 + eta*x2*xi*y4 + eta*x2*y1 + eta*x2*y2 - eta*x2*y3 - eta*x2*y4 + eta*x3*xi*y1 - eta*x3*xi*y2 + eta*x3*xi*y3 - eta*x3*xi*y4 - eta*x3*y1 - eta*x3*y2 + eta*x3*y3 + eta*x3*y4 - eta*x4*xi*y1 + eta*x4*xi*y2 - eta*x4*xi*y3 + eta*x4*xi*y4 + eta*x4*y1 + eta*x4*y2 - eta*x4*y3 - eta*x4*y4 + 2*eta*y1**2 - 4*eta*y1*y2 + 2*eta*y2**2 - 2*eta*y3**2 + 4*eta*y3*y4 - 2*eta*y4**2 - x1*xi*y1 + x1*xi*y2 - x1*xi*y3 + x1*xi*y4 + x1*y1 + x1*y2 - x1*y3 - x1*y4 + x2*xi*y1 - x2*xi*y2 + x2*xi*y3 - x2*xi*y4 - x2*y1 - x2*y2 + x2*y3 + x2*y4 + x3*xi*y1 - x3*xi*y2 + x3*xi*y3 - x3*xi*y4 - x3*y1 - x3*y2 + x3*y3 + x3*y4 - x4*xi*y1 + x4*xi*y2 - x4*xi*y3 + x4*xi*y4 + x4*y1 + x4*y2 - x4*y3 - x4*y4 - y1**2 + 2*y1*y2 + 2*y1*y3 - 2*y1*y4 - y2**2 - 2*y2*y3 + 2*y2*y4 - y3**2 + 2*y3*y4 - y4**2)/16

    and an expression

    !J := - eta*x1*y2 + eta*x1*y3 + eta*x2*y1 - eta*x2*y4 - eta*x3*y1 + eta*x3*y4 + eta*x4*y2 - eta*x4*y3 - x1*xi*y3 + x1*xi*y4 + x1*y2 - x1*y4 + x2*xi*y3 - x2*xi*y4 - x2*y1 + x2*y3 + x3*xi*y1 - x3*xi*y2 - x3*y2 + x3*y4 - x4*xi*y1 + x4*xi*y2 + x4*y1 - x4*y3

    I have reasoned that

    1. J = 8 and
    2. !E contains all the terms of J

    Therefore I would like to replace all the terms in !E by 8.

    I have tried a LET rule but this just clears !J and does nothing to !E.

    Please advise,

    Thanks

     
    • Francis Wright

      Francis Wright - 2022-08-24

      Try assigning !E as you have done, but do not assign !J. Instead, use the assignment to !J the other way around, i.e.

      let - eta*x1*y2 + eta*x1*y3 + eta*x2*y1 - eta*x2*y4 - eta*x3*y1 + eta*x3*y4 + eta*x4*y2 - eta*x4*y3 - x1*xi*y3 + x1*xi*y4 + x1*y2 - x1*y4 + x2*xi*y3 - x2*xi*y4 - x2*y1 + x2*y3 + x3*xi*y1 - x3*xi*y2 - x3*y2 + x3*y4 - x4*xi*y1 + x4*xi*y2 + x4*y1 - x4*y3 = !J;
      

      Then evaluate !E. I find that !J appears in the result. You could replace !J by 8 in the above let rule. Does that help? If so, it should work for your second problem as well.

      Francis

       
      • Arthur Norman

        Arthur Norman - 2022-08-24

        As a comment that does not address your main problem, I might note that if
        you go
        off raise,lower;
        then Reduce will not case-fold your input, as in
        1: off raise,lower;

        2: (a+A)^3;

        3 2 2 3
        A + 3A a + 3Aa + a

        and if you wish to use upper case names like J (which is quite reasonable)
        that may be tidier for you....

        Arthur

        Footnote:
        In the very old days everything within Reduce was spely in upper case,
        and the "raise" flag was introduced so that people could present lower
        case input so that what they typed looked a bit less like 1960s Fortran.
        At some stage both CSL and PSL changed so that the internal names were in
        lower case. So for one sort of backwards compatibility PSL keeps on/off
        raise as the switch to fole case to the system one, while CSL used on/off
        lower for forcing things to lower case. We have WONDERED about making
        Reduce case sensitive by default but believe that almost any change we
        make in this whole area would bite some existing users and the scripts
        and habits they have. Hence for this my suggestion of "off raise,lower;"
        which leaves Reduce case sensitive regardless.

        On Wed, 24 Aug 2022, Francis Wright wrote:

        Try assigning !E as you have done, but do not assign !J. Instead, use
        the assignment to !J the other way around, i.e.
        let - eta*x1*y2 + eta*x1*y3 + eta*x2*y1 - eta*x2*y4 - eta*x3*y1 + eta*x3*y4 + eta*x4*y2 - eta*x4*y3 - x1*xi*y3 + x1*xi*y4 + x1*y2 - x1*y4 + x2*xi*y3 - x2*xi*y4 - x2*y1 + x2*y3 + x3*xi*y1 - x3*xi*y2 - x3*y2 + x3*y4 - x4*xi*y1 + x4*xi*y2 + x4*y1 - x4*y3 = !J;
        Then evaluate !E. I find that !J appears in the result. You could
        replace !J by 8 in the above let rule. Does that help? If so, it should
        work for your second problem as well.

        Francis

         
        ❤️
        1
      • videohead

        videohead - 2022-08-26

        Yes it does but only on shorter expressions such as my second example. The substitution does not work on my first example.

         
  • videohead

    videohead - 2022-08-24

    Another example

    !T1 := ( !A*!R1 - !C*!S1);
    !T2 := ( !A*!R2 - !C*!S2);
    !T3 := ( !A*!R3 - !C*!S3);
    !T4 := ( !A*!R4 - !C*!S4);
    
    !E1 := (-!D*!R1 + !B*!S1);
    !E2 := (-!D*!R2 + !B*!S2);
    !E3 := (-!D*!R3 + !B*!S3);
    !E4 := (-!D*!R4 + !B*!S4);
    
    G := !T1*k1 + !T2*k2 + !T3*k3 + !T4*k4;
    H := !E1*k1 + !E2*k2 + !E3*k3 + !E4*k4;
    M := !T1*k5 + !T2*k6 + !T3*k7 + !T4*k8;
    N := !E1*k5 + !E2*k6 + !E3*k7 + !E4*k8;
    
    G*N - H*M;
    

    Again I'd like to substitute B*A - C*D for J (or 8) in the final expression that contains 24 pairs of terms such as !A*!B*R1*S2*k1*k6 and -!C*!D*R1*S2*k1*k6 which can be together written as J*R1*S2*k1*k6.

    I have tried SUB({!A*!B - !C*!D = !J}, G*N - H*M) but I got the error:
    ***** (difference (times A B) (times C D)) invalid as kernel

     

    Last edit: videohead 2022-08-24
  • Eberhard Schruefer

    Maybe this will help you with your original problem.
    Remeber the definition of a quotient and remainder.

    p = a*q + r

    Now let E be p and (J - 8) be q, then r can be interpreted
    as a 'substitution'.

    In Reduce simply calculate

    remainder(num !E, !J - 8);

    Eberhard

     

Log in to post a comment.