Skip to content
Permalink
Browse files

add noDovision rule

not included in 'all', but you could use it to make patterns matching
fractions easier.
  • Loading branch information...
christianp committed Oct 22, 2018
1 parent 23dba94 commit f2928f2aa27bd93443911e1f8792afdae50a4e4c
Showing with 54 additions and 48 deletions.
  1. +18 −16 runtime/scripts/jme-rules.js
  2. +18 −16 tests/jme-runtime.js
  3. +18 −16 tests/numbas-runtime.js
@@ -1597,15 +1597,20 @@ var simplificationRules = jme.rules.simplificationRules = {
],
*/
};
// these rules conflict with noLeadingMinus
var canonicalOrderRules = [
['(`+- ?);x+(`+- ?);y `where canonical_compare(x,y)=1','ag','y+x'],
['?;x*?;y `where canonical_compare(x,y)=-1','ag','y*x'],
]
var expandBracketsRules = [
['(?;x + ((`+- ?)`+);y) * ?;z','ag','x*z+y*z'],
['?;x * (?;y + ((`+- ?)`+);z)','ag','x*y+x*z']
]
var conflictingSimplificationRules = {
// these rules conflict with noLeadingMinus
canonicalOrder: [
['(`+- ?);x+(`+- ?);y `where canonical_compare(x,y)=1','ag','y+x'],
['?;x*?;y `where canonical_compare(x,y)=-1','ag','y*x'],
],
expandBrackets: [
['(?;x + ((`+- ?)`+);y) * ?;z','ag','x*z+y*z'],
['?;x * (?;y + ((`+- ?)`+);z)','ag','x*y+x*z']
],
noDivision: [
['?;top/(?;base^(?`? `: 1);degree)','','top * base^(-degree)']
]
}
/** Compile an array of rules (in the form `[pattern,conditions[],result]` to {@link Numbas.jme.rules.Rule} objects
* @memberof Numbas.jme.rules
* @method
@@ -1626,16 +1631,13 @@ var compileRules = jme.rules.compileRules = function(rules,name)
}
var all=[];
var compiledSimplificationRules = {};
var notAll = ['canonicalOrder','expandBrackets'];
for(var x in simplificationRules)
{
for(var x in simplificationRules) {
compiledSimplificationRules[x] = compiledSimplificationRules[x.toLowerCase()] = compileRules(simplificationRules[x],x);
if(!notAll.contains(x)) {
all = all.concat(compiledSimplificationRules[x].rules);
}
}
compiledSimplificationRules['canonicalorder'] = compileRules(canonicalOrderRules,'canonicalOrder');
compiledSimplificationRules['expandbrackets'] = compileRules(expandBracketsRules,'expandBrackets');
for(var x in conflictingSimplificationRules) {
compiledSimplificationRules[x] = compiledSimplificationRules[x.toLowerCase()] = compileRules(conflictingSimplificationRules[x],x);
}
compiledSimplificationRules['all'] = new Ruleset(all,{});
jme.rules.simplificationRules = compiledSimplificationRules;
});
@@ -6370,15 +6370,20 @@ var simplificationRules = jme.rules.simplificationRules = {
],
*/
};
// these rules conflict with noLeadingMinus
var canonicalOrderRules = [
['(`+- ?);x+(`+- ?);y `where canonical_compare(x,y)=1','ag','y+x'],
['?;x*?;y `where canonical_compare(x,y)=-1','ag','y*x'],
]
var expandBracketsRules = [
['(?;x + ((`+- ?)`+);y) * ?;z','ag','x*z+y*z'],
['?;x * (?;y + ((`+- ?)`+);z)','ag','x*y+x*z']
]
var conflictingSimplificationRules = {
// these rules conflict with noLeadingMinus
canonicalOrder: [
['(`+- ?);x+(`+- ?);y `where canonical_compare(x,y)=1','ag','y+x'],
['?;x*?;y `where canonical_compare(x,y)=-1','ag','y*x'],
],
expandBrackets: [
['(?;x + ((`+- ?)`+);y) * ?;z','ag','x*z+y*z'],
['?;x * (?;y + ((`+- ?)`+);z)','ag','x*y+x*z']
],
noDivision: [
['?;top/(?;base^(?`? `: 1);degree)','','top * base^(-degree)']
]
}
/** Compile an array of rules (in the form `[pattern,conditions[],result]` to {@link Numbas.jme.rules.Rule} objects
* @memberof Numbas.jme.rules
* @method
@@ -6399,16 +6404,13 @@ var compileRules = jme.rules.compileRules = function(rules,name)
}
var all=[];
var compiledSimplificationRules = {};
var notAll = ['canonicalOrder','expandBrackets'];
for(var x in simplificationRules)
{
for(var x in simplificationRules) {
compiledSimplificationRules[x] = compiledSimplificationRules[x.toLowerCase()] = compileRules(simplificationRules[x],x);
if(!notAll.contains(x)) {
all = all.concat(compiledSimplificationRules[x].rules);
}
}
compiledSimplificationRules['canonicalorder'] = compileRules(canonicalOrderRules,'canonicalOrder');
compiledSimplificationRules['expandbrackets'] = compileRules(expandBracketsRules,'expandBrackets');
for(var x in conflictingSimplificationRules) {
compiledSimplificationRules[x] = compiledSimplificationRules[x.toLowerCase()] = compileRules(conflictingSimplificationRules[x],x);
}
compiledSimplificationRules['all'] = new Ruleset(all,{});
jme.rules.simplificationRules = compiledSimplificationRules;
});
@@ -5335,15 +5335,20 @@ var simplificationRules = jme.rules.simplificationRules = {
],
*/
};
// these rules conflict with noLeadingMinus
var canonicalOrderRules = [
['(`+- ?);x+(`+- ?);y `where canonical_compare(x,y)=1','ag','y+x'],
['?;x*?;y `where canonical_compare(x,y)=-1','ag','y*x'],
]
var expandBracketsRules = [
['(?;x + ((`+- ?)`+);y) * ?;z','ag','x*z+y*z'],
['?;x * (?;y + ((`+- ?)`+);z)','ag','x*y+x*z']
]
var conflictingSimplificationRules = {
// these rules conflict with noLeadingMinus
canonicalOrder: [
['(`+- ?);x+(`+- ?);y `where canonical_compare(x,y)=1','ag','y+x'],
['?;x*?;y `where canonical_compare(x,y)=-1','ag','y*x'],
],
expandBrackets: [
['(?;x + ((`+- ?)`+);y) * ?;z','ag','x*z+y*z'],
['?;x * (?;y + ((`+- ?)`+);z)','ag','x*y+x*z']
],
noDivision: [
['?;top/(?;base^(?`? `: 1);degree)','','top * base^(-degree)']
]
}
/** Compile an array of rules (in the form `[pattern,conditions[],result]` to {@link Numbas.jme.rules.Rule} objects
* @memberof Numbas.jme.rules
* @method
@@ -5364,16 +5369,13 @@ var compileRules = jme.rules.compileRules = function(rules,name)
}
var all=[];
var compiledSimplificationRules = {};
var notAll = ['canonicalOrder','expandBrackets'];
for(var x in simplificationRules)
{
for(var x in simplificationRules) {
compiledSimplificationRules[x] = compiledSimplificationRules[x.toLowerCase()] = compileRules(simplificationRules[x],x);
if(!notAll.contains(x)) {
all = all.concat(compiledSimplificationRules[x].rules);
}
}
compiledSimplificationRules['canonicalorder'] = compileRules(canonicalOrderRules,'canonicalOrder');
compiledSimplificationRules['expandbrackets'] = compileRules(expandBracketsRules,'expandBrackets');
for(var x in conflictingSimplificationRules) {
compiledSimplificationRules[x] = compiledSimplificationRules[x.toLowerCase()] = compileRules(conflictingSimplificationRules[x],x);
}
compiledSimplificationRules['all'] = new Ruleset(all,{});
jme.rules.simplificationRules = compiledSimplificationRules;
});

0 comments on commit f2928f2

Please sign in to comment.
You can’t perform that action at this time.