sursumCorda

922 Reputation

13 Badges

2 years, 206 days

MaplePrimes Activity


These are replies submitted by sursumCorda

@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("⋅" = " ", %);

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).

@Thomas Richard Right. But consequently, if one has installed Python before, one will have to add a multiple Python on the machine (when installing Maple). Will such a Python installation be optional in future Maple releases?

I think that you mean: 

Python:-ImportModule("import math, numpy as np");
Python:-DefineFunction("def Concentration_calculation(C_0, Q, V_r, m_b, rho, R, Gamma_i, delta_t=1):\n\tt = np.arange(0, 360*60, delta_t)\n\tC_i = [C_0]\n\tfor i in range(len(t)-1):\n\t\tdC = -(Q/V_r)*(1-math.exp(-3*m_b*math.sqrt(Gamma_i/(rho*t[i+1]))/(math.sqrt(math.pi)*Q*R)))*C_i[i]\n\t\tC_i.append(C_i[i] + dC*delta_t)\n\treturn t, C_i"):

@Carl Love Many thanks. This is an impressive procedure. (At least the computation can be done in one-third of a minute!

The fourth parameter `D` being 0 appears to mean that not all digits can be used, but there exists a bug in your program:

A161786__2(1, 1, 10, 0); # though it is not hard to fix it 
Error, (in A161786__2) Array index out of range

.

@dharr Thanks. In practice, I find that most use of “convert(p, 'base', 10)” can be simply replaced by faster “[`convert/base`:-MakeSplit(length(p), 1, 10)(p)]”, but to use it, one has to set "kernelopts('opaquemodules' = false):" in advance (which is somewhat dangerous). Besides, after converting integers to strings, I also try to call StringTools:-RegMatch directly, but Maple's regular expression engine seems to be not optimized enough ("Regular expressions" are extremely arcane, but they are known for being very powerful as well.). 
As for the `ithprime`, I believe that its inefficiency is because it's "
implemented in the high-level Maple programming language". But I don't know why such a fundamental function (for a math software) is not built into the core of the Maple computation engine …. 

4 5 6 7 8 9 10 Last Page 6 of 19