herbie-fp / herbie

Optimize floating-point expressions for accuracy

Home Page:https://herbie.uwplse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Herbie Web FPCore Invalid Formula on valid expression

samayala22 opened this issue · comments

It seems that Herbie Web cannot evaluate complex FPCore expressions.

For example, take this expression from bench/mathematics/gui.fpcore

(FPCore (a b angle x-scale y-scale)
  :name "Simplification of discriminant from scale-rotated-ellipse"
  (let* ([θ (* (/ angle 180) PI)]
         [F (* (* b a) (* b (- a)))]
         [A (/ (+ (pow (* a (sin θ)) 2) (pow (* b (cos θ)) 2))
                x-scale x-scale)]
         [B (/ (* 2 (- (pow b 2) (pow a 2)) (sin θ) (cos θ))
                x-scale y-scale)]
         [C (/ (+ (pow (* a (cos θ)) 2) (pow (* b (sin θ)) 2))
                y-scale y-scale)])
        (- (* B B) (* 4 A C))))

The web demo returns a Demo Error:

Invalid formula (FPCore (a b angle x-scale y-scale) :name "Simplification of discriminant from scale-rotated-ellipse" (let* ([θ (* (/ angle 180) PI)] [F (* (* b a) (* b (- a)))] [A (/ (+ (pow (* a (sin θ)) 2) (pow (* b (cos θ)) 2)) x-scale x-scale)] [B (/ (* 2 (- (pow b 2) (pow a 2)) (sin θ) (cos θ)) x-scale y-scale)] [C (/ (+ (pow (* a (cos θ)) 2) (pow (* b (sin θ)) 2)) y-scale y-scale)]) (- (* B B) (* 4 A C)))). Formula must be a valid program using only the supported functions. Please [go back](https://herbie.uwplse.org/demo/) and try again.

herbie shell works fine, which confirms that the expression is valid.

Is this a limitation of the web version ? I am unable to find any information anywhere on the website or in the documentation.

commented
(FPCore (x) (+ x 1 1))

The + function in the web version seems not support multiple parameters.

Hi @inkydragon, thanks for the bug report. The issue here is that the Herbie shell desugars products and quotients with more than two arguments, while the web demo doesn't. That's definitely pretty confusing! I'll fix that. Though I should note that variary plus / minus / times / divide isn't really standard FPCore and maybe it's not actually a good thing that we support it.