Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 29 2019 01:29
    chakravala labeled #21
  • Jan 29 2019 01:27
    chakravala closed #10
  • Jan 29 2019 01:27
    chakravala closed #13
  • Jan 29 2019 01:25
    chakravala commented #13
  • Jan 29 2019 01:22
    chakravala labeled #23
  • Jan 28 2019 17:39
    flipgthb starred chakravala/Reduce.jl
  • Jan 27 2019 15:59
    chakravala commented #23
  • Jan 27 2019 13:50
    atthom commented #23
  • Jan 26 2019 16:30
    chakravala commented #23
  • Jan 26 2019 01:39
    atthom opened #23
  • Jan 22 2019 11:27
    chakravala labeled #22
  • Jan 22 2019 09:35
    chakravala commented #22
  • Jan 22 2019 09:34
    chakravala closed #22
  • Jan 22 2019 09:34
    chakravala commented #22
  • Jan 22 2019 02:12
    cscherrer commented #22
  • Jan 22 2019 00:02
    chakravala commented #22
  • Jan 21 2019 21:08
    cscherrer opened #22
  • Jan 21 2019 19:53
    cscherrer commented #21
  • Jan 21 2019 19:29
    chakravala commented #21
  • Jan 21 2019 19:23
    chakravala commented #21
chriselrod
@chriselrod

Was hoping going back to rcall would fix this:

julia> ex2 = :(exp(-a*exp(-x)-b*x)*x^2)
:(exp(-a * exp(-x) - b * x) * x ^ 2)

julia> int(ex2,:x,-Inf,Inf)
:(((((((((((e ^ ((e ^ (2inf) * e ^ inf * b * inf + 2a) / e ^ inf) * sub(x=inf, int(x ^ 2 / e ^ ((e ^ x * b * x + e ^ x * x + a) / e ^ x), x)) * a * b ^ 2 + 2 * e ^ ((e ^ (2inf) * e ^ inf * b * inf + 2a) / e ^ inf) * sub(x=inf, int(x / e ^ ((e ^ x * b * x + e ^ x * x + a) / e ^ x), x)) * a * b + 2 * e ^ ((e ^ (2inf) * e ^ inf * b * inf + 2a) / e ^ inf) * sub(x=inf, int(1 / e ^ ((e ^ x * b * x + e ^ x * x + a) / e ^ x), x)) * a) - e ^ ((e ^ (2inf) * e ^ inf * b * inf + 2a) / e ^ inf) * sub(x=-inf, int(x ^ 2 / e ^ ((e ^ x * b * x + e ^ x * x + a) / e ^ x), x)) * a * b ^ 2) - 2 * e ^ ((e ^ (2inf) * e ^ inf * b * inf + 2a) / e ^ inf) * sub(x=-inf, int(x / e ^ ((e ^ x * b * x + e ^ x * x + a) / e ^ x), x)) * a * b) - 2 * e ^ ((e ^ (2inf) * e ^ inf * b * inf + 2a) / e ^ inf) * sub(x=-inf, int(1 / e ^ ((e ^ x * b * x + e ^ x * x + a) / e ^ x), x)) * a) + e ^ ((2 * e ^ inf * b * inf + a) / e ^ inf) * b ^ 2 * inf ^ 2) - 2 * e ^ ((2 * e ^ inf * b * inf + a) / e ^ inf) * b * inf) + 2 * e ^ ((2 * e ^ inf * b * inf + a) / e ^ inf)) - e ^ (e ^ inf * a) * b ^ 2 * inf ^ 2) - 2 * e ^ (e ^ inf * a) * b * inf) - 2 * e ^ (e ^ inf * a)) / (e ^ ((e ^ (2inf) * e ^ inf * b * inf + 2a) / e ^ inf) * b ^ 3))

But:

julia> rcall(:(int(exp(-a*exp(-x)-b*x)*x^2),x,-Inf,Inf))
ERROR: Reduce: Nested :tuple block structure not supported
Stacktrace:
 [1] show_expr(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Expr) at /home/chris/.julia/v0.6/Reduce/src/parser.jl:505
 [2] unparse(::Expr) at /home/chris/.julia/v0.6/Reduce/src/parser.jl:547
 [3] Type at /home/chris/.julia/v0.6/Reduce/src/rexpr.jl:38 [inlined]
 [4] #rcall#14(::Array{Symbol,1}, ::Array{Symbol,1}, ::Function, ::Expr) at /home/chris/.julia/v0.6/Reduce/src/rexpr.jl:292
 [5] rcall(::Expr) at /home/chris/.julia/v0.6/Reduce/src/rexpr.jl:292

julia> rcall(:(int($ex2,x,-Inf,Inf) ))
:(int(exp(-a * exp(-x) - b * x) * x ^ 2, x, -inf, inf))

The answer to that involves the di- and tri-gamma functions, and requires a > 0 && b > 0.

I'd have to learn more about Reduce to know what is all possible. But I also definitely like the idea of it being able to work on matrices.
chriselrod
@chriselrod

"Julia does not have any fully native computer algebra packages, so this can help work around that. I wouldn't recommend using the package for doing things that you could otherwise do natively with Julia; but it should be a good tool for those situations where an external symbolic computation is essential for code generation."

That's probably true for generated functions in general. Your code would probably compile faster if instead you wrote out explicit versions for all of them.

Maybe if you're expecting some numbers to be especially popular, it would be best to explicitly write those versions (possibly using Reduce or some other CAS to derive the expression for you , and then copy + paste -- I know Chris Rackauckas has often used Mathematica for that)
so the bulk of the work doesn't have to be redone upon every compilation, and then make a generated version as a fallback for rarer cases.
Dream Scatter
@chakravala
Thanks for your feedback. I will look into those errors, it should be possible to handle the infinities.
Dream Scatter
@chakravala
To correctly calculate the infinities, use int(:( x^2 * exp(-x^2/2 ) ), :x, "-infinity", "infinity") because the parser currently does not recognize the Inf Julia type at the moment, but REDUCE strings work.
julia> int(:( x^2 * exp(-x^2/2 ) ), :x, "-infinity", "infinity")
:(sqrt(π) * sqrt(2))

julia> rcall(:(int( x^2 * exp(-x^2/2 ) , x, -Inf, Inf)))
:(sqrt(π) * sqrt(2))
Dream Scatter
@chakravala
Based on reading the REDUCE manual, it would seem that the di-gamma and tri-gamma functions are not supported, you'd have to communicate with the upstream REDUCE developers about that.
Dream Scatter
@chakravala

As for the Nested :tuple block structure not supported error, it seems you made a mistake with your parenthesis, it should have been entered like this:

julia> rcall(:(int(exp(-a*exp(-x)-b*x)*x^2,x,-Inf,Inf)))
:(int(exp(-a * exp(-x) - b * x) * x ^ 2, x, -inf, inf))

julia> int(ex2,:x,"-infinity","infinity")
:(int(exp(-a * exp(-x) - b * x) * x ^ 2, x, -inf, inf))

which also appears to be an unsupported integral (from the upstream REDUCE end) at first glance

when an integral cannot be evaluated by REDUCE, it just returns the expression back

Dream Scatter
@chakravala

However, the REDUCE documentation does describe how to set the positivity of variables:

http://www.reduce-algebra.com/manual/manualse68.html#x83-15900010.2

Dream Scatter
@chakravala
The newest master branch of Reduce.jl parser now supports the Julia Inf and -Inf values of Float64:
julia> int(:( x^2 * exp(-x^2/2 ) ), :x, -Inf, Inf)
:(sqrt(π) * sqrt(2))
chriselrod
@chriselrod

On the di- and tri-gamma functions, I see your Julia docs already mention support for polygamma. Polygamma(0,x) == digamma(x) and polygamma(1,x) == trigramma(x).
So the answer to the likely unsupported integral is: a^-b*Gamma(b)*( (log(a)-polygamma(0,b))^2 + polygamma(1,b) ).
Not sure how many special functions like the bessel, hypergeometrics, etc, it does support. Not sure how likely Reduce developers are to be able to increase support for things like that.

Likely unsupported, because it requires a > 0 && b > 0. Perhaps it could return an answer, given those conditions. From the Wolfram sandbox:
https://sandbox.open.wolframcloud.com/app/objects/384d34c1-ac46-46a5-ad28-b91ed2876d5e#sidebar=compute
Assuming[a > 0 && b > 0, Integrate[Exp[-(a Exp[-x]) - b x] x^2, {x, -Infinity, Infinity}]]
Is where I got the answer. If I leave off the constraint, it'll return the same answer within a conditional expression.
Not sure how well Reduce handles conditionals; I'll get around to looking through the docs more thoroughly as I try to use it more. For now, http://www.reduce-algebra.com/manual/manualse16.html#x25-380005.3 appears to only cover user-provided conditionals.

Also, I'm glad I can pass reduce strings as a fall back. Trying to follow the example on the conditionals:

julia> rcall( :(abs(a*b*c)), "let sign(a) => 1, sign(b) => 1" )
ERROR: Reduce: 
***** nil not defined as switch 


abs(c)*a*b


***** nil not defined as switch 
Stacktrace:
 [1] ReduceCheck(::String) at /home/celrod/Downloads/JuliaPro-0.6.0.1/JuliaPro/pkgs-0.6.0.1/v0.6/Reduce/src/Reduce.jl:62
 [2] read(::Reduce.PSL) at /home/celrod/Downloads/JuliaPro-0.6.0.1/JuliaPro/pkgs-0.6.0.1/v0.6/Reduce/src/Reduce.jl:84
 [3] readsp(::Reduce.PSL) at /home/celrod/Downloads/JuliaPro-0.6.0.1/JuliaPro/pkgs-0.6.0.1/v0.6/Reduce/src/Reduce.jl:88
 [4] #rcall#13(::Array{Symbol,1}, ::Array{Symbol,1}, ::Function, ::Reduce.RExpr) at /home/celrod/Downloads/JuliaPro-0.6.0.1/JuliaPro/pkgs-0.6.0.1/v0.6/Reduce/src/rexpr.jl:245
 [5] (::Reduce.#kw##rcall)(::Array{Any,1}, ::Reduce.#rcall, ::Reduce.RExpr) at ./<missing>:0
 [6] #rcall#14(::Array{Symbol,1}, ::Array{Symbol,1}, ::Function, ::Expr) at /home/celrod/Downloads/JuliaPro-0.6.0.1/JuliaPro/pkgs-0.6.0.1/v0.6/Reduce/src/rexpr.jl:278
 [7] (::Reduce.#kw##rcall)(::Array{Any,1}, ::Reduce.#rcall, ::Expr) at ./<missing>:0
 [8] rcall(::Expr, ::String, ::Vararg{String,N} where N) at /home/celrod/Downloads/JuliaPro-0.6.0.1/JuliaPro/pkgs-0.6.0.1/v0.6/Reduce/src/rexpr.jl:282

So, I see Reduce itself returned the right answer, but the parser failed.

Dream Scatter
@chakravala
You are using rcall incorrectly there. Extra arguments to rcall have to be REDUCE switch names passed as Julia symbols, you can't just send it any random string. That is why the REDUCE error tells you that you did not enter a defined switch. For int and df it's different, since those can accept extra args. You have to make 2 separate calls to rcall if you want to first evaluate a REDUCE string and then a Julia expression object like this:
julia> rcall("let sign(a) => 1, sign(b) => 1")
""

julia> rcall( :(abs(a*b*c)))
:(abs(c) * a * b)
chriselrod
@chriselrod
Okay, cool, thanks
Dream Scatter
@chakravala

The only extra arguments that rcall takes are REDUCE switch names that are defined, for example:

julia> rcall(:(x^2+2x+1),:factor)
:((x + 1) ^ 2)

julia> factor(:(x^2+2x+1))
:((x + 1) ^ 2)

But you can also call REDUCE switches with the syntax in multiple ways

chriselrod
@chriselrod
Unfortunately, still get the same result for that integral.
Also, perhaps it would be worth adding the "solve" switch? But I can still use it through rcall:
julia> rcall(:(solve(((m - x) ^ 2 - s) / s ^ 2, s)))
:($(Expr(:cell1d, :(s = (m ^ 2 - 2 * m * x) + x ^ 2))))
Dream Scatter
@chakravala
Thanks for sending me all these examples, the solve and cell syntax is not handled yet, but I can look into that. At the moment I don't have time available to implement more features, but this weekend I might.
Dream Scatter
@chakravala
Note that solve is not a switch. Please take a look at the REDUCE manual to understand what a switch is. Also, the REDUCE developers are worth contacting on SourceForge, I can't speak for what they will or will not implement.
chriselrod
@chriselrod
No worries -- thanks for addressing my concerns. I'll look at the manual more before bugging you further.
Dream Scatter
@chakravala
Sure thing, I appreciate the feedback, it will help accelerate the development of Reduce.jl
Dream Scatter
@chakravala
By the way, on the curent master branch you can fully use the solve command, no more issue
julia> solve(((:m - :x) ^ 2 - :s) / :s ^ 2, :s)
1-element Array{Any,1}:
 :(s = (m ^ 2 - 2 * m * x) + x ^ 2)
Electrokek
@Electrokek
image.png
Electrokek
@Electrokek
Hello everyone) Sorry for this probably stupid question (please don't judge me a lot: I'm starting in using programs for problem-solving). Could anybody give a hint how can I implement a substitutional procedure for numerical values instead symbolic ones (like in the attached picture). It is a difficult to me to understand why Reduce give me :d instead numerical result. Thank you in advance) and sorry for English type mistakes