Git Product home page Git Product logo

Comments (7)

pavpanchekha avatar pavpanchekha commented on June 3, 2024 1

Ok, so there are actually a few things going on.

First of all, the original program is only inaccurate for a relatively small range, for x and y between 5 and 28. For larger values, erf(x) - erf(y) returns 0, which is actually the closest floating-point result for the correct answer. Since the range is small, Herbie doesn't sample many points in it (only one in (2048/3)^2 β‰ˆ 466k points falls into this range) and ends up basically ignoring it. So Herbie was "correctly" determining that the original expression had very little error and didn't need any changes. The best way to fix this is to add a precondition, either using :pre (if on the command line) or by clicking the "Additional options" link (if on the web version).

Second of all, one of Herbie's rewrite rules (erfc-erf) was less general than it should have been. I've tweaked that in the last commit.

from herbie.

pavpanchekha avatar pavpanchekha commented on June 3, 2024

Great question, I'll look into it. I think I know why but give me a moment to prove out my theory.

from herbie.

cossio avatar cossio commented on June 3, 2024

Awesome! Thanks for taking a look. Actually I'm trying to find a robust expression to compute the variance of a truncated normal (https://en.wikipedia.org/wiki/Truncated_normal_distribution#Two_sided_truncation[2]).
My manual attempts have failed so far.
Will you release a new version of Herbie with the erf rules fix so I can try it? Thanks!
Edit: I'll try compiling from master.

from herbie.

cossio avatar cossio commented on June 3, 2024

I tried erf(x) - erf(y) with precondition x > y on Herbie master but I still don't get a transformation to erfc. Maybe I need to do something else?

from herbie.

pavpanchekha avatar pavpanchekha commented on June 3, 2024

Hi @cossio, I got good results when I specified the precondition 5 < x < 28 and 5 < y < 28. I bet reasonably similar bounds on x and y would work.

from herbie.

cossio avatar cossio commented on June 3, 2024

Thanks. I get

image

Don't know why it doesn't simplify the square root.

In fact, it seems that Herbie gets to (βˆ’erfc(x))+erfc(y) as an intermediate expression, but then applies a couple of rules that introduce the square roots (which seem superfluous to me).

image

from herbie.

pavpanchekha avatar pavpanchekha commented on June 3, 2024

Yeah, Herbie does that sometimes, and I don't know why. I've been meaning to look into it. In some cases, that may twiddle some low-order bit in just the right way to minutely increase accuracy, but it might also be totally useless. I'll add it to my list of things to look into.

from herbie.

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.