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.

My computer Plato is having a technical issue.

One of the main computers which I’ve been using, that is named ‘Plato’, that was running Debian / Stretch, has experienced a major technical problem. When I got home this afternoon, I found it was not running. And, when I pushed the power button, it did not turn on.

A basic, automatic idea which would pop into people’s heads is, ‘The power-supply burned out.’ If the only task which lies ahead really was, to replace the power supply, I’d have it easy. This is a tower-computer from the year 2011, with a Sabertooth X58 motherboard.

  • The correct power-supplies for this old MB may have become hard to find,
  • Even if I had a replacement power-supply, it would be very cumbersome to replace because the harnesses of the present one loops behind too many recessed compartments, within the case.

The only thing I’ve done so far, is to perform a diagnostic test. I disconnected all the jacks between the power-supply and the MB, and retried the power button. My purpose behind that was, the idea that modern power supplies will refuse to turn on, if they sense a short-circuit between their load, and ground. Thus, if the power supply had been able to resume, with the MB disconnected, I’d know it was the MB, and I’d also know there’s no point in replacing the power-supply. But thankfully, the power-supply also did not power up like that. So I reconnected the power-supply to the MB.

So as it stands, I don’t know the best way to proceed, but am without the use of that trusty computer for now.

(Update 2/7/2019, 14h15 : )

One reason this apparent loss is unfortunate is the fact that, being my only Debian / Stretch computer, that computer was also the only one, which had “SageMath” installed and working on it. So my available Computer Algebra Systems are reduced to “Maxima” and “Yacas” for now.

(Update 2/9/2019, 18h50 : )

Actually, I’ve learned that my so-called diagnostic test was pointless. The power button these days, does not have a direct connection to the power-supply, to signal that the power-supply should turn on. The power button has its connection to the M.B., which tells the power-supply to turn on. Therefore, with the M.B. disconnected from the power-supply, there was no way for the power-supply even to get the signal, to turn on.

A personal friend of mine has lent me a power-supply tester, so that I’ll next be able to test that more properly. And, hoping that it is just the power-supply which is faulty, I’ll look into replacing it.

(As of 2/7/2019, 14h15 … )

Continue reading My computer Plato is having a technical issue.

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.

A Hypothetical Algorithm…

One of the ideas which I’ve written about often is, that when certain Computer Algebra Software needs to compute the root of an equation, such as of a polynomial, an exact Algebraic solution, which is also referred to as the analytical solution, or symbolic Math, may not be at hand, and that therefore, the software uses numerical approximation, in a way that never churned out the Algebraic solution in the first place. And while it might sound disappointing, often, the numerical solution is what Engineers really need.

But one subject which I haven’t analyzed in-depth before, was, how this art might work. This is a subject which some people may study in University, and I never studied that. I can see that in certain cases, an obvious pathway suggests itself. For example, if somebody knows an interval for (x), and if the polynomial function of (x), that being (y), happens to be positive at one end of the interval, and negative at the other end, then it becomes feasible to keep bisecting the interval, so that if (y) is positive at the point of bisection, its value of (x) replaces the ‘positive’ value of (x) for the interval, while if at that new point, (y) is negative, its value for (x) replaces the ‘negative’ value of (x) for the interval. This can be repeated until the interval has become smaller than some amount, by which the root is allowed to be inaccurate.

But there exist certain cases in which the path forward is not as obvious, such as what one should do, if one was given a polynomial of an even degree, that only has complex roots, yet, if these complex roots nevertheless needed to be found. Granted, in practical terms such a problem may never present itself in the lifetime of the reader. But if it does, I just had lots of idle time, and have contemplated an answer.

(Updated 1/30/2019, 13h00 … )

Continue reading A Hypothetical Algorithm…