How do I get rid of "unable to match delimiters" error message?

resolvent's picture

for n from 1 to 2
do
if(isprime(L[n]) then 7
else 9;
end if;
end do;

No matter combination of semicolons or colons I put
at the end of each line or omit,
I cannot get this little test routine not to spit
back "unable to match delimiters" error message.

L := [4, 5];
P1 := [-8, 9];
if (5 > 6) then P1[1]
else L[2];
end if;

Ironically, this routine worked. I do not see the difference.

acer's picture

mismatched round brackets

Remove the ( round bracket between "if" and "isprime".

acer

resolvent's picture

Good eye!

I did not catch the extra ) I needed.

The following routine

L := [4, 5]:
for n to 2
do
if (isprime(L[n])) then 7;
else 9;
end if;
end do;

executes with no error messages. But it
outputs nothing.

My output should be
9 # because L[1] = 4 is not prime
7 # because L[2] = 5 is prime

Also, I notice that when I cut and paste
my program from Maple into this textbox,
the line breaks disappear -
I had to put them back in above manually
- and the parentheses around
isprime(L[n])
disappear. I had to put those back in manually
just now, too. Why?

acer's picture

printlevel

I don't know anything about pasting into mapleprimes, sorry.

But the other issue, about what is printed, I can answer.

You code does not comprise a "routine". It's not a Maple procedure. It's what's known as "top-level" code.

As such, it is governed by Maple's printing rules. These can be changed (at the top-level, and also from within procedures) by using the printlevel setting. See ?printlevel for details.

The default is printlevel=1. So, with a for-do and if-then embedded within it, then anything occuring inside the `then` or `else` sections won't normally get printed.

But, now, set printlevel:=2 and run that code again. Both the 7 and the 9 are printed.

Of course, this is all just control of the display. Assignments and such get done regardless of whether their results are displayed.

Some people like to use print or printf statements to get certain things, and only certain things, printed by their code. Others make use of the fact that procedures, when run, will cause their returning values to be printed. I find that sufficient myself, and would recommend using procedures for even small tasks (for this, and lots of other reasons besides).

acer

resolvent's picture

Printlevel

Thanks!
printlevel:=2:
worked

printlevel=2:
failed. Just yielded 1=2 as output.
(1 being the default value for printlevel, as you said.)

resolvent's picture

How do I display "X = " X output on a single line? Max of list?

Please replace this text with the link to your file.
The link can be found in the File Manager

View 5348_Maple Flow Control Example.mw on MapleNet or Download 5348_Maple Flow Control Example.mw
View file details

Robert Israel's picture

How do I...

For "X = " X output:

> printf("X = %a\n",X);

For the max of a list W of numbers:

> max(op(W));
acer's picture

all one big comment

It appears as if the comments (starting with # symbol) and the code in the problem area of your Document are being interpreted by Maple as being all on one line. So anything that appeared after the comment symbol, including the code, was being treated as part of one big long comment. As one big comment, it wouldn't execute. At least, that's what it looked like after conversion to 1D input, and that would exactly match the behaviour being seen.

I suggest one of two possible ways to get around this problematic behaviour. The first is to write your code in 1D Math input, preferably in a Worksheet not a Document, where such discrepancies are very much rarer. (You can even change preferences, globally for future sessions, for both those aspects.) The second choice is to use text input for comments when using 2D Math and Documents.

The max() routine will give the maximum of an expression sequence. For a list L, the expression sequence of its contents is op(L). The printf() routine can format and print things nicely. It works much like it does in the C language. There is an additional qualifier, %a, which stands for algebraic (I think). For your code and list W, it could be like this

printf("Max = %a\n", max(op(W)));

acer

resolvent's picture

# comments?

What needless complications by Maple!
I OUGHT to be able to put
as many comment lines
into my Worksheet in Math Mode as I want.

I just checked.
If I have
# comment
Block of Maple math code

it executes properly.

But if I have
# comment 1
# comment 2
Block of Maple math code

I get the delimiting error message.

acer's picture

ignore

Please ignore. This was an accidental duplicate post.

acer

resolvent's picture

Comments disabled my program

My program - the uploaded one - has added comments
which have disabled my program. Why?

Robert Israel's picture

Comments

1) You're using Document mode and 2D Math input. Unless you need it, why not use Worksheet mode and 1D Maple input, where you can see what is Maple input and what isn't? In particular, it's much better for programming.

2) Comments with # are really old-style, appropriate for command-line Maple or worksheets in early releases of Maple V, before there were text regions. Apparently the document interface can't handle them correctly, but there's no need to use them. Use text regions instead.

But do I understand you correctly, that you didn't have those comments in the file before you uploaded it? Were they text regions before, and Maple converted them into comments in 2D math? That would be a rather bad bug.

resolvent's picture

Modes

I see nothing on the screen which tells me whether
I am in Worksheet or Document mode.
I just open with the default, which I believe
is Worksheet mode.
Also, I have just used the default math mode,
which is 2-D.
This is how things were set up when I first
opened Maple when I first bought it. These
are the modes I've stuck to ever since.

I've tried playing with the dropdown menu
with all the different types of math modes:
2-D, Warning, 2-D Output, Text Output, Error,
Diagnostic. I have no idea what those things mean.
However, I HAVE noticed that my file always tends
to "jump" back into the default 2-D Math mode.

Correct: I did NOT have those comments in the file
before I uploaded it. I experimented with adding
comments afterwards.

Scott03's picture

Re:Modes

When you first install Maple, you are given a choice between Worksheet or Document Mode. The default can be switched by going to Tools>Option and under the Interface Tab the selection is beside "Default format for new worksheets". If you just want to change modes for the next worksheet/document but you don't want to change your default, you can do this by going to File>New and select the mode for the new worksheet.

To tell what mode you are when you open up Maple, just look at the left most part where the cursor is. If it looks like this


then you are in Document Mode. If it looks like this

you are in worksheet mode. The main difference you should notice is that the worksheet mode has [> at the left most part.

Scott

Doug Meade's picture

Default Settings

The out-of-the-box defaults for Maple 11 are documents with 2D Math Notation.

As I recall, the first time Maple is started, you are given a choice to choose documents or worksheets as the default. (Most new users don't know enough to make an informed decision at this point, and I believe the pre-selected default is document.)

The first thing we have every one of our calculus students do in the computer lab is to reset these defaults to open worksheets with Maple notation for input.

Here are the instructions for doing this:

  1. go to the Tools menu and select Options ...
  2. click on the Interface tab
  3. set the Default format for new worksheets to Worksheet
  4. click on the Display tab
  5. set the Input display to Maple Notation
  6. at the bottom of the Options window, click Apply Globally

The last step is critical. If you select Apply to session (the default) these settings will be lost the next time you start Maple. But, if you follow these directions once, then you don't have to worry about this again. (If you want a document, you can always open one using File ... New.)

Once we get through this, the students have many fewer problems with our labs.

Doug

---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
JacquesC's picture

Wow

To quote Doug Meade:

Once we get through this [changing to worksheet mode and maple notation], the students have many fewer problems with our labs.

That is a serious indictment. Document Mode and the equation editor were designed to ease the burden of beginners. If you, of all people, feel that it is easier for your students to use Worksheets and maple notation, that is saying something quite serious. That a bunch of old foggies here on primes prefer this is fully expected, as that is completely standard "design" in many other disciplines, where you have a beginner mode and an 'expert' mode. But if you think that 'expert' mode is actually easier to grasp for beginners, that's deserves some real attention.

I hope that Maplesoft will invite you up to Maple HQ for a week to sit you down with their developers so that they can fix things so that you feel you can use 'beginner mode' for your students. Or at least, that's what all my books on usability and customer-centric design tell me ought to happen.

Robert Israel's picture

Wow?

I fully agree with Doug. It's also one of the first things I tell my students, and I've stated my opinions
many times, here in newsgroups, and to Maplesoft. I'm only surprised that you find this surprising.

JacquesC's picture

Surprise factor

My surprise comes from my impression of Doug -- I thought he had a higher pain threshold. In other words, that he would inflict more pain on himself for the purpose of better pedagogy for the sake of his students. But apparently, even with that in mind, Document Mode still is too much for Doug and his students to take. That is where the surprise came from.

Doug Meade's picture

Interface issues and teaching

Let me add some details about the front lines on which I am fighting -- I mean, teaching.

First, I am an old-timer who is most comfortable with my fingers on the keys. I can type. It slows me down to use the mouse or to use multi-key command sequences.

While I admit to being an old-timer, I do not admit to be an old Doug who can't learn any new tricks.

Second, it's not about me. All calculus students at the University of South Carolina spend one hour each week in the computer lab. I oversee the lab coordinators, who give detailed guidance to the TAs who actually meet the students. Most TAs have very limited (if any) prior exposure to Maple (or any mathematical software). So, we have to give the TAs simple, easy-to-learn skills and techniques that they can feel comfortable teaching to students less than one week after they first see them.

I readily admit that document mode and 2D math input are more attractive than worksheets and Maple notation. The problems with document mode and 2D math input can be summarized with two statements:

  • actions and options can be very sensitive to the state from which they are initiated
  • there is no clear trace of exactly what was done to obtain a specific action.

Students do not have the mathematical sophistication to understand how small changes in the selection can lead to such large differences in the context menus produced.

Students cannot see the instructor's hands and keyboard to know exactly what was done to enter something that leaves no trace. And, their attention is diverted from the presentation whenever they try something on their own - as they are instructed to do. Miss the wrong step in an interface-based construction and there is no hope of catching up!

To me, the interface issues are not solved by creating more tutors and templates. While there is a place for tutors and templates, in the end they boil down to the equivalent of a button on a calculator -- they teach nothing about the mathematics. I want students to learn to use Maple as a powerful tool for solving problems. I want students to get a better understanding of the structure of the mathematics. I want students to have to formulate a sequence of steps that allows them to move (logically) from the given information to a solution.

For all the stump speeches I've given lately you might think I had some political aspirations. (:-))

Doug

---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
resolvent's picture

1.5 paragraphs worth repeating from Doug Meade

"Students cannot see the instructor's hands and keyboard to know exactly what was done to enter something that leaves no trace. And, their attention is diverted from the presentation whenever they try something on their own - as they are instructed to do. Miss the wrong step in an interface-based construction and there is no hope of catching up!

To me, the interface issues are not solved by creating more tutors and templates. While there is a place for tutors and templates, in the end they boil down to the equivalent of a button on a calculator -- they teach nothing about the mathematics."

I have never found software tutorials helpful.

Robert Israel's picture

Example

A good example of what's wrong with 2D Math input is implied multiplication. At first sight it looks like a great idea: we can type 3 x y just like we'd write it on a blackboard. But on second thought it's not such a great idea.

In 1D math, students can easily accept the idea of using the * key for multiplication: they've been using it on their calculators for years. The rule is extremely simple and consistent: to multiply, use *. And if you forget to do it, Maple gives you a friendly "missing operator or ;" error to remind you.

In 2D math, you don't need the *, but you do need a space. Well, sometimes you do: 3x is OK, (a + b)y is
OK, but x(a+b) is not OK; 3(a+b) is not OK in Classic but may or may not be OK in Standard, depending on a setting in the Typesetting Rule Assistant. On the other hand, putting a space in sin (a+b), which was OK in 1D math, is not OK in 2D math in Standard but is OK in Classic. What a mess!

And none of the "not OK" cases causes a syntax error, they just make your results wrong.

Moreover, in these nice italic proportional fonts, it can be rather difficult to tell whether you have a space or not. Try typing f L + eV in 2D math; could you tell at a glance which has a space and which doesn't?

So, would you really suggest that a beginner should use 2D math input?

resolvent's picture

Multiplication

My brother, the expert Java programmer and non-mathematician,
admitted to me that he just threw up his hands in digust
over this "crazy language"!

2D math seems to confuse (or confuses the user)
over issues of displaying data versus manipulating data.

JacquesC's picture

I would not, but

that's because I, like you, prefer simple rules. The rule of using * for multiplication is simple; the rules for when it can be omitted are not.

Note that part of the problem is that Maple is dynamically typed. If Maple were statically typed, then it would be possible to overload space/juxtaposition to mean both application and multiplication, because then there would always be enough context to clarify which it has to be. In fact, even more overloading is possible. And that is how mathematicians do it too - they know, in advance, what type their "objects" are, so there is no confusion caused by their notational overloading. The real mistake in the design of the interface rules for implicit multiplication is the hope that this can be done context-free.

artificial intelligence?

So, would Maple need a sort of artificial intelligence that "knows in advance" what is the context to make it work?

JacquesC's picture

That is not how I would do it

My preferred method would be to use polymorphism. In this case, juxtaposition could be a new operator whose meaning could be fixed whenever there is enough information available. Rather like what happens with =, as we discussed in recently.

At least, that would be a Maple-compatible way of doing things. In a completely new system, the possibilities are much bigger still. Nevertheless, I might still favour the polymorphic solution.

Doug Meade's picture

Another example (2d math input)

Here's another example of what I consider to be wrong with 2D Math Input.

The Accessing solutions from procedures forum topic refers readers to a worksheet .

This worksheet was prepared with 2D Math Input.

The procedure uses the name "beta_star". But, if I type this sequence of characters, I see βstar. If I want to get "beta_star" in the code, I have to type "beta\_star" (the _ must be escaped).

I know this has been discussed before, but I want to point this out as another example of nice looking results from 2D Math Input that require non-intuitive knowledge on the part of the user.

Personally, I would rather have slightly less attractive code that does not require any tricks to enter.

Just more of my opinions,

Doug

---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/

 

resolvent's picture

Thank you!

I always had Document Mode and Worksheet Mode backwards.
I had always assumed I was working in Worksheet Mode
when I found out I had been in Document Mode all along.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}