diff --git a/expreduce/builtin_power.go b/expreduce/builtin_power.go index 6b5d489..34cb744 100644 --- a/expreduce/builtin_power.go +++ b/expreduce/builtin_power.go @@ -272,5 +272,10 @@ func GetPowerDefinitions() (defs []Definition) { Name: "PolynomialGCD", }) defs = append(defs, Definition{Name: "SquareFreeQ"}) + defs = append(defs, Definition{ + Name: "PSimplify", + OmitDocumentation: true, + ExpreduceSpecific: true, + }) return } diff --git a/expreduce/cas_test.go b/expreduce/cas_test.go index 632e672..b65600d 100644 --- a/expreduce/cas_test.go +++ b/expreduce/cas_test.go @@ -12,6 +12,8 @@ import ( var testmodules = flag.String("testmodules", "", "A regexp of modules to test, otherwise test all modules.") +var testsyms = flag.String("testsyms", "", + "A regexp of symbols to test, otherwise test all symbols.") var verbosetest = flag.Bool("verbosetest", false, "Print every test case that runs.") var deftimings = flag.Bool("deftimings", false, @@ -19,6 +21,7 @@ var deftimings = flag.Bool("deftimings", false, func TestIncludedModules(t *testing.T) { var testModEx = regexp.MustCompile(*testmodules) + var testSymEx = regexp.MustCompile(*testsyms) defSets := GetAllDefinitions() numTests := 0 lhsDefTimeCounter := TimeCounter{} @@ -32,6 +35,9 @@ func TestIncludedModules(t *testing.T) { } fmt.Printf("Testing module %s\n", defSet.Name) for _, def := range defSet.Defs { + if !testSymEx.MatchString(def.Name) { + continue + } es := NewEvalState() def.AnnotateWithDynamic(es) td := TestDesc{ diff --git a/expreduce/resources/power.m b/expreduce/resources/power.m index a629a27..55532c6 100644 --- a/expreduce/resources/power.m +++ b/expreduce/resources/power.m @@ -36,6 +36,8 @@ PolynomialQ[p_.*v_^Optional[exp_Integer], v_] := If[FreeQ[p, v] && Positive[exp], True, False]; PolynomialQ[p_, v_] := If[FreeQ[p, v], True, False]; +(*Seemingly undocumented version with no variable specification:*) +PolynomialQ[p_] := PolynomialQ[p, Variables[p]]; Attributes[PolynomialQ] = {Protected}; Tests`PolynomialQ = { ETests[ @@ -84,7 +86,8 @@ ESameTest[True, PolynomialQ[x^y, 1]] ], EKnownFailures[ ESameTest[True, PolynomialQ[2*x^2-3x+2, 2]], - ESameTest[True, PolynomialQ[2*x^2-3x, 2]] + ESameTest[True, PolynomialQ[2*x^2-3x, 2]], + ESameTest[False, PolynomialQ[x/y]] ] }; @@ -385,3 +388,23 @@ ESameTest[False, SquareFreeQ[(2 x + 3)^2]] ] }; + +PSimplify[expr_] := expr; +PSimplify[p_?PolynomialQ/q_?PolynomialQ] := + If[Length[Variables[p]] === 1 && Variables[p] === Variables[q], + PolynomialQuotient[p, q, Variables[p][[1]]], p/q]; +Tests`PSimplify = { + ESimpleExamples[ + ESameTest[-1 + x^2, PSimplify[(1 - 2*x^2 + x^4)/(-1 + x^2)]], + ESameTest[4*x, PSimplify[(-4*x + 4*x^3)/(-1 + x^2)]], + ESameTest[-1 - x + x^3 + x^4, PSimplify[(1 - x^2 - x^3 + x^5)/(-1 + x)]], + ESameTest[2*x + 5*x^2 + 5*x^3, PSimplify[(-2*x - 3*x^2 + 5*x^4)/(-1 + x)]], + ESameTest[-6 + 11*x - 6*x^2 + x^3, PSimplify[(18 - 39*x + 29*x^2 - 9*x^3 + x^4)/(-3 + x)]], + ESameTest[13 - 15*x + 4*x^2, PSimplify[(-39 + 58*x - 27*x^2 + 4*x^3)/(-3 + x)]], + ESameTest[-3 - x + 3*x^2 + x^3, PSimplify[(-9 - 6*x + 8*x^2 + 6*x^3 + x^4)/(3 + x)]], + ESameTest[-2 + 6*x + 4*x^2, PSimplify[(-6 + 16*x + 18*x^2 + 4*x^3)/(3 + x)]] + ], EKnownDangerous[ + ESameTest[12 + 4*x - 15*x^2 - 5*x^3 + 3*x^4 + x^5, PSimplify[(-108 - 108*x + 207*x^2 + 239*x^3 - 81*x^4 - 153*x^5 - 27*x^6 + 21*x^7 + 9*x^8 + x^9)/(-9 - 6*x + 8*x^2 + 6*x^3 + x^4)]], + ESameTest[12 - 54*x - 33*x^2 + 18*x^3 + 9*x^4, PSimplify[(-108 + 414*x + 717*x^2 - 324*x^3 - 765*x^4 - 162*x^5 + 147*x^6 + 72*x^7 + 9*x^8)/(-9 - 6*x + 8*x^2 + 6*x^3 + x^4)]] + ], +};