[{"data":1,"prerenderedAt":330},["ShallowReactive",2],{"project-41740568":3},{"id":4,"name":5,"line":5,"line_source":6,"title":7,"url":8,"domain":9,"maker":10,"posted_at":11,"year":12,"points":13,"comments":14,"rank_in_year":15,"shown_in_year":16,"top":17,"tier":18,"category":19,"subcategory":20,"format":21,"keywords":22,"reception":26,"sentiment":27,"stance_mix":28,"scored_comments":32,"aspects":33,"strip":38,"post_text":40,"what":41,"said":74,"maker_in_thread":154,"shape":163,"grid":167,"attempts":293,"same_week":294,"maker_shows":35,"maker_hidden":322,"reader_version":323,"card":324},"41740568","Chebyshev approximation calculator","title","Show HN: Chebyshev approximation calculator","https:\u002F\u002Fstuffmatic.com\u002Fchebyshev\u002F","stuffmatic.com","stuffmatic",1728043758,2024,278,51,239,3515,7,"legend","dev_tools","code generator","web_app",[23,24,25,20],"chebyshev approximation","function approximation","polynomial approximation","debated",-0.038,{"positive":29,"neutral":30,"mixed":31,"critical":30},3,4,0,11,{"execution":34,"idea":36},{"positive":35,"critical":30},1,{"positive":37,"critical":31},2,[31,31,31,31,31,31,31,39,31,31,31,31,31,31,35,31,35,31,39,31,31,31,31,31,31,31,31,35,39,35,31,29,31,29,29,31,31,31,31,31],5,"Hi everyone,\n\nhere's a web app I made that generates code for efficiently approximating mathematical functions. This is useful when performance matters more than perfect accuracy, for example in embedded systems.\n\nThe app uses Chebyshev expansions, which despite their theoretical depth result in suprisingly compact and readable code in practice. This code is generated for you and using it does not require any knowledge of the underlying theory.\n\nSource code and more info:  https:\u002F\u002Fgithub.com\u002Fstuffmatic\u002Fchebyshev-calculator",{"problem":42,"audience":48,"pricing":52,"motivation":53,"time_to_build":52,"stack":59,"openness":71,"stage":72,"team_size":73},{"value":43,"source":44,"evidence":45},"Efficiently approximating mathematical functions when performance matters more than perfect accuracy.","maker",[46],{"id":47},"post",{"value":49,"source":44,"evidence":50},"Developers working on performance-sensitive code, such as embedded systems.",[51],{"id":47},null,{"value":54,"source":44,"evidence":55},"Chebyshev approximation code was hard to find, so the maker built a tool to generate it.",[56],{"id":57,"by":10,"text":58},"41741484","Thanks for the kind words. I also found it surprisingly hard to find working Chebyshev approximation code. Hopefully this project will change that :)",[60],{"value":61,"source":62,"evidence":63},"JavaScript","inferred",[64,67],{"id":65,"by":10,"text":66},"41741462","Or, since the function expression is just JavaScript, singularities can also be avoided like this: x == 0 ? 1 : Math.sin(x) \u002F x",{"id":68,"by":69,"text":70},"41741953","Zeetah","Nice! I'd like to generate a Chebyshev approximation for a set of X, Y sensor values. Any hints on how to modify your code to do that?","open_source","launched","unknown",{"praise":75,"objections":92,"requests":108,"questions":123,"alternatives":131},[76],{"value":77,"source":78,"evidence":79},"Nicely done and useful; compact generated code makes Chebyshev methods accessible.","commenter",[80,84,88],{"id":81,"by":82,"text":83},"41740963","jaymzcampbell","This is really nicely done! Great work. I fell in love with just how efficient these can be and it explained a lot about why many of the trig and other mathematical functions…",{"id":85,"by":86,"text":87},"41741407","xioxox","Excellent work. I wanted to do this recently, but it was surprisingly hard to find code to calculate an approximation. I've bookmarked it for when I next need a quick…",{"id":89,"by":90,"text":91},"41741441","ArmedSandwich","This is really nice. Wish I had it back in university, it would have made learning the Chebyshev expansions a lot more interesting than they were.",[93],{"value":94,"source":78,"evidence":95},"Fails on functions with singularities or undefined points, such as sinc at zero or 1\u002Fx.",[96,100,104],{"id":97,"by":98,"text":99},"41741945","Fredkin","Math.sin(x)\u002Fx (the sinc function) for 7 terms over [-3,3] gives coefficients c0...c6 that are all NaNs. Is this a bug? To work around it, I handled the x near zero case by just…",{"id":101,"by":102,"text":103},"41740995","hggigg","Rather nice that. I like it. Doesn't handle divide by zero very well though i.e. f(x)=1\u002Fx. Should probably consider that as undefined rather than a bad expression.",{"id":105,"by":106,"text":107},"41742165","Majromax","> Math.sin(x)\u002Fx (the sinc function) for 7 terms over [-3,3] gives coefficients c0...c6 that are all NaNs. Is this a bug? That wouldn't exactly be a bug. The code is undoubtedly…",[109,116],{"value":110,"source":78,"evidence":111},"Support for rational function approximations.",[112],{"id":113,"by":114,"text":115},"41743536","roger_","Great work, looks useful! Any chance you can add a rational function version?",{"value":117,"source":78,"evidence":118},"Import of tabular sensor data.",[119,120],{"id":68,"by":69,"text":70},{"id":121,"by":10,"text":122},"41742474","You could look into using the ChebyshevExpansion class directly. It takes as one of its arguments a callback that returns f(x) for a given x. In your case, f(x) would be your…",[124],{"value":125,"source":78,"evidence":126},"Why not use Horner or Estrin evaluation methods.",[127],{"id":128,"by":129,"text":130},"41745710","mgaunard","why not evaluate polynomials using horner or estrin methods",[132,143],{"value":133,"source":78,"evidence":134},"Chebfun",[135,139],{"id":136,"by":137,"text":138},"41743226","Rayhem","Obligatory callout to Nick Trefethen (et. al.)'s Chebfun[1] which extends this stuff in just about every direction you can think of. 'Chebfuns' are to functions as floats are to…",{"id":140,"by":141,"text":142},"41748504","janwas","hm, why not Chebfun? Result is a rational polynomial so we have to divide, but that seems fine\u002Ffast on servers.",{"value":144,"source":78,"evidence":145},"Sollya",[146,150],{"id":147,"by":148,"text":149},"41742166","orlp","I've had good results in the past with sollya: https:\u002F\u002Fwww.sollya.org\u002F. Note: results. The software itself is a bit of a pain to use.",{"id":151,"by":152,"text":153},"41747219","pclmulqdq","Sollya is probably the best modern tool for doing this. Under the hood, it does a Remez approximation followed by LLL to quantize to floating point. No use of Chebyshev directly.",{"comments":39,"answered":37,"key":155},[156,159,162],{"id":157,"text":158},"41741004","Thank you! Yes it does feel a bit magical, both the mathematical aspects and the fact that it all boils down to a few lines of code in practice.",{"id":160,"text":161},"41742523","Yes, that is a bug, good catch. The app should show an error if the function is not defined in all chebyshev nodes. Like you have already discovered, it's easy to work around…",{"id":57,"text":58},{"commenters":164,"max_depth":17,"maker_replies":39,"first_comment_mins":165,"lifespan_hours":166},36,54,151,[168,172,175,178,180,182,184,187,190,192,194,195,196,198,200,202,204,206,208,210,211,214,217,219,220,224,225,228,232,235,238,241,244,247,250,254,256,257,261,262,265,267,271,273,275,278,280,282,284,288,291],[169,31,31,170,171,31],"41741611","other\u002Fneutral\u002Fnone","herodotus",[173,31,31,170,174,31],"41742652","aghilmort",[176,31,31,170,177,31],"41742969","ratedgene",[179,31,31,170,174,31],"41744004",[181,31,31,170,152,31],"41744135",[183,31,31,170,141,31],"41748495",[185,31,31,170,186,31],"41745744","amadio",[188,31,31,170,189,31],"41747393","alleycat5000",[81,35,39,191,82,31],"maker\u002Fpositive\u002Fexecution",[157,35,31,193,10,35],"maker\u002Fpositive\u002Fnone",[147,37,31,170,148,31],[151,37,31,170,152,31],[140,37,31,197,141,31],"commenter\u002Fneutral\u002Fnone",[199,37,31,197,152,31],"41750705",[201,37,31,197,141,31],"41755736",[203,37,31,197,152,31],"41760731",[205,37,31,197,141,31],"41802009",[97,29,35,207,98,31],"project\u002Fcritical\u002Fexecution",[105,29,31,209,106,31],"commenter\u002Fneutral\u002Fexecution",[160,29,31,207,10,35],[212,29,35,207,213,31],"41750196","beyondCritics",[215,30,31,170,216,31],"41742329","richrichie",[85,39,39,218,86,31],"project\u002Fpositive\u002Fidea",[57,39,31,193,10,35],[221,222,31,170,223,31],"41745908",6,"hwc",[136,17,31,170,137,31],[226,17,31,170,227,31],"41747356","kxyvr",[229,230,31,170,231,31],"41742005",8,"atum47",[233,230,31,170,234,31],"41742058","mandibles",[236,230,31,170,237,31],"41742150","EdgeExplorer",[239,230,31,170,240,31],"41746464","o11c",[242,230,31,170,243,31],"41742456","kevin_thibedeau",[245,230,31,170,246,31],"41743863","CamperBob2",[248,230,31,170,249,31],"41745714","magicalhippo",[251,252,35,207,253,31],"41759142",9,"linvs",[89,255,39,218,90,31],10,[101,32,35,207,102,31],[258,32,29,259,260,31],"41741211","project\u002Fneutral\u002Fexecution","tgv",[65,32,31,259,10,35],[68,263,29,264,69,31],12,"project\u002Fneutral\u002Fidea",[121,263,31,266,10,35],"project\u002Fneutral\u002Fdocs",[268,269,31,170,270,31],"41742856",13,"anonzzzies",[113,272,29,264,114,31],14,[128,274,29,259,129,31],15,[276,274,31,197,277,31],"41746035","gjm11",[279,274,31,197,129,31],"41763944",[281,274,31,197,277,31],"41783674",[283,274,31,197,129,31],"41786052",[285,286,31,197,287,31],"41743615",16,"sfpotter",[289,286,31,197,290,31],"41743749","lainga",[292,286,31,197,287,31],"41743776",[],[295,299,304,308,312,317],{"id":296,"name":297,"points":298,"category":19},"41742278","One",506,{"id":300,"name":301,"points":302,"category":303},"41776878","Kotlin Money",427,"languages",{"id":305,"name":306,"points":307,"category":19},"41780297","Player.style",392,{"id":309,"name":310,"points":311,"category":19},"41764635","ARIA DevTools",272,{"id":313,"name":314,"points":315,"category":316},"41743327","LiveKit Agents",266,"ai",{"id":318,"name":319,"points":320,"category":321},"41780255","URL expander",213,"other",false,"v2",{"id":325,"name":5,"line":5,"ai":322,"cat":19,"year":12,"points":13,"comments":14,"rec":26,"s":326,"top":17,"kw":327,"maker":10,"domain":9,"tier":18,"attempts":31,"strip":328,"url":8,"mix":329,"praise":77,"objection":94,"sub":20},41740568,-0.04,[23,24,25,20],"0000000500000010105000000001510303300000",[29,30,31,30],1794036662268]