Code Monkey home page Code Monkey logo

Comments (5)

sritchie avatar sritchie commented on May 30, 2024

@littleredcomputer , does this ring any bells?

from sicmutils.

littleredcomputer avatar littleredcomputer commented on May 30, 2024

from sicmutils.

sritchie avatar sritchie commented on May 30, 2024

Yes, @littleredcomputer another thing I noticed, and wasn't sure where to investigate, is that the simplifier sorts * and + calls in different order. Obviously we need to be careful here for non-commutative operations, but I know that there are many tests where we get different results (just a different order) if we don't use the hermetic-simplify-fixture.

from sicmutils.

sritchie avatar sritchie commented on May 30, 2024

@littleredcomputer now that I've stared at some rules code, I see the same comment from Alexey (bubble sort!) in his "commutativity" code. He handles this by matching the entire list of arguments and sorting the whole thing at once.
https://github.com/axch/rules/blob/master/simplifiers.scm#L52

Can we do something similar, and match a full stack of partials? I think the original scmutils code has rules to:

  • turn nests into products, handling partials that are exponentiated
  • THEN sort the terms inside the product

But the latter is bubble-sorted, so we can still make it better.

Here's the scheme:

(def canonicalize-partials*
  (ruleset
   ;; First turn nests into products.
   ((partial :i*) ((partial :j*) :f))
   =>
   ((* (partial :i*) (partial :j*)) :f)

   ((partial :i*) ((* (partial :j*) :more*) :f))
   =>
   ((* (partial :i*) (partial :j*) :more*) :f)

   ;; Exponentiation of operators makes things hairy
   ((expt (partial :i*) :n) ((partial :j*) :f))
   =>
   ((* (expt (partial :i*) :n) (partial :j*)) :f)

   ((partial :i*) ((expt (partial :j*) :n) :f))
   =>
   ((* (partial :i*) (expt (partial :j*) :n)) :f)

   ((expt (partial :i*) :n) ((expt (partial :j*) :m) :f))
   =>
   ((* (expt (partial :i*) :n) (expt (partial :j*) :m)) :f)


   ;; Already some accumulation
   ((partial :i*) ((* (partial :j*) :more*) :f))
   =>
   ((* (partial :i*) (partial :j*) :more*) :f)

   ((expt (partial :i*) :n) ((* (partial :j*) :more*) :f))
   =>
   ((* (expt (partial :i*) :n) (partial :j*) :more*) :f)

   ((partial :i*) ((* (expt (partial :j*) :m) :more*) :f))
   =>
   ((* (partial :i*) (expt (partial :j*) :m) :more*) :f)

   ((expt (partial :i*) :n) ((* (expt (partial :j*) :m) :more*) :f))
   =>
   ((* (expt (partial :i*) :n) (expt (partial :j*) :m) :more*) :f)

   ;; Next sort products, if OK
   #_#_#_(((* :xs* (partial :i*) :ys* (partial :j*) :zs*)
           ;; TODO check that this is waht we mean with symbol
           (:? f symbol?))
          :args*)
   (let ((args (expression args)))
     (and commute-partials?
          (symb:elementary-access? i args)
          (symb:elementary-access? j args)
          (list< j i)))
   (((* :xs* (partial :j*) :ys* (partial :i*) :zs*) :f)
    :args*)
   ))

from sicmutils.

sritchie avatar sritchie commented on May 30, 2024

This seems to have... just fixed itself, as a result of some other twitches we've had in the codebase! #285 changes the series implementation and marks the close of this mystery bug.

from sicmutils.

Related Issues (20)

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.