sursumCorda

1239 Reputation

15 Badges

2 years, 232 days

MaplePrimes Activity


These are replies submitted by sursumCorda

@acer Thanks. Actually, I don't quite understand why the creators and designers chose such a rule; in my opinion, this is somewhat unnecessary. For instance, if there is no automatic simplification process, “(a-b)/3” will only take one `-` and one `/`, but as the automatic simplification exists, it always immediately becomes “a*(1/3)+b*((-1)/3)”, which is, in effect, of less simplicity. Doesn't this simply make some (numerical) evaluations more complicated/expensive?

The help page says that automatic simplification … cannot be controlled. Does this mean that it is always impossible to switch off some of rules used by the automatic simplification process? (Well, although this may not be essential, I do not think that this is very convenient for the so-called "live programming".)

@minhthien2016 For some unknowable reason, GraphTheory:-FindClique only returns the first clique it can find (By contrast Mathematica's FindClique  does attempt to find all cliques.), so one has to enumerate all vertex subsets …. However, one may count the "130 results" manually

restart;
Sol := ListTools:-MakeUnique(sort~(ListTools:-FlattenOnce([seq(map((x, y) -> [x[], y], numtheory:-sum2sqr((33*sqrt(3))**2 - z^2), z), z = 0 .. trunc(sqrt((33*sqrt(3))**2/3)))]))):
Sol := convert(convert(ArrayTools:-GeneralOuterProduct(ListTools:-FlattenOnce(combinat:-permute~(Sol)), `*`~, ListTools:-Flatten(eval(MmaTranslator:-Mma:-Distribute([[-1, 1] $ 3], list), list = `[]`), 3 - 1)), list), Matrix):
M__0 := Sol.Sol^%T:
M__1, M__2 := ArrayTools:-Replicate(LinearAlgebra:-Diagonal(M__0), 1, 416), ArrayTools:-Replicate(LinearAlgebra:-Diagonal(M__0)^%T, 416, 1):
G0 := GraphTheory:-Graph((`{}`@lhs)~(select[4](foldl, eval(apply), rcurry(`=`, 8/3*(33*sqrt(3))**2), rhs, op(2, M__1 + M__2 - 2*M__0)))):
G || (1 .. 26) := op(GraphTheory:-InducedSubgraph~(G0, GraphTheory:-ConnectedComponents(G0))):
andseq(GraphTheory:-IsIsomorphic(G || i, G || (i + 1)), i = 1 .. 25);
                              true

GraphTheory:-DrawGraph(G1, style = spring, stylesheet = "legacy");

Now we know that there are 5*26 tetrahedra in total.

@Carl Love Thanks. As for my StringTools-based version, I find a strange thing. 

In the auxiliary procedure aux, I only use 

parse(String(seq('length(str), str[1]', str = temp)))

which turns out to be inefficient.
According to string buffer constructor, the StringBuffer constructor efficiently builds long strings in pieces by appending the pieces one at a time, yet after changing it into 

 local sb := StringBuffer();
 seq(sb:-appendf("%d%c", length(str), str[1]), str in temp);
 parse(sb:-value(clear))

the new one remains to be less efficient.
Nevertheless, if I simply replace the original String with cat, i.e., 

parse(cat(seq('length(str), str[1]', str = temp)))

(and others leave unchanged), the updated code will immediately become unexpectedly efficient (nearly 3.5s (which is very close to Mma-implementation's 2.5s)). 
Why is there such a mysterious performance distinction between String and cat? The documentation just tells us that "unlike the cat function, String always returns a single string, never a name, unevaluated concatenation (||), or sequence", but this is irrelevant to the performance. 

@Carl Love I believe that the fastest way is: 

if rtable_is_zero(A[2]) then
    …

Surprisingly, EqualEntries({entries(A[2], 'nolist')}, {0}) is also very fast.

@dharr Thanks. I'm astonished to see that the speed of your code beats that of mine (that is, manipulating text directly) instead, since a number of routines provided by the StringTools package essentially make use of and accordingly benefit from compiled libraries, while your code doesn't even call any external functions. (Anyway, I still don't know why the uncompiled Mathematica implementation runs quite fast. Maybe there'll be a dramatic speed-up in some future release. Let's look forward to seeing this.)

@Axel Vogt Hmm, this means that one has to change softwares (and ways of thinking) at each stage, which may retard (or even waste) productive computing in certain cases. The help page notes that "since the importing of NAG routines into Maple is an ongoing project, future releases will include the ability to handle a larger selection of input shapes and storage modes". This sentence is about the LinearAlgebra package, but I intend to know if future Maple releases will introduce more highly efficient optimization routines (because the add-on Global Optimization Toolbox cannot solve non-convex mixed-integer nonlinear problems as well). 

@Axel Vogt I read that "the Optimization package solvers rely on a built-in library of optimization routines provided by the Numerical Algorithms Group". And according to Optimization : NAG FL Interface, "mixed integer nonlinear programming" is supported in fact, but Maple's documentation simply writes that assume = integer is "only accepted by the Optimization:-LPSolve command". This is strange.

@vv Thanks. But the elapsed time is quite long; on my low-end computer, executing this code takes about six minutes. And it is strange that the returned values are not the optimum: 

Actually, the original problem (not posted here, since it is more expensive) asks for twenty variables (rather than nine variables). Is it possible to speed up the optimization processing (so that a medium-scale analogue can also be solved in an acceptable time)?

@Kitonum Thanks. This's justified (and faster). But if the problem has twenty variables, I'll have to write 20 do loops, which seems to be somewhat inadvisable. (Yes, the original problem asks for twenty variables instead of nine variables, but as this problem appears to be too expensive for a low-end computer, I just post a modified version here. (I choose "nine" because (-(-5)^3*(9-1))^(1/3) is simply a nice number.))

@vv I second that. I once wanted to use a more uncommon function in my question (to avoid certain non-essential "tricks"), but at last I gave up, as a simple function can achieve the desired effect as well.

@Axel Vogt Thanks. But it appears that this doesn't work for other functions.

Another potential workaround is: 

> m := Matrix([[1, 1, 3], [0, 1, 0], [0, I, 2]], datatype = complex(sfloat)):
> UseHardwareFloats := false:++Digits:
> add(residue~('z'/(exp('z') - 1)*LinearAlgebra:-MatrixInver\
> se('z'*LinearAlgebra:-IdentityMatrix(LinearAlgebra:-Dimens\
> ion(m)) - m), 'z' = lambda), lambda in ListTools:-MakeUniq\
> ue(LinearAlgebra:-Eigenvalues(m, output = list), 1, testfloat, 1));
                  [0.58197670686 + 0. I    -0.33869688735 + 0.20926639797 I    -0.80682426410 + 0. I]
                  [                                                                                 ]
                  [     0. + 0. I                0.58197670686 + 0. I                0. + 0. I      ]
                  [                                                                                 ]
                  [     0. + 0. I                0. - 0.26894142136 I          0.31303528550 + 0. I ]

Unfortunately, the default value of Digits is not enough here. (And I don't think that this is efficient (though not ineffective) for other functions.)

@dharr Thanks for your detailed analysis.
I read that "many LinearAlgebra package functions use NAG routines to carry out computations", while the LinearAlgebra['MatrixFunction'] does not make use of this external library. This is strange, since such routines are available (according to F01 (Matop) : matrix functions) in fact. 

@dharr Thanks. But I do not understand why the obsolete linalg:-matfunc (whose use is discouraged) performs better even with the default 10-digit precision. Equally, can't the built-in LinearAlgebra:-MatrixFunction go beyond the basics?

@Thomas Richard Actually, the OP's purpose is to display "x^2-2*x-3*x+6,x^2+3*x-7*x-21,x^2-9*x-10*x+90" instead of "x^2-5*x+6,x^2-4*x-21,x^2-19*x+90". For such a purpose, one may make use of InertForm:-Display(… have to be processed in advance …, inert = false)

However, this is not very easy (though not impossible) to handle. In Mathematica, one can simply use: 

In[1]:= HoldForm[x^2-a*x-b*x+a*b]/.Distribute[{{a,b}}\[Rule]{{2,3},{-3,7},{9,10}},List,Rule,List,Rule/*Thread]

          2                     2                      2
Out[1]= {x  - 2 x - 3 x + 2 3, x  - -3 x - 7 x - 3 7, x  - 9 x - 10 x + 9 10}

There are also some other Hold* in Mma, yet I cannot find similar direct commands in Maple.

First 10 11 12 13 14 15 16 Last Page 12 of 23