zenterix

400 Reputation

5 Badges

2 years, 363 days

MaplePrimes Activity


These are questions asked by zenterix

I am reading the Maple Programming Guide chapter 3 "Maple Expressions". There are subsections on "Indexed Expressions" and "Member Selection".

The following is based on reading these sections.

Consider the following module definition

m := module() export e, f:=2; end module:

What is the difference between m[e] and m:-e or m[f] and m:-f?

The documentation says that both evaluate module m's export e but the difference is that the index selection form will evaluate e before resolving the export.

What does this mean exactly?

When I try out in a worksheet both m[f] and m:-f return 2 and m[e] and m:-e return the name e.

I am going through the documentation on ScientificConstants and trying things out in a worksheet.

My first question about this package is about the following

with(ScientificConstants)

GetConstants()

`A[r](alpha)`, `A[r](d)`, `A[r](e)`, `A[r](h)`, `A[r](n)`, `A[r](p)`, E[h], F, G, G[0], K[J], M[Earth], M[Sun], M[u], N[A], Phi[0], R, R[Earth], R[K], R[infinity], V[m], Z[0], a[0], a[e], a[mu], alpha, b, c, c[1, L], c[1], c[2], e, epsilon[0], g, g[e], g[mu], g[n], g[p], gamma[e], gamma[n], gamma[p], gamma_prime[h], gamma_prime[p], h, hbar, k, l[P], lambda[C, mu], lambda[C, n], lambda[C, p], lambda[C, tau], lambda[C], m[P], m[alpha], m[d], m[e], `m[e]/m[mu]`, m[h], m[mu], m[n], m[p], m[tau], `m[tau]c^2`, m[u], mu[0], mu[B], mu[N], mu[d], `mu[d]/mu[e]`, mu[e], `mu[e]/mu[p]`, `mu[e]/mu_prime[p]`, mu[mu], mu[n], `mu[n]/mu_prime[p]`, mu[p], mu_prime[h], `mu_prime[h]/mu_prime[p]`, mu_prime[p], n[0], r[e], sigma, sigma[e], sigma_prime[p], t[P]

(1)

Copy and paste from the list above.

GetConstant(g[n])

neutron_g_factor, symbol = g[n], derive = 2*mu[n]/mu[N]

(2)

Manually try to type in g__n.

GetConstant(g__n)

Error, (in ScientificConstants:-GetConstant) `g__n` is not a known Constant

 

NULL

Why doesn't the latter work?

Download ScientificConstants.mw

I have multiple questions on how Units[TestDimensions] works from reading the Maple documentation. I will use this thread to ask them.

My first question regards the difference between Unit(expr) and units inserted using shortcut (CMD+SHIFT+U) on a mac?

restart

Automatically loading the Units[Simple] subpackage
 

 

What is the difference between the following two commands?

Units:-TestDimensions(x*Unit('m')+y*Unit('s'), output = dimensions)

{x::(length^(-1+_t3[7, 1])*mass^_t3[7, 2]*time^_t3[7, 3]*electric_current^_t3[7, 4]*thermodynamic_temperature^_t3[7, 5]*amount_of_substance^_t3[7, 6]*luminous_intensity^_t3[7, 7]*currency^_t3[7, 8]*amount_of_information^_t3[7, 9]*logarithmic_gain^_t3[7, 10]), y::(length^_t3[7, 1]*mass^_t3[7, 2]*time^(-1+_t3[7, 3])*electric_current^_t3[7, 4]*thermodynamic_temperature^_t3[7, 5]*amount_of_substance^_t3[7, 6]*luminous_intensity^_t3[7, 7]*currency^_t3[7, 8]*amount_of_information^_t3[7, 9]*logarithmic_gain^_t3[7, 10]), (x*Units:-Unit(m))::(length^_t3[7, 1]*mass^_t3[7, 2]*time^_t3[7, 3]*electric_current^_t3[7, 4]*thermodynamic_temperature^_t3[7, 5]*amount_of_substance^_t3[7, 6]*luminous_intensity^_t3[7, 7]*currency^_t3[7, 8]*amount_of_information^_t3[7, 9]*logarithmic_gain^_t3[7, 10]), (y*Units:-Unit(s))::(length^_t3[7, 1]*mass^_t3[7, 2]*time^_t3[7, 3]*electric_current^_t3[7, 4]*thermodynamic_temperature^_t3[7, 5]*amount_of_substance^_t3[7, 6]*luminous_intensity^_t3[7, 7]*currency^_t3[7, 8]*amount_of_information^_t3[7, 9]*logarithmic_gain^_t3[7, 10]), (x*Units:-Unit(m)+y*Units:-Unit(s))::(length^_t3[7, 1]*mass^_t3[7, 2]*time^_t3[7, 3]*electric_current^_t3[7, 4]*thermodynamic_temperature^_t3[7, 5]*amount_of_substance^_t3[7, 6]*luminous_intensity^_t3[7, 7]*currency^_t3[7, 8]*amount_of_information^_t3[7, 9]*logarithmic_gain^_t3[7, 10])}

(1)

Units:-TestDimensions(2*Unit(m)+y*Unit(s), output = dimensions)

{y::(length/time), (y*Units:-Unit(s))::length, (2*Units:-Unit(m)+y*Units:-Unit(s))::length}

(2)

NULL

I think my question is what is the difference between inserting units using CMD+SHIFT+U on a mac, which generates the units as seen in the first command, versus using Unit(expr) as in the second version of the command?

Download Units_-_TestDimensions.mw

I read in the programming guide that to print the body of Maple library commands we set the Maple interface variable `verboseproc` to 2 then use the print command passing in the procedure we're interested in as argument.

Built-in kernel commands are compiled in machine code and not written in Maple language so we cannot view their definitions.

According to the guide, if we try to print such procedures we will see that the procedure has only an `option builtin` statement and no visible body.

If I try to view `Units:-TestDimensions`, as follows

```interface(verboseproc=1);
print(Units:-TestDimensions);

```

then what I see is

In this case there isn't the `option builtin` but neither is there a visible body.

Is this procedure built-in or is there a way to see the code?

I am reading the documentation on the `Units[Simple]` package.

There is a section that says

"In the Simple Units environment, in contrast to the Standard and Natural environments, unassigned variables are not automatically assumed to represent unit-free quantities. For example, 5m+x is a valid expression if x is unassigned, because x may represent a length. On the other hand (5m+x)(6s+x) is an invalid expression because the first factor implies that x represents a length and the second factor implies that x is a duration."

The way I understood this paragraph is that in Units:-Simple an unassigned variable is not assumed to represent a unit-free quantity, but in Units:-Standard it is assumed to represent a unit-free quantity.

Consider the expression 5m+x. This expression works in Units:-Simple but not in Units:-Standard.

Units:-Simple adds a quantity 5m to a quantity without units. But why can one add a quantity with units to a quantity without units?

Units:-Standard tries to add a quantity 5m to a quantity that is assumed to have units. What units are assumed?

Next, consider (5m+x)(6s+x).

This fails in both packages, as can be seen below (actually, for some reason, the embed below is not showing the expressions typed in for Units:-Standard, but can be seen if you download the worksheet I imagine).

restart

with(Units:-Simple)

5*Unit('m')+x

5*Units:-Unit(m)+x

(1)

(5*Unit('m')+x)*(6*Unit('s')+x)

Error, (in Units:-Simple:-*) the following expressions imply incompatible dimensions: {5*Units:-Unit(m)+x, 6*Units:-Unit(s)+x}

 

restart

with(Units:-Standard)

(5*Unit('m')+x)*(6*Unit('s')+x)

Error, (in Units:-Standard:-+) the units `m` and `1` have incompatible dimensions

 

5*Unit('m')+x

Error, (in Units:-Standard:-+) the units `m` and `1` have incompatible dimensions

 

NULL

So my question is, what exactly is the difference between considering unassigned variables to be unit-free vs not unit-free?

Download Units_Simple_vs_Standard.mw

2 3 4 5 6 7 8 Last Page 4 of 20