Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cookbook example for using lazy-expression syntax AND add to manual #2560

Closed
wants to merge 0 commits into from

Conversation

mibillen
Copy link
Contributor

@mibillen mibillen commented Jul 6, 2018

I've created a simple cookbook example that uses the lazy-expression syntax ( ? : ) for nested if-else statements. The cookbook includes a python script that has the same if-else statement so that new users can see how to go from a more familiar way of writing these expressions to what is needed in the function expressions.

I've also modified the manual to explain the lazy-expression and point to this new cookbook.

Copy link
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing this! I let other comment on whether the python part of this PR is useful to include, but I am of course in favor of including the cookbook and the section in the manual.

Therefore, the lazy-expression syntax is recommended.

As a simple example using the lazy-expression syntax, the statement ``if $1<x<4$ then output 1, else output 0''
can be expressed as \texttt{(1<x\ \&\&\ x<4\ ?\ 1\ :\ 0)}. Multiple, nested if-else expressions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write this as (1<x \&\& x<4) ? (1) : (0) instead? Otherwise you are relying on the operator precedence rules between && and ? (and I have no idea what they are for the mu parser).

@mibillen
Copy link
Contributor Author

mibillen commented Jul 9, 2018

Okay, I made the change to the manual file, then added, commitded and pushed... and I see that my comment from the commit is showing up... so I'm guessing that I did this step of making a change to a pull request correctly. Let me know if I need to do something else.

The reason I added the python file example is that I found the idea of writing these nested if-else statements in muparser syntax very intimidating until I did exactly what this example does... I wrote it out in python and then translated it to the one-line expression. From there I could see better how to think through the logic. I do think it will be helpful to students, and those with less c++ programming experience like me.

@jaustermann
Copy link
Contributor

Thanks @mibillen for contributing this! I wonder if adding this cookbook to section 5 (cookbooks) in the manual would be useful. I worry that as the manual is growing people tend to just go to the cookbooks rather than reading through things before that and therefore might miss this. It seems like it could fit quite well in section 5.3 (Geophysical setups). That way you could also discuss things like this: "In addition, the parameter file shows how to run aspect to just check initial conditions are set correctly (by using and End time of zero and setting the solver tolerances to large values)." This is a useful tip but where it is now most people would never see it.
[Related to that, Pull Request #2409 might be relevant to you, which got merged during the hackathon. You can now do initial adaptive refinement without solving the equations and / or without assigning the initial temperature IF the refinement criterium doesn't depend on the solution and / or the initial temperature.]

@mibillen
Copy link
Contributor Author

@jaustermann - thanks for suggesting to actually add this within the cookbook section of the manual. I thought about whether i should do this also and wasn't sure if the cookbook was too simple. But I agree that helping new users (like me) past the apparently simple things (like how to I just check in the initial condition) is useful.

Is there an 'ordering' logic to the cookbooks? Do I just add at the end of the section you suggested (chronological order). Or, since this is a very simple example, should I add it at the beginning?

@jaustermann
Copy link
Contributor

Great, I think it would be a worthwhile addition! Looking through the cookbooks again - maybe tagging it on at the end of 5.2. (Simple setups) would make sense, so this would then be 5.2.13? I'm not sure if there is a specific order (chronological or otherwise).
You might have already seen this, but there is also a section in the manual on how to write a cookbook (section 6.3) in case that is useful. Thanks for contributing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants