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

Support for Rules and Patterns #1209

Closed
LukeLongworth opened this issue Jun 27, 2024 · 7 comments
Closed

Support for Rules and Patterns #1209

LukeLongworth opened this issue Jun 27, 2024 · 7 comments
Assignees
Milestone

Comments

@LukeLongworth
Copy link
Contributor

The set of functions for rules and patterns
looks like it would be useful for manipulation of certain symbolic expressions. Should some or all of these functions be unbanned?

Some use case examples in the documentation are:

  • Selectively applying trigonometric identity substitutions, such as ( let(sin(a)^2, 1 - cos(a)^2), letsimp (sin(x)^4) ) to give cos(x)^4 - 2*cos(x)^2 + 1
  • Automatically simplifying some expressions involving factorials

My own use case that inspired me to look into this (may or may not be possible, I'm not sure):

  • Declaring I and O to be multiplicative and additive identities respectively for symbolic matrix expression simplification
@sangwinc sangwinc added this to the 4.7.0 milestone Jul 3, 2024
@sangwinc
Copy link
Member

sangwinc commented Jul 3, 2024

@LukeLongworth, this looks very reasonable to add. Can you please provide examples of exactly what you do need?

@sangwinc
Copy link
Member

sangwinc commented Jul 3, 2024

@LukeLongworth we may have a snag here. If you try just let(sin(a)^2, 1 - cos(a)^2) in Maxima then the return value is a new kind of operator -> which we've not accommodated. Indeed, using ?print you get

((MTEXT SIMP) ((MEXPT SIMP) ((%SIN SIMP) $A) 2) | --> |
 ((MPLUS SIMP) 1 ((MTIMES SIMP) -1 ((MEXPT SIMP) ((%COS SIMP) $A) 2)))) 

To fully support this feature we need to expand the parser (comments @aharjula?), or we insist on a workaround as shown here cfd0887#diff-aad04ae351ba675f6ae80a98e32ef7c4b57f41d6e0c614ec9f6d84e3b0d8ae28R2944 which avoids the problem of this return value in the Maxima -> PHP connection.

@aharjula
Copy link
Member

aharjula commented Jul 3, 2024

Well, wrapping it and piping the return value out to some bit bucket instead of returning it would be the workaround for now. You can naturally add a new operator to the current parser, but:

  1. The current parser is not really configurable, so the operator would also exist for the students, and if it needs to exist for them, then it might affect some parsing error messages.
  2. Is it just a return value in an interesting form, or is it really an operator that can be used? Do we really want to parse things that could never be input?

I would rather start investing in the next-gen parser with its configurable lexers so that one could when needed, use a lexer that accepts that as an operator and otherwise allow simpler ones to be used. This would have less vocabulary and, thus, simpler syntax error messages. Basically, if it currently aims to provide localisable syntax lexers, it can easily also adjust and provide a larger syntax parser for return values from the CAS, or author side code, when need be.

@sangwinc
Copy link
Member

sangwinc commented Jul 3, 2024

I agree @aharjula that adapting the parser is too much work for this case, and probably prone to causing more problems. We'll document the use of let0. There is likely to be little error trapping when we forget as the parser throws an exception which will bring everything to an end...

@LukeLongworth could you create some use-cases and perhaps some docs?

@sangwinc
Copy link
Member

sangwinc commented Nov 5, 2024

@LukeLongworth I would really like to get this functionality into the next release (19th Nov). Do you have anything to add, e.g. some compelling use-cases?

sangwinc added a commit that referenced this issue Nov 6, 2024
Support for Rules and Patterns #1209
@sangwinc sangwinc closed this as completed Nov 7, 2024
@LukeLongworth
Copy link
Contributor Author

@sangwinc I haven't been able to experiment with this, as I usually just use the CAS chat in our local install to play around with Maxima.

The thing that originally drove me to investigate this was symbolic matrix algebra. I wanted Maxima to understand that I is an identity matrix, and O is a zero matrix, with appropriate simplification following.

I can also imagine a use case where more complex simplifications could be managed. I have had many headaches with a particular implicit partial differentiation question we have, where rearranging the original equations before differentiating will produce valid answers (ignoring any domain restrictions that get introduced) that STACK won't recognise. One possible solution would be to ask STACK to, for example, look for any expressions of the form t^2*cos(3*y) and replace them with x*z if one of the given equations was x*z = t^2*cos(3*y).

If this functionality gets into the next version of STACK, I would be happy to play around and write some example use cases. 19th of November might even give us enough time to include it in our December update! It would be a rare treat for us to actually be on the latest version for a while.

@sangwinc
Copy link
Member

sangwinc commented Nov 8, 2024

Thanks @LukeLongworth, this is in the dev branch, and scheduled for the next release. Please do make use of this and add examples and "know how" here:
https://github.com/maths/moodle-qtype_stack/blob/dev/doc/en/CAS/Rules.md
Your matrix example is in the docs and the test cases...

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

No branches or pull requests

3 participants