Carl Love

Carl Love

28070 Reputation

25 Badges

13 years, 34 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Soldalma Tables, modules, and procedures (which you're calling functions) have a special feature called last name evaluation. That means that if they are assigned to a name, then that name needs to be evaluated to one level (with eval) before you can "see inside". (The purpose of this feature is, partly, to prevent the display of large objects every time their name is invoked.) So, you just need to do

ToInert(eval(r));

_Inert_PROC(_Inert_PARAMSEQ(_Inert_NAME("x")), _Inert_LOCALSEQ(), _Inert_OPTIONSEQ(_Inert_NAME("operator"), _Inert_NAME("arrow")), _Inert_EXPSEQ(), _Inert_STATSEQ(_Inert_POWER(_Inert_PARAM(1), _Inert_INTPOS(2))), _Inert_DESCRIPTIONSEQ(), _Inert_GLOBALSEQ(), _Inert_LEXICALSEQ(), _Inert_EOP(_Inert_EXPSEQ()))

or

dismantle(eval(r));

PROC(11) #[operator, arrow]
   EXPSEQ(2)
      NAME(4): x
   EXPSEQ(1)
   EXPSEQ(3)
      NAME(5): operator
      NAME(4): arrow
   EXPSEQ(1)
   PROD(3)
      PARAM(2): [1]
      INTPOS(2): 2
   EXPSEQ(1)
   EXPSEQ(1)
   EXPSEQ(1)
   BINARY(2)
      1
   EXPSEQ(1)

The command indets doesn't do much with procedures, as far as I know.

What specific thing about r are you trying to find? You can also take apart expressions (including procedures and modules) with op (short for operand). The reason that I didn't mention this before is that there's no way to completely take apart an expression with a single call to op. It needs to be done piece by piece or level by level.

Every procedure has exactly eight operands, many of which will be NULL for most procedures:

op(1, eval(r)); #parameters (which you called "arguments") with their types
op(2, eval(r)); #locals
op(3, eval(r)); #options
op(4, eval(r)); #remember table
op(5, eval(r)); #description
op(6, eval(r)); #declared globals
op(7, eval(r)); #lexicals
op(8, eval(r)); #declared return type

This list, with (very brief) definitions of those terms, can be found at ?proc. A procedure's statement sequence isn't one of its operands, but, as you can see above, ToInert gives this information.

Parameters have a type only if you declare them to have a type, which you didn't for your r. Likewise for the return type of the procedure. If you want to give these things types, then do something like:

r:= proc(x::algebraic)::algebraic; x^2 end proc;

An argument is what a parameter gets replaced with. So, if you subsequenty issue the command

r(3);

then 3 becomes the argument for parameter x.

@toandhsp Yes, the syntax of add was expanded in Maple 2015 to allow one argument. For Maple 18 and earlier, one-argument add needs to be replaced with (`+`@op) (when the argument is a list or set).

AllDistinctIntegerSquares:= proc(C::[integer,integer,integer], R::posint)
uses LT= ListTools;
local
     L, s, p, V, X, c, S,
     CP:= combinat:-cartprod([seq([$ map(`+`, -R..R, c)], c= C)])
;
     for s in
          combinat:-choose(
               select(
                    X-> nops({X[]}) = 3 and (`+`@op)((X-~C)^~2) = R^2, #on the sphere
                    {'CP[nextvalue]()' $ (2*R+1)^3}
               ),
               3
          )
     do
          if nops(op~(s)) <> 9 then next end if;
          for p in combinat:-permute(s) do
               V:= map(`-`, p[2..3], p[1]); #adjacent sides vectors
               S:= [p[1], p[2], p[2]+V[2], p[3]];                
               if
                    nops({op~(S)[]}) = 12 and  #all distinct integers
                    inner(V[]) = 0 and         #two adjacent sides at right angles
                    `=`((`+`@op@`^`~)~(V,2)[]) #equal-length diagonals
               then
                    L[S[]]:= ();
                    break
               end if
          end do
     end do;
     map(`?[]`, {entries(LT:-Classify(convert, {indices(L)}, 'set'), 'nolist')}, [1])
end proc:

@MrYouMath If you have Maple 16 or later, you can download Iterator for free from the Maple Applications Center, and I highly recommend it.

However, this will work in older Maple:

n:= 4:
CP:= combinat:-cartprod([[0,1]$n]):
subsMatrix:= <seq(<CP[nextvalue]()[]>^+, k= 1..2^n)>;

A:= [seq(a[i], i= 1..n)]:
CP:= combinat:-cartprod([[0,1]$n]): #Need to re-initialize the iterator!
subsEqs:= [seq(select(e-> rhs(e)=0, A=~ CP[nextvalue]()), k= 1..2^n)];

Let me know if that works. You still haven't said your Maple version. Please edit the Question's header.

@gkfighting I'm not sure what you mean by "number each sum", but for numeric evaluation you can do something like this:

eval(%, [k= 100, l= 100, x= .3, y=.4, a= .5, b= .6]);
eval(subs(Sum= add, %));

This'll work regardless of which of the sum expressions that you use.

Here's a version that'll work on older Maple. It uses combinat:-cartprod instead of Iterator:-CartesianProduct. I also added some significant efficiency improvements based on the coordinates being distinct integers.

AllDistinctIntegerSquares:= proc(C::[integer,integer,integer], R::posint)
uses LT= ListTools;
local
     L, s, p, V, X, c, S,
     CP:= combinat:-cartprod([seq([$ map(`+`, -R..R, c)], c= C)])
;
     for s in
          combinat:-choose(
               select(
                    X-> nops({X[]}) = 3 and add((X-~C)^~2) = R^2,
                    {'CP[nextvalue]()' $ (2*R+1)^3}
               ),
               3
          )
     do
          if nops(op~(s)) <> 9 then next end if;
          for p in combinat:-permute(s) do
               V:= map(`-`, p[2..3], p[1]);
               S:= [p[1], p[2], p[2]+V[2], p[3]];                
               if nops({op~(S)[]}) = 12 and inner(V[]) = 0 and `=`((add@`^`~)~(V,2)[]) then
                    L[S[]]:= ();
                    break
               end if
          end do
     end do;
     map(`?[]`, {entries(LT:-Classify(convert, [indices(L)], set), 'nolist')}, [1])
end proc:

@gkfighting I seriously doubt that Maple can put the expression into the form (23) through any mathematically valid simplification/transformation process. Actually, I can't get Maple to even verify that the two forms are equivalent. Maple's ability to manipulate symbolic sums is limited---must less than its ability to manipulate symbolic integrals. Plus, while form (23) may look simpler, in some senses it is not because it's a quadruply nested sum. The form that I put it in has no nested sums.

Regarding your second question: It's beyond my mathematical knowledge. Hopefully someone else with more knowledge will respond.

@toandhsp You can if you download the Iterator package from the Maple Applications Center.

I deleted your immediately prior cruder form of this Question.

@Markiyan Hirnyk Here is the relevant paper directly uploaded to MaplePrimes: NumericMinimalSurfaceAlgorithm.pdf

You're right: It shouldn't return NULL. I'd consider a case where it returns NULL a bug. For a transformation, Maple should return either an expression or an error message. The returned expression may be the same as the input expression (we call it returning unevaluated) if the computation is too complicated to perform. So, would you please show the expression for which you get NULL output? For the example that I tried, I get unevaluated output:

inttrans:-mellin(LerchPhi(z, 1, 2), z, s);

     mellin(LerchPhi(z, 1, 2), z, s)

@Østerbro 

These versions remove the repetition of the input:

Display:= proc(e::uneval)
uses T= Typesetting;
local
     pre:= subsindets(e, uneval(name), eval, 1),
     r:= eval(pre),
     Ty_pre:= T:-Typeset(e)
;    
     if indets(pre, And(name, satisfies(u-> u<>eval(u)))) = {} then
          print(r)
     else
          print(
               evalindets(                    
                    subs("⁢"= "*", Ty_pre),  
                    specfunc(string, T:-mi),
                    proc(n)
                    local pn:= eval(parse(op(n)));
                         if pn::numeric then T:-mn(sprintf("%a", pn))
                         else T:-Typeset(T:-EV(pn))
                         end if 
                    end proc
               ) =
               evalf(r)
          )
     end if;
     r
end proc:

And the same thing for what Acer called the "weaker" version:

Display:= proc(e::uneval)
uses T= Typesetting;
local
     pre:= subsindets(e, uneval(name), eval, 1),
     r:= eval(pre),
     Ty_pre:= T:-Typeset(e)
;    
     if indets(pre, And(name, satisfies(u-> u<>eval(u)))) = {} then
          print(r)
     else
          print(
               evalindets(                    
                    subs("⁢"= "*", Ty_pre),  
                    specfunc(string, T:-mi),
                    proc(n)
                    local pn:= eval(parse(op(n)));
                         if pn::numeric then
                              T:-mn(sprintf("%a", pn))
                         elif type(pn, numeric &* 'specfunc'('anything', Units:-Unit)) then
                              T:-Typeset(T:-EV(pn))
                         else n
                         end if  
                    end proc
               ) =
               evalf(r)
          )
     end if;
     r
end proc:

@Østerbro Of the two versions of Display that Acer posted in his most-recent Reply, which are you using in your most-recent .pdf file?

@Vic Oh, I see now that you said Maple 16, not Maple 2016 (the current version). I misread that as Maple 2016. I don't think the downloaded Iterator will work with Maple 16. Not sure.

@Vic It comes prepackaged with Maple 2016. If you have Maple 2015 or Maple 18, you can download it for free from the Maple Applications Center.

@Vic You don't need to consider a < b because you only need to search forward of the current position. You can change your procedure to this:

ListProcess:= proc(A::list)
local k,b;
     for k to nops(A)-1 do
          if member(A[k][[2,1]], A[k+1..], 'b') and b::odd then return end if
     end do;
     A
end proc:

First 399 400 401 402 403 404 405 Last Page 401 of 709