3 ms·
Here's some Clojure code I wrote for the Emmy computer algebra system that implements polynomial interpolation with a few different algorithms described in Nume
by sritchie 4y ago
Here's some Clojure code I wrote for the Emmy computer algebra system that implements polynomial interpolation with a few different algorithms described in Numerical Recipes:
https://github.com/mentat-collective/emmy/blob/main/src/emmy/polynomial/interpolate.cljc https://github.com/mentat-collective/emmy/blob/main/src/emmy...
I discovered while writing this that I could express each of these algorithms as folds that consumed a stream of points, accumulating a progressively higher order polynomial.
Here's the same sort of thing but for rational function interpolation: https://github.com/mentat-collective/emmy/blob/main/src/emmy/rational_function/interpolate.cljc https://github.com/mentat-collective/emmy/blob/main/src/emmy...
- robomartin 4y agoI want to commend you for the detail and quality in the comments in your code. These days that's a luxury. Open source projects tend to take the "and then a miracle occurs" approach to comments. I'm old school, my comments look like yours; lots of detail, background and explanations, so I can easily get back into the code five or ten years later.
- sritchie 4y agoThank you, that's really nice to read. I really leaned in to these essay-style namespaces for this project; I spent _so_ much time deciphering old numerical algorithms ported from uncommented FORTRAN, and decided that I had to go the other direction. Someday I'll get around to publishing a static site that renders the math in the comments, like these: - https://samritchie.io/functional-numerical-methods https://samritchie.io/functional-numerical-methods (numerical integration written in stateless functional style) - https://samritchie.io/dual-numbers-and-automatic-differentiation https://samritchie.io/dual-numbers-and-automatic-differentia... (automatic differentiation that works on higher order functions etc) Send me some of your (public) code to read!
- robomartin 4y ago> Send me some of your (public) code to read! That's a bit difficult, as most of my work is proprietary, under NDA or aerospace. Here's an excerpt from a C control panel menu processor, just to show how far I go. One line of active code vs. 21 lines of comments. This was written 16 years ago. I can get back into this codebase almost instantly because of the documentation. More importantly, code reuse is also very easy for the same reason. case BUTTON_ENTER: // ENTER button clicked // // This has the effect of calling the "DURING" handler for the currently selected // menu. // // ***NOTE*** // It is the responsibility of the ON_ENTRY handler to decide whether or not // to capture the message loop by asserting "state_handler_wants_priority" // // Once done with the message loop "state_handler_wants_priority" should be cleared, // typically in the ON_EXIT routine // // It is up to the handler to do something (or not) with messages. // // Parent menus do not generally do much because they are navigation // stopping points and their messages are fully handled by the menu_processor() parser. // // Child menus that are not parents and, therefore, perform a function, // might want to do some work before the menu_processor() parser by capturing messages // before they are delivered to the menu_processor() parser. // dispatch_handler(current_state, DURING); break; I also like to do this sort of thing, in this case, Verilog code from a custom FPGA-based SDRAM controller: // COMMAND TABLE ---------------------------------------------------------------------------------- // Use the following template for assignment of SDRAM commands from this table: // // {SDRAM_CSn, SDRAM_RASn, SDRAM_CASn, SDRAM_WRn} <= COMMAND_NOP; // Issue command // // CSn RASn CASn WRn // | | | | parameter COMMAND_NOP = {1'b0, 1'b1, 1'b1, 1'b1}; parameter COMMAND_ACT = {1'b0, 1'b0, 1'b1, 1'b1}; parameter COMMAND_RD = {1'b0, 1'b1, 1'b0, 1'b1}; parameter COMMAND_WR = {1'b0, 1'b1, 1'b0, 1'b0}; parameter COMMAND_BST = {1'b0, 1'b1, 1'b1, 1'b0}; parameter COMMAND_PRE = {1'b0, 1'b0, 1'b1, 1'b0}; parameter COMMAND_REF = {1'b0, 1'b0, 1'b0, 1'b1}; parameter COMMAND_LMR = {1'b0, 1'b0, 1'b0, 1'b0}; parameter COMMAND_IOEN = {1'b0, 1'b0, 1'b0, 1'b0}; parameter COMMAND_IODIS = {1'b0, 1'b0, 1'b0, 1'b0}; parameter MODE_REGISTER_DEFAULT = 14'b000000_0_011_0_111; // CAS length = 3 // | | | | // | | | Burst length: 000 = 1; 001 = 2; 010 = 4; 011 = 8; 111 = Full page // | | | // | | Burst type: 0 = Sequential; 1 = Interleaved // | | // | CAS Latency: 010 = 2; 011 = 3; // | // Write mode: 000000 = Burst read and burst write. // 000010 = Burst read and single write. Yes, it's a lot of work, and it is, without a doubt, worth the effort.