Carl Love

Carl Love

28035 Reputation

25 Badges

12 years, 321 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@Joe Riel I think that the variable order in that third argument to simplify matters in this case. In order to get the desired result, I must make this [e2,e1].

@MDD I think that you've mixed up the argument order and that what you should have is

... elif ormap(HasSubexpression, [n*a, n*b], [a*n*z^3+t-1, -m*x]) then ....

The first argument of HasSubexpression is the subexpression to search for; the second argument is the polynomial or set or list of polynomials to be searched through.
 

Also, ormap always returns truefalse, or FAIL[*1] so 

... elif ormap(...) = true then ... 

can always be simplified to

... elif ormap(...) then ....


[*1] In general, ormap can return any of the three values of Maple's three-valued logic: truefalseFAIL. But in the present context, it'll always be true or false.

What does "to separate" mean in this context? I'm familiar with the term meaning to get all occurences of one variable on one side of  an equation and all occurences of another on the other side, but that doesn't seem to apply here.

@tomleslie Was this Answer possibly intended for another Question? I can't see any relationship between this Answer and this Question (with its atttached worksheet).

@MDD Since 3-b = 2 - (b-1), in some sense it does contain b-1 (and this is the way that algsubs, but not has, views it). So, in order for me to proceed, you'll need to give a precise definition of what it means for a subexpression to "appear" in a polynomial.

@MDD 

I wrote it to work exclusively for products because that's what I thought that you wanted. But that can be easily changed:

HasSubexpression:= proc(s::algebraic, e)
local S;
   has(algsubs(s= S, e), S)
end proc:

Note the reversed argument order, as discussed two Replies above.

@MDD The order of the arguments of has seems unnatural to me, and it's usually inconvenient. For any membership-testing procedure, the item being looked up ought to be the first argument, and item being searched through ought to be the second. I continued that wrong order with HasProduct. It ought to be changed to

HasProduct:= proc(p::`*`, e)
local P;
   has(algsubs(p= P, e), P)
end proc:

Then the ormap can be done more naturallly, without the need to curry HasProduct:

ormap(HasProduct, A, B)

@MDD 

ormap(a-> HasProduct(B,a), A);

@DJJerome1976 My procedure does exactly what you asked for---"to form all the possible quotients (positive and negative) with numerator in one set and denominator in the other set, ignoring duplicates"---yet you've made no response.

@Carl Love The above procedure could be improved by using a builtin (hence fast) procedure icontent that's specifically for polynomials over the rationals and combines the work of ilcm and igcd. Specifically, f/icontent(f) is an integer polynomial the GCD of whose coefficients is 1.

Also, 0 needn't be included in returned results unless the polynomial has no constant term.

The new procedure is

RationalRoots:= proc(F::polynom(rational))
description "Returns the set of candidate rational roots";
uses It= Iterator, NT= NumberTheory;
local 
   f:= expand(F), r,  
   R:= {
      seq(
         `/`(seq(r)), 
         r= It:-CartesianProduct(
            ((S-> `if`(S={1}, {-1,1}, S)) @ NT:-Divisors @~ (tcoeff,lcoeff))(f/icontent(f))  
         )
      ), 
      `if`(ldegree(f)>0, 0, '()')
   }
;
   R union `-`~(R)
end proc
:   

The S-> `if`(S={1}, {-1,1}, S) is needed because, unfortunately, Iterator:-CartesianProduct won't accept singleton factors. It's a bad policy to not handle such degenerate cases.

@Jeremyad 

I would say all that Acer said had I got to it first. I'm only replying now because I thought that I'd give an additional explanation of the need for unapply. Maple has two primitive constructors for procedures (aka functions[*1]):

(parameters)->  body (containing a single expression)

and

proc(parameters)
   header (possibly empty)  
   body (possibly containing multiple statements and expressions)
end proc

The first form is also called an arrow expression[*2]. Once formed, there's no practical difference between the two; indeed, the first form can always be readily and automatically converted to the second. In either case, any references to the parameters within the header or body must be direct and explicit. If there are indirect references, one must use another method to construct the procedure. The most common and most important of these is unapply, whose basic syntax is

unapply(
   single-expression body, possibly unevaluated, possibly containing indirect
      references to the parameters
,
   parameters
)

A second method uses subs to substitute expressions directly into existing procedures. This method is not limited to single expressions. It'd probably be best if I didn't delve further into this one now, but I'd be happy to when your need arises.

There are a few other methods of constructing procedures which are only suitable for expert users, most notably ToInert / FromInert. The vast majority of indirect reference procedures can be constructed by unapply. Of the remainder, the vast majority can be constructed by subs.

[*1] Function is the usual term for this in computer-science literature, and this corresponds somewhat to mathematical functions; however, in Maple usage, function has another, unrelated meaning (see help page ?type,function) as a one-dimensional, labelled, ordered container object.

[*2] These arrow expressions are also called lambda expressions in the terminology of functional programming.

@Rouben Rostamian  You used an arbitrary initial guess. Is there ever a situation where u(t0, x) (my generalization of u(0, x)) is not  the best choice of initial iteration?

@mmcdara I intentionally answered only the direct question asked by the OP, not the entire problem posed in the quote they gave. Now, I came back to this thread to followup.

@Adam Ledger Did you restart?

@asma khan It could be done like this:

M:= < 1, 2, 9;
      2, 3, 5;
      3, 4, 0 >
:
int~(M, t= -1..1);

It's not necessary to enter a matrix on multiple lines as I've done above. I just do that for clarity of presentation.

First 265 266 267 268 269 270 271 Last Page 267 of 708