Code Monkey home page Code Monkey logo

6.3e-sidescroller's People

Contributors

andrewwang996 avatar bancona avatar faraazn avatar fephsun avatar lahuang4 avatar larryoatmeal avatar notmahi avatar

Stargazers

 avatar  avatar

Watchers

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

Forkers

notmahi

6.3e-sidescroller's Issues

Remove 0*x when simplifying in Add (Difficulty: 1)

Right now, Add keeps terms with a const_factor of 0. For example,

ans = Add([Var('x'), Multiply([N(-1), Var('x')])])
print(ans) # Gives us 0 x

Fix this, so that any term with a const_factor of 0 is removed at the end of the simplify method of Add.

Minus signs inside Add (Difficulty: 1)

When we print an Add operation, minus signs show up in a dumb way. For example,

total = Add([2, Multiply([N(-5), Var('x')])])
print(total) # Results in 2 + -5x, which is not very good.

Fix this, so that we don't print the addition symbol for terms with negative coefficients.

Refactor the simplify() interface (Difficulty: 2)

Right now, simplify() modifies the expression in place. This won't work for simplifying some expressions, like logarithms. Log(xy) needs to be simplified to Add([Log(x), Log(y)]), which can't be done by modifying the Log expression, because the result is actually an Add expression.

You should make all the simplify()'s in our code instead return a new Expr object. This is the new usage:

var1 = Add([N(5), Var('x')]).simplify()
var2 = Add([Var('x'), Var('y')]).simplify()
var3 = Add([var1, var2]).simplify()
print(var3)

This can be done without rewriting very much of our code at all.

Implement distributive property (Difficulty: 4)

Inside Multiply, add the ability to distribute over Add terms. For example,

term1 = Add([N(2), Var('x')])
term2 = Add([N(3), Var('x')])
total = Multiply([term1, term2])
print(total)

Should result in x^2 + 5x + 6.

Compare expressions for equality (Difficulty: 3 or 4, not too sure)

We would like a function that determines whether two simplified expressions are equal. For example:

x1 = Add([Var('x'), N(5)])
x2 = Add([N(5), Var('x')])
print(IsEqual(x1, x2)) # Expected to be True

You'll have to do some designing to figure out how to implement a robust equals operator. The key problem is that Add and Multiply are commutative: x+5 and 5+x are the same thing.

Create a Log expression (Difficulty: 3)

Allow natural logarithms, using a Log class. A Log expression should contain one expression inside of it, which represents the operand of the logarithm. For example:

x = Log(Add([Var('x'), N(3)]))

Log should support the following simplification operations:

  • Log(a*b) = Log(a) + Log(b)
  • Log(a^k) = k * Log(a) for a constant k

Hint: I recommend doing this after someone finishes the issue about refactoring the simplify operation (#3)

Implement exponents for real (Difficulty: 2)

Right now, we only support exponents of a single variable, like x^3, using VarExponent. This bug is to implement arbitrary positive integer exponents, like (4xy)^5. After you implement this, you should be able to do:

ans = Exponent(Multiply([Var('x'), Var('y')]), 3)
print(ans) # Expect x^3 y^3

Hint: Exponent doesn't have to be a class - you might find it easier to define it as a function that returns a Multiply expression.

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.