Pattern Matching

36 views
Skip to first unread message

Navneet Ojha

unread,
Jan 19, 2015, 3:59:47 AM1/19/15
to mathpip...@googlegroups.com

Hello everyone,
 I am Navneet Ojha, and new to mathpiper. I am exploring mathpiper, And got to know Pattern matching is one of its capability. One application of pattern matching is defining new function. But when referring the documentation and trying to define some functions, it is giving error. For eg. if using this :- IsIntegerGreaterThanZero(_n) <-- (IsInteger(n) And n>0); , it is giving parsing error near token 'And'.
Also in some examples i have seen there is a function 'Simplify' but when trying to use it, giving an error <Simplify> not defined.

I know I am close to the point, but need some guidance.

Thank you :)

Ted Kosan

unread,
Jan 19, 2015, 2:47:01 PM1/19/15
to mathpip...@googlegroups.com
Navneet wrote:

> But when referring to the
> documentation and trying to define some functions, it is giving error. For
> eg. if using this :- IsIntegerGreaterThanZero(_n) <-- (IsInteger(n) And
> n>0); , it is giving parsing error near token 'And'.

First, I recommend that you use the latest development release of
MathPiperIDE if you are not already doing so:

http://www.mathpiper.org/development-releases


Around a year and a half ago, the syntax of MathPiper was
significantly changed. The two documents that have been updated to
match the new syntax are the "Introduction to Programming with
MathPiper" book and the "Exploring STEM with MathPiper" book that are
available at the above website. However, neither of these books cover
MathPiper's more advanced functions.

Most of the other documentation that is in the MathPiper repository
still contains the old syntax. Also, some of the function
documentation that is in the MathPiperDocs plugin in MathPiperIDE
still needs to be updated to the new syntax.

This is one way to create the above rule (by convention, the names of
user defined rules begin with a lower case letter):

In> integerGreaterThanZero(n_) <-- Integer?(n) And? n >? 0;
Result: True

In> integerGreaterThanZero(3)
Result: True

In> integerGreaterThanZero(-1)
Result: False



Information on this rulebase can be obtained using the RulebaseDump function:

In> RulebaseDump("integerGreaterThanZero")
Result: True
Side Effects:
Rulebase: integerGreaterThanZero

Precedence: 0,
Rule Type: org.mathpiper.lisp.rulebases.PatternRule,
Arity: 1,
Parameters: arg1<hold=false>,
Predicates: (Pattern) True,
Variables: n,
Types: Variable: _; ,
Body:
Integer?(n) And? n >? 0



The rulebase can be deleted using the Retract function:

In> Retract("integerGreaterThanZero", All)
Result: True

In> RulebaseDump("integerGreaterThanZero")
Result: True
Side Effects:
Rule not defined



> Also in some examples i have seen there is a function 'Simplify' but when
> trying to use it, giving an error <Simplify> not defined.

The Simplify function was removed from MathPiper when MathPiper was
changed to use the Java version of Reduce
(http://www.reduce-algebra.com/) to perform advanced mathematical
calculations (such as Factor, Solve, Expand, Differentiate, and
Integrate). Reduce automatically simplifies the results it returns,
and so these results do not need to be further simplified.

At some point in time I would like to add simplification capabilities
back to MathPiper. However, according the the paper "Algebraic
Simplification a Guide for the Perplexed" by Joel Moses,
simplification is challenging to implement properly:

https://inst.cs.berkeley.edu/~cs282/sp02/readings/moses-simp.pdf

Therefore, I have been holding off on adding simplification
capabilities back into MathPiper until I understand simplification
better.

If you have further questions, feel free to ask them :-)

Ted
Reply all
Reply to author
Forward
0 new messages