pagan

5147 Reputation

23 Badges

17 years, 122 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are replies submitted by pagan

@MobiusPizza Something like this?

restart:

E := proc()
local arg, cf, term, uf, formuoftminusblah, i, j, accum, thispass;
  # This compound type tests for form u(t-blah).
  # It may be possible to use a simpler specfunc(anything,u) if it is
  # known that all calls to u() will be of the form u(t-blah). 
  formuoftminusblah:='specfunc({satisfies(T->patmatch(T,a::identical(t)+
                                                        b::nonunit(algebraic))=true),
                                identical(t)}, u)';
  # Combine, to handle powers of u(t-blah).
  arg:=simplify(combine(args[1]));
  # Replace integer powers of u(t-blah)
  # according to whether exponent is odd.
  arg:=subsindets(arg, formuoftminusblah^satisfies(TT->is(TT,integer)=true),        
                  T->`if`(is(op(2,T),odd),op(1,T),1));
  if arg = 1 then
    return 1;
  elif type(arg,satisfies(T->is(T,'constant')=true)) then
    return arg;
  elif type(arg,formuoftminusblah) then
    return -1/N;
  elif type(arg,'`+`') then
    return map(procname,args);
  elif type(arg,'`*`') then
    uf, term := selectremove(type,arg,formuoftminusblah);
    if type(uf,`*`) then
      # This conditional section tests equality of
      # multiplicands u(t-a), u(t-b), etc, under assumptions
      # on a, b, etc. It makes replacement, for equality under `is`.
      accum := op(nops(uf),uf);
      for i from 1 to nops(uf)-1 do
        thispass:=false;
        for j from i+1 to nops(uf) do
          if is(op(op(i,uf))=op(op(j,uf)))=true then
            thispass:=true;
            break;
          end if;
        end do;
        if thispass then
          accum := accum * op(j,uf);
        else
          accum := accum * op(i,uf);
        end if;
      end do;
      # Combine again, to handle powers of u(t-blah).
      uf := simplify(combine(accum));
      # Replace integer powers of u(t-blah) once again,
      # according to whether exponent is odd.
      uf := subsindets(uf, formuoftminusblah^satisfies(TT->is(TT,integer)=true),        
                       T->`if`(is(op(2,T),odd),op(1,T),1));
    end if;
    if uf <> 1 then
      uf := -1/N;
    end if;
    if type(term,'`*`') then
      cf, term := selectremove(type,term,
                               satisfies(t->is(t,'constant')=true));
      if cf = 1 then
        return uf*'procname'(args);
      else
        return uf*cf*procname(term);
      end if
    else
      return uf*procname(term);
    end if;
  end if;
  'procname'(args);
end proc:

E(Pi);

                               Pi

E(a);

                              E(a)

E(a) assuming a::realcons;

                               a

E(a*b*c*u(t-k)) assuming a::realcons, b::realcons, c::realcons;

                              a b c
                            - -----
                                N  

E(a+b);

                          E(a) + E(b)

E(u(t-x));

                                1
                              - -
                                N

E(u(t-a)*u(t-b));

                                1
                              - -
                                N

E(u(t-a)*u(t-b)) assuming a=b; # more difficult

                               1

E(u(t-a)^c * u(t-b)^(d-1)) assuming a=b, c::even, d::even; # more difficult

                                1
                              - -
                                N

E(Pi*u(t-x-y)*u(t-p));

                                Pi
                              - --
                                N 

E(Pi*u(t-x-y)*u(t-p)) assuming p=x+y;

                               Pi

E(u(t-x-y)^a) assuming a::even;

                               1

E(u(t-x-y)^a) assuming a::odd;

                                1
                              - -
                                N

E(u(t-x-y)^a * u(t-z)^2) assuming a::odd;

                                1
                              - -
                                N

E(u(t-x-y)^a * u(t-x-y)^(a+1)) assuming a::odd;

                                1
                              - -
                                N

E(u(t-x-y)^a * u(t-z)^2 + Pi/2*u(t-w)^b) assuming a::odd, b::odd;

                             1   Pi 
                           - - - ---
                             N   2 N

E(u(t));

                                1
                              - -
                                N

E(u(t)^a * u(t-z)^3 + Pi/2*u(t-w)^b) assuming a::odd, b::odd, z=0;

                                Pi 
                            1 - ---
                                2 N

ut := tau -> u(t-tau);

                      tau -> u(t - tau)

assume(seq(p[i]::realcons,i=0..3),
       k::realcons,
       seq(b[i]::realcons,i=1..2));

G := x = k*(ut(0)+b[1]*ut(1)+b[2]*ut(2));

          x = k (u(t) + b[1] u(t - 1) + b[2] u(t - 2))

NL := y = p[3]*x^3+p[2]*x^2+p[1]*x+p[0];

                       3         2                
             y = p[3] x  + p[2] x  + p[1] x + p[0]

L1 := collect(expand(subs(G, NL)), {u, u(t-2), u(t-1)}):

R0 := simplify(E(lhs(L1)) = E(rhs(L1))):

simplify(R0,size);

          1  /
   E(y) = -- \
           2  
          N   

 //    3                    2   /          2\                  3\  
-\\b[1]  + (3 + 3 b[2]) b[1]  + \3 + 3 b[2] / b[1] + (b[2] + 1) / N

                \       3
   - 6 b[1] b[2]/ p[3] k 

     //    2           2\  2                             \      
   + \\b[1]  + 1 + b[2] / N  + (2 b[2] + 2) b[1] + 2 b[2]/ p[2] 

   2                                      2\
  k  - N p[1] (b[1] + b[2] + 1) k + p[0] N /

@MobiusPizza Something like this?

restart:

E := proc()
local arg, cf, term, uf, formuoftminusblah, i, j, accum, thispass;
  # This compound type tests for form u(t-blah).
  # It may be possible to use a simpler specfunc(anything,u) if it is
  # known that all calls to u() will be of the form u(t-blah). 
  formuoftminusblah:='specfunc({satisfies(T->patmatch(T,a::identical(t)+
                                                        b::nonunit(algebraic))=true),
                                identical(t)}, u)';
  # Combine, to handle powers of u(t-blah).
  arg:=simplify(combine(args[1]));
  # Replace integer powers of u(t-blah)
  # according to whether exponent is odd.
  arg:=subsindets(arg, formuoftminusblah^satisfies(TT->is(TT,integer)=true),        
                  T->`if`(is(op(2,T),odd),op(1,T),1));
  if arg = 1 then
    return 1;
  elif type(arg,satisfies(T->is(T,'constant')=true)) then
    return arg;
  elif type(arg,formuoftminusblah) then
    return -1/N;
  elif type(arg,'`+`') then
    return map(procname,args);
  elif type(arg,'`*`') then
    uf, term := selectremove(type,arg,formuoftminusblah);
    if type(uf,`*`) then
      # This conditional section tests equality of
      # multiplicands u(t-a), u(t-b), etc, under assumptions
      # on a, b, etc. It makes replacement, for equality under `is`.
      accum := op(nops(uf),uf);
      for i from 1 to nops(uf)-1 do
        thispass:=false;
        for j from i+1 to nops(uf) do
          if is(op(op(i,uf))=op(op(j,uf)))=true then
            thispass:=true;
            break;
          end if;
        end do;
        if thispass then
          accum := accum * op(j,uf);
        else
          accum := accum * op(i,uf);
        end if;
      end do;
      # Combine again, to handle powers of u(t-blah).
      uf := simplify(combine(accum));
      # Replace integer powers of u(t-blah) once again,
      # according to whether exponent is odd.
      uf := subsindets(uf, formuoftminusblah^satisfies(TT->is(TT,integer)=true),        
                       T->`if`(is(op(2,T),odd),op(1,T),1));
    end if;
    if uf <> 1 then
      uf := -1/N;
    end if;
    if type(term,'`*`') then
      cf, term := selectremove(type,term,
                               satisfies(t->is(t,'constant')=true));
      if cf = 1 then
        return uf*'procname'(args);
      else
        return uf*cf*procname(term);
      end if
    else
      return uf*procname(term);
    end if;
  end if;
  'procname'(args);
end proc:

E(Pi);

                               Pi

E(a);

                              E(a)

E(a) assuming a::realcons;

                               a

E(a*b*c*u(t-k)) assuming a::realcons, b::realcons, c::realcons;

                              a b c
                            - -----
                                N  

E(a+b);

                          E(a) + E(b)

E(u(t-x));

                                1
                              - -
                                N

E(u(t-a)*u(t-b));

                                1
                              - -
                                N

E(u(t-a)*u(t-b)) assuming a=b; # more difficult

                               1

E(u(t-a)^c * u(t-b)^(d-1)) assuming a=b, c::even, d::even; # more difficult

                                1
                              - -
                                N

E(Pi*u(t-x-y)*u(t-p));

                                Pi
                              - --
                                N 

E(Pi*u(t-x-y)*u(t-p)) assuming p=x+y;

                               Pi

E(u(t-x-y)^a) assuming a::even;

                               1

E(u(t-x-y)^a) assuming a::odd;

                                1
                              - -
                                N

E(u(t-x-y)^a * u(t-z)^2) assuming a::odd;

                                1
                              - -
                                N

E(u(t-x-y)^a * u(t-x-y)^(a+1)) assuming a::odd;

                                1
                              - -
                                N

E(u(t-x-y)^a * u(t-z)^2 + Pi/2*u(t-w)^b) assuming a::odd, b::odd;

                             1   Pi 
                           - - - ---
                             N   2 N

E(u(t));

                                1
                              - -
                                N

E(u(t)^a * u(t-z)^3 + Pi/2*u(t-w)^b) assuming a::odd, b::odd, z=0;

                                Pi 
                            1 - ---
                                2 N

ut := tau -> u(t-tau);

                      tau -> u(t - tau)

assume(seq(p[i]::realcons,i=0..3),
       k::realcons,
       seq(b[i]::realcons,i=1..2));

G := x = k*(ut(0)+b[1]*ut(1)+b[2]*ut(2));

          x = k (u(t) + b[1] u(t - 1) + b[2] u(t - 2))

NL := y = p[3]*x^3+p[2]*x^2+p[1]*x+p[0];

                       3         2                
             y = p[3] x  + p[2] x  + p[1] x + p[0]

L1 := collect(expand(subs(G, NL)), {u, u(t-2), u(t-1)}):

R0 := simplify(E(lhs(L1)) = E(rhs(L1))):

simplify(R0,size);

          1  /
   E(y) = -- \
           2  
          N   

 //    3                    2   /          2\                  3\  
-\\b[1]  + (3 + 3 b[2]) b[1]  + \3 + 3 b[2] / b[1] + (b[2] + 1) / N

                \       3
   - 6 b[1] b[2]/ p[3] k 

     //    2           2\  2                             \      
   + \\b[1]  + 1 + b[2] / N  + (2 b[2] + 2) b[1] + 2 b[2]/ p[2] 

   2                                      2\
  k  - N p[1] (b[1] + b[2] + 1) k + p[0] N /

@MobiusPizza You may have noticed that there is a difference between type-checking and property-checking, where by property I mean the kind of quality that `assume` places.

If I am understanding you right, you're trying to get some functionality similar to what `define` gives, but also for assumed names. Is that right?

Are you asking how to code some of it up, explicitly (by hand)? If so, then does this help?

restart:
g := proc()
local arg, cf, term;
   arg := _passed[1];
   if arg = 1 then
      if _npassed=1 then
         return 1;
      end if;
   elif type(arg,'constant')
     or is(arg,`constant`) then
      return arg*procname(1,_passed[2 .. -1])
   elif type(arg,'`+`') then
      return map(procname,_passed)
   elif type(arg,'`*`') then
      cf, term := selectremove(type,arg,
                   {'constant',satisfies(t->is(t,'constant'))});
      if cf = 1 then
        return ('procname')(_passed)
      else
        return cf*procname(term,_passed[2 .. -1])
      end if
   end if;
  ('procname')(_passed)
end proc:


g(a+b);
                          g(a) + g(b)

g(4);
                               4

g(4*a);
                             4 g(a)

g(a+b+4*c+6*(d+e)+11);
          g(a) + g(b) + 4 g(c) + 6 g(d) + 6 g(e) + 11

# nothing yet is known about z

g(z);
                              g(z)

g(4*(a+z)+Pi*6*z*(z*b+c)+11);
           4 g(a) + 4 g(z) + 6 Pi g(z (z b + c)) + 11

assume(z::realcons);

g(z);
                               z

g(4*(a+z)+Pi*6*z*(z*b+c)+11);
           4 g(a) + 4 z + 6 Pi z (z g(b) + g(c)) + 11

@MobiusPizza You may have noticed that there is a difference between type-checking and property-checking, where by property I mean the kind of quality that `assume` places.

If I am understanding you right, you're trying to get some functionality similar to what `define` gives, but also for assumed names. Is that right?

Are you asking how to code some of it up, explicitly (by hand)? If so, then does this help?

restart:
g := proc()
local arg, cf, term;
   arg := _passed[1];
   if arg = 1 then
      if _npassed=1 then
         return 1;
      end if;
   elif type(arg,'constant')
     or is(arg,`constant`) then
      return arg*procname(1,_passed[2 .. -1])
   elif type(arg,'`+`') then
      return map(procname,_passed)
   elif type(arg,'`*`') then
      cf, term := selectremove(type,arg,
                   {'constant',satisfies(t->is(t,'constant'))});
      if cf = 1 then
        return ('procname')(_passed)
      else
        return cf*procname(term,_passed[2 .. -1])
      end if
   end if;
  ('procname')(_passed)
end proc:


g(a+b);
                          g(a) + g(b)

g(4);
                               4

g(4*a);
                             4 g(a)

g(a+b+4*c+6*(d+e)+11);
          g(a) + g(b) + 4 g(c) + 6 g(d) + 6 g(e) + 11

# nothing yet is known about z

g(z);
                              g(z)

g(4*(a+z)+Pi*6*z*(z*b+c)+11);
           4 g(a) + 4 g(z) + 6 Pi g(z (z b + c)) + 11

assume(z::realcons);

g(z);
                               z

g(4*(a+z)+Pi*6*z*(z*b+c)+11);
           4 g(a) + 4 z + 6 Pi z (z g(b) + g(c)) + 11

I don't quite see why you need to call `solve` repeatedly, if you already have an expression in which all parameters are present. I mean could you not just vary those other parameters using `eval` instead, while re-using the expression with the very same _Zn in it?

It's not too hard to pick off the _Zn, if you really want its name, as it has assumptions on it.

> eq:=x+s*exp(x * sigma)-mu-s=0: 
> S:=solve(eq, x,AllSolutions);


1
- ----- (LambertW(_Z4, sigma s exp(sigma mu + sigma s))
sigma

- sigma mu - sigma s)

> indets(S,And(name,`local`));

{_Z4}

> about(op(1,%));

Originally _Z4, renamed _Z4~:
is assumed to be: integer

> select(hasassumptions,indets(S,name));
{_Z4}

I don't quite see why you need to call `solve` repeatedly, if you already have an expression in which all parameters are present. I mean could you not just vary those other parameters using `eval` instead, while re-using the expression with the very same _Zn in it?

It's not too hard to pick off the _Zn, if you really want its name, as it has assumptions on it.

> eq:=x+s*exp(x * sigma)-mu-s=0: 
> S:=solve(eq, x,AllSolutions);


1
- ----- (LambertW(_Z4, sigma s exp(sigma mu + sigma s))
sigma

- sigma mu - sigma s)

> indets(S,And(name,`local`));

{_Z4}

> about(op(1,%));

Originally _Z4, renamed _Z4~:
is assumed to be: integer

> select(hasassumptions,indets(S,name));
{_Z4}

The simplify(...,size) command is sometimes useful. But not always... it might not suffice for handling the 3rd column of table 2.

> x:=1/6^(1/2)*(3-sqrt(5))^(1/2);

(1/2)
1 (1/2) / (1/2)\
- 6 \3 - 5 /
6

> simplify(radnormal(x),size);

1 (1/2) / (1/2) \
- 3 \5 - 1/
6

> x:=1/6^(1/2)*(3+sqrt(5))^(1/2);

(1/2)
1 (1/2) / (1/2)\
- 6 \3 + 5 /
6

> simplify(radnormal(x),size);

1 (1/2) / (1/2) \
- 3 \5 + 1/
6

@Alejandro Jakubi Yes, using TypeMK is what Robert suggested in his post.

R.L. suggested lprinting the atomic identifier produced from 2D Math input. Doing that for f^-1 produces

  `#mrow(msup(mi("f"),mrow(mo("&uminus0;"),mn("1"))))`

which I feel typesets as output more attractively than does your suggestion

  `#msup(mi("f"),mn("−1")`

It's not just a question of &minus; verus &uminus0; since the following also has better spacing between f and the exponent

  `#mrow(msup(mi("f"),mrow(mo("−"),mn("1"))))`

Maybe one day someone will provide Maple language constructors for such things.

@Alejandro Jakubi Your solution using f@@(-1) is handy, but it displays with brackets around the power of -1, like f@@(-1)

Robert L. showed that he wanted f^`-1`without brackets.

This is the sort of post that is helpful to lots of people. Good stuff.

A few things about gem 1. The unwanted automatic conversion of (r^2-(r-y)^2)^(1/2)to sqrt(r^2-(r-y)^2) seems due to using `sqrt` instead of power 1/2, no?

Compare,

plots:-display(plots:-textplot([1,3/2,typeset(sqrt(r^2-(r-y)^2))]),
plots:-textplot([1,1,typeset((r^2-(r-y)^2)^(1/2))]),
view=[0..2,0..2]);

The programmatic example of using subs(F=f^(`-1`),F(x)) in the legend might be more simply coded as,

plot(x, x=0..1, legend=subs(F=f^(Typesetting:-Typeset(-1)),F(x)));

You didn't mention it, but one of the relevant aspects is that subs(F=f^(`-1`),F(x)) produces an italicized -1, while the Typeset method shows as an upright character.

Lastly, it looks like there's a problem with what gets displayed as regular output (not in a plot) for the input

`&+-`(x, 1/2);

when the GUI's Typesetting level is "Maple Standard" and not "Extended" (see Tools->Options-Display).

@toooldforthis A numeric value such as 2, or 3640.43, can be applied as a function call. The result of such an applied function call is... wait for it... the very same value itself. When you omit the multiplication then a(...) is a function call. So if `a` is a number then a(...) returns as the value of `a` itself.

restart;
v1 := evalf(30*Pi/(180.)):
v2 := evalf(120*Pi*(1/180)):
r1 := 600:
r2 := 1800:
sol:=solve({r1 = a*(1-e^2)/(1+e*cos(v1)),
            r2 = a*(1-e^2)/(1+e*cos(v2))}, {a, e});

              {a = 3640.434288, e = 0.8452994611}

va := Pi;
                               Pi

eval( a, sol );
                          3640.434288

eval( a(1-e^2), sol );
                          3640.434288

eval( a*(1-e^2), sol );
                          1039.230484

3640.43(1-e^2+a+b+c+h+k);
                            3640.43

I had no problem getting this to work using 1D Maple Notation. Note that in 2D Math input mode you could use an explicit multiplication sign or a blank space between `a` and `(` to denote implied multiplication. I feel that such implicit multiplication makes such pitfalls more prevalent.

@toooldforthis A numeric value such as 2, or 3640.43, can be applied as a function call. The result of such an applied function call is... wait for it... the very same value itself. When you omit the multiplication then a(...) is a function call. So if `a` is a number then a(...) returns as the value of `a` itself.

restart;
v1 := evalf(30*Pi/(180.)):
v2 := evalf(120*Pi*(1/180)):
r1 := 600:
r2 := 1800:
sol:=solve({r1 = a*(1-e^2)/(1+e*cos(v1)),
            r2 = a*(1-e^2)/(1+e*cos(v2))}, {a, e});

              {a = 3640.434288, e = 0.8452994611}

va := Pi;
                               Pi

eval( a, sol );
                          3640.434288

eval( a(1-e^2), sol );
                          3640.434288

eval( a*(1-e^2), sol );
                          1039.230484

3640.43(1-e^2+a+b+c+h+k);
                            3640.43

I had no problem getting this to work using 1D Maple Notation. Note that in 2D Math input mode you could use an explicit multiplication sign or a blank space between `a` and `(` to denote implied multiplication. I feel that such implicit multiplication makes such pitfalls more prevalent.

@Wang Gaoteng If you think that you've found a bug then you can submit it using the SCR form here.

@Wang Gaoteng If you think that you've found a bug then you can submit it using the SCR form here.

First 28 29 30 31 32 33 34 Last Page 30 of 81