Carl Love

Carl Love

28100 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@GoitaHass 

If works almost the same in Maple as in Matlab. You just need to append ~ to the operator to make it elementwise. Like this:

A -~ 5;

@tomleslie didn't say that your original was ugly; I gave it a vote up. But since you said that it was "awkward" and "ugly", I thought that I'd show you an alternative.

Regarding the op(3.., S): There are several things to note about this:

  • op(3.., S) returns NULL if has two arguments. This is in contrast with op(3, S), which would generate an error.
  • op(3.., S) transcribes not just the third argument (if it exists), but all subsequent arguments.
  • There's nothing stopping a user from including extra arguments in an inert Sum, for whatever reason, even though they have no official meaning to Maple. Perhaps they're used as a sort of comment field. Presumably such a user would want the extra arguments retained in the transformed Sum
  • Perhaps in the future meaningful extra arguments (such as options) will be added to sum, just as they've been added to int and Int. Including the op(3.., S) now means that this code will work then. Insulating code against potential future changes in the environment is a form of robustness.

@tomleslie You may find the following modification of your procedure more palatable. It doesn't use subsop. It builds a new sum from the components of the old rather than making substitutions in the old.

ShiftSum:= proc(S::specfunc({Sum,sum}), p::integer)
local ind:= op([2,1], S);
     op(0,S)(eval(op(1,S), ind= ind+p), ind= map(`-`, op([2,2], S), p), op(3.., S))
end proc:

 

@acer I don't think that it's a bug. I think that names that appear in procedure headers are always names, never evaluated.

@vv Brilliant!

For those who eschew verbose code, it can be condensed to

createModule2:= proc(A::Matrix(square))
uses LA= LinearAlgebra;
     module()
     export
          det:= subs('dim'= LA:-Dimension(A), (x::Matrix(dim))-> LA:-Determinant(x))
     ;
     end module
end proc;

@Christopher2222 If you want the closest fraction with a given denominator, then you'll need to use round instead of floor.

@Doug Meade Since the OP said "inch fraction" rather than "fraction", I took that to mean that the denominator had to be a power of two. It's traditional to use only dyadic fractions when specifying inches. You'll notice this in the size specifications for hardware (nuts, sockets, screws, etc.).

My procedure doesn't specify the number of bits for the numerator; it specifies the maximum number of bits to allow for the numerator, which is equivalent to specifying the maximum power of two to allow for the denominator, (the fractional part being always less than one).

@charlesforgy I agree with Stephen Forrest that the error is unlikely to be in the passing of the list. You mentioned "Maple's method of passing data structures by reference." I don't understand how this could make any difference for a list. The contents of the list are another matter. I'm suspicious about your b1b2, ..., bn. What type are they? Are they something mutable like Vectors or tables? Are they names? If so, are they global or local names? Note that names created with ||cat, or nprintf are always global.

@Kitonum The assignment r:= table() creates an empty table. This is necessary to obtain correct output in case there are no twin primes between a and Lim. It also makes it clear that r is a table

@Kitonum Here's a modification with proper return-value output.

twinprimes:= proc(a::realcons, Lim::realcons)
local
     a0:= `if`(a::prime, a, nextprime(a)),
     b:= nextprime(a0),
     r:= table(),
     n
;
     for n while b <= Lim do
          if b-a0 = 2 then r[n]:= [a0,b] end if;
          (a0,b):= (b,nextprime(a0))
     end do;
     convert(r, list)
end proc:

 

@Ronan There's no problem at l=1 or n. Maple understands the concept of an empty sum.

How is it that dsolve doesn't catch the square-bracket error? In this case dsolve produced normal-looking output, and it's by using that output that an error is produced.

@Vrbatim 

That's because sqrt(2) is algebraic and is a subpart of 2.0*sqrt(2). But, even though is algebraic, numeric complex constants don't "contain" as a subpart. The only operands of 2.+3.*I are 2. and 3., no I. The is used to input a numeric complex constant, but it's not stored as part of that constant. 

If you want to express the principal square root of -1 as an algebraic number, it'll be safer to use RootOf(_Z^2+1, index=1). It'll be more convenient if you set an alias to this.

@tomleslie Note that if you remove the return from your procedure, it'll produce exactly the same result: all five solutions. The significant difference between yours and the OP's isn't the return; it's the use of commas instead of semicolons.

Here's a perhaps-irrelevant code shortening: The entire procedure can be replaced by

LTTS:= solve0||(1..5)@~(rhs-lhs);

 

@Markiyan Hirnyk It's a partial solution because you supplied the simplified value, 0, rather than Maple coming up with it by itself.

First 438 439 440 441 442 443 444 Last Page 440 of 709