C_R

30 Reputation

0 Badges

1 years, 268 days

MaplePrimes Activity


These are replies submitted by C_R

@acer 

At the end it comes down to definitions what round bracket parentheses are used for in Maple. I tried my best to figure it out myself with the help of distributed bits and pieces of Maples help system. It did not work out.

The fact that () serves several purposes makes an accurate definition challenging but not impossible. I have always been impressed by the consistence and accuracy of Maples help system, but maybe () is simply too big to be addressed appropriately.

I still have the feeling that we touch matters here that will stay with Maple forever. The more I think about it, the more I am puzzled that no explicit mentioning of the syntactic purposes of () is available.

Thanks again for clarifying!

 

PS.: You are right about whattype. I should have deleted it. It is a remainder of my struggle to work it out myself.

 

 

 

Thank you, this helped allot!

I really cannot understand why such a cool feature (most computer languages do not provide) is not worth mentioning in Maples official documentation. If my interpretation is correct ()() is rather a special syntax than anything else. A few sentences and examples in the programming guide would probably be sufficient.

After my delightful (and time consuming) but finally unsuccessful consultation of Maples help system I can at least see that it is not so easy to find an appropriate place for ()(). Its neither an operator nor a function (ignoring for a moment that almost everything is a procedure in Maple). It takes actions on “things” which can be arguments, parameters, or variables (and probably more). On top of it, parentheses are widely used in math and can therefore lead to misinterpretations in a different context. Compared to this, [] and {} are rather simple to interpret. On the contrary, math without parentheses is difficult to imagine. Even more astonishing is the fact that Maples help system is silent when it comes to parentheses. Still with the help of your explanations, it all makes sense now how ()() functions. So why not: do good things and talk about it?

From an academic standpoint I am still curious where (if at all) parenthesized expressions are located in Maples list of operator precedence.   

From a practical standpoint I am wondering if there is anything that can only be done with ()() syntax.

With all these insights I have taken the opportunity to brush up my “experiments” on ()() in the attached worksheet. I hope they are helpful for others – provided that they can find them here.
 

Parentheses
From: help("ProgrammingGuide,Chapter02")

The left and right parentheses group terms in an expression, arguments in a function call, and parameters in a procedure definition.

(a+b)*c; cos(Pi);
proc( x, y, z )
  x+y+z;
end proc:

(a+b)*c

 

-1

(1)

The left and right parentheses are also used to select components from certain data structures (programmer indexing).

 

 

In the absense of a dedicated help page one could add:

 

()(): Two pairs of parentheses

A pair of left and right parentheses (the left pair) entered directly before a second pair of parentheses (the right pair) group terms (of the left pair) before acting on terms of the second pair.

The content of left pair "transforms" the content of the right pair to an output.

No whitespace is allowed between pairs. An element-wise operator "~" can be placed between the parentheses.

 

Examples:

 

map() vs. ()()

map(proc (x) options operator, arrow; x+10 end proc, [1, 2, 3])

[11, 12, 13]

(2)

`~`[proc (x) options operator, arrow; x+10 end proc]([1, 2, 3])

[11, 12, 13]

(3)

`~`[proc (x) options operator, arrow; x+10 end proc]([1, 2, 3])

[11, 12, 13]

(4)

expr := u[1, 1]*u[2, 3]+u[1, 1, 2]

u[1, 1]*u[2, 3]+u[1, 1, 2]

(5)

map(`[]`@op, indets(expr, indexed));

{[1, 1], [2, 3], [1, 1, 2]}

(6)

(`[]`@op)~(indets(expr, indexed));

{[1, 1], [2, 3], [1, 1, 2]}

(7)

`~`[`[]`@op](indets(expr, indexed));

{[1, 1], [2, 3], [1, 1, 2]}

(8)
 

White space between parentheses, nested parentheses and more than two parentheses  

((f(x))(g))(x)NULL

((f(x))(g))(x)

(9)

(f(x))(g(x))

(f(x))(g(x))

(10)

f(x)*g(x)

f(x)*g(x)

(11)
 
The grouping effect of the left pair of parentheses

`~`[`@`(`[]`, op)](indets(expr, indexed))

{[1, 1], [2, 3], [1, 1, 2]}

(12)

`@`(`[]`, `~`[op](indets(expr, indexed)))

`@`(`[]`, {1, 2, 3})

(13)

' ' instead of ()

`~`['`@`(`[]`, op)'](indets(expr, indexed))

{[1, 1], [2, 3], [1, 1, 2]}

(14)
 

Number of terms

One term

whattype(`^`)

procedure

(15)

2 terms

whattype(seq)

procedure

(16)

3 terms (2 one the lhs, 1 on the rhs)

`~`[whattype]([sin, cos, sin^2, cos^2, 1])

[procedure, procedure, `^`, `^`, integer]

(17)

a^b

a^b

(18)

(seq, seq)(i, i = 1 .. 4)

1, 2, 3, 4, 1, 2, 3, 4

(19)

(cos^2+sin^2 = 1)(x)

cos(x)^2+sin(x)^2 = 1

(20)

whattype(a^b)

`^`

(21)

whattype(1, 2, 3, 4, 1, 2, 3, 4)

exprseq

(22)

whattype(cos(x)^2+sin(x)^2 = 1)

`=`

(23)

whattype(a, b)

exprseq

(24)

whattype(i, i = 1 .. 4)

exprseq

(25)

On the rhs 2D-Math x = x was not applied. Instead 1D-Math (1)(x)=1 was executed.  

 

() vs. ()()

sin(x)

sin(x)

(26)

a^b

a^b

(27)

lhs(a = b)^2/rhs(a = b)^2

a^2/b^2

(28)

f(g(h(x)))

f(g(h(x)))

(29)

plot(sin)

 

sin(x)

sin(x)

(30)

a^b

a^b

(31)

((lhs/rhs)^2)(a = b)

a^2/b^2

(32)

(`@`(`@`(f, g), h))(x)

f(g(h(x)))

(33)

plot(sin)

 
 

 

Other related help pages

help("syntax") a parenthesized expression "

help("operators,precedence")

help("examples,functional") 

help("Definition,bracket")

help("term")

 

NULL


 

Download On_parentheses.mw

Can you provide an enlarged screen shot?

“Substitute Into”: I am not sure if I understand correctly. What I frequently do is for example: subs((2),(1)). Here I do not need to attribute a name to (1) in order to substitute something into it.

But maybe you refer to the following behavior of Maple that I overlooked: When hiding an equation label by Format>Equation Labels>Selection each instance of an equation label in a Maple input is replaced by the output the equation label is referring to. This could cause two unwanted effects: Firstly, all Maple inputs referring to equation labels to be hidden would blow up by output insertion. Secondly, this replacement process might be not reversible (although it is in the attached example on “hidden labels” in text passages; see Note 1).

With that in mind only two supposedly low hanging fruits are left from my original list:

  • In a text passage or Maple input: Double click on a label reference to open the insert label dialogue (crtl-L) in order to change the reference (instead of deleting the reference and inserting a new reference). A nice time saver because I frequently have to correct or modify input.
  • For larger documents: A search function for equation labels in a document.

Would this be feasible without changing the equation label iimplementaion too much?

In case a rethink of equation labels is something you consider it might be an opportunity to rename them to “expression labels” since they refer to much more than equations.

 

Labeling_inside_text_passages.mw

Although, I have not observed any issues with the pdf export for my examples, I fully support that there is a strong need for a working and bug free export function.

Maple made strong progress in providing solutions for industry. These guys need in most cases proper and (even more important) error free documentation to document their work.

I also tried rtf export for further processing with word which resulted in unsatisfactory screen layout (I remember missing equation labels in Maple 2020).

If Maple 2021 export to Latex is so good as it seems why not converting this by a “smart” integrated converter to pdf.

Page 1 of 1