Carl Love

Carl Love

28055 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

The problem with Kitonum's Answer is that the solve is executed for each iteration. The (potential) problem with Tom Leslie's Answer is that it isn't a single statement. The solution to both problems is the oft-neglected sequencing operator. It works very much like seq except that, like most Maple commands (but unlike seq), its arguments are evaluated before being passed.

{b=j, eval(solve({x+b*y=0, b*x-y=10}, {x,y}), b= j)[]} $ j= 10..20;

     {b = 10, x = 100/101, y = -10/101}, {b = 11, x = 55/61, y = -5/61}, {b = 12, x = 24/29, y = -2/29},
     {b = 13, x = 13/17, y = -1/17}, {b = 14, x = 140/197, y = -10/197}, {b = 15, x = 75/113, y = -5/113},
     {b = 16, x = 160/257, y = -10/257}, {b = 17, x = 17/29, y = -1/29}, {b = 18, x = 36/65, y = -2/65},
     {b = 19, x = 95/181, y = -5/181}, {b = 20, x = 200/401, y = -10/401}

The example structure C that you showed is not a set: it's a sequence: its order matters, and members may be repeated. If you want to subtract a member from a set, then use the Answer by Thomas Dean. If you want to remove all occurences of a member B from a sequence C, then use

remove(`=`, [C], B)[];

Note that the is not enclosed in { } in the solve command below.

Sol:= [solve(f, omega)];
min(select(`>`, Sol, 0));

Here's a procedure that will cancel the lowest floating-point power of 10 (positive or negative) in any fraction:

Cancel10s:= (E::algebraic)->
     `if`(
          hastype(E,And(float,Not(identical(0.)))),
          `/`((numer,denom)(E)/~10^ilog10~(indets(E,And(float,Not(identical(0.)))))[1]),
          E
      )
;

(Note that ilog10 also works for negative floats.) If the input is not a single fraction, it'll be rearranged to one. An expression mathematically equivalent to the input is returned in all cases, although it may not be the desired result if the expression contains nested floats. 

 

@smith_alpha 

Here are five methods for creating and filling a list. I've listed them in increasing order by the amount of computational resources that they take. Never use #5: It's very wasteful and never necessary. I only include it because it's the way that most people come up with on their own instead of #3 or #4. There are many situations where you can't use #1 or #2 and must resort to #3 or #4.

#1
f:= [seq(i, i= 1..3)];

#2
f:= ['i' $ 'i'= 1..3];

#3
f:= Vector():
for i to 3 do f(i):= i end do:
f:= convert(f, list);

#4
f:= table():
for i to 3 do f[i]:= i end do:
f:= convert(f, list);

#5
f:= []:
for i to 3 do f:= [op(f), i] end do;

There must be something additional known about (other than about its degree of differentiability) in order for the identity to be true. Proof: Suppose u(x,y,z,w) = x. This u satisfies any possible degree-of-differentiability requirement. Since there are no derivatives taken with respect to x3 or y3, we can ignore any factors that depend only on those variables. (Alternatively, we could suppose, without loss of generality, that x3-y3 = 1.) Then the expression that you're taking the derivatives of is equivalent to w below. Execute the following Maple code:

u:= (x,y,z,w)-> x:
w:= add((x||k - y||k)^2, k= 1..3)^(-1/2)*u(x3*y1-x1*y3+x2-y2, 0, 0, 0):
diff(w,x1,y2)-diff(w,y1,x2):
eval(%, [x1=1,x2=2,x3=3,y1=4,y2=5,y3=2]);

Maple returns a number other than 0.

So, what are the assumptions made on u in the paper?

First do the permutations of the lists, then convert the lists to Arrays, for example like this:

Array~(combinat:-permute([1,2,3]));

Never use array (with a lowercase a); it's deprecated. Use Array instead. Likewise for matrix and vector.

 

Yes, it certainly seems like a bug. Here's a quick workaround:

fsolve(evalf(P), complex);

evalindets(eq, fraction, evalf);

How about this?

degrees:= m-> map(x-> x=degree(m,x), indets(m)):
degrees(x*y^2);

Here's an object-oriented implementation of circular lists that allows for all of the multitude of types of indexing that ordinary lists allow (including unevaluated indices) and has as transparent an interface as I could manage. That is, I tried to make everything look like ordinary lists.


An object-oriented implementation of circular lists.

restart:


module CircularList()
option
     `Author: Carl Love, 2015-Jul-29`,
     object
;
export
     List, #the underlying list

     ModuleType::static:= proc(CL,t1,t2,$)
          nargs=3 implies CL:-List::list(t2)
     end proc,

     ModuleApply::static:= proc()
     local CL:= Object(CircularList);
          CL:-List:= [args];
          CL
     end proc,

     #Make circular lists prettyprint just like lists.
     ModulePrint::static:= CL-> CL:-List,

     `?[]`::static:= proc(CL,K)     
     local L:= CL:-List, N:= nops(L), k:= K[], n, _k;

           #Allow all types of index specifications that ordinary lists do.
           if not K::{
                          identical([]),
                          [{
                               list,
                               integer,
                               And(algebraic, Not(complexcons)),
                               range({integer, And(algebraic, Not(complexcons))})                             
                          }]
                     }

           #Return same error message as ordinary lists.
           then error "invalid subscript selector"

           #NULL index extracts the underlying sequence.
           elif K=[] then L[]
           
           #A list of indices returns a sub-CircularList.
           elif k::list then ModuleApply(map2(thisproc, CL, `[]`~(k))[])

           #A range of integers returns a sub-CircularList, but the range must be
           #a valid index for the underlying list.
           elif k::range(integer) then ModuleApply(L[k][])

           #If the CircularList is empty, return NULL.
           elif N=0 then

           #For plain integers, use modular arithmetic.
           elif k::integer then
                n:= modp(k,N);             
                if n=0 then n:= N end if;
                L[n]

           #The index has an unevaluated component.
           else             
                subs(_k= k, 'CL[_k]')
           end if
     end proc
;
end module:    
      

Examples

L1:= CircularList(x1,x2,x3,x4);

thismodule

L2:= CircularList(y1,y2,y3,y4);

thismodule

L1[7];

x3

L2[0];

y4

Just like ordinary lists, unevaluated indices are allowed.

x:= L1[n^2];

(thismodule)[object, `Author: Carl Love, 2015-Jul-29`]

eval(x, n= 3);

x1

type(L1, CircularList);

true

type(L1,'CircularList'(name));

true

type(L1,'CircularList'(posint));

false

Empty circular lists are allowed.

L3:= CircularList();

thismodule

They return NULL for any single specific index.

x:= L3[3];

"x:="

Garbage indices are rejected with the same message as for ordinary lists.

L1[.3];

Error, (in CircularList:-?[]) invalid subscript selector

 

A NULL index extracts the underlying sequence.

L1[];

x1, x2, x3, x4

Ranges of indices must be such that they work for the underlying list (no modular arithmetic is done). They return a sub-CircularList

L1[2..4];

thismodule

Lists of indices may be modular. They also return a sub-CircularList.

L2[[7,3,1]];

thismodule

Ranges with unevaluated parts are allowed.

L2[1..m];

(thismodule)[object, `Author: Carl Love, 2015-Jul-29`]

And they return a sub-CircularList when evaluated.

eval(%, m=3);

thismodule


Download CircularLists.mw

Replace solve with eliminate. (The arguments can stay the same.) Remove the assign command. The solution returned by eliminate comes in two parts, each a set. The first set is the solutions for variables that you specified in the second argument. Inspect it very carefully. Is the form what you expected? Make sure that you spelled the variable names the same in all use instances. Maple is case sensitive. I'm somewhat skeptical that you spelled them all correctly because the solution looks weird to me. The second set returned by eliminate is a set of expressions which must be equal to 0 in order for the first set to actually be a solution.

It is only slow if you try to display the results in the Standard GUI. There is no reason to display 17550 3x3 listlists. Just end your statement with a colon rather than a semicolon (to suppress display) and the allstructs will run in 0.1 seconds.

There are very small discontinuities in the piecewise function due to roundoff errors during its creation. The solution is to create the piecewise function at a higher Digits setting than is used during the fsolve. For example, setting Digits:= 20 before defining the function and then changing to Digits:= 15 before doing the fsolve works.

What have you tried?? The obvious thing to try is factor, which will tell you immediately that the polynomial can't be factored.

Several other points:

  • The polynomial isn't huge by Maple standards.
  • I don't think that you know what it means to know something a priori. It means to know something because it has been proven in the mathematical (or pure logic) sense of proof. That seems to be precisely what you don't have in this case. To know something by experience or by observation is to know it a posteriori.
  • There's no need to attempt a partial factorization in this case. The command factor will tell you in a blink of an eye that the polynomial can't be factored at all.
  • Please post your expressions with explicit multiplication signs--- * ---so that they can be copy-and-pasted directly into Maple.
First 253 254 255 256 257 258 259 Last Page 255 of 395