Carl Love

## 23943 Reputation

9 years, 309 days
Natick, Massachusetts, United States
My name was formerly Carl Devore.

## simplify...

Change from 0.5 to 1/2. Then simplify f(x) before plotting:

plot(simplify(f(x)), x= 0..10); I wouldn't call it a "bug". It's just the usual floating point abnormalities that come from evaluating a complicated expression. Note that the unsimplified f(x) has 10 positive and 10 negative terms with denominators ranging from 10 to 19,353,600 and powers as high as x^10.

## Sampling distributions: Binomial, Hyperg...

Let's suppose that the population is infinite, or at least so large that the 100 people are an insignificant fraction of it. Then the "sampling distribution" is Binomial(100, 0.3). Suppose that we want to draw 9 samples of size 100 from that population, and count the number in each sample who'll get sick:

[seq](trunc(x), x= Statistics:-Sample(Binomial(100, .3), 9));

[28, 20, 26, 36, 35, 38, 33, 40, 23]

Now let's suppose that the population is some known relatively small number, say 300. Then the number of those who'll get sick is 300*0.3 = 90. Still, we want 9 samples of size 100. The sampling distribution is Hypergeometric(300, 90, 100)

[seq](trunc(x), x= Statistics:-Sample(Hypergeometric(300, 90, 100), 9));
[32, 30, 28, 38, 33, 25, 28, 33, 29]

## expand(simplify(...))...

The desired form can be obtained by

In other words, eq_5_23 is used to eliminate L__ad from eq_5_22. It makes no difference whether you use eq_5_23 or eq_5_23x. There's a way to combine the operations simplifyeval, and solve in the above called "simplifying with side relations" (see help page ?simplify,siderels):

I'm having trouble conceiving of this operation as a generalized form of the standard algebraic operation "collecting", but I haven't given it much thought.

## Function vs procedure; argument vs param...

There are three distinct ways to interpret your Question. By "distinct", I mean that your Question is not vague; the different interpretations are based on different definitions of function and input, which are words that you used in your Question. @tomleslie  and @dharr  have each given correct solutions (although Tom's is far more elaborate than need be) to exactly one of those interpretations (each picking a different interpretation). But I am convinced that it's that third as-yet-unmentioned interpretation that you're really interested in, although you may not realize that yet.

First, we need precise definitions of functionprocedureparameter, and argument in the specific context of Maple code and this Question.

Function and procedure (which are fairly common words of technical English) are often used somewhat interchangeably in computer science, in the Maple community (such as this forum), and even in Maple documentation. However, when they are used as type names in Maple code, they are completely distinct, mutually exclusive, without overlap [I realize that that's redundant; I'm just emphasizing]. Both function and procedure are keywords that can be used as type names in Maple code.

FunctionSuppose that f is an unassigned variable (aka, a symbol or name). Then expressions such as f()f(a,b,c), and f(1,2,3) are of type function. The a, b, c,  1, 2, 3, etc. are called arguments. Functions (in this sense) are simply static data structures; they don't "do" any computations; rather, they are objects upon which computations are done. (In the complete definition of type function, the f can be more general than just a symbol or name; however, those cases alone are adequate to complete this discussion.) Note that f by itself is not a function. A function must have an argument sequence, even if it's empty as with f()

Procedure: An expression such as (x, y, z)-> (x+y)/z is a procedure. (There are other ways to make procedures, but the arrow -> is sufficient for our purposes.) The items on the left side of the -> are called parameters; unlike arguments, they are always names (and, more specifically, symbols).

Usually (but certainly not always) a procedure will be assigned to a name, as in p:= (x, y, z)-> (x + y + z). Then the procedure can be "called" (aka "invoked", "run", "used", "executed") via p(a, b, c)p(1, 2, 3), etc. The a, b, c,  1, 2, 3, etc. are called arguments, just like with a function. Procedures can be called in other ways, but the values substituted for (or passed to) the parameters are still called arguments. Note that the procedure is the assigned value of itself and alone; in contrast to a function, it's not the presence of arguments that makes it a procedure; rather it's the presence of a parameter sequence (which is possibly the empty sequence) in the assigned value that does that.

So, the word "input" that you used in your Question could mean either parameters or arguments, and the word "function" that you used could mean either function or procedure. You haven't used the words incorrectly; rather, the issue is that their common definitions in technical English aren't precise enough for this Question. The three possible interpretations of your Question are that you want to count

1. the arguments of a function,
2. the arguments passed to a procedure, or
3. the parameters of a procedure.

So, you may be thinking that there's a fourth possibily---the parameters of a function---but there's no such thing under the precise definition of function being used here.

Maple syntax allows a procedure to be passed a different number of arguments than it has parameters. The count of arguments or parameters is called arity, which is a noun derived from the adjectival suffix -ary used in words such as binaryunarynullaryternary, etc. In other words, arity is the formal word for what you've called "input number" and "domain number".

• Tom's Answer shows an excessively elaborate method to count the arguments of a function. It's excessive because it can be done simply with the command nops, e.g., nops(f(a, b, c)) returns 3. The command name nops stands for number of operands

• The Answer by dharr shows a method to count the number of arguments passed to a procedure. The keywords _npassed or nargs can be used for this. They mean exactly the same thing. These keywords are only meaningful when used within the code of the procedure.

• But I think that you want to count (and also, to list) the parameters of a procedure. That's the only way to perform the operation that you pseudo-coded in your Reply to dharr's Answer.

A procedure created with the arrow -> is also of type operator. The code I give in the rest of this Answer is only meant to be used with that type of procedure. Other procedures allow for far-more-complicated kinds of parameter specifications for which this code will not always work.

The parameters of an operator-procedure (such as p given above) can be counted by

nops([op](1, eval(p)))

The symbols of its parameters can be listed by

convert~(op~(1, [op](1, eval(p))), `local`)

Using this, your pseudo-coded example can be written in Maple like this:

F:= (x,y,z)-> (r[x]+r[y])*r[z]:

G:= proc(f::And(procedure, operator), n::nonnegint)
local params:= convert~(op~(1, [op](1, eval(f))), `local`)[];
(`+`(params) + f(params)/2)*n
end proc
:

G(F, 3);

This is a generalization of the procedure dharr gave for the same puspose. It'll work for some cases for which his will not, (although I think it's likely that his will work for all the cases that you're actually interested in). The 3 problematic cases are

1. procedures that aren't operators: my code specifically rejects them;
2. parameter symbols which have been assigned values as global variables: these will work superficially with dharr's code, but the output value will change when it's "evaluated", which is very likely to happen automatically;
3. parameters with a type specification, such as n::nonnegint.

## Mental-Maple solution...

Here are the steps that I used. I only used Maple to do a simplified version of the integral (and, later, to do a verification in exact arithmetic). I'm sure that more steps could be done with Maple, but I didn't try because doing them in my head was easy enough, and likely faster.

1. Use eq1 to eliminate c in eq2.
2. Factor (m/2/(m+2))^(1/m) out of the integral and move it to the other side of the equation.
3. The remaining integral is int((Z^2 - x^2)^(1/m), x= 0..Z). Maple 2022.1 will do this integral, giving me
(Z^2)^(1/m)*GAMMA(1/m+1)*Z*sqrt(Pi)/2/GAMMA(1/m+3/2).
4. Combine the powers of to get Z^((m+2)/m) and move the other factors to the other side of the equation.
5. Raise both sides to power m/(m+2) to get
Z = (alpha*2*GAMMA(1/m+3/2)/GAMMA(1+1/m)/sqrt(Pi)*(2*(m+2)/m)^(1/m))^(m/(m+2)).
6. Substitute this for in eq1 to get c.
7. I verified my solution for and c in exact arithmetic at alpha=6, m=2 (same as acer). I didn't do a decimal-arithmetic and/or numeric-integration verification. Amazingly, I didn't make a single mistake rearranging all those fractions in my head.

I've implicitly assumed Z >= 0; thus both the integrand and the integral are nonnegative.

## Inconsistent -- no solution...

The system can be seen with the naked eye (due to the repetition of coefficients) to be inconsistent. There is no solution. Indeed, in a sense, it's maximally inconsistent: Every pair of equations is inconsistent.

## Make coeffs return a table...

The way that coeffs is used in Christian Wolinski's Answer is so common to me (yet awkward also) that in almost all cases I replace coeffs with this:

Coeffs:= (e::algebraic, v::{list, set, thistype}({name, function}))->
local T, C:= coeffs(e,v,T); table(sparse, [T]=~[C])
:

This makes the usage more like coeff and much less awkward:

F:=2*y*sin(beta*x)+6*z*cos(beta*x)+24*sin(beta*x)*cos(beta*x):
C:= Coeffs(F, [sin,cos](beta*x)):

C[sin(beta*x)];

2 y

C[cos(beta*x)];
6 z

C[(sin*cos)(beta*x)];
24

My procedure Coeffs above is essentially the same as in the Answer that you linked to but that you said didn't work for you. The crucial difference that makes this one work for your case is that I included function in the allowed variable types.

## op...

Do you need to use specifically numer and denom for this purpose? If not, then you could just extract the 1st and 2nd operands of the inert quotient. For example,

x:= 3%/6:
op(1,x); op(2,x);

It's also possible to overload numer and denom so that they detect the presence of inert quotients and respond accordingly. This is fairly easy, but it's overkill if what I suggested in the first paragraph fulfills your need. On the other hand, an overload solution might be preferable if you want to apply numer and denom to general non-inert expressions that contain inert quotients as subexpressions.

## _nresults...

Reading Matlab's help page for deal, I see that its purpose is to work around a purely syntactic issue with multiple assignment. An equivalent in Maple could use the keyword _nresults, which gives a count of the number of operands on the left side of the assignment operator. The keyword only works inside a procedure; so since we need a procedure anyway, we might as well name it deal:

deal:= X-> `if`(_nresults=undefined, X, seq(copy(X), _nresults));

#Example:
(A,B):= deal(Matrix(2,2));

Note that copy behaves correctly even for objects that can't be copied (which are called immutable in Maple).

Maple has a package named MTM (not to be confused with the package named Matlab) that has Maple analogues of a large number of Matlab commands with exactly the same names that they have in Matlab. (But it doesn't have deal.) Thus, this package helps you translate Matlab code to Maple. The MTM package works strictly within Maple; on other the hand, the Matlab package is for sending commands to an actively running copy of Matlab.

## What are you "solve"ing?...

I don't understand the purpose of your solve commands, and I don't think Maple understands either. What is m? The highly symbolic output of these solve commands is obviously useless for plotting the 4 vertices of a rectangle.

Are you trying to circumscribe an ellipse with the minimal rectangle whose sides are parallel to the coordinate axes? If so, then your aa and bb should be the maximal x and y values on the ellipse. These can computed via implicit differentiation (command implicitdiff(ell, y, x)) for arbitrary ab, and theta. I get

aa:= sqrt((a^2-b^2)*cos(theta)^2 + b^2);
bb:= sqrt((b^2-a^2)*cos(theta)^2 + a^2);

## indets...

If p is the PLOT structure, then do

rhs~(indets(p, "originalview"=anything))[];
[-0.986250000000000071 .. 9.98625000000000007, -1. .. 1.]

Using "magic" position numbers and op seems risky: The numbers could easily change. Using getdata is slightly more robust, but still involves magic numbers. My method is based on the keyword "originalview"; it uses no magic numbers.

Edit: The identical(...that I had before is superfluous: A string constant can be used itself as a type.

## Posts vs Questions...

I recently wrote a lengthy description of the distinction between Posts and Questions. It is the second Comment attached to this Post. The vast majority of threads are classified as Questions. For example, clicking on "Active Conversations" shows all threads in reverse chronological order by most-recent update, 50 per page. At the moment the first page shows 44 Questions and 6 Posts.

Regarding the phrase "posting a question": Yes, in common English, one definition of the verb to post is to place written material where it can be read by the general public. This usage is hundreds of years old. English has several times as many nouns as verbs. The definitions of the verbs gradually become more general than the nouns (if any) that they were originally associated with. (A post is a long piece of wood driven into the ground. Attaching written material to a post thus became posting it.)

It's not clear to me whether you just want to add the numeric entries, or if you want to do something else as well. If you just want to add the numeric entries, then all that you need to do is

The entries that haven't been defined will simply be ignored; there's no need for you to sort or remove or account for them in any way.

I strongly recommend that in the future, you use Array, not array, which has been obsolete for nearly 20 years.

## solve, log10...

Q1: To get all 3 complex solutions, you can do

solve(c^3 = 1000)

To restrict solutions to the real case, do

solve({c^3 = 1000, c > 0})

Q2: The command for a base-10 logarithm is log10(...). The command for a base-b logarithm is log[b](...), and that can also be used when b=10.

Q3: The inverse function of y=log[b](xis x=b^y.

## nprintf and MathML...

I don't think that it's possible to get color-enriched text with printf (not sure about that). But it can be done with nprintf (which has identical syntax to printf) like this:

```#With the improvements suggested by acer:
Vprint:= (v::{string, symbol}, k)->
nprintf('`#mrow(mn("%s]", mathcolor= "green"), mn(" is %a"));`', v, k)
:
Vprint(`1:1`, 4);
```

The operators inside the string (mrowmn,  mo, etc.) are not documented in Maple's help. They're from a language called MathML for which there are numerous online help pages. For example, Google search "MathML mrow" (without the quotes). (There are some MathML features that don't work in Maple.)

The green can be replaced by any 6-digit hexadecimal RGB (Red Green Blue) code preceded by #; for example, #00A000 is a medium green.

The same MathML operators (mrowmn, etc.) can be accessed from the Typesetting package, as shown by acer. Whether you do it with Typesetting or nprintf, Maple's Standard GUI display will prettyprint them the same. But Maple's kernel will treat them differently: The output of nprintf is a symbol (in the specific Maple sense of that word), and it can be used as a vertex label in a Graph; but the output of Typesetting is a function (in the specific Maple sense of that word), and it cannot be used in a Graph. If you're only interested in the prettyprinted display, acer's Typesetting method is easier to code in a procedure.

 1 2 3 4 5 6 7 Last Page 1 of 352
﻿