-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doc errors #385
Comments
This might be related |
Was fixed at some point, all of the examples work fine for me. However, that probably should be covered by running doctests. using SymbolicUtils
julia> @syms w z α::Real β::Real
(w, z, α, β)
julia> r1 = @rule sin(2(~x)) => 2sin(~x)*cos(~x)
sin(2 * ~x) => (2 * sin(~x)) * cos(~x)
julia> r1(sin(2z))
2sin(z)*cos(z)
julia> r1(sin(3z)) === nothing
true
julia> r1(sin(2*(w-z)))
2cos(w - z)*sin(w - z)
julia> r1(sin(2*(w+z)*(α+β))) === nothing
true
julia> r2 = @rule sin(~x + ~y) => sin(~x)*cos(~y) + cos(~x)*sin(~y);
julia> r2(sin(α+β))
sin(β)*cos(α) + cos(β)*sin(α)
julia> @syms x y z
(x, y, z)
julia> @rule(+(~~xs) => ~~xs)(x + y + z)
3-element view(::Vector{Any}, 1:3) with eltype Any:
z
y
x
julia> r3 = @rule ~x * +(~~ys) => sum(map(y-> ~x * y, ~~ys));
julia> r3(2 * (w+w+α+β))
4w + 2α + 2β
julia> 2 * (w+w+α+β)
2(2w + α + β)
julia> @syms a b c d
(a, b, c, d)
julia> r = @rule ~x + ~~y::(ys->iseven(length(ys))) => "odd terms";
julia> @show r(a + b + c + d)
r(a + b + c + d) = nothing
julia> @show r(b + c + d)
r(b + c + d) = "odd terms"
"odd terms"
julia> @show r(b + c + b)
r(b + c + b) = nothing
julia> @show r(a + b)
r(a + b) = nothing
julia> @syms x y z
(x, y, z)
julia> acr = @acrule((~a)^(~x) * (~a)^(~y) => (~a)^(~x + ~y))
ACRule((~a) ^ ~x * (~a) ^ ~y => (~a) ^ (~x + ~y))
julia> acr(x^y * x^z)
x^(y + z)
julia> @syms x::Real y::Real
(x, y)
julia> sqexpand = @rule (~x + ~y)^2 => (~x)^2 + (~y)^2 + 2 * ~x * ~y
(~x + ~y) ^ 2 => (~x) ^ 2 + (~y) ^ 2 + 2 * ~x * ~y
julia> sqexpand((cos(x) + sin(x))^2)
sin(x)^2 + 2sin(x)*cos(x) + cos(x)^2
julia> pyid = @rule sin(~x)^2 + cos(~x)^2 => 1
sin(~x) ^ 2 + cos(~x) ^ 2 => 1
julia> pyid(cos(x)^2 + sin(x)^2) === nothing
true
julia> acpyid = @acrule sin(~x)^2 + cos(~x)^2 => 1
ACRule(sin(~x) ^ 2 + cos(~x) ^ 2 => 1)
julia> acpyid(cos(x)^2 + sin(x)^2 + 2cos(x)*sin(x))
1 + 2sin(x)*cos(x)
julia> using SymbolicUtils.Rewriters
julia> sqexpand = @rule (~x + ~y)^2 => (~x)^2 + (~y)^2 + 2 * ~x * ~y
(~x + ~y) ^ 2 => (~x) ^ 2 + (~y) ^ 2 + 2 * ~x * ~y
julia> acpyid = @acrule sin(~x)^2 + cos(~x)^2 => 1
ACRule(sin(~x) ^ 2 + cos(~x) ^ 2 => 1)
julia> csa = Chain([sqexpand, acpyid])
Chain(SymbolicUtils.AbstractRule[(~x + ~y) ^ 2 => (~x) ^ 2 + (~y) ^ 2 + 2 * ~x * ~y, ACRule(sin(~x) ^ 2 + cos(~x) ^ 2 => 1)], false)
julia> csa((cos(x) + sin(x))^2)
1 + 2sin(x)*cos(x)
julia> Chain([@acrule sin(~x)^2 + cos(~x)^2 => 1])((cos(x) + sin(x))^2)
(sin(x) + cos(x))^2
julia> cas = Chain([acpyid, sqexpand])
Chain(SymbolicUtils.AbstractRule[ACRule(sin(~x) ^ 2 + cos(~x) ^ 2 => 1), (~x + ~y) ^ 2 => (~x) ^ 2 + (~y) ^ 2 + 2 * ~x * ~y], false)
julia> cas((cos(x) + sin(x))^2)
sin(x)^2 + 2sin(x)*cos(x) + cos(x)^2
julia> using SymbolicUtils.Rewriters: RestartedChain
julia> rcas = RestartedChain([acpyid, sqexpand])
RestartedChain{Vector{SymbolicUtils.AbstractRule}}(SymbolicUtils.AbstractRule[ACRule(sin(~x) ^ 2 + cos(~x) ^ 2 => 1), (~x + ~y) ^ 2 => (~x) ^ 2 + (~y) ^ 2 + 2 * ~x * ~y])
julia> rcas((cos(x) + sin(x))^2)
1 + 2sin(x)*cos(x)
julia> Fixpoint(cas)((cos(x) + sin(x))^2)
1 + 2sin(x)*cos(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, lots of broken examples in the docs:
https://symbolicutils.juliasymbolics.org/rewrite/
The text was updated successfully, but these errors were encountered: