Comments (5)
There are many rules we can apply to elementary functions such as exp(x), sin(x) and sinh(x). Here, I would like to ask which of the following is appropriate for the purpose of this library. I'd like to send a PR for selected rules.
(1) auto-simplification of argument: sin(x + y - (x + y)) = sin(0) = 0
(2) undefined and infinities : sin(infinity) = undefined
(3) zero, one, pi, and j: sin(pi) = 0
, sin(j) = j*sinh(1)
(4) known rational multiples of pi: sin(1/4*pi) = 1/sqrt(2)
, ...
(5) multiples of j: sin(j*x) = j*sinh(x)
(6) remove pi term: sin(2*pi + x) = sin(x)
, sin(pi + x) = -sin(x)
, sin(1/2*pi + x) = cos(x)
, sin(3/2*pi + x) = -cos(x)
(7) negative argument: sin(-x) = -sin(x)
(8) negative first term: sin(-x + y) = -sin(x - y)
(9) forward-inverse identities: sin(asin(x)) = x
and more....
(2), (3) and (7) are already partially implemented.
from mathnet-symbolics.
Regarding (1): in general, auto-simplification should not expand expressions. However, in this case it might be a bug that the inner expression is not auto-simplified to zero already (need to rethink this). So, once fixed, this should work out of the box.
from mathnet-symbolics.
@cdrnet, I think so. Now it is clear -(a + b)
is not auto-simplified to -a - b
. In that respect, returns in the below table are very acceptable, except (d). For consistency, how about to allow only minus or -1 to be distributed inside the parenthesis. i.e. -(a + b) = -a - b
. I think the last column may be the correct behavior.
No | Input | Return | Expected |
---|---|---|---|
(a) | a + b - (a + b) | a + b - (a + b) | 0 |
(b) | a + b + (-a - b) | 0 | 0 |
(c) | a + b - 2*(a + b) | a + b - 2*(a + b) | a + b - 2*(a + b) |
(d) | -(a + b) + 2*(a + b) | a + b | -a - b + 2*(a + b) |
(e) | -a - b + 2*(a + b) | -a - b + 2*(a + b) | -a - b + 2*(a + b) |
(f) | 2*(a + b) - 2*(a + b) | 0 | 0 |
from mathnet-symbolics.
Yes, we'd only distribute -1, otherwise the product is not just a technical artifact of our internal representation (-x
is (-1)*x
internally). d) would no longer auto-simplify to a+b
, but that may be ok.
I agree, I'd also expect the auto-simplified form of the last column.
from mathnet-symbolics.
I can get the last column by simply adding a rule(| Sum ax as x' ...
) to the valueMul
function as shown below.
and multiply x y =
...
let rec valueMul (v:Value) x =
if Value.isZero v then zero else
match x with
...
| Product ax -> if Value.isOne v then x else Product (Values.unpack v::ax)
| Sum ax as x'-> if Value.isOne v then x' // intentionally distribute -1, e.g. -(a + b) = -a - b
else if Value.isMinusOne v then ax |> List.map (function xi -> valueMul v xi) |> Sum
else Product [Values.unpack v; x']
| x -> if Value.isOne v then x else Product [Values.unpack v; x]
- Just now, I sent new PR. Please let me know if there is a better way...
from mathnet-symbolics.
Related Issues (20)
- Processing does not end
- "not supported" exception with divide by zero in equation
- FSI
- Errors parsing and evaluating complex-valued string
- Evaluation of an expression dealing with Vector
- MathML eq
- Solving simple equations or HOT 3
- Expression.Zero.Equals() Bug? HOT 2
- Rational.Simplify gets stuck in endless loop HOT 3
- Problem with eager numeric calculation HOT 1
- Automatically escape special LaTeX characters in symbol names HOT 4
- What about cooperation? HOT 3
- Latex HOT 8
- Multiplication signs being removed by Latex.formatvisual function HOT 4
- Simplify a string of variables and numbers - vb HOT 2
- How to use variables in algebra problems using a string? HOT 2
- How to add Parsing and Evaluation of the min and max functions HOT 2
- Approximation.Real vs FloatingPoint.Real
- No effective way to generate large sums
- Order of expressions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mathnet-symbolics.