symengine / SymEngine.jl

Julia wrappers of SymEngine
MIT License
192 stars 43 forks source link

Is it possible to use something like 1-x:1:10-x #239

Open zhaoli-IHEP opened 2 years ago

zhaoli-IHEP commented 2 years ago

We were trying to calculate like (1-x)*(2-x)*(3-x)*...*(10-x). And now we use (1:10).-x, which in fact gives in REPL 1 - x:1:10 - x. However, it seems we cannot directly use 1 - x:1:10 - x or 1 - x:one(Basic):10 - x. Could it have some way to do this?

isuruf commented 2 years ago
diff --git a/src/mathops.jl b/src/mathops.jl
index 335cf2c..ec765d1 100644
--- a/src/mathops.jl
+++ b/src/mathops.jl
@@ -97,7 +97,7 @@ Base.convert(::Type{Basic}, x::Irrational{:φ}) = (1 + Basic(5)^Basic(1//2))/2
 Base.convert(::Type{BasicType}, x::Irrational) = BasicType(convert(Basic, x))

 ## Logical operators
-Base.:<(x::SymbolicType, y::SymbolicType) = N(x) < N(y)
+Base.:<(x::SymbolicType, y::SymbolicType) = N(expand(x - y)) < 0
 Base.:<(x::SymbolicType, y) = <(promote(x,y)...)
 Base.:<(x, y::SymbolicType) = <(promote(x,y)...)

will get you a little bit closer, but not enough. It will then fail with calculating remainder.

Maybe overriding steprange_last is the best approach here?