sursumCorda

1324 Reputation

15 Badges

3 years, 321 days

MaplePrimes Activity


These are replies submitted by sursumCorda

@Carl Love & @mmcdara Many thanks. Maybe such functionalities can be built into the underlying core so that Maple can sort rows of the rtable in-place.

@nm Thanks for your advice. But they behave differently. For example, 

ArrayTools:-SortBy(<4, 1, 1 | 0, 2, 5 | 7, 9, 8>, [.., 1]);
                           [1  2  9]
                           [       ]
                           [1  5  8]
                           [       ]
                           [4  0  7]

ArrayTools:-SortBy(<4, 1, 1 | 0, 2, 5 | 7, 9, 8>, 'column', [1, 3, 2]);
Error, (in ArrayTools:-SortBy) for 2-D rtable, expecting either list of indices or keyword column/row and index to specify what is to be sorted

while my purpose is: first sort the rows of the input 2-D array in specific order based on the elements in the specified column, then sort rows that have equal elements in the specified column based on the elements in the next specified column, and so forth. (Also, I hope that there will be a multidimensional analogue.)

@mmcdara Thanks for your test. I think that when working with Statistics, perharps using Sort@Trim is better (since they are in the same toolchain).
As for your last point, the reason is that you only measure the average time (instead of the total time). The MatLab code given in that Blog is: 

    tic
    for i=1:300
        y=mink(x,j*100);
    end
    minkResults(j)=toc;

 So “CodeTools:-Usage(..., 'interations' = 300)” should be changed to something like

to 5 do (*warm up the code to avoid its first-time costs*) od:
time[real]('(Statistics:-Sort@Statistics:-Trim)( … )' $ 3e2);

 Besides, though there exists a one-dimensional Statistics:-Sort function, is there a similar sortrows/sortcols in Maple?

@dharr Thanks. This is also useful, because the input data can contain any element.

@mmcdara Thanks. I think this function is just what I am seeking, although it appears to only handle numeric objects with real values.
Besides, in your worksheet, "the sorted 1000 smaller" runs much faster than "the 1000 smaller". Maybe there is some mistake?

@jalal For example, 

InertForm:-Display(InertForm:-Parse("2*sqrt(3)"), 'inert' = false);
subs("&sdot;" = "&#32;", %);

Do you mean combinat:-randcomb([`+`, `*`, `-`], 1)? 

@Carl Love Thanks. I think that I know why `Iterator:-CartesianProduct` is not faster; later I find a bug in `Iterator:-CartesianProduct`. Below is the output from showstat(Iterator:-CartesianProduct::ModuleCopy): 

ModuleCopy := proc(self::Iterator:-CartesianProduct, proto::Iterator:-CartesianProduct, L::seq({list, set}) := seq(proto:-L), {compile::truefalse := false, rank::posint := 1}, $)

So by default the iterator is not compiled. However, even if I specify “'compile' = true” manually, the compiled iterator still runs slower (!) than your uncompiled `CP[6]`, which is really strange. 

@ecterrab I think that what the OP wants is a direct shortcut key for the overbar U+0305 (something like an overscript with long underlines).

@Carl Love In the main code, “It:-CartesianProduct(DigitSets())” is used. Suppose that DigitSets() is {0, 1, 2, 3}, {0, 1, 2, 3}. Is there any difference among 

Iterator:-CartesianProduct({0, 1, 2, 3}, {0, 1, 2, 3}):
Iterator:-MixedRadixGrayCode([3 + 1, 3 + 1]):
Iterator:-MultiSeq(<0, 0> .. <3, 3>):
Iterator:-MixedRadixTuples([3 + 1, 3 + 1]):
combinat:-cartprod([{0, 1, 2, 3}, {0, 1, 2, 3}]):

?

Strangely, the faster gmp_isprime is a "undocumented protected name". I'm not sure why it wasn't officially documented.

I also try to use a faster primes generator; in theory, the following program should be quite efficient: (Assume that one has installed the most recent Primesieve under E:\Primesieve\bin\.) 

A161786__3 := proc(m::nonnegint, n::posint := 1, b(*ase*)::And(posint, Non(1)) := 10, o(*ccurrence*)::posint := 4, ` $`)::'Vector'(prime):
    description "Dependency: primesieve winget package.":
	options hfloat:
	local p::string := ifelse(n = 1, "1", ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" ", n - 1, " -n -p"))[2]), vec := rtable(1 .. 0, datatype = integer[4], subtype = Vector[column]), numberDecompose := (radix, uintlen) -> (thisproc(args) := convert(['tmp' = 'd', [''irem'('tmp', radix, ''tmp'')' $ uintlen]], procedure, 'locals' = ['tmp'::posint], 'params' = ['d'::posint])), v::integer[0 .. b - 1], C(*ounter*);
	if b = 10 then
		to m do
			p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
			if member(o, rhs~({StringTools:-CharacterFrequencies(p, 'digit')})) then
				vec ,= parse(p)
			fi
		od
	elif b = 2 then
		to m do
			p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
			if member(o, rhs~({StringTools:-CharacterFrequencies(Bits:-String(parse(p)), 'binary')})) then
				vec ,= parse(p)
			fi
		od
	elif b = 16 then
		to m do
			p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
			if member(o, rhs~({StringTools:-CharacterFrequencies(convert(parse(p), 'hex'), 'hdigit')})) then
				vec ,= parse(p)
			fi
		od
	elif b = 8 then
		to m do
			p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
			if member(o, rhs~({StringTools:-CharacterFrequencies(sprintf("%o", parse(p)), 'octal')})) then
				vec ,= parse(p)
			fi
		od
	elif b = 4 then
		to m do
			p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
			if member(o, rhs~({StringTools:-CharacterFrequencies(String(op(Bits:-Split(parse(p), 2))), "0123")})) then
				vec ,= parse(p)
			fi
		od
	elif b = 2**(local k := ilog2(b)) then
		if k < 8 then
			to m do
				p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
				if member(o, rhs~({StringTools:-CharacterFrequencies(convert(Bits:-Split(parse(p), k) +~ 1, 'bytes'))})) then
					vec ,= parse(p)
				fi
			od
		else
			to m do
				p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
				C := table('sparse');
				for v in Bits:-Split(parse(p), k) do
					++C[v]
				od;
				if member(o, {entries(C, 'nolist')}) then
					vec ,= parse(p)
				fi
			od
		fi
	elif b < 2**8 then
		to m do
			p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
			if member(o, rhs~({StringTools:-CharacterFrequencies(convert(numberDecompose(b, evalhf['hfloat'](trunc(log[b](p)) + 1))(p) +~ 1, 'bytes'))})) then
				vec ,= parse(p)
			fi
		od
	else
		to m do
			C := table('sparse');
			p := ssystem(cat("\"E:/Primesieve/bin/primesieve.exe\" 1 ", p, " -n -p"))[-1];
			for v in numberDecompose(b, ilog[b](p) + 1)(p) do
				C[v]++
			od;
			if member(o, entries(C, 'output = Array')) then
				vec ,= parse(p)
			fi
		od
	fi;
	vec
end:

But unfortunately, the overhead of communication between Maple and Cmd (i.e., ssystem) appears to seriously weaken its advantage … I hope there will be a faster generator/iterator for prime numbers in a furture Maple release.

@Carl Love There is no problem in recent versions, but since `inttrans` is a "table-based package" (and the use of “inttrans:-invlaplace” is invalid in legacy Maple), for backward compatibility, I think that using “inttrans[':-invlaplace']” is somewhat better. 

Besides, the documentation of colondash is outdated. 
Member Selection Operator says that 

For example, to call the exported procedure Chi of the combinat package, use combinat[':-Chi']. (Alternatively, since the combinat package is implemented as a module, you could equally use combinat:-Chi, but the latter syntax works only with module-based packages.)

Using Packages also says that

While modern packages are implemented as modules, some older packages are implemented as tables or procedures. … For these packages, :- notation is not supported. The long form notation for such packages … can be accessed by using unevaluation quotes as PackageName['command'](arguments).

Actually, those old packages are now compatible with the use of binary `:-` operator.
A few years ago, there used to be an option (Was this information helpful?—No: Tell us what we can do better.) at the bottom of the help page, yet today it disappears. 

@Carl Love Oops, I just found it and edited my reply. Thanks.

@Carl Love I believe that this is related. 

restart;
libname := subs(FileTools:-JoinPath([kernelopts(':-toolboxdir' = "Physics Updates"), "lib"]) = NULL, [(tmp := libname)])[]:
inttrans[':-invlaplace'](1/(s + a), s, t);
                           exp(-a t)

libname := tmp:
forget(inttrans[':-invlaplace']);
inttrans[':-invlaplace'](1/(s + a), s, t);
                            exp(a t)

 

In addition, 

> inttrans['invlaplace'](inttrans['laplace'](ln(t^2+1), t, s), s, t); # Maple 2023.1 
 = 
                              / 2    \
                          2 ln\t  + 1/

So Maple thinks that ㏑(t2+1)=2㏑(t2 + 1)…? 

Additional examples: 
 

> 

restart;

> 

_EnvUseHeavisideAsUnitStep := true

> 

interface(version)``

`Standard Worksheet Interface, Maple 2023.1, Windows 10, July 7 2023 Build ID 1723669`

> 

with(inttrans, laplace, invlaplace):

> 

t^nu*exp(-a*t):
laplace(%, t, s) assuming Re(nu) > -1:

> 

%% = invlaplace(%, s, t) assuming Re(nu) > -1;

t^nu*exp(-a*t) = t^nu*exp(-a*t)

(1)
> 

eval(%%%, nu = 0):
laplace(%, t, s):

> 

%% = invlaplace(%, s, t);

exp(-a*t) = exp(a*t)

(2)
> 

(exp(-b*t) - exp(a*t))/t:
laplace(%, t, s):

> 

%% = invlaplace(%, s, t);

(exp(-b*t)-exp(a*t))/t = (exp(b*t)-exp(-a*t))/t

(3)
> 

ln(t**2 + 1):
laplace(%, t, s):

> 

%% = invlaplace(%, s, t);

ln(t^2+1) = 2*ln(t^2+1)

(4)
> 

1/sqrt(Pi*t) - a*exp(a**2*t)*erfc(a*sqrt(t)):
laplace(%, t, s):

> 

%% = invlaplace(%, s, t);

1/(Pi*t)^(1/2)-a*exp(a^2*t)*erfc(a*t^(1/2)) = 1/(Pi*t)^(1/2)+a*(exp(a^2*t)*erf(a*t^(1/2))-exp(-a^2*t))

(5)
> 

abs(sin(Pi*t)):
laplace(%, t, s):

> 

%% = invlaplace(%, s, t);

abs(sin(Pi*t)) = Pi*invlaplace(coth((1/2)*s)/(Pi^2+s^2), s, t)

(6)
> 

Ci(a*t):

> 

laplace(%, t, s) assuming a::positive:

> 

%% = invlaplace(%, s, t) assuming a::positive;

Ci(a*t) = -(1/2)*invlaplace(ln((a^2+s^2)/a^2)/s, s, t)

(7)
> 

2*(ln(a) - Ci(a*t)):

> 

laplace(%, t, s) assuming a::positive:

> 

%% = invlaplace(%, s, t) assuming a::positive;

2*ln(a)-2*Ci(a*t) = 2*ln(a)-2*Ci(a*t)

(8)
> 

Heaviside(t - a)/sqrt(t):

> 

laplace(%, t, s) assuming a::nonnegative:

> 

%% = invlaplace(%, s, t) assuming a::nonnegative;

Heaviside(t-a)/t^(1/2) = invlaplace((Pi/s)^(1/2)*erfc((s*a)^(1/2)), s, t)

(9)
> 

piecewise(t >= a, 1/sqrt(t)):

> 

laplace(%, t, s) assuming a::nonnegative:

> 

%% = invlaplace(%, s, t) assuming a::nonnegative;

piecewise(a <= t, 1/sqrt(t), 0) = piecewise(a <= t, 1/sqrt(t), 0)

(10)
> 

 


 

Download ilaplace.mw

(1) is correct, but (2), (3), (4), and (5) are wrong.
And for uknown reason, Maple cannot calculate (6), (7), (9), and (10).

First 8 9 10 11 12 13 14 Last Page 10 of 23