Skip to content

Commit d6b79e6

Browse files
committed
sqrtProduct and sqrtDivision rules use agc flags
This allows them to match them up to associativity and commutativity, and with other subexpressions in-between.
1 parent 4eb4d5d commit d6b79e6

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

runtime/scripts/jme-rules.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,10 +2107,10 @@ var simplificationRules = jme.rules.simplificationRules = {
21072107
['(`! `+- $n);x * (real:$n/real:$n`?);n','asg','n*x']
21082108
],
21092109
sqrtProduct: [
2110-
['sqrt(?;x)*sqrt(?;y)','','sqrt(x*y)']
2110+
['sqrt(?;x)*sqrt(?;y)','agc','sqrt(x*y)']
21112111
],
21122112
sqrtDivision: [
2113-
['sqrt(?;x)/sqrt(?;y)','','sqrt(x/y)']
2113+
['sqrt(?;x)/sqrt(?;y)','agc','sqrt(x/y)']
21142114
],
21152115
sqrtSquare: [
21162116
['sqrt(?;x^2)','','x'],

tests/jme-runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8650,10 +8650,10 @@ var simplificationRules = jme.rules.simplificationRules = {
86508650
['(`! `+- $n);x * (real:$n/real:$n`?);n','asg','n*x']
86518651
],
86528652
sqrtProduct: [
8653-
['sqrt(?;x)*sqrt(?;y)','','sqrt(x*y)']
8653+
['sqrt(?;x)*sqrt(?;y)','agc','sqrt(x*y)']
86548654
],
86558655
sqrtDivision: [
8656-
['sqrt(?;x)/sqrt(?;y)','','sqrt(x/y)']
8656+
['sqrt(?;x)/sqrt(?;y)','agc','sqrt(x/y)']
86578657
],
86588658
sqrtSquare: [
86598659
['sqrt(?;x^2)','','x'],

tests/jme/jme-tests.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,16 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal
22232223
assert.equal(simplifyExpression('a/(b/c*d)', 'all'), 'a*c/(b*d)', 'a/(b/c*d)');
22242224
});
22252225

2226+
QUnit.test('Simplify surds', function(assert) {
2227+
function simplifyExpression(expr,rules) {
2228+
return Numbas.jme.display.simplifyExpression(expr,rules || '',Numbas.jme.builtinScope);
2229+
}
2230+
2231+
assert.equal(simplifyExpression('sqrt(a)*x*sqrt(b)','all'), 'sqrt(a*b)*x');
2232+
assert.equal(simplifyExpression('sqrt(a)*(x*sqrt(b))','all'), 'sqrt(a*b)*x');
2233+
assert.equal(simplifyExpression('x/sqrt(a)*sqrt(b)','all'), 'x*sqrt(b/a)');
2234+
});
2235+
22262236
QUnit.test('brackets involving subtraction', function(assert) {
22272237
function simplifyExpression(expr,rules) {
22282238
return Numbas.jme.display.simplifyExpression(expr,rules || '',Numbas.jme.builtinScope);

tests/numbas-runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7986,10 +7986,10 @@ var simplificationRules = jme.rules.simplificationRules = {
79867986
['(`! `+- $n);x * (real:$n/real:$n`?);n','asg','n*x']
79877987
],
79887988
sqrtProduct: [
7989-
['sqrt(?;x)*sqrt(?;y)','','sqrt(x*y)']
7989+
['sqrt(?;x)*sqrt(?;y)','agc','sqrt(x*y)']
79907990
],
79917991
sqrtDivision: [
7992-
['sqrt(?;x)/sqrt(?;y)','','sqrt(x/y)']
7992+
['sqrt(?;x)/sqrt(?;y)','agc','sqrt(x/y)']
79937993
],
79947994
sqrtSquare: [
79957995
['sqrt(?;x^2)','','x'],

0 commit comments

Comments
 (0)