Rubrum Acer

27078 Reputation

29 Badges

17 years, 70 days
Ontario, Canada

Social Networks and Content at

"You do not need to leave your room. Remain sitting at your table and listen. Do not even listen, simply wait, be quiet, still and solitary. The world will freely offer itself to you to be unmasked, it has no choice, it will roll in ecstasy at your feet." -- Franz Kafka

MaplePrimes Activity

These are replies submitted by acer

@one man If you are allowed the somewhat ad hoc use of 1.*10^(-10) as a starting point for NextZero then one could use fsolve similarly, ie, where you called NextZero in the loop (after instantiating with numeric values for ns):

   fsolve(eqn, 1.*10^(-10)..infinity)

For example,

N := 60: L := 10: a := 2*10^(-12):
ns := [.9603, .9647, .9691]:
eqn := proc (A) options operator, arrow; ns[i]-1+(N/A+(A*L)^(L/(1-L)))^((1-L)/L)*(2+a*exp((N/A+(A*L)^(L/(1-L)))^(1/L))/(A*L*(N/A+(A*L)^(L/(1-L)))^((L-1)/L)+a*exp((N/A+(A*L)^(L/(1-L)))^(1/L))))/(A*L) end proc:
for i to nops(ns) 
  fsolve(eqn, 1.*10^(-10)..infinity);
end do;


I'll note that at default Digits=10 not all the NextZero results you showed are accurate to ten digits.

@golnaz The conditions under which the different computational path is taken by fsolve here is a bit complicated.

The following happens to handle both your equations. And fortunately it's not horribly expensive for these examples. I am not saying that it will handle all other possible examples. There is one internal solving method (one of the constructed inverse iterators) which happens to work for these two examples. But its construction depends on the form into which the algebraic expression is cast.


N := 60: L := 10: a := 2*10^(-12):

eqn1 := ns=1-((((N/A)+((A*L)^(L/(1-L))))^((1-L)/L))/(A*L))*(2+(a*exp((((N/A)+((A*L)^(L/(1-L)))))^(1/L)))/((A*L*(((N/A)+((A*L)^(L/(1-L))))^((L-1)/L)))+((a*exp((((N/A)+((A*L)^(L/(1-L)))))^(1/L)))))):

neweqn1 := combine(evala(expand(eqn1))):

seq(fsolve(neweqn1), ns=[0.9603,0.9647,0.9691]);

0.9300682773e-9, 0.3054144319e-8, 0.1172662805e-7


eqn2 := r=16*(((A*L*(((N/A)+((A*L)^(L/(1-L))))^((L-1)/L)))+((a*exp((((N/A)+((A*L)^(L/(1-L)))))^(1/L))))))/(((A*L*(((N/A)+((A*L)^(L/(1-L))))^((L-1)/L))))^2):

neweqn2 := combine(evala(expand(eqn2))):

seq(fsolve(neweqn2), r=[0.2,0.1]);

0.9940260022e-7, 0.1056608562e-3


[edit] I think that reliance on the above fortuitous form is not the best approach for you. I think that it'd be better to use ranges nudged slightly off singular points, since that can usually be automated.

@Syed Asadullah Shah Your code makes F as a table. Do you understand than F(3), F(2), F(k+2) is not correct Maple syntax for indexing into that?

Do you understand what I meant by an instance of pade*(...) in the code?

Perhaps you might start by making syntax corrections.

@golnaz I will submit a bug report against this.

I notice that the following succeeds even without specifying the much reduced range for A. It's following a different path inside the internal fsolve:-fsolve96CplxUni routine.


N := 60: L := 10: a := 2*10^(-12):


seq( fsolve(evala(eqn)), ns=[0.9603,0.9647,0.9691] );

0.9300682773e-9, 0.3054144319e-8, 0.1172662805e-7


@Syed Asadullah Shah Please answer properly.

@Syed Asadullah Shah 

Please answer my question properly: What do you mean by F(k+2)? Did you mean F[k+2] instead?

Don't repost the same worksheet.

@DJJerome1976 There seems to be an issue with the 2D Input's parser, in particular with how it resolves the name Degree when used in that local declaration. The 2D parser is not resolving that to the binding of the GraphTheory package's export, despite the fact that with(GraphTheory) was previously executed. That problem doesn't occur with 1D input.

Here's an alternative (using Maple 2022.1, which I think may be the same version as you):



n := 4; degrees := [1, 2, 2, 3]

L := NonIsomorphicGraphs(n, output = graphs, outputform = adjacency)

map(proc (u) local g, d; g := GraphTheory:-Graph(u); d := sort(GraphTheory:-Degree(g)); `if`(d = degrees, g, NULL) end proc, [L])

[GRAPHLN(undirected, unweighted, [1, 2, 3, 4], Array(1..4, {(1) = {4}, (2) = {3, 4}, (3) = {2, 4}, (4) = {1, 2, 3}}), `GRAPHLN/table/8`, 0)]



Why haven't you bothered to attach the actual data (Mat2)?

@Thomas Richard I do not know of any launching option or init file setting that would change that limit.

I tried editing my init file and including a concocted line for FileMRU11. When I launched the GUI that entry did not appear in the drop-list, and it vanished upon full closing.

@nm The (mapped) operator,


is a procedure in its own right. It declares its own z as its (only) procedural parameter. That z is not a parameter or local of a procedure within which that inner prodecure is defined.

Consider this example:

  f := proc(x)
    local p, r;
    p := proc(z) z^2; end proc;
    r := z -> sin(z);
  end proc;

The "z" that is a parameter of
   proc(z) z^2; end proc
is not a local or parameter of f.

The "z" that is a parameter of
   z -> sin(z)
is not a local or parameter of f.

The "z" that is a parameter of
is not a local or parameter of f.

Please add any closely related followup example here, instead of in a separate Question thread.

@C_R You wrote, "What I just tried: When this equation is inserted into an evalf call, "t54" and "la" are defined as double in the C code (without requiring your solution).

codegen neither requires your solution nor evalf workarounds (which make the code less clean)."

You just described something as involving an "evalf call", and then characterize than that as not being an "evalf workaround".

By the way, I deliberately didn't mention the approach of wrapping in an evalf call since that could possibly alter the structure (prematurely). That's one reason why I went for the type approach. Another possible reason is that roundoff error might produce inferior float approximations -- you didn't mention using evalf[15] or (possibly necessarily) even higher working precision. Another reason is that some targeted variable (which one hopes to be declared float) might only appear in equations that also involve variables that one wants declared integer. Forcibly specifying the types of the (Maple language) procedure seems like a much tighter and generally better approach.

CodeGeneration[C] tries to deduce the types of variables during its pass through the code. Yes, the absence of floats in formulas can lead it to figure an integer rather than a float type declaration; that aspect is by design. Yes, it is known to be quirky with regard to the defaulttype option. That's not really news. That's all part of why I'd instead suggest putting type specifications on the procedure's parameters.

@C_R I don't understand what you're now trying to say or ask, sorry. In particular, I don't understand what "required" means in your Reply.

Using "float[8]" as type-specification of the Maple language procedure's parameters induced CodeGeneration[C] to translate to a C language declaration with "double". And the Maple procedure can be generated with that effect specified programmatically, which is what you originally seemed to be asking. It's unclear to me how you might now be trying to follow that up.

It's true that CodeGeneration[C] has some warts. It might not always do as good a job as does Compiler:-Compiler. And so on.

I cannot recall seeing anyone use "double" as a type in Maple in a highly useful and practical scenario. It happens that CodeGeneration, Matrix/Array/Vector & LinearAlgebra/Statistics, and Compiler:-Compile, etc, know about the Maple type float[8]. I personally would not expect any of those to understand "double" to mean the same thing as "float[8]".

It may be that someone added a Maple type "double" in Maple 2015. I'd be surprised if they had also made the effort to make all the Maple contexts that recognized "float[8]" also accept "double" in the very same ways. I think that doing so would be misdirected effort.

You are missing a multiplication between one instance of Pi and the bracket that immediately follows it.

You'll need to correct that, either with an explicit multiplication symbol or (if still using 2D Input) an extra space.

(In an Answer below this was corrected in the 1D plaintext input.)

@mmcdara Perhaps this will explain a little.

The elementwise tidle syntax is less flexible here, and goes for speed. (Less flexibility and terseness often go together...) The map command provides flexibility here.



S := Sample(Binomial(10, 1/3), 3);

S := Vector[row](3, {(1) = 5.0, (2) = 5.7, (3) = 2.0}, datatype = float[8])

S[2] := 5.7: S;

Vector[row]([5., 5.70000000000000, 2.])

op(0,S), rtable_options(S, datatype);

Vector[row], float[8]


The row Vector S has float[8] datatype. That means that any rational or integer placed within it gets
stored as a floating-point number.

The next variant preserves that float[8] datatype. The command round does indeed get applied and
produces integers, but once the results get stored in this rtable the datatype stricture causes them
to once again become floating-point values (64bit floats, stored contiguously in memory).


S2 := map[evalhf](round, S);

S2 := Vector[row](3, {(1) = 5.0, (2) = 6.0, (3) = 2.0}, datatype = float[8])

op(0,S2), rtable_options(S2, datatype);

Vector[row], float[8]


The next variant does not preserve the datatype. So the generated integers can remain. The result
here is also row Vector.


S3 := map(round, S);

S3 := Vector[row](3, {(1) = 5, (2) = 6, (3) = 2})

op(0,S3), rtable_options(S3, datatype);

Vector[row], anything


For reasons of efficiency and syntactic-efficiency elementwise operations (using tilde) attempt to
use kernel builtins or evalhf'able operations if available, and in such a way preserve the datatype.


The terse elementwise syntax F~(...) doesn't have a convenient way to add extra options and be
flexible. (Extra options within the bracket modify the individual calls to F, and thus can't modify
how the elementwise mechanism itself works.)

In the absence of flexibility, this variant goes for speed when possible, and in this example acts
like the S2 variant above.

The next variant preserves that float[8] datatype. The command round does indeed get applied
and produces integers, but once the results get stored in this rtable the datatype stricture causes
them to once again become floating-point values (64bit floats, stored contiguously in memory).

This is like the S2 variant above.


S4 := round~(S);

S4 := Vector[row](3, {(1) = 5.0, (2) = 6.0, (3) = 2.0}, datatype = float[8])

op(0,S3), rtable_options(S2, datatype);

Vector[row], float[8]


Btw, I didn't do any conversion to list, since it's not needed here and seems more complicated.

ps. Sometime I switch to Source mode in the Mapleprimes editor, and paste in output from Maple's Commandline Interface (or from the GUI with prettyprint=1) between <pre></pre> tags. That can be related to whether my rtable outputs appear explicitly instead of as some strange handle.

First 6 7 8 9 10 11 12 Last Page 8 of 502