Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Provide a way to represent 1-(-1) #3

Open
kevinbarabash opened this issue Aug 15, 2015 · 4 comments
Open

Provide a way to represent 1-(-1) #3

kevinbarabash opened this issue Aug 15, 2015 · 4 comments
Assignees

Comments

@kevinbarabash
Copy link

    var expr = new Expression("1");
    expr = expr.subtract(-1);
    console.log(expr.toString());

prints out 1+1 which is what I would expect looking at the code. It would be nice if subtraction could have a separate representation from adding the inverse. I'd like to use your library to create an interactive math widget. If users start with 1 and the action they take is to subtract -1 then I'd like them see 1-(-1) before giving them the option to rewrite it as 1+1. Not sure if this is something you'd want in algebra.js or not.

@nicolewhite
Copy link
Owner

Hey Kevin,

Yeah, that's not really supported out of the box since everything is automatically reduced and combined. I can't think of a way to accomplish what you want that isn't really hacky, given the current functionality.

I wonder if it would make sense to add a simplify argument or something to all of the operations. Something like:

var expr = new Expression(1);
expr = expr.subtract(-1, simplify=false)
console.log(expr.toString());
1 - (-1)

Then,

expr = expr.simplify()
console.log(expr.toString());
2

I think that would be really awesome functionality for the use case of building interactive tutorials. Just not sure how much work it involves. :)

@kevinbarabash
Copy link
Author

After thinking about it a bit, this is probably an unreasonable request because it would probably require significant changes to the current data structures. It's probably best to leave things be with the current auto-simplify behavior.

@nicolewhite
Copy link
Owner

I don't think it's unreasonable. As I mentioned on Hacker News, I think interactive math widgets / tutorials is a great use case of the library and so I have no problem adding features to focus on that. I've created #4 for this. While this won't cover the specific case of displaying 1 - (-1) rather than 1 + 1, I think the changes to the code to allow unsimplified expressions will bring me closer to being able to do that.

@kevinbarabash
Copy link
Author

Cool. I'll reopen this then.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants