epostma

1494 Reputation

19 Badges

16 years, 42 days
Maplesoft

Social Networks and Content at Maplesoft.com

Maple Application Center
I am the manager of the Mathematical Software Group, working mostly on the Maple library. I have been working at Maplesoft since 2007, mostly on the Statistics and Units packages and on contract work with industry users. My background is in abstract algebra, in which I completed a PhD at Eindhoven University of Technology. During my studies I was always searching for interesting questions at the crossroads of math and computer science. When I came to Canada in 2007, I had nothing but a work permit, some contacts at Maplesoft (whom I had met at a computer algebra conference a year earlier), and a plan to travel around beautiful Canada for a few months. Since Maplesoft is a company that solves more interesting math and computer science related questions than just about anywhere else, I was quite eager to join them, and after about three months, I could start.

MaplePrimes Activity


These are Posts that have been published by epostma

Hi everyone,

I'd like to draw your attention to a package we recently uploaded to the Maple Cloud, here. You can download the package from the linked Cloud page, or directly from here as a workbook file: NaturalLanguage.maple. I'll include a lightly edited version of the "cover sheet" that introduces the package below. I have left the first four sections folded closed - you can see those in the linked Maple Cloud page or the workbook - because I think the last section is the most interesting.
 

Using natural language models in Maple


This package explores using large language models such as ChatGPT for processing natural language in Maple. Let's load the package from source, save it in this workbook, and load it.

restart

read "this:///lib/NaturalLanguage.mpl"

savelib('NaturalLanguage', "this://")

with(NaturalLanguage)

Warning, the NaturalLanguage package is an experimental package designed as an interface to publicly available large language models such as ChatGPT. Use of this package is entirely at the user's risk. Results may be inconsistent, misleading, or flat out incorrect. 

[Explain, GetCommand, GetMath, Query, RawQuery]

(1)

We note there is a warning: we will see output of large language models, which will often include inaccurate statements. Please keep this in mind - this is not (yet?) technology that you want to use to build a bridge!

We also note that there are five publically exposed commands. Let's look at them in turn.

RawQuery

   

Query

   

GetMath

   

GetCommand

   

Explain

 
• 

The Explain command asks the given model to explain the item in the query. After an explanation, you can ask for more detail by issuing the command Explain(more), Explain("go on"), Explain(elaborate), Explain(further), Explain("continue"), or minor variations. The item you ask about can be a mathematical expression, equation, list of equations, or a string.

• 

The default model is GPT-4; you can select the other model by using the model = ChatGPT option, or forcing use of the GPT-4 model by using the model = GPT4 option. Note that OpenAI may deprecate and disable models, so the set of models supported may change in the future.

display(Explain(x^2+y^2=1));display(Explain(x^2+y^2 = 1))

This equation represents a circle with a radius of 1 centered at the origin (0,0) on a coordinate plane.

 

display(Explain(more));display(Explain(more))

The equation x^2 + y^2 = 1 represents a circle in a two-dimensional plane (specifically, a Cartesian plane).

The center of the circle is at the origin of the coordinates (0,0) and its radius is 1. This is because any point (x, y) on the circle is a distance r (the radius) away from the center, and by the Pythagorean theorem, this distance is given by the square root of (x^2 + y^2). The fact that x^2 + y^2 = 1 implies that the radius r = sqrt(1) = 1.

This fundamental equation is also the unit circle in trigonometry, where angles are measured in radians. The coordinates (x, y) represent the cosine and sine of the angle respectively. The unit circle is a crucial concept in trigonometry, complex number theory, and calculus. It simplifies many mathematical concepts and provides a geometric interpretation of a variety of phenomena in physical sciences and engineering.

 

display(Explain(Re(exp(x*I + y*I)) = Re(exp(x*I)) * Re(exp(y*I)) - Im(exp(x*I)) * Im(exp(y*I))));display(Explain(Re(exp(I*x+I*y)) = Re(exp(I*x))*Re(exp(I*y))-Im(exp(I*x))*Im(exp(I*y))))

The equation seems to be using Euler's formula, which states that e^(ix) = cos(x) + i*sin(x). The 'Re' refers to the real part of a complex number, and 'Im' refers to the imaginary part. So, if you put Euler's formula in there your equation is equivalent to cos(x + y) = cos(x)cos(y) - sin(x)sin(y), which is basically the well-known trigonometric formula for the cosine of a sum. In a nutshell, it's dealing with the trigonometric identities and properties of exponential functions with complex numbers.

 

display(Explain("go on", model = ChatGPT));display(Explain("go on", model = ChatGPT))

The given equation appears to be dealing with the real part of a complex exponential expression. Let's break it down step by step to understand its meaning:

1. The equation involves the expression e^(i*x+i*y), where e represents Euler's number (~2.718), i is the imaginary unit (√(-1)), and x and y are real numbers.
2. The expression e^(i*x+i*y) can be rewritten using Euler's formula: e^(i*x+i*y) = cos(x+y) + i*sin(x+y). This is a complex number in the form a + bi, where 'a' represents the real part (Re) and 'b' represents the imaginary part (Im).
3. The real part of e^(i*x+i*y) is, therefore, Re(e^(i*x+i*y)) = cos(x+y).
4. The right side of the equation consists of the product of two complex exponential expressions: Re(e^(i*x))*Re(e^(i*y))-Im(e^(i*x))*Im(e^(i*y)).
5. The expression Re(e^(i*x)) represents the real part of e^(i*x), which is cos(x), and Im(e^(i*x)) represents the imaginary part of e^(i*x), which is sin(x).
6. Similarly, Re(e^(i*y)) represents the real part of e^(i*y), which is cos(y), and Im(e^(i*y)) represents the imaginary part of e^(i*y), which is sin(y).
7. Therefore, the right side becomes: (cos(x)*cos(y)) - (sin(x)*sin(y)).

So, the equation Re(e^(i*x+i*y)) = Re(e^(i*x))*Re(e^(i*y))-Im(e^(i*x))*Im(e^(i*y)) essentially states that the real part of e^(i*x+i*y) (i.e., cos(x+y)) is equal to the real part of e^(i*x) (i.e., cos(x)) multiplied by the real part of e^(i*y) (i.e., cos(y)), minus the imaginary part of e^(i*x) (i.e., sin(x)) multiplied by the imaginary part of e^(i*y) (i.e., sin(y)).

In simpler terms, the equation is connecting the real part of the sum of two complex exponential expressions with the product of the real parts and the difference of the imaginary parts of those individual expressions.

 

display(Explain(Re(sigma) < 0));display(Explain(Re(sigma) < 0))

The inequality "Re(sigma) < 0" is a statement in complex number theory. It is saying that the real part (Re) of a complex number sigma is less than zero. This means that the complex number is to the left of the imaginary axis in the complex number plane. This kind of inequality is often used in the study of complex functions, in areas such as control systems or signal processing in electrical engineering, and also in number theory and the study of dynamical systems in mathematics.

 

display(Explain(continue));display(Explain(continue))

The inequality "Re(sigma) < 0" is typically related to the field of complex numbers. Here, "Re" stands for the real part of a complex number and "sigma" is usually used to represent a complex number. So, "Re(sigma) < 0" is saying that the real part of the complex number sigma is negative.

Complex numbers are usually written in the form a + bi, where a and b are real numbers and i is the imaginary unit. The "Re" in "Re(sigma)" refers to the a part of this form, i.e. the real part of the complex number.

This inequality is often found in fields like control systems engineering or signal processing. For instance, in control systems, all the poles of a stable system must have a negative real part. Another context you might come across this inequality is in complex analysis, one might examine the region where the real part of a complex function is negative. So, the inequality "Re(sigma) < 0" expresses that a complex number is in the left half of the complex plane, which is often crucial for the stability of many systems in engineering.

 

display(Explain("The Maple command simplify"));display(Explain("The Maple command simplify"))

The Maple command "simplify" is used to simplify mathematical expressions. In Maple, this command applies various rules to reduce an equation or expression to its simplest or most compact form.

For example, if you have an equation like `(x^3 - x^2)/x^2`, using the simplify command would reduce it to `x - 1`. It simplifies algebraic expressions, performs factorization, combines like terms, cancel out common factors, etc.

The general syntax is `simplify(expr)`, where `expr` is the expression that you want to simplify. The simplified expression is returned as output.

Please note that the simplifications made by this command are based on general rules and may not always give the expected results for some specific expressions due to the complexity of mathematical simplifications.

 

display(Explain(continue, model=ChatGPT));display(Explain(continue, model = ChatGPT))

The Maple command "simplify" is used to simplify mathematical expressions. It takes an expression as input and attempts to find a simplified form by applying various algebraic rules and simplification techniques.

When you use the "simplify" command, Maple applies a series of simplification steps, which can include:

1. Expanding and factoring polynomials: This step expands products of terms and factors out common terms.
2. Simplifying fractions: The command simplifies fractions by canceling common factors in the numerator and denominator.
3. Simplifying trigonometric expressions: Maple applies trigonometric identities to simplify expressions involving trigonometric functions.
4. Simplifying logarithmic and exponential expressions: The command applies rules of logarithms and exponents to simplify expressions with these functions.
5. Simplifying square roots and radicals: It simplifies square roots by expressing them in simplest radical form.
6. Simplifying expressions involving absolute values: Maple simplifies absolute value expressions by considering different cases based on the sign of the argument.
7. Applying mathematical identities and rules: The command uses various mathematical identities and rules to simplify expressions further.

The "simplify" command in Maple is very powerful and can handle a wide range of mathematical expressions. However, it may not always produce the most simplified form, as simplification can sometimes be a subjective task. In such cases, you can try using other commands or options available in Maple to refine the simplification process.

To use the "simplify" command in Maple, you can simply type "simplify(expression)" where "expression" represents the mathematical expression you want to simplify.

 

display(Explain("Weight of a W10X54 beam?"))

The weight of a W10X54 beam refers to the weight specification of a beam in the W Beam series, commonly used in construction and engineering projects. The nomenclature "W10X54" is decoded as follows:

- W: it stands for 'wide flange', a type of structural steel beam where the flanges are parallel to each other.
- 10: it indicates the nominal depth of the wide flange, which is about 10 inches.
- 54: it indicates the weight of the beam per linear foot, which is about 54 pounds.

So, a W10X54 beam weighs 54 pounds per foot.

 

display(Explain(further))

"Weight of a W10X54 beam" refers to the weight of a specific kind of structural steel beam used in construction and architecture. The "W" stands for "wide flange", which is a particular type of I-beam.

The "10" means the nominal depth of the beam in inches (also known as its height when standing upright).

The "54" represents the beam's weight per foot in pounds. In other words, for every foot of length the beam has, it weighs 54 pounds.

 So if you have a W10X54 beam that is 10 feet long, its total weight would be 540 pounds (10 feet times 54 pounds per foot).

Please note that these are nominal dimensions and may not exactly match the true dimensions of the beam due to manufacturing variables.

 

NULL

 

What do you think? Will this be an important part of mathematical software in the near future, or are we still far away from that point? We'd love to hear your opinions.

Hi everyone! It's been a remarkably long time since I posted on MaplePrimes -- I should probably briefly reintroduce myself to the community here. My name is Erik Postma. I manage the mathematical software group at Maplesoft: the team that writes most of the Maple-language code in the Maple product, also known as the math library. You can find a longer introduction at this link.

One of my tasks at Maplesoft is the following. When a request for tech support comes in, our tech support team can usually answer the request by themselves. But no single person can know everything, and when specialized knowledge of Maple's mathematical library is needed, they ask my team for help. I screen such requests, answer what I can by myself, and send the even more specialized requests to the experts responsible for the appropriate part of the library.

Yesterday I received a request from a user asking how to unwrap angles occurring in an expression. This is the general idea of taking the fact that sin(phi) = 'sin'(phi + 2*Pi), and similarly for the other trig functions; and using it to modify an expression of the form sin(phi) to make it look "nicer" by adding or subtracting a multiple of 2*Pi to the angle. For a constant, real value of phi you would simply make the result be as close to 0 as possible; this is discussed in e.g. this MaplePrimes question, but the expressions that this user was interested in had arguments for the trig functions that involved variables, too.

In such cases, the easiest solution is usually to write a small piece of custom code that the user can use. You might think that we should just add all these bits and pieces to the Maple product, so that everyone can use them -- but there are several reasons why that's not usually a good idea:

  • Such code is often too specialized for general use.
  • Sometimes it is reliable enough to use if we can communicate a particular caveat to the user -- "this will not work if condition XYZ occurs" -- but if it's part of the Maple library, an unsuspecting user might try it under condition XYZ and maybe get a wrong answer.
  • This type of code code generally doesn't undergo the careful interface design, the testing process, and the documentation effort that we apply to the code that we ship as part of the product; to bring it up to the standards required for shipping it as part of Maple might increase the time spent from, say, 15 minutes, to several days.

That said, I thought this case was interesting enough to post on MaplePrimes, so that the community can take a look - maybe there is something here that can help you with your own code.

So here is the concrete question from the user. They have expressions coming from an inverse Laplace transform, such as:

with(inttrans):
F := -0.3000*(-1 + exp(-s))*s/(0.0500*s^2 + 0.1*s + 125);
f := invlaplace(F, s, t)*u(t);
# result: (.1680672269e-1*exp(1.-1.*t)*Heaviside(t-1.)*(7.141428429*sin(49.98999900*t-
#         49.98999900)-357.*cos(49.98999900*t-49.98999900))+.1680672269e-1*(-7.141428429*sin
#         (49.98999900*t)+357.*cos(49.98999900*t))*exp(-1.*t))*u(t)

I interpreted their request for unwrapping these angles as replacing the expressions of the form sin(c1 * t + c0) with versions where the constant term was unwrapped. Thinking a bit about how to be safe if unexpected expressions show up, I came up with the following solution:

unwrap_trig_functions := module()
local ModuleApply := proc(expr :: algebraic, $)
  return evalindets(expr, ':-trig', process_trig);
end proc;

local process_trig := proc(expr :: trig, $)
  local terms := convert(op(expr), ':-list', ':-`+`');
  local const, nonconst;
  const, nonconst := selectremove(type, terms, ':-complexcons');
  const := add(const);
  local result := add(nonconst) + (
    if is(const = 0) then
      0;
    else
      const := evalf(const);
      if type(const, ':-float') then
        frem(const, 2.*Pi);
      else
        frem(Re(const), 2.*Pi) + I*Im(const);
      end if;
    end if);
  return op(0, expr)(result);
end proc;
end module;

# To use this, with f defined as above:
f2 := unwrap_trig_functions(f);
# result: (.1680672269e-1*exp(1.-1.*t)*Heaviside(t-1.)*(7.141428429*sin(49.98999900*t+
#         .27548346)-357.*cos(49.98999900*t+.27548346))+.1680672269e-1*(-7.141428429*sin(
#         49.98999900*t)+357.*cos(49.98999900*t))*exp(-1.*t))*u(t)

Exercise for the reader, in case you expect to encounter very large constant terms: replace the calls to frem above with the code that Alec Mihailovs wrote in the question linked above!

Student's t distribution is named after William Sealy Gosset's pseudonym, Student. He published using this pseudonym because his employer, the Guinness brewery in Ireland, did not allow its employees to publish scientific papers after an incident where trade secrets were disclosed. In this blog...

This post is a further development of my earlier question in reply to John's post. I have implemented a basic version of the CANDECOMP/PARAFAC algorithm referred to on Wikipedia and described 

 

This is the fourth and final part of a blog post, the first three parts of which can be found here: Generating Samples from Custom Probability Distributions (I)

1 2 Page 1 of 2