A little cheat-sheet, on how to wrap Python mpmath procedurals inside regular SageMath expressions.

The following link should not be taken, as the complete solution to anybody else’s computing task, in which my readers might want to wrap Python code for use in SageMath. In fact, I don’t even consider myself an expert in either of these subjects.

For people who do not know, “SageMath” is a combination of “Computer Algebra System” – ‘CAS’ – and ‘Numerical Toolbox’. SageMath is written using multiple languages, mainly Python. And, the ‘Maxima’ CAS back-end was written in LISP. ‘mpmath’ is a specific Python package, that allows Multi-Precision Arithmetic.

The integration of ‘mpmath’ is particularly straightforward, because Sage already uses this package. But the principles that would be used for other Python packages are similar. An interface must be established, by which Sage objects can be translated into the objects specific to the external Python packages, and back into objects that Sage can recognize again. Objects that Sage finds particularly useful, are ‘Symbolic Functions’ – that are to be manipulated algebraically – and ditto for ‘Symbolic Expressions’.

If worse comes to worst, then the data generated by the external, ‘wrapped’ code, may be converted into native Python objects such as ~Strings~. However, Sage does not recognize strings as valid Symbolic Expressions. So, one way around that could be, to call Sage’s ‘sage_eval()‘ function on the strings. (:1)

 

http://dirkmittler.homeip.net/LambertW%20Test%203%20–%20Sage.html

 

(Updated 7/28/2021, 12h15… )

Continue reading A little cheat-sheet, on how to wrap Python mpmath procedurals inside regular SageMath expressions.

Scilab emphasizes, that the Linux world is rich with Technical / Scientific Computing platforms…

In my previous posting, I listed several (Open-Source) platforms for Computing, available under Linux at no cost, which have emphasis on Technical and Scientific applications. These platforms differ from conventional programming languages, in that conventional languages mainly specialize in allowing applications to be built, that perform a highly specialized function, while technically oriented platforms allow a user to define Math problems to be solved, to do so, and then to define a whole new Math problem to be solved…

My previous posting had also hinted that, when it comes to Computing tools of this kind, I prefer ‘the lean and mean approach’, in which the learning of specialized scripting languages would be kept to a minimum, but where, through his or her own resourcefulness, the User / Scientist knows how to apply Math, to solve their problem…

Yet, solutions do exist which go entirely in a different direction, and I’d say that “Scilab” is one of them. Under Debian Linux, one usually installs it as a collection of packages, from standard repositories, using the package manager.

Scilab is an application – and a workbench – with a rich GUI. It combines many features. But again, If somebody wanted to use it for real problem-solving, what would really count is, to learn its scripting language (which I have not done). Yet, Scilab typically comes with many Demos that tend to work reliably out-of-the-box, so that, even without knowing the scripting language, users can treat themselves to some amount of eye-candy, just by clicking on those….

 

Screenshot_20210709_062947

Screenshot_20210709_063146

Screenshot_20210709_063651

 

As I’ve stated repeatedly, sometimes I cannot gauge whether certain Scientific Computing platforms are really worth their Salt – especially since in this case, they won’t cost much more than a household quantity of salt does. ;-)  But, if the reader finds that he or she needs a powerful GUI, then maybe, Scilab would be the choice for them?

 

Dirk

 

How 3D-plotted, implicit functions are often inferior, to ISO-Surfaces rendered for 3D Gaming.

One of the subjects which I revisited in recent weeks has been, that either Computer Algebra Systems, or other numeric toolboxes, may plot functions. And a fact that should be pointed out is, that to plot a function, either as a 2D or a 3D plot, is always numeric, even if it’s being offered as part of what a ‘CAS’ can do (a “Computer Algebra System”). And so, a subcategory of what is sometimes offered, is a 3D plot, of an implicit function, kind of like this one:

hyperboloid

This is a plot, of complementary hyperboloids, which are the 3D counterparts to 2D hyperbola.

What some people might just wonder is, how the refined toolbox works, that plots this type of implicit function. And one way in which this can be done, is by generating an ISO-Surface, which is a derived mesh, along which a Density that has been computed from X, Y and Z parameters, crosses a threshold-value, which can just be named (H) for the sake of this posting.

And, in turn, such an ISO-Surface can be computed, by using the ‘Marching cubes algorithm‘. If it gets used, this algorithm forms a geometry shader, which accepts one Point as input topology, and which outputs a number of triangles from (0) to (4).

The question which this posting poses is, whether the mesh which is output by such an algorithm, will always include vertex-normals. And the short answer is No. Applications exist, in which normals are computed, and applications exist where normals are not computed. And so, because some users are used to high-end gaming, and used to seeing shaded surfaces, which can only really be shaded if normals have been made available to a fragment shader, those users might find themselves asking, why Mathematical plotting algorithms might exist, which never compute real normals.

(Updated 5/07/2020, 16h15… )

Continue reading How 3D-plotted, implicit functions are often inferior, to ISO-Surfaces rendered for 3D Gaming.

Noticing when SageMath is using IPython, instead of Maxima.

One of the subjects of my recent postings, has been a Computer Algebra System called “SageMath”, which I was able to install on my Debian / Stretch (Debian 9) computer named ‘Plato’. One of the distinctions which I left slightly blurred about this, is the distinction between Computer Algebra, and Numerical Tools. The former refers to the ability of a computer to manipulate symbols, in the way Algebra manipulates them, but to solve equations which Humans might just find tedious or too time-consuming to solve. This can lead to answers that are theoretically exact, but which can sometimes be useless because the numerical equivalent is only available indirectly.

Numerical Tools are more numerous under Linux, and offer theoretically inexact solutions to equations, simply because the numerical answers have a limited number of decimal places after the point or comma. Yet, the numerical answers can sometimes be much more useful than Algebraic answers, for reasons that I think are self-explanatory.

SageMath offers both. In order to do Algebra, SageMath uses “Maxima” as its back-end. And under Debian Linux, installing SageMath actually installs a separate version of Maxima, which users are not supposed to use directly.

Continue reading Noticing when SageMath is using IPython, instead of Maxima.