Giter Site home page Giter Site logo

chakravala / reduce.jl Goto Github PK

View Code? Open in Web Editor NEW
231.0 12.0 16.0 1.88 MB

Symbolic parser for Julia language term rewriting using REDUCE algebra

Home Page: http://www.reduce-algebra.com/

License: BSD 2-Clause "Simplified" License

Julia 100.00%
reduce symbolic-computation term-rewriting repl parser-generator syntax-tree metaprogramming computer-algebra math algebra

reduce.jl's Introduction

Reduce.jl

Reduce.jl

Symbolic parser generator for Julia language expressions using REDUCE algebra term rewriter

DOI Docs Stable Docs Dev Join the chat at gitter Build Status Build status Coverage Status codecov.io

The premise behind Reduce.jl is based on the idea that Symbol and Expr types can be translated into computer algebra rewrite commands and then automatically parsed back into Julia ASTs, essentially extending the Julia language into a fully programable symbolic AST rewrite environment.

REDUCE is a system for general algebraic computations of interest to mathematicians, scientists and engineers:

  • exact arithmetic using integers and fractions; arbitrary precision numerical approximation;
  • polynomial and rational function algebra; factorization and expansion of polynomials and rational functions;
  • differentiation and integration of multi-variable functions; exponential, logarithmic, trigonometric and hyperbolic;
  • output of results in a variety of formats; automatic and user controlled simplification of expressions;
  • substitutions and pattern matching of expressions; quantifier elimination and decision for interpreted first-order logic;
  • solution of ordinary differential equations; calculations with a wide variety of special (higher transcendental) functions;
  • calculations involving matrices with numerical and symbolic elements; general matrix and non-commutative algebra;
  • powerful intuitive user-level programming language; generating optimized numerical programs from symbolic input;
  • Dirac matrix calculations of interest to high energy physicists; solution of single and simultaneous equations.

Interface for applying symbolic manipulation on Julia expressions using REDUCE's term rewrite system:

  • reduce expressions are RExpr objects that can parse into julia Expr objects and vice versa;
  • interface link communicates and interprets via various reduce output modes using rcall method;
  • high-level reduce-julia syntax parser-generator walks arbitrary expression to rewrite mathematical code;
  • import operators from REDUCE using code generation to apply to arbitrary computational expressions;
  • interactive reduce> REPL within the Julia terminal window activated by } key;
  • extended arithmetic operators +,-,*,^,/,// compute on Symbol and Expr types;
  • provides hundreds of internal and external methods each supporting many argument types.

Additional packages that depend on Reduce.jl are maintained at JuliaReducePkg.

The upstream REDUCE software created by Anthony C. Hearn is maintained by collaborators on SourceForge.

This package is a heavily modifed version of Nathan Smith's Maxima.jl with many additional features.

Setup

The Reduce package provides the base functionality to work with Julia and Reduce expressions, provided that you have redcsl in your path. On GNU/Linux/OSX/Windows, Pkg.build("Reduce") will automatically download a precompiled binary for you. If you are running a different Unix operating system, the build script will download the source and attempt to compile redcsl for you, success depends on the build tools installed. Automated testing for Travis CI and appveyor using Linux, OSX, and Windows are fully operational using Reduce.

julia> Pkg.add("Reduce"); Pkg.build("Reduce")
julia> using Reduce
Reduce (Free CSL version, revision 4521),  11-March-2018 ...

For users who wish to experimentally apply additional precompilation, it is possible to enable extra precompilation scripts by setting the environment variable ENV["REDPRE"] = "1" in julia (only effective when Reduce is being compiled).

View the documentation stable / latest for more features and examples.

This Reduce package for the Julia language was created by github.com/chakravala for mathematics and computer algebra research with the upstream developed REDUCE software. Please consider donating to show your thanks and appreciation to this Julia project for interfacing the upstream REDUCE language at liberapay, GitHub Sponsors, Patreon, or contribute (documentation, tests, examples) in the repository.

Usage

The extended algebraic symbolic expression mode of Reduce.jl is activated with ForceImport.jl by

@force using Reduce.Algebra

This locally extends native Julia functions to Symbol and Expr types in the current module without extending global methods. Alternatively, the methods it provides can be accesed by prefixing Algebra. in front of the method.

Reduce expressions encapsulated into RExpr objects can be manipulated within julia using the standard syntax. Create an expression object either using the RExpr("expression") string constructor or R"expression". Additionally, arbitrary julia expressions can also be parsed directly using the RExpr(expr) constructor. Internally RExpr objects are represented as an array that can be accessed by calling *.str[n] on the object.

When Reduce is used in Julia, standard arithmetic operations are now extended to also work on Symbol and Expr types.

julia> 1-1/:n
:((n - 1) // n)

julia> ans^-:n
:(1 // ((n - 1) // n) ^ n)

julia> limit(ans,:n,Inf)
ℯ = 2.7182818284590...

Julia abstract syntax trees are automatically converted into sequences of reduce statements (using RExpr constructor) that are in return parsed into julia quote blocks usig parse. The rcall method is used to evaluate any type of expression.

julia> :(int(sin(im*x+pi)^2-1,x)) |> rcall
:((1 - (ℯ ^ (4x) + 4 *^ (2x) * x)) // (8 *^ (2x)))

However, there are often multiple equivalent ways of achieving the same result:

julia> int(sin(im*:x+π)^2-1,:x)
:((1 - (ℯ ^ (4x) + 4 *^ (2x) * x)) // (8 *^ (2x)))

The output of rcall will be the same as its input type.

julia> "int(sin(y)^2, y)" |> rcall
"( - cos(y)*sin(y) + y)/2"

Use rcall(expr,switches...) to evaluate expr using REDUCE mode switches like :expand, :factor, and :latex.

julia> :((x+im+π)^2; int(1/(1+x^3),x)) |> RExpr
^(+(x,i,pi),2);
int(/(1,+(1,^(x,3))),x);

julia> rcall(ans,:horner) |> parse
quote
    ((π + 2x) * π + 2 *+ x) * im + x ^ 2) - 1
    ((2 * sqrt(3) * atan((2x - 1) // sqrt(3)) - log((x ^ 2 - x) + 1)) + 2 * log(x + 1)) // 6
end

Mathematical operators and REDUCE modes can be applied directly to Expr and RExpr objects.

julia> Expr(:function,:(fun(a,b)),:(return 4x^4-44x^3+61x^2+270x-525)) |> horner
:(function fun(a, b)
        return ((4 * (x - 11) * x + 61) * x + 270) * x - 525
    end)

Additionally, REDUCE switch statements can be used as macros to control evaluation of expressions.

julia> @rounded @factor x^3-2x+1
:((x + 1.61803398875) * (x - 1) * (x - 0.61803398875))

Most core features have a corresponding Julia method, but language features that have not been implemented yet can also be directly evaluated with rcall using a synergy of julia syntax.

julia> Expr(:for,:(i=2:34),:(product(i))) |> rcall
:(@big_str "295232799039604140847618609643520000000")

The squash function provides a way to reduce full program blocks into simplified functions, e.g.

julia> Expr(:function,:(example(a,b)),quote
           z = 3
           target = z * :a * :b
           z -= 1
           target += z*(1-:a)*(1-:b)
       end) |> squash |> factor
:(function example(a, b)
        (5b - 2) * a - 2 * (b - 1)
    end)

where z is a program variable and :a and :b are symbolic variables.

Loading packages

Packages which come shipped with REDUCE can be loaded with the load_package method. For example, the optimize method is available with

julia> load_package(:scope)

julia> Algebra.optimize(:(z = a^2*b^2+10*a^2*m^6+a^2*m^2+2*a*b*m^4+2*b^2*m^6+b^2*m^2))
quote
    g40 = b * a
    g44 = m * m
    g41 = g44 * b * b
    g42 = g44 * a * a
    g43 = g44 * g44
    z = g41 + g42 + g40 * (2g43 + g40) + g43 * (2g41 + 10g42)
end

Other packages can be loaded, but not all of them come with pre-defined Julia dispatch methods.

Matrices

Some special support for symbolic matrices has also been added to Reduce.Algebra methods,

julia> [:x 1; :y 2]^-1
2×2 Array{Any,2}:
 :(2 / (2x - y))   :(-1 / (2x - y))
 :(-y / (2x - y))  :(x / (2x - y))

The jacobian method has been added to the ReduceLinAlg package, which is dedicated to the LINALG extra package included with Reduce binaries.

julia> using ReduceLinAlg

julia> eqns = [:x1-:x2, :x1+:x2-:x3+:x6t, :x1+:x3t-:x4, 2*:x1tt+:x2tt+:x3tt+:x4t+:x6ttt, 3*:x1tt+2*:x2tt+:x5+0.1*:x8, 2*:x6+:x7, 3*:x6+4*:x7, :x8-sin(:x8)]
8-element Array{Expr,1}:
 :(x1 - x2)
 :(x1 - ((x3 - x6t) - x2))
 :((x3t - x4) + x1)
 :(x4t + x6ttt + x3tt + x2tt + 2x1tt)
 :((10x5 + x8 + 20x2tt + 30x1tt) // 10)
 :(2x6 + x7)
 :(3x6 + 4x7)
 :(x8 - sin(x8))

julia> vars = [:x1, :x2, :x3, :x4, :x6, :x7, :x1t, :x2t, :x3t, :x6t, :x7t, :x6tt, :x7tt];

julia> jacobian(eqns, vars) |> Reduce.mat
8×13 Array{Any,2}:
 1  -1   0   0  0  0  0  0  0  0  0  0  0
 1   1  -1   0  0  0  0  0  0  1  0  0  0
 1   0   0  -1  0  0  0  0  1  0  0  0  0
 0   0   0   0  0  0  0  0  0  0  0  0  0
 0   0   0   0  0  0  0  0  0  0  0  0  0
 0   0   0   0  2  1  0  0  0  0  0  0  0
 0   0   0   0  3  4  0  0  0  0  0  0  0
 0   0   0   0  0  0  0  0  0  0  0  0  0

The package also provides a demonstration of how additional Reduce methods can be imported into Julia.

Output mode

Various output modes are supported. While in the REPL, the default nat output mode will be displayed for RExpr objects.

julia> :(sin(x*im) + cos(y*MathConstants.φ)) |> RExpr

     (sqrt(5) + 1)*y
cos(-----------------) + sinh(x)*i
            2

This same output can also be printed to the screen by calling print(nat(r)) method.

It is possible to direclty convert a julia expression object to LaTeX code using the latex method.

julia> print(@latex sin(x) + cos(y*MathConstants.φ))
\begin{displaymath}
\cos \left(\left(\left(\sqrt {5}+1\right) y\right)/2\right)+\sin \,x
\end{displaymath}

Internally, this command essentially expands to rcall(:(sin(x) + cos(y*MathConstants.φ)),:latex) |> print, which is equivalent.

latex-equation

In IJulia the display output of RExpr objects will be rendered LaTeX with the rlfi REDUCE package in latex mode.

REPL interface

Similar to ? help and ; shell modes in Julia, Reduce provides a reduce> REPL mode by pressing shift+] as the first character in the julia terminal prompt. The output is in nat mode.

reduce> df(atan(golden_ratio*x),x);

          2              2
 sqrt(5)*x  + sqrt(5) - x  + 1
-------------------------------
           4      2
       2*(x  + 3*x  + 1)

Troubleshooting

If the reduce> REPL is not appearing when } is pressed or the Reduce pipe is broken, the session can be restored by simply calling Reduce.Reset(), without requiring a restart of julia or reloading the package. This kills the currently running Reduce session and then re-initializes it for new use.

Otherwise, questions can be asked on gitter/discourse or submit your issue or pull-request if you require additional features or noticed some unusual edge-case behavior.

AbstractTensors interoperability

By importing the AbstractTensors.jl module, the Reduce is able to correctly bypass operations on TensorAlgebra elements to the correct methods within the scope of the Reduce.Algebra module. This requires no additional overhead for the Grassmann.jl or Reduce packages, because the AbstractTensors interoperability interface enables separate precompilation of both.

Background

The Reduce package currently provides a robust interface to directly use the CSL version of REDUCE within the Julia language and the REPL. This is achieved by interfacing the abstract syntax tree of Expr objects with the parser generator for RExpr objects and then using an IOBuffer to communicate with redpsl.

REDUCE is a system for doing scalar, vector and matrix algebra by computer, which also supports arbitrary precision numerical approximation and interfaces to gnuplot to provide graphics. It can be used interactively for simple calculations but also provides a full programming language, with a syntax similar to other modern programming languages. REDUCE has a long and distinguished place in the history of computer algebra systems. Other systems that address some of the same issues but sometimes with rather different emphasis are Axiom, Macsyma (Maxima), Maple and Mathematica. REDUCE is implemented in Lisp (as are Axiom and Macsyma), but this is completely hidden from the casual user. REDUCE primarily runs on either Portable Standard Lisp (PSL) or Codemist Standard Lisp (CSL), both of which are included in the SourceForge distribution. PSL is long-established and compiles to machine code, whereas CSL is newer and compiles to byte code. Hence, PSL may be faster but CSL may be available on a wider range of platforms.

Releases of Reduce.jl enable the general application of various REDUCE functionality and packages to manipulate the Julia language to simplify and compute new program expressions at run-time. Intended for uses where a symbolic pre-computation is required for numerical algorithm code generation.

Julia is a high-level, high-performance dynamic programming language for numerical computing. It provides a sophisticated compiler, distributed parallel execution, numerical accuracy, and an extensive mathematical function library. Julia’s Base library, largely written in Julia itself, also integrates mature, best-of-breed open source C and Fortran libraries for linear algebra, random number generation, signal processing, and string processing. The strongest legacy of Lisp in the Julia language is its metaprogramming support. Like Lisp, Julia represents its own code as a data structure of the language itself. Since code is represented by objects that can be created and manipulated from within the language, it is possible for a program to transform and generate its own code. This allows sophisticated code generation without extra build steps, and also allows true Lisp-style macros operating at the level of abstract syntax trees.

reduce.jl's People

Contributors

chakravala avatar dan-robertson avatar ghyatzo avatar githubtomtom avatar gitter-badger avatar staticfloat avatar tkelman avatar tomyun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reduce.jl's Issues

factor function clogs the pipe and then fails

Hello,

I've been trying to use the function Algebra.factor(r...) but upon calling Algebra.factor(:b) as shown in the docs (where :b is one of my variables) i get the following output

julia> Algebra.factor(:b)
┌ Warning: Reduce pipe clogged by factor function, failure after 17 tries
└ @ Reduce ~/.julia/packages/Reduce/gkKoh/src/Reduce.jl:73
ERROR: Reduce: If generated code has many calls to factor, try to minimize the number of calls with REDUCE switches and use `Reduce.Reset()` if you'd like to start a new pipe.
Stacktrace:
 [1] #parse_args#69(::Int64, ::typeof(parse_args), ::String, ::RExpr) at /Users/ghyatzo/.julia/packages/Reduce/gkKoh/src/parser.jl:358
 [2] #parse_args at ./none:0 [inlined]
 [3] #factor#225 at /Users/ghyatzo/.julia/packages/Reduce/gkKoh/src/parser.jl:437 [inlined]
 [4] factor at /Users/ghyatzo/.julia/packages/Reduce/gkKoh/src/parser.jl:437 [inlined]
 [5] factor(::Symbol) at /Users/ghyatzo/.julia/packages/Reduce/gkKoh/src/parser.jl:798
 [6] top-level scope at none:0

A M(W)E is

using Reduce
@force using Reduce.Algebra
using ReduceLinAlg

Algebra.factor(:b)

what could be the issue?

ChatGPT analysis of Reduce.jl parser

The given code appears to be a set of regular expressions (regex) defined in the programming language to match certain patterns in strings. Each regex is represented as a string.

Here's a breakdown of each regex:

  1. const prefix = r"(?<!\))(([A-Za-z_][A-Za-z_0-9]*)|([\^+\/-])|([*]{1,2})|(- ))(?=\()"

    • This regex is used to match prefixes in an expression that precede an opening parenthesis "(" but are not preceded by a closing parenthesis ")".
    • It captures four groups:
      • [A-Za-z_][A-Za-z_0-9]*: Matches an identifier (variable name) consisting of letters, numbers, and underscores, starting with a letter or underscore.
      • [\^+\/-]: Matches an arithmetic operator (^, +, /, or -).
      • [*]{1,2}: Matches an asterisk (*) occurring one or two times consecutively.
      • (- ): Matches a hyphen followed by a space ("- ").
    • The lookbehind (?<!\)) ensures that there is no closing parenthesis before the matched prefix, and the lookahead (?=\() ensures that there is an opening parenthesis immediately after the prefix.
  2. const parens = r"\(((?>[^\(\)]+)|(?R))*\)"

    • This regex is used to match parentheses and their contents in an expression.
    • It uses recursion to handle nested parentheses.
    • ((?>[^\(\)]+)|(?R))* matches any non-empty sequence of characters that are not parentheses or recursively matches nested parentheses.
    • \(...\) matches the opening and closing parentheses themselves.
  3. const braces = r"{((?>[^{}]+)|(?R))*}"

    • This regex is similar to the previous one but used to match curly braces and their contents in an expression.
  4. const infix1 = r"^(([\^\+\/])|([*]{1,2})|( -)|( \+)|( [*]{1,2})|( /)|( \^))"

    • This regex is used to match infix operators at the beginning of an expression.
    • It captures eight groups:
      • [\^\+\/]: Matches an arithmetic operator (^, +, or /).
      • [*]{1,2}: Matches an asterisk (*) occurring one or two times consecutively.
      • ( -): Matches a space followed by a hyphen (" -").
      • ( \+): Matches a space followed by a plus sign (" +").
      • ( [*]{1,2}): Matches a space followed by an asterisk (*) occurring one or two times consecutively.
      • ( /): Matches a space followed by a forward slash (" /").
      • ( \^): Matches a space followed by a caret (" ^").
    • The caret (^) at the beginning of the regex anchors the pattern to the start of the string.
  5. const infix2 = r"(([\^+\/])|([*]{1,2}))$"

    • This regex is used to match infix operators at the end of an expression.
    • It is similar to infix1, but without the caret (^) at the beginning and with the dollar sign ($) at the end to anchor the pattern to the end of the string.
  6. const assign = r"^([A-Za-z_ ][A-Za-z_0-9 ]*)(:=)"

    • This regex is used to match an assignment statement in the form of "variable_name := ".

It captures two groups:
- [A-Za-z_ ][A-Za-z_0-9 ]*: Matches an identifier (variable name) consisting of letters, numbers, and underscores, starting with a letter or underscore, followed by any number of alphanumeric characters or spaces.
- :=: Matches the assignment operator (colon followed by equals sign).

Please note that the regex patterns are provided as raw strings (prefixed with r in some programming languages) to handle special characters and escape sequences appropriately.

@int128_str error when using solve

Hello;
I'm having the following problem:

julia> 1.1111e-15*:a
:((11111a) / 10000000000000000000)

julia> solve(1.111e-15*:a)
(:(a = 0),)

julia> solve(1.1111e-15*:a)
ERROR: Reduce: Macro Core.var"@int128_str" block structure not supported

10000000000000000000

I'm using Reduce version v1.2.9

Get Julia handle for REDUCE procedures?

Given this code:

julia> """
       procedure andb(a, b);
       if a=1 and b=1 then 1 else 0;
       """ |> rcall
"andb"

How would I be able to "mirror" it into Julia REPL?

image

(I can use rcall, but that seems a bit convoluted)

simplification/factorization of expressions

Hello
This report may not be about a bug but about a lack of documentation.
How do I simplify/factorize the rather big symbolic expression intersectionPointPair computed below using reduce.jl ?
Neither intersectionPointPair |> factor or Algebra.optimize(intersectionPointPair) seem to be the way to do it.

using Reduce
using Grassmann
load_package(:scope)

@basis S"∞∅+++"

A = :xa*v1 + :ya*v2 + :za*v3
B = :xb*v1 + :yb*v2 + :zb*v3
C = :xc*v1 + :yc*v2 + :zc*v3
D = :xd*v1 + :yd*v2 + :zd*v3

pA = ↑(A)
pB = ↑(B)
pC = ↑(C)
pD = ↑(D)

pO = ↑(0*v1+0*v2+0*v3)
p∞ = ↑(v∞)

AB = pA ∧ pB
CD = pC ∧ pD

planeAOB = pA ∧ pB ∧ pO ∧ v∞
planeCOD = pC ∧ pD ∧ pO ∧ v∞

S = pA ∧ pB ∧ pC ∧ pD

intersectionPointPair = planeAOB ∨ planeCOD ∨ S

promotion fails for subtyping

@subtype SymReal <: Real

SymReal(:x) * im

I'm wondering if there should be some specialization for subtypes of Real etc.?

Errors when using Unicode string

julia> using Reduce
Reduce (Free CSL version, revision 5286), 01-Mar-20 ...
REPL mode REDUCE initialized. Press } to enter and backspace to exit.

reduce> α;
ERROR: StringIndexError("α;", 2)
Stacktrace:
 [1] string_index_err(::String, ::Int64) at ./strings/string.jl:12
 [2] getindex at ./strings/string.jl:250 [inlined]
 [3] parserepl(::String) at /Users/tomyun/.julia/packages/Reduce/fWMAZ/src/repl.jl:32
 [4] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [5] invokelatest at ./essentials.jl:711 [inlined]
 [6] (::REPL.var"#do_respond#38"{Bool,typeof(Reduce.parserepl),REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:724
 [7] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [8] invokelatest at ./essentials.jl:711 [inlined]
 [9] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/LineEdit.jl:2354
 [10] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:1055
 [11] run_repl(::REPL.AbstractREPL, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:206
 [12] (::Base.var"#764#766"{Bool,Bool,Bool,Bool})(::Module) at ./client.jl:383
 [13] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [14] invokelatest at ./essentials.jl:711 [inlined]
 [15] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:367
 [16] exec_options(::Base.JLOptions) at ./client.jl:305
 [17] _start() at ./client.jl:484

On the other hand, running the same statement via rcall() seems to work fine.

julia> "α;" |> rcall
"!#03b1;"

julia> ans |> RExpr

α

In the meantime, calling a similar statement can make my REPL stuck indefinitely.

julia> "αα;" |> rcall

# no response

Asynchronous concurrency gets Reduce confused

The following test works. But take out the Semaphore and it hangs and/or scrambles the results. Perhaps Reduce.jl should be using a semaphore/mutex internally? This problem arose when I was using Reduce.jl with Genie.jl, and it caused some hard to debug problems, such as one HTTP request hanging until the next request came in, or having rcall return the result from someone else's query.

using Reduce

reduce_sem = Base.Semaphore(1)

println("create")
tasks = []
for i in 1:10
    t = @task begin
        println("begin $i")
        Base.acquire(reduce_sem)
        println("rcall $i")
        y = :($i * x) |> rcall
        println("$i -> $y")
        Base.release(reduce_sem)
        println("released")
    end
    push!(tasks, t)
end

println("schedule")
for t in tasks
    schedule(t)
end

println("wait")
for t in tasks
    wait(t)
end

Error when trying to build package Reduce.

julia> Pkg.build("Reduce")
  Building Reduce → `~/.julia/packages/Reduce/YlFQE/deps/build.log`
┌ Error: Error building `Reduce`: 
│   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
│                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100   746  100   746    0     0    490      0  0:00:01  0:00:01 --:--:--   490
│ 
│ gzip: stdin: not in gzip format
│ tar: Child returned status 1
│ tar: Error is not recoverable: exiting now
│ ERROR: LoadError: failed process: Process(`tar -xvf reduce.tar.gz`, ProcessExited(2)) [2]
│ Stacktrace:
│  [1] error(::String, ::Base.Process, ::String, ::Int64, ::String) at ./error.jl:42
│  [2] pipeline_error at ./process.jl:695 [inlined]
│  [3] #run#505(::Bool, ::Function, ::Cmd) at ./process.jl:653
│  [4] run(::Cmd) at ./process.jl:651
│  [5] top-level scope at /home/kir/.julia/packages/Reduce/YlFQE/deps/build.jl:61
│  [6] include at ./boot.jl:317 [inlined]
│  [7] include_relative(::Module, ::String) at ./loading.jl:1038
│  [8] include(::Module, ::String) at ./sysimg.jl:29
│  [9] include(::String) at ./client.jl:388
│  [10] top-level scope at none:0
│ in expression starting at /home/kir/.julia/packages/Reduce/YlFQE/deps/build.jl:30
│ Building Reduce.jl with CSL binaries ... 
└ @ Pkg.Operations /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Pkg/src/Operations.jl:1068

I think there is a problem with tar-gz file which contains Reduce. Actually, it is definitely NOT a tar-gz archive (it cannot be opened).

Actually, this problem can be avoided, for example: I go to the site with Reduce files and manually install the latest version: Reduce-svn4717-src with tar-gz format. Then I place this archive into deps folder with the proper name "reduce.tar.gz" and commented out the line
download(http*date[ρ]*"/linux64"*src*rsvn[ρ]*"_amd64.tgz"*dl,joinpath(wdir,rtg))
in build.jl.

And there is definitely a problem with the line 10 in build file:

global ver = read(f,String) |> parse
ERROR: MethodError: no method matching parse(::String)

So you have to write parse(Int, "2") for example.

Type-piracy?

While

Fully extends the +,-,*,^,/,// operators to work with Symbol and Expr types by building on the new parser features from the previous release, along with many other new capabilities now available.

is a very good feature, it's also type-piracy. I wonder if there's a safer way to implement that without losing the functionality.

Unable to load into Julia Markdown

When I enter

using Reduce

In a Julia markdown, it doesn't load after hours, most packages load in a little over a minute. So, I think it's a problem with Reduce.

It loads into the REPL just fine, and I can execute all sorts of manipulations, as well as gnuplots.

Base.Meta.ParseError("invalid operator \"--\"") when multiprocessing

Hello,

I'm using your package with a huge list of expression.
Basically, I'm doing this:

res = map(exp -> (exp, rcall(exp)), res)

It run correctly but it is taking forever and my CPU is barely used.

So I wanted to speed things up with multiprocessing. I tried with pmap, @threads, @spawn and @distributed and starting with julia -p 6 in deed.

Most of the time I get this error :

ERROR: LoadError: On worker 2:
Base.Meta.ParseError("invalid operator \"--\"")

Or no error but no increase in speed (and CPU < 10%).

Moreover, I have this error without doing any multiprocessing.
With the same code I can crash if I start julia ./script.jl
but I don't crash inside the REPL julia> include("GenerateFormula4.jl")
I'm using Windows 10.

I'm still new to Julia so I'm not sure what could cause the problem.

Benchmarks

It would be good to benchmark against SymEngine for some matrix operations + inversions to see what the difference between the two are.

Type-constrained functions

Some context... I'd like to be able to manipulate logpdfs of Distributions. In most cases this is delegated to a special function. For example,

logpdf(Normal(μ, σ), x)

calls

normlogpdf(μ::Real, σ::Real, x::Number) = normlogpdf(zval(μ, σ, x)) - log(σ)

which calls

normlogpdf(z::Number) = -(abs2(z) + log2π)/2

These type constraints don't seem Reduce-friendly. Here's a simple test:

julia> f(x) = x + 3
f (generic function with 1 method)

julia> f(:x)
:(x + 3)

julia> g(x::Real) = x + 3
g (generic function with 3 methods)

julia> g(:x)

This seems to hang.

I could fall back on hacking Distributions.jl or pasting the code in. But it would be pretty great to instead annotate an RExpr with a type. Is this possible?

Undefined Error on rs

Hey! I want to use Reduce.Reset() function in the REPL command line. But there is an error that says:
ERROR: UndefVarError: rs not defined. Here rs is a variable that appears in the function code. So I was wondering if there is something I missed or if it is an issue. Thanks in advance!

Conflict on multiplication

julia> using ForceImport
julia> @force using Reduce.Algebra
Reduce (Free CSL version, revision 4534), 05-Apr-18 ...
WARNING: ignoring conflicting import of Algebra.* into Main

julia> a=:x
:x

julia> a*1
ERROR: MethodError: no method matching *(::Symbol, ::Int64)
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:424
  *(::Bool, ::T<:Number) where T<:Number at bool.jl:101
  *(::Complex{Bool}, ::Real) at complex.jl:255

Reduce Not loading in JuliaPro

I'm getting the following error:

julia> using Reduce
INFO: Precompiling module Reduce.
ERROR: InitError: MethodError: no method matching contains(::String, ::Regex)
Closest candidates are:
contains(::Function, ::Any, ::Any) at reduce.jl:664
contains(::AbstractString, ::AbstractString) at strings/search.jl:378
Stacktrace:
[1] ReduceCheck at /home/matt/programs/juliapro/JuliaPro-0.6.2.1/JuliaPro/pkgs-0.6.2.1/v0.6/Reduce/src/Reduce.jl:60 [inlined]
[2] macro expansion at /home/matt/programs/juliapro/JuliaPro-0.6.2.1/JuliaPro/pkgs-0.6.2.1/v0.6/Reduce/src/Reduce.jl:209 [inlined]
[3] anonymous at ./:?
[4] Load() at /home/matt/programs/juliapro/JuliaPro-0.6.2.1/JuliaPro/pkgs-0.6.2.1/v0.6/Reduce/src/Reduce.jl:224
[5] init() at /home/matt/programs/juliapro/JuliaPro-0.6.2.1/JuliaPro/pkgs-0.6.2.1/v0.6/Reduce/src/Reduce.jl:191
[6] _include_from_serialized(::String) at ./loading.jl:157
[7] _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:200
[8] _require(::Symbol) at ./loading.jl:498
[9] require(::Symbol) at ./loading.jl:405
during initialization of module Reduce

Add compatibility with other mathematical software

Thanks for all the work in Reduce.jl, it is a great tool.
I need to complement it with Polymake.jl (to study some properties of the Newton polytope of a polynomial,
it is for CRNT.jl.
So, I need the exponents of a polynomial as Julia vectors of integers, and ideally another Julia vector, with the same order, containing the coefficients.
For this, I started with the exponent of a term

function extractexponentsofterm(T::RExpr)
    return v->Algebra.deg(T,v)
end

julia> z=R"2*x*y^2+4*x^2-1"

      2        2
4*x  + 2*x*y  - 1
    
julia> extractexponentsofterm(Algebra.lterm(z,:y)).([:x,:y,:z])
3-element Array{RExpr,1}:
 1
 2
 0

But I am not sure how to iterate over all the term of a polynomial, and how to extract the coefficient neither.
One can iterate over z:=z-lterm(z) but requiring arithmetic operations seems not optimal.

Missing `+` overload when trying to create a point with symbolic coefficients

So I wanted to make a symbolic sphere using Reduce.jl symbols. I started off by making a point like this:

using Grassmann, Reduce;

X = :x*v1 + :y*v2 + :z*v3
pt = ↑(X)

But I get an error:

MethodError: no method matching +(::Float64, ::Expr)
Closest candidates are:
  +(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:529
  +(::Float64, !Matched::Float64) at float.jl:401
  +(::AbstractFloat, !Matched::Bool) at bool.jl:106
  ...

Stacktrace:
 [1] +(::Float64, ::Float64, ::Expr, ::Expr, ::Expr) at ./operators.jl:529
 [2] ∑(::Float64, ::Float64, ::Expr, ::Vararg{Expr,N} where N) at /home/micah/.julia/packages/AbstractTensors/4KbT3/src/AbstractTensors.jl:280
 [3] macro expansion at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:0 [inlined]
 [4] *(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:856
 [5] ^(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Int64) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/algebra.jl:615
 [6] macro expansion at ./none:0 [inlined]
 [7] literal_pow at ./none:0 [inlined]
 [8] ↑(::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/Grassmann.jl:124
 [9] top-level scope at In[6]:2

I can get around this by first defining:

using Base;
Base.:+(a::Float64, b::Expr) = a*v+b;

It fixes the problem, for now, but seems a little too hacky to make a PR worthy solution. I tried:

using Base;
Base.:+(a::Number, b::Expr) = a*v+b;

and got:

MethodError: +(::Simplex{⟨∞∅+++⟩,0,v,Float64}, ::Expr) is ambiguous. Candidates:
  +(a::T, b::Union{Expr, Symbol, #s71, #s70} where #s70<:Complex where #s71<:Real) where T<:TensorGraded in Grassmann at /home/micah/.julia/packages/Grassmann/EjCrQ/src/algebra.jl:706
  +(a::Number, b::Expr) in Main at In[7]:2
Possible fix, define
  +(::T, ::Expr) where T<:TensorGraded

Stacktrace:
 [1] +(::Float64, ::Expr) at ./In[7]:2
 [2] +(::Float64, ::Float64, ::Expr, ::Expr, ::Expr) at ./operators.jl:529
 [3] ∑(::Float64, ::Float64, ::Expr, ::Vararg{Expr,N} where N) at /home/micah/.julia/packages/AbstractTensors/4KbT3/src/AbstractTensors.jl:280
 [4] macro expansion at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:0 [inlined]
 [5] *(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:856
 [6] ^(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Int64) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/algebra.jl:615
 [7] macro expansion at ./none:0 [inlined]
 [8] literal_pow at ./none:0 [inlined]
 [9] ↑(::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/Grassmann.jl:124
 [10] top-level scope at In[7]:3

By this point I got kinda lost trying to define

Possible fix, define
  +(::T, ::Expr) where T<:TensorGraded

unsupported parse on subscripts and superscripts

some symbols like :x₁ (:x\_1<tab>) or :x¹ (:x\^1<tab>) have incorrect action.

julia> using SyntaxTree, Reduce

julia> @force using Reduce.Algebra

julia> :x₁
:x₁

julia> typeof(:x₁)
Symbol

julia> RExpr(:x₁)
Error showing value of type RExpr:
ERROR: Reduce: 

Declare x operator ?  (Y or N)

Type Y or N


at
Stacktrace:
 [1] ReduceCheck at /home/user/.julia/packages/Reduce/m2Cjk/src/Reduce.jl:50 [inlined]
 [2] read(::Reduce.PSL) at /home/user/.julia/packages/Reduce/m2Cjk/src/Reduce.jl:85
 [3] rcall(::RExpr; on::Array{Symbol,1}, off::Array{Symbol,1}) at /home/user/.julia/packages/Reduce/m2Cjk/src/rexpr.jl:473
 [4] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::RExpr) at /home/user/.julia/packages/Reduce/m2Cjk/src/rexpr.jl:127
 [5] display(::REPL.REPLDisplay, ::MIME{Symbol("text/plain")}, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:214
 [6] display(::REPL.REPLDisplay, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:218
 [7] display(::Any) at ./multimedia.jl:328
 [8] #invokelatest#1 at ./essentials.jl:710 [inlined]
 [9] invokelatest at ./essentials.jl:709 [inlined]
 [10] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:238
 [11] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:223
 [12] (::REPL.var"#do_respond#54"{Bool,Bool,REPL.var"#64#73"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:822
 [13] #invokelatest#1 at ./essentials.jl:710 [inlined]
 [14] invokelatest at ./essentials.jl:709 [inlined]
 [15] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/LineEdit.jl:2355
 [16] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:1144
 [17] (::REPL.var"#38#42"{REPL.LineEditREPL,REPL.REPLBackendRef})() at ./task.jl:356

julia> RExpr(:(x₁))
Error showing value of type RExpr:
ERROR: Reduce: 

Declare x operator ?  (Y or N)

Type Y or N


at
Stacktrace:
 [1] ReduceCheck at /home/user/.julia/packages/Reduce/m2Cjk/src/Reduce.jl:50 [inlined]
 [2] read(::Reduce.PSL) at /home/user/.julia/packages/Reduce/m2Cjk/src/Reduce.jl:85
 [3] rcall(::RExpr; on::Array{Symbol,1}, off::Array{Symbol,1}) at /home/user/.julia/packages/Reduce/m2Cjk/src/rexpr.jl:473
 [4] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::RExpr) at /home/user/.julia/packages/Reduce/m2Cjk/src/rexpr.jl:127
 [5] display(::REPL.REPLDisplay, ::MIME{Symbol("text/plain")}, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:214
 [6] display(::REPL.REPLDisplay, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:218
 [7] display(::Any) at ./multimedia.jl:328
 [8] #invokelatest#1 at ./essentials.jl:710 [inlined]
 [9] invokelatest at ./essentials.jl:709 [inlined]
 [10] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:238
 [11] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:223
 [12] (::REPL.var"#do_respond#54"{Bool,Bool,REPL.var"#64#73"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:822
 [13] #invokelatest#1 at ./essentials.jl:710 [inlined]
 [14] invokelatest at ./essentials.jl:709 [inlined]
 [15] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/LineEdit.jl:2355
 [16] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /build/julia-CrxBG0/julia-1.5.3+dfsg/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:1144
 [17] (::REPL.var"#38#42"{REPL.LineEditREPL,REPL.REPLBackendRef})() at ./task.jl:356

environment:

Linux 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux

Debian ⛬  julia/1.5.3+dfsg-3

[[Reduce]]
deps = ["AbstractTensors", "ForceImport", "LinearAlgebra", "REPL", "ReplMaker", "SyntaxTree"]
git-tree-sha1 = "8c2a1b94300d0a1a475fc651518cef24db1f0b79"
uuid = "93e0c654-6965-5f22-aba9-9c1ae6b3c259"
version = "1.2.12"

Deadlock situation with function expressions

The Reduce.jl, the following works
using Reduce
Reduce.expand(“3x+2y+2.12x+3.2y”)

However if I try the following
expand(“f(X,Y)+2g(X1,X2,X2)+2f(X,Y)”)
it gets into an infinite loop. If I interrupt once, and try again then it comes out with a prompt
“Type Y or N?;\n3f(x,y) + 2g(x1,x2,x2)”

and on the third time, it works well.
“3f(x,y) + 2g(x1,x2,x2)”
Looking into the code, it appears that there is an error check which prompts the Type Y or N? Is this an intended check? Can this be fixed?
This is a nice package that helps in quite a bit of symbolic expression simplifications. It would be nice to have this fixed. Or any other suggestions to work around it (instead of manually interrupting this 2 times).

Thanks for the help/suggestions

using Reduce expand("3x+2y+2.12x+3.2y") expand("f(X,Y)+2g(X1,X2,X2)+2f(X,Y)")

Substituting single expression without using a tuple.

Hello,

I've encountered the following issue:
Algebra.sub(:(r=1), expr) that returns an error where sub does not have the method sub(::Expr, expr)

Instead by writing
Algebra.sub((:(r=1),), expr) hence putting :(r=1) inside a tuple works .

I actually went to check the source code and the sub function only has methods for tuples of expressions.
I personally find the notation (:(r=1),) rather confusing. Can't something like the following be implemented?
Algebra.sub(s::Expr, expr) = Algebra.sub(string(list(s)), expr).

I tested it and it works
Any particular reason why the single expression is not implemented?

Thanks

bug in the parsing of parenthesis with extra whitespace

Hello
is it me or there is a bug in the regressive product implementation ?

using Reduce
using Grassmann

@basis S"∞∅+++"

A = :xa*v1 + :ya*v2 + :za*v3
B = :xb*v1 + :yb*v2 + :zb*v3
C = :xc*v1 + :yc*v2 + :zc*v3
D = :xd*v1 + :yd*v2 + :zd*v3

pA = ↑(A)
pB = ↑(B)
pC = ↑(C)
pD = ↑(D)

pO = ↑(0*v1+0*v2+0*v3)
p∞ = ↑(v∞)

AB = pA ∧ pB
CD = pC ∧ pD

planeAOB = pA ∧ pB ∧ pO ∧ v∞
planeCOD = pC ∧ pD ∧ pO ∧ v∞

S = pA ∧ pB ∧ pC ∧ pD

intersectionPointPair = planeAOB ∨ planeCOD ∨ S

julia> intersectionPointPair = planeAOB ∨ planeCOD ∨ S
ERROR: type Nothing has no field match
Stacktrace:
[1] getproperty(::Any, ::Symbol) at ./Base.jl:20
[2] #parse_expr#46(::Int64, ::typeof(parse_expr), ::String, ::RExpr) at .julia/packages/Reduce/4dmwd/src/parser.jl:251
[3] (::getfield(Reduce, Symbol("#kw##parse_expr")))(::NamedTuple{(:be,),Tuple{Int64}}, ::typeof(parse_expr), ::String, ::RExpr) at ./none:0
[4] #parse#76(::Int64, ::typeof(parse), ::RExpr) at .julia/packages/Reduce/4dmwd/src/parser.jl:438
[5] parse(::RExpr) at .julia/packages/Reduce/4dmwd/src/parser.jl:438
[6] convert at .julia/packages/Reduce/4dmwd/src/rexpr.jl:414 [inlined]
[7] unfold_expr_force(::Symbol, ::Symbol, ::Expr, ::Expr) at .julia/packages/Reduce/4dmwd/src/parser.jl:847
[8] #unfold_expr#77(::Bool, ::typeof(Reduce.unfold_expr), ::Symbol, ::Symbol, ::Expr, ::Expr) at .julia/packages/Reduce/4dmwd/src/parser.jl:806
[9] unfold_expr(::Symbol, ::Symbol, ::Expr, ::Expr) at .julia/packages/Reduce/4dmwd/src/parser.jl:801
[10] unfold(::Symbol, ::Symbol, ::Expr, ::Expr) at .julia/packages/Reduce/4dmwd/src/parser.jl:863
[11] ∑(::Expr, ::Expr) at .julia/packages/Reduce/4dmwd/src/parser.jl:793
[12] addmulti!(::StaticArrays.SizedArray{Tuple{32},Any,1,1}, ::Expr, ::UInt64, ::Grassmann.Dimension{5}) at .julia/packages/Grassmann/cEoGT/src/algebra.jl:101
[13] meetaddmulti!(::Signature{5,3,0x0000000000000002,0,0}, ::StaticArrays.SizedArray{Tuple{32},Any,1,1}, ::UInt64, ::UInt64, ::Expr) at .julia/packages/Grassmann/cEoGT/src/algebra.jl:155
[14] ∨(::MultiVector{Any,⟨∞∅+++⟩,32}, ::MultiVector{Any,⟨∞∅+++⟩,32}) at .julia/packages/Grassmann/cEoGT/src/algebra.jl:906
[15] top-level scope at REPL[19]:1

StackOverflowError when evaluating `repart` and `impart` of `im` unit

Hello,
When I evaluate Algebra.repart(im) or Algebra.impart(im), I get a StackOverflowError. I can fix it by writing 1im in the argument, but the problem is that sometimes the manipulation of other expressions produce the symbol im, so I can't use eval on them.

I don't know how to fix this, so thanks in advance.

parsing of REDUCE for expression broken in Julia 1.10

The parsing of REDUCE for statements is broken with Julia 1.10 and I am not currently planning on figuring out how to fix it:

julia> Expr(:for, :(i = 2:34), :(product(i))) |> RExpr |> Reduce.parse
:($(Expr(:incomplete, Base.Meta.ParseError("ParseError:\n# Error @ none:1:6\nfor i\n#    └ ── premature end of input", Base.JuliaSyntax.ParseError(Base.JuliaSyntax.SourceFile("for i", 0, "none", 1, [1, 6]), Base.JuliaSyntax.Diagnostic[Base.JuliaSyntax.Diagnostic(6, 5, :error, "premature end of input"), Base.JuliaSyntax.Diagnostic(6, 5, :error, "invalid iteration spec: expected one of `=` `in` or `∈`"), Base.JuliaSyntax.Diagnostic(6, 5, :error, "premature end of input"), Base.JuliaSyntax.Diagnostic(6, 5, :error, "Expected `end`")], :other)))) = 2:34 * product(im))

julia> ans |> dump
Expr
  head: Symbol =
  args: Array{Any}((2,))
    1: Expr
      head: Symbol incomplete
      args: Array{Any}((1,))
        1: Base.Meta.ParseError
          msg: String "ParseError:\n# Error @ none:1:6\nfor i\n#    └ ── premature end of input"
          detail: Base.JuliaSyntax.ParseError
            source: Base.JuliaSyntax.SourceFile
              code: SubString{String}
                string: String "for i:=2:34 product(i)"
                offset: Int64 0
                ncodeunits: Int64 5
              byte_offset: Int64 0
              filename: String "none"
              first_line: Int64 1
              line_starts: Array{Int64}((2,)) [1, 6]
            diagnostics: Array{Base.JuliaSyntax.Diagnostic}((4,))
              1: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "premature end of input"
              2: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "invalid iteration spec: expected one of `=` `in` or `∈`"
              3: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "premature end of input"
              4: Base.JuliaSyntax.Diagnostic
                first_byte: Int64 6
                last_byte: Int64 5
                level: Symbol error
                message: String "Expected `end`"
            incomplete_tag: Symbol other
    2: Expr
      head: Symbol call
      args: Array{Any}((3,))
        1: Symbol :
        2: Int64 2
        3: Expr
          head: Symbol call
          args: Array{Any}((3,))
            1: Symbol *
            2: Int64 34
            3: Expr
              head: Symbol call
              args: Array{Any}((2,))
                1: Symbol product
                2: Symbol im

no method matching keymap(::Vector{Dict}}


julia> using Reduce
[ Info: Precompiling Reduce [93e0c654-6965-5f22-aba9-9c1ae6b3c259]
ERROR: InitError: MethodError: no method matching keymap(::Vector{Dict})
Closest candidates are:
  keymap(::Any, ::Union{REPL.LineEdit.HistoryPrompt, REPL.LineEdit.PrefixHistoryPrompt}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\LineEdit.jl:2007
  keymap(::Union{Vector{Dict{Any, Any}}, Vector{Dict{Char, Any}}}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\LineEdit.jl:1610
  keymap(::REPL.LineEdit.PromptState, ::REPL.LineEdit.Prompt) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\REPL\src\LineEdit.jl:2505
  ...
Stacktrace:
 [1] initrepl(parser::typeof(Reduce.parserepl); prompt_text::String, prompt_color::Symbol, start_key::Char, repl::REPL.LineEditREPL, mode_name::String, valid_input_checker::Function, keymap::Dict{Char, Any}, completion_provider::REPL.REPLCompletionProvider, sticky_mode::Bool, startup_text::Bool)
   @ ReplMaker ~\.julia\packages\ReplMaker\pwo5w\src\ReplMaker.jl:78
 [2] repl_init(repl::REPL.LineEditREPL)
   @ Reduce ~\.julia\packages\Reduce\1n3pM\src\repl.jl:45
 [3] repl_init
   @ ~\.julia\packages\Reduce\1n3pM\src\repl.jl:60 [inlined]
 [4] __init__()
   @ Reduce ~\.julia\packages\Reduce\1n3pM\src\Reduce.jl:322
 [5] _include_from_serialized(path::String, depmods::Vector{Any})
   @ Base .\loading.jl:597
 [6] _require_from_serialized(path::String, cache::Base.TOMLCache)
   @ Base .\loading.jl:649
 [7] _require(pkg::Base.PkgId, cache::Base.TOMLCache)
   @ Base .\loading.jl:952
 [8] require(uuidkey::Base.PkgId, cache::Base.TOMLCache)
   @ Base .\loading.jl:836
 [9] require(into::Module, mod::Symbol)
   @ Base .\loading.jl:824
during initialization of module Reduce
julia> versioninfo()
Julia Version 1.6.0-DEV.913
Commit 4c805d2310 (2020-09-14 14:07 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Xeon(R) E-2176M  CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8

Simple Reduce Statement Fails to Compile Inside Module

The following code snippet runs just fine in Julia 1.2, unless it's put into a module.

module DebugModule

using ForceImport
@force using Reduce.Algebra
using ReduceLinAlg


f(a,b) = (:x - a) * (:x - b)
g(a,b) = int( f(a,b), :x)

# comment this out and the module loads,  or simply copy and paste the code
# and it works
g0 = g(:a,:b) - sub( (:(x=b), ), g(:a,:b))

end # module

Now see what happens when I try to use this module.

julia> using DebugModule
[ Info: Recompiling stale cache file /home/matt/.julia/compiled/v1.2/DebugModule.ji for DebugModule [top-level]
ERROR: LoadError: Base.Meta.ParseError("invalid operator \"--\"")
Stacktrace:
 [1] #parse#1(::Bool, ::Bool, ::Bool, ::typeof(Base.Meta.parse), ::String, ::Int64) at ./meta.jl:129
 [2] #parse at ./tuple.jl:0 [inlined]
 [3] #parse#4(::Bool, ::Bool, ::typeof(Base.Meta.parse), ::String) at ./meta.jl:160
 [4] parse at ./meta.jl:160 [inlined]
 [5] |>(::String, ::typeof(Base.Meta.parse)) at ./operators.jl:854
 [6] #parse_expr#46(::Int64, ::typeof(Reduce.parse_expr), ::String, ::Reduce.RExpr) at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:317
 [7] (::getfield(Reduce, Symbol("#kw##parse_expr")))(::NamedTuple{(:be,),Tuple{Int64}}, ::typeof(Reduce.parse_expr), ::String, ::Reduce.RExpr) at ./none:0
 [8] #parse#76(::Int64, ::typeof(parse), ::Reduce.RExpr) at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:438
 [9] parse at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:438 [inlined]
 [10] convert at /home/matt/.julia/packages/Reduce/4dmwd/src/rexpr.jl:414 [inlined]
 [11] unfold_expr_force(::Symbol, ::Symbol, ::Expr, ::Symbol) at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:847
 [12] #unfold_expr#77(::Bool, ::typeof(Reduce.unfold_expr), ::Symbol, ::Symbol, ::Expr, ::Symbol) at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:806
 [13] unfold_expr(::Symbol, ::Symbol, ::Expr, ::Symbol) at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:801
 [14] unfold(::Symbol, ::Symbol, ::Expr, ::Symbol) at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:863
 [15] int(::Expr, ::Symbol) at /home/matt/.julia/packages/Reduce/4dmwd/src/parser.jl:793
 [16] g(::Symbol, ::Symbol) at /mnt/WorkSpace/projects/Maestro/GlucoseSource/DebugModule.jl:10
 [17] top-level scope at /mnt/WorkSpace/projects/Maestro/GlucoseSource/DebugModule.jl:14
 [18] include at ./boot.jl:328 [inlined]
 [19] include_relative(::Module, ::String) at ./loading.jl:1094
 [20] include(::Module, ::String) at ./Base.jl:31
 [21] top-level scope at none:2
 [22] eval at ./boot.jl:330 [inlined]
 [23] eval(::Expr) at ./client.jl:432
 [24] top-level scope at ./none:3
in expression starting at /mnt/WorkSpace/projects/Maestro/GlucoseSource/DebugModule.jl:14
ERROR: Failed to precompile DebugModule [top-level] to /home/matt/.julia/compiled/v1.2/DebugModule.ji.
Stacktrace:
 [1] compilecache(::Base.PkgId, ::String) at ./loading.jl:1253
 [2] _require(::Base.PkgId) at ./loading.jl:1013
 [3] require(::Base.PkgId) at ./loading.jl:911
 [4] require(::Module, ::Symbol) at ./loading.jl:906

julia> 

If I copy and paste the code into the julia REPL it works fine and the module loads if the last line,
g0 = g(:a,:b) - sub( (:(x=b), ), g(:a,:b)) is commented out. This looks like a bug to me.

Using the SCOPE package

Hey 👋 ,

I am interested in using the SCOPE package in Reduce to optimize the evaluation of multivariate polynomials in my package StaticPolynomials.

Working with the string interface I get the result I want out of REDUCE:

julia> using Reduce;
loadReduce (Free CSL version, revision 4534), 05-Apr-18 ...

julia> load_package(:SCOPE)

julia> rcall("z:=a^2*b^2+10*a^2*m^6+a^2*m^2+2*a*b*m^4+2*b^2*m^6+b^2*m^2");

julia> rcall("OPTIMIZE z:=:z")
"g2 := m*m;\ng1 := g2*g2;\nz := a*a*(g2 + b*b + 10*g2*g1) + g2*b*(2*g2*a + b*(2*g1 + 1))"

But I cannot find a way to express this in a way such that I can avoid strings and only work with expressions. Just a way to convert the result of the last call back to expressions would also be sufficient for me. I think there is a hacky version using find-and-replace as well as Meta.parse, but is there a better way dealing with this?

Default linux Reduce binaries require X windows libraries

Using Reduce.jl on linux defaults to the gui version of the Reduce csl binaries, which in turn require some X windows and other graphics libraries to exist. If the user has a non-graphic workstation (e.g. headless server), the user must either

  • manually install the missing, but unused, libraries,
  • manually install non-gui binaries (the psl binaries are suitable) and link to them, or
  • manually compile Reduce csl with the --no-gui configuration option.

I plan on submitting a PR installing the psl binaries by default if csl does not already exist on the user's machine. Is there any downside to using the psl binaries of Reduce instead of the csl version? The Reduce repository does not contain the no-gui csl binaries (that I could find).

Incorrect parsing with `f1` due to floating point

Hi,
I'm having some trouble using the exponential function, see below:

julia> using Reduce
Reduce (Free CSL version, revision 4534), 05-Apr-18 ...

julia> @force using Reduce.Algebra

julia> f = :f1
:f1

julia> a = exp(-6*f)
:(1 / ℯ ^ 60.0f0)

julia> Algebra.on(:rounded)

julia> b = sub("f1=1.0",a)
8.7565107627e-27

julia> exp(-6.0)
0.0024787521766663585

To me it looks like some kind of parsing error, since a symbol without a number (i.e. f = :f) works as expected.

Ambiguity with power

julia> t = IndependentVariable(:t)
IndependentVariable(t)

julia> t^4
ERROR: MethodError: ^(::ModelingToolkit.Variable, ::Int64) is ambiguous. Candidates:
  ^(x::ModelingToolkit.Expression, y::Number) in ModelingToolkit at /Users/dpsanders/.julia/v0.6/MacroTools/src/utils.jl:260
  ^(x::Number, p::Integer) in Base at intfuncs.jl:198
Possible fix, define
  ^(::ModelingToolkit.Expression, ::Integer)
Stacktrace:
 [1] literal_pow(::Base.#^, ::ModelingToolkit.Variable, ::Type{Val{4}}) at ./intfuncs.jl:208

Matrices

I am wondering how exactly Reduce.jl is handling matrices. I see that REDUCE itself has matrix support: are you using that or relying on generic algorithms on Julia matrices or calling into REDUCE?

The key that I am looking for is, for J a symbolic Jacobian, calculating (I-gamma*J)^-1 for small enough Jacobians (size <16?) and simplifying the expression. A SymEngine based version in ParameterizedFunctions.jl which works okay but is all pointers to C++ variables which ruins precompilation and is quite different from working on Julia ASTs. ModelingToolkit.jl is using a Julia-defined operation tree which isn't type stable so it's as slow as you'd expect. REDUCE looks like it should have the answer here, so I'm curious to see what it looks like.

Wrong result for sum((1-x)^(2*i), i, 0, n)

julia> rcall(:(sum((1-x)^(2*i), i, 0, n)))
:((-((x - 1) ^ (2n)) * (x - 1) ^ 1) // ((x - 2) * x))

The result should be something like

:((((x - 1) ^ (2n)) * (x - 1) ^ 2 - 1) // ((x - 2) * x))

High memory usage

Hello,
When I run

foreach(_->solve(:a + 1), 1:1e6)

or

foreach(_->(:a + 1), 1:1e6)

The RAM usage gets higher until all the memory of my laptop is used up

PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                                  
436545 user      20   0 1320336 440560 142848 R  66,7   2,8   4:01.32 julia                                                                                    
436592 user      20   0 6660304   5,7g   8776 S  40,7  38,1   2:15.18 reduce  

I'm using Reduce v1.2.10 and Julia v1.5.3

Too many right parentheses

I'm trying to solve a system of eight equations involving 8 unknowns. I don't think it's too complicated but I got the following "too many right parenthese" error:

julia> phy_in_alphas = RDAB.solve(eqns, tuple(Symbol.(:phy_, 1:nphy)...) )   # use of "phi" hangs !!!
ERROR: Reduce: 
solve({-(+(phy_1,phy_4))=-(+(alpha_1,alpha_2,alpha_3,alpha_4)),-(-(-(*(phy_1,
phy_4),*(phy_2,phy_3)),phy_5),phy_8)=+(*(alpha_1,alpha_2),*(alpha_1,alpha_3),*(
alpha_1,alpha_4),*(alpha_2,alpha_3),*(alpha_2,alpha_4),*(alpha_3,alpha_4)),+(-(-
(*(phy_1,phy_8),*(phy_2,phy_7)),*(phy_3,phy_6)),*(phy_4,phy_5))=-(+(*(alpha_1,
alpha_2,alpha_3),*(alpha_1,alpha_2,alpha_4),*(alpha_1,alpha_3,alpha_4),*(alpha_2
,alpha_3,alpha_4))),-(*(phy_5,phy_8),*(phy_6,phy_7))=*(alpha_1,alpha_2,alpha_3,
alpha_4),$$$);
at line 1

***** Too many right parentheses 
Stacktrace:
 [1] ReduceCheck at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/Reduce.jl:60 [inlined]
 [2] read(::Reduce.PSL) at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/Reduce.jl:95
 [3] readsp at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/Reduce.jl:99 [inlined]
 [4] rcall(::Reduce.RExpr; on::Array{Symbol,1}, off::Array{Symbol,1}) at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/rexpr.jl:473
 [5] rcall(::Reduce.RExpr) at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/rexpr.jl:438
 [6] |> at ./operators.jl:823 [inlined]
 [7] parse_args(::String, ::Reduce.RExpr; be::Int64) at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/parser.jl:343
 [8] r_args(::String, ::SubString{String}, ::Array{Any,1}; be::Int64) at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/parser.jl:383
 [9] parse_args(::String, ::Reduce.RExpr, ::Reduce.RExpr; be::Int64) at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/parser.jl:331
 [10] #solve#207 at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/parser.jl:437 [inlined]
 [11] solve at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/parser.jl:437 [inlined]
 [12] solve(::NTuple{8,Expr}, ::NTuple{8,Symbol}) at /Users/Thomas/.julia/packages/Reduce/HgVTl/src/args.jl:230
 [13] top-level scope at REPL[25]:1

julia> for i in 1:length(eqns)
           println(i, " : ", eqns[i])
       end
1 : -((phy_1 + phy_4)) == -((alpha_1 + alpha_2 + alpha_3 + alpha_4))
2 : ((phy_1 * phy_4 - phy_2 * phy_3) - phy_5) - phy_8 == alpha_1 * alpha_2 + alpha_1 * alpha_3 + alpha_1 * alpha_4 + alpha_2 * alpha_3 + alpha_2 * alpha_4 + alpha_3 * alpha_4
3 : ((phy_1 * phy_8 - phy_2 * phy_7) - phy_3 * phy_6) + phy_4 * phy_5 == -((alpha_1 * alpha_2 * alpha_3 + alpha_1 * alpha_2 * alpha_4 + alpha_1 * alpha_3 * alpha_4 + alpha_2 * alpha_3 * alpha_4))
4 : phy_5 * phy_8 - phy_6 * phy_7 == alpha_1 * alpha_2 * alpha_3 * alpha_4
5 : :phy_3 == :alpha_5
6 : :phy_6 == :alpha_6
7 : :phy_7 == :alpha_7
8 : :phy_8 == :alpha_8

is there any way to prevent the error by setting something? thanks.

Rational "//" used instead of "/"

Hi,
Manipulating Julia expressions seems like an awesome and convenient tool!
However, using "//" poses a problem when trying to evaluate expressions, eg:

julia> using Reduce
Reduce (Free PSL version, revision 4218), 22-Sep-2017 ...

julia> rcall(:(int( x^3 * exp(-x^2), x)))
:(-((x ^ 2 + 1)) // (2 * e ^ (x ^ 2)))

Rational division is that it is invalid for Floats, making the above expressions invalid. I can try to work around this through writing code such as:

julia> @generated function intexp(x, ::Val{N}) where N
                  f = rcall(:(int( x^$N * exp(-x^2), x)))
                  f.args[1] = :/
                  f
              end
julia> @generated function intoutexp(::Val{N}, ::Type{T} = Float64) where {N,T}
                  f = rcall(:(int( x^$N * exp(-x^2), x, -Inf, Inf)))
                  if isa(f, Expr) && f.args[1] == ://
                      f.args[1] = :/
                  end
                  :(convert(T,$f))
              end

To get things to work as intended (at least in the use cases I've tried).

Simply searching the repository for // didn't return any hits, and I'm not familiar with Reduce so I couldn't quickly see how to make the change myself.

libtinfo.so.5 no such file or directory

In a linux system, after Pkg.add("Reduce") and Pkg.build("Reduce"), I get the following error trying to load Reduce

julia> using Reduce
[ Info: Precompiling Reduce [93e0c654-6965-5f22-aba9-9c1ae6b3c259]
[ Info: Precompiling extra Reduce methods (set `ENV["REDPRE"]="0"` to disable)
/home/paul/.julia/packages/Reduce/sobXf/deps/usr/lib/reduce/cslbuild/csl/reduce: error while loading 
shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
ERROR: LoadError: LoadError: IOError: write: broken pipe (EPIPE)
Stacktrace:

@latex with Rexpr errors

julia> @latex RExpr(:n)
ERROR: LoadError: Reduce: 
rexpr($$$;
at line 1

***** Too few right parentheses 

[Upstream] Integration error? (cannot parse unusual output format)

My use-case is:

x = :x
int(log(x)/x, x, 0, 1)  # works fine
int(log(x)/(x - 1), x, 0, 1) # error

ERROR: Reduce: 
*hold(limit)$$$$
at line 1

***** Too few right parentheses 


 - 2*limit!+(( - 2*int(log(x)/(2*x**2 + x),x) + log(x)**2)/4,x,0) - sub(x=1,int(
log(x)/(2*x**2 + x),x)) - 2*pi**2

Conditional application of rewrite (substitution) rules?

Is there a way to apply sets of rewrite rules conditionally (based on the unification of the pattern variables of the rules)? Can you give an example?

The introspection of Julia together with powerful symbolic math manipulation makes it a very powerful platform for numerical metaprogramming.

I have been dreaming of a way to, for example, have a general matrix multiplication routine and get the high-performance blocking automatically. But also produce specializations automatically, for triangular, banded, symmetric matrices, etc.

Missing method for √

On Reduce.jl v1.2.6 √:x results in a MethodError, I'd expect it to work in the same way as sqrt(:x). Same issue for √(::Expr).
This is a small issue that can easily be worked around by defining the functions by hand.

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.0 (2020-03-21)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Reduce
Reduce (Free CSL version, revision 5286), 01-Mar-20 ...
REPL mode REDUCE initialized. Press } to enter and backspace to exit.

julia> @force using Reduce.Algebra

julia> sqrt(:x)
:(sqrt(x))

julia> √:x
ERROR: MethodError: no method matching sqrt(::Symbol)
Closest candidates are:
  sqrt(::Float16) at math.jl:1114
  sqrt(::Complex{Float16}) at math.jl:1115
  sqrt(::Missing) at math.jl:1167
  ...
Stacktrace:
 [1] top-level scope at REPL[4]:1

julia> import Base.√

julia> √(x::Symbol) = sqrt(x) # Add the missing method definition
sqrt (generic function with 20 methods)

julia> √:x # now it works
:(sqrt(x))

[Upstream] Syntax error with sqrt of rational expression

I was checking out Reduce's capabilities for partial differentiation and I was excited since for my use case it's better than automatic differentiation. Unfortunately, it seems to crash for moderately complex expressions.

I've included a MWE below which shows a trivial working example (case 0), two complex working examples (cases 1 and 2), and finally a slightly more complex version which fails (case 3).

julia> :(df(x^2+t^2, x)) |> rcall
:(2x)

julia> :(df((1 - ((a + b*t)^2*(c*v1 + d*v2 + e*v3))/(f)^2)^(1/2), t)) |> rcall
:((-((d * v2 + ℯ * v3 + c * v1)) * (a + b * t) * b) / (sqrt(-((d * v2 + ℯ * v3 + c * v1)) * (a + b * t) ^ 2 + f ^ 2) * abs(f)))

julia> :(df((1 - ((a + b*t)^2*(c*v1 + d*v2 + e*v3))/(t)^2)^(1/2), t)) |> rcall
:(((a * c * v1 + a * d * v2 + a * ℯ * v3 + b * c * t * v1 + b * d * t * v2 + b * ℯ * t * v3) * a) / (sqrt(-((d * v2 + ℯ * v3 + c * v1)) * (a + b * t) ^ 2 + t ^ 2) * abs(t) * t))

julia> :(df((1 - ((a + b*t)^2*(c*v1 + d*v2 + e*v3))/(f+t)^2)^(1/2), t)) |> rcall
ERROR: Reduce: 
***** Syntax error: f(
+++ Error attempt to take car of an atom: 1
Stacktrace:
 [1] ReduceCheck at /Users/alex/.julia/packages/Reduce/TI9IX/src/Reduce.jl:60 [inlined]
 [2] read(::Reduce.PSL) at /Users/alex/.julia/packages/Reduce/TI9IX/src/Reduce.jl:95
 [3] readsp at /Users/alex/.julia/packages/Reduce/TI9IX/src/Reduce.jl:99 [inlined]
 [4] #rcall#40(::Array{Symbol,1}, ::Array{Symbol,1}, ::Function, ::RExpr) at /Users/alex/.julia/packages/Reduce/TI9IX/src/rexpr.jl:464
 [5] #rcall at ./none:0 [inlined]
 [6] #rcall#41(::Array{Symbol,1}, ::Array{Symbol,1}, ::Function, ::Expr) at /Users/alex/.julia/packages/Reduce/TI9IX/src/rexpr.jl:497
 [7] rcall at /Users/alex/.julia/packages/Reduce/TI9IX/src/rexpr.jl:497 [inlined]
 [8] |>(::Expr, ::typeof(rcall)) at ./operators.jl:813
 [9] top-level scope at none:0
julia> 

The right most variable to appear in case 1 is f. Case two replaces f by t. Case 3 puts in that position f + t, which seems to cause the failure.

Are there known limitations on the complexity of the AST for operations like df?

InitError: IOError redcsl

when
I type :using Reduce
I recieve: IOError: could not spawn /home/zhg/.julia/packages/Reduce/1n3pM/src/../deps/usr/bin/redcsl: no such file or directory (ENOENT)
IOError: could not spawn redcsl: no such file or directory (ENOENT)
So anyone can do me a favor what,s wrong
My OS :manajro xcfe
julia :1.5.3
Thank you

Windows installation

julia> Pkg.build("Reduce")
INFO: Building Reduce
Downloading reduce binaries...
Installing reduce binaries...
DONE

julia> Pkg.test("Reduce")
INFO: Testing Reduce
getheap: HeapAlloc failed
Reduce: A Portable General-Purpose Computer Algebra SystemError During Test
  Test threw an exception of type Base.UVError
  Expression: rcall($(Expr(:quote, :((1 + pi)^ 2)))) == convert(Expr, RExpr(rcall("(1+pi)**2")))
  write: broken pipe (EPIPE)
  Stacktrace:
   [1] try_yieldto(::Base.##296#297{Task}, ::Task) at .\event.jl:189
   [2] wait() at .\event.jl:234
   [3] uv_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at .\stream.jl:811
   [4] unsafe_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at .\stream.jl:832
   [5] clear at C:\Users\Chris\.julia\v0.6\Reduce\src\Reduce.jl:80 [inlined]
   [6] write(::Reduce.PSL, ::String) at C:\Users\Chris\.julia\v0.6\Reduce\src\Reduce.jl:87
   [7] #rcall#33(::Array{Symbol,1}, ::Array{Symbol,1}, ::Function, ::Reduce.RExpr) at C:\Users\Chris
\.julia\v0.6\Reduce\src\rexpr.jl:384
   [8] (::Reduce.#kw##rcall)(::Array{Any,1}, ::Reduce.#rcall, ::Reduce.RExpr) at .\<missing>:0
   [9] #rcall#34(::Array{Symbol,1}, ::Array{Symbol,1}, ::Function, ::Expr) at C:\Users\Chris\.julia\
v0.6\Reduce\src\rexpr.jl:422
   [10] rcall(::Expr) at C:\Users\Chris\.julia\v0.6\Reduce\src\rexpr.jl:422
   [11] include_from_node1(::String) at .\loading.jl:576
   [12] include(::String) at .\sysimg.jl:14
   [13] process_options(::Base.JLOptions) at .\client.jl:305
   [14] _start() at .\client.jl:371
ERROR: LoadError: There was an error during testing
while loading C:\Users\Chris\.julia\v0.6\Reduce\test\runtests.jl, in expression starting online 6
=========================================[ ERROR: Reduce ]==========================================

failed process: Process(`'C:\Users\Chris\AppData\Local\Julia-0.6.2\bin\julia.exe' -Cx86-64 '-JC:\Use
rs\Chris\AppData\Local\Julia-0.6.2\lib\julia\sys.dll' --compile=yes --depwarn=yes --check-bounds=yes
 --code-coverage=none --color=yes --compilecache=yes 'C:\Users\Chris\.julia\v0.6\Reduce\test\runtest
s.jl'`, ProcessExited(1)) [1]

====================================================================================================
ERROR: Reduce had test errors

this is after adding 64BIT to /deps/osbit.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.