Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No div impl between numbers and polynomials #93

Closed
sritchie opened this issue Aug 25, 2020 · 5 comments
Closed

No div impl between numbers and polynomials #93

sritchie opened this issue Aug 25, 2020 · 5 comments
Labels

Comments

@sritchie
Copy link
Member

The following code, in a namespace with the proper imports like sicmutils.simplify-test:

(sicmutils.simplify/hermetic-simplify-fixture
 (fn []
   (g/simplify
    (g/mul 0.5
           (g/div 1 (g/mul 2 'x))))))

Throws:

Execution error (Error) at (<cljs repl>:1).
No method in multimethod 'sicmutils.generic/div' for dispatch value: [#object[Number] :sicmutils.polynomial/polynomial]

Everything works if we use (/ 1 2) to generate a ratio. Do we want to handle a floating point number here?

Well, of course we do. I guess I would expect here that maybe the simplifier would do nothing, and return (/ 0.5 (* 2 x)).

@sritchie sritchie added the bug label Aug 25, 2020
@littleredcomputer
Copy link
Collaborator

littleredcomputer commented Aug 25, 2020 via email

@sritchie
Copy link
Member Author

looks like it doesn't. I can try and dig in to where this multiplication is happening, too. possibly notable is that it times out, and only succeeds (with that error) when I wrap it with hermetic-simplify-fixture. More demons to chase!

@littleredcomputer
Copy link
Collaborator

littleredcomputer commented Aug 25, 2020 via email

@sritchie
Copy link
Member Author

Okay, I fixed this by adding an explicit implementation of invert for polynomials in the rational-function namespace:

(defmethod g/invert [::p/polynomial] [^Polynomial p]
  (make (p/make-constant (.-arity p) 1) p))

@sritchie
Copy link
Member Author

Adding this to #169 .

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

No branches or pull requests

2 participants