From 1568ebc0fccef72362d7bdb9570e49678d35eb99 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Tue, 7 May 2024 07:37:22 -0700 Subject: [PATCH] More test coverage for coeff `coeff` works with symbolic and non-integral powers. However, this case is not covered in unit tests. Add tests to preserve this functionality into the future. --- docs/src/manual/functions.md | 6 +++--- test/coeff.jl | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/src/manual/functions.md b/docs/src/manual/functions.md index c8084aa38..44d93b1ae 100644 --- a/docs/src/manual/functions.md +++ b/docs/src/manual/functions.md @@ -51,7 +51,7 @@ du Note that what has been done here is that the imperative Julia code for the function `lorenz` has been transformed into a declarative symbolic graph. Importantly, the code of `lorenz` is transformed -into an expression consisting only of primitive registered fucntions, +into an expression consisting only of primitive registered functions, things like `*` and `-`, which come pre-registered with Symbolics.jl This then allows for symbolic manipulation of the expressions, allowing things like simplification and operation @@ -66,7 +66,7 @@ to C code, are used, then the tracing process will error. However, we note that symbolic tracing by definition does not guarantee that the exact choices. The symbolic expressions -may re-distribute the arithmatic, simplify out expressions, or +may re-distribute the arithmetic, simplify out expressions, or do other modifications. Thus if this function is function is sensitive to numerical details in its calculation, one would not want to trace the function and thus would instead register it @@ -187,4 +187,4 @@ The derivative is defined similarly to the macro case: function Symbolics.derivative(interp::AbstractInterpolation, args::NTuple{1, Any}, ::Val{1}) Symbolics.unwrap(derivative(interp, Symbolics.wrap(args[1]))) end -``` \ No newline at end of file +``` diff --git a/test/coeff.jl b/test/coeff.jl index 1bb74854d..d8edaf41e 100644 --- a/test/coeff.jl +++ b/test/coeff.jl @@ -9,6 +9,11 @@ import Symbolics: coeff @test isequal(coeff(2a, x), 0) @test isequal(coeff(a*x, x), a) @test isequal(coeff(2x*a, x), 2a) +# Symbolic powers: +@test isequal(coeff(a*x^b, x^b), a) +@test isequal(coeff(a*x^(b+1), x^(b+1)), a) +# Irrational powers: +@test isequal(coeff(a*x^sqrt(2), x^sqrt(2)), a) @test isequal(coeff(a + x, x), 1) @test isequal(coeff(2(a + x), x), 2)