Skip to content

Commit

Permalink
More test coverage for coeff
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
NAThompson committed May 7, 2024
1 parent b8f7cf6 commit 1568ebc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/src/manual/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
```
```
5 changes: 5 additions & 0 deletions test/coeff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1568ebc

Please sign in to comment.