@@ -819,7 +819,7 @@ JXG.extend(JXG.JessieCode.prototype, /** @lends JXG.JessieCode.prototype */ {
819
819
_genericParse : function ( code , cmd , geonext , dontstore ) {
820
820
var i , setTextBackup , ast , result ,
821
821
ccode = code . replace ( / \r \n / g, '\n' ) . split ( '\n' ) ,
822
- // options = {},
822
+ options = { } ,
823
823
cleaned = [ ] ;
824
824
825
825
if ( ! dontstore ) {
@@ -850,9 +850,10 @@ JXG.extend(JXG.JessieCode.prototype, /** @lends JXG.JessieCode.prototype */ {
850
850
ast = this . CA . removeTrivialNodes ( ast ) ;
851
851
}
852
852
if ( this . CAS ) {
853
- // Search for expression of form `D(f, x)` and determine the
853
+ // Search for expression of form `D(f, x)` and determine the
854
854
// the derivative symbolically.
855
855
ast = this . CAS . expandDerivatives ( ast , null , ast ) ;
856
+
856
857
// options.method = options.method || "strong";
857
858
// options.form = options.form || "fractions";
858
859
// options.steps = options.steps || [];
@@ -866,6 +867,18 @@ JXG.extend(JXG.JessieCode.prototype, /** @lends JXG.JessieCode.prototype */ {
866
867
case 'manipulate' :
867
868
result = this . compile ( ast ) ;
868
869
break ;
870
+ case 'simplify' :
871
+ if ( Type . exists ( this . CAS ) ) {
872
+ options . method = options . method || "strong" ;
873
+ options . form = options . form || "fractions" ;
874
+ options . steps = options . steps || [ ] ;
875
+ options . iterations = options . iterations || 1000 ;
876
+ ast = this . CAS . simplify ( ast , options ) ;
877
+ result = this . CAS . compile ( ast ) ;
878
+ } else {
879
+ result = this . compile ( ast ) ;
880
+ }
881
+ break ;
869
882
case 'getAst' :
870
883
result = ast ;
871
884
break ;
@@ -916,6 +929,21 @@ JXG.extend(JXG.JessieCode.prototype, /** @lends JXG.JessieCode.prototype */ {
916
929
return this . _genericParse ( code , 'manipulate' , geonext , dontstore ) ;
917
930
} ,
918
931
932
+ /**
933
+ * Manipulate JessieCode.
934
+ * This consists of generating an AST with parser.parse,
935
+ * apply simplifying rules from CAS
936
+ * and compile the AST back to JessieCode with minimal number of parentheses.
937
+ *
938
+ * @param {String } code JessieCode code to be parsed
939
+ * @param {Boolean } [geonext=false] Geonext compatibility mode.
940
+ * @param {Boolean } [dontstore=false] If false, the code string is stored in this.code.
941
+ * @return {String } Simplified JessieCode code
942
+ */
943
+ simplify : function ( code ) {
944
+ return this . _genericParse ( code , 'simplify' ) ;
945
+ } ,
946
+
919
947
/**
920
948
* Get abstract syntax tree (AST) from JessieCode code.
921
949
* This consists of generating an AST with parser.parse.
0 commit comments