
(FPCore (x y) :precision binary64 :pre TRUE (* x (+ y 1.0)))
double code(double x, double y) {
return x * (y + 1.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (y + 1.0d0)
end function
public static double code(double x, double y) {
return x * (y + 1.0);
}
def code(x, y): return x * (y + 1.0)
function code(x, y) return Float64(x * Float64(y + 1.0)) end
function tmp = code(x, y) tmp = x * (y + 1.0); end
code[x_, y_] := N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x * (y + (1)) END code
x \cdot \left(y + 1\right)
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (* x (+ y 1.0)))
double code(double x, double y) {
return x * (y + 1.0);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (y + 1.0d0)
end function
public static double code(double x, double y) {
return x * (y + 1.0);
}
def code(x, y): return x * (y + 1.0)
function code(x, y) return Float64(x * Float64(y + 1.0)) end
function tmp = code(x, y) tmp = x * (y + 1.0); end
code[x_, y_] := N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x * (y + (1)) END code
x \cdot \left(y + 1\right)
(FPCore (x y) :precision binary64 :pre TRUE (fma x y x))
double code(double x, double y) {
return fma(x, y, x);
}
function code(x, y) return fma(x, y, x) end
code[x_, y_] := N[(x * y + x), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (x * y) + x END code
\mathsf{fma}\left(x, y, x\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= (+ y 1.0) -5.0) (* x y) (if (<= (+ y 1.0) 2.0) (* x 1.0) (* x y))))
double code(double x, double y) {
double tmp;
if ((y + 1.0) <= -5.0) {
tmp = x * y;
} else if ((y + 1.0) <= 2.0) {
tmp = x * 1.0;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y + 1.0d0) <= (-5.0d0)) then
tmp = x * y
else if ((y + 1.0d0) <= 2.0d0) then
tmp = x * 1.0d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y + 1.0) <= -5.0) {
tmp = x * y;
} else if ((y + 1.0) <= 2.0) {
tmp = x * 1.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y + 1.0) <= -5.0: tmp = x * y elif (y + 1.0) <= 2.0: tmp = x * 1.0 else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (Float64(y + 1.0) <= -5.0) tmp = Float64(x * y); elseif (Float64(y + 1.0) <= 2.0) tmp = Float64(x * 1.0); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y + 1.0) <= -5.0) tmp = x * y; elseif ((y + 1.0) <= 2.0) tmp = x * 1.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y + 1.0), $MachinePrecision], -5.0], N[(x * y), $MachinePrecision], If[LessEqual[N[(y + 1.0), $MachinePrecision], 2.0], N[(x * 1.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF ((y + (1)) <= (2)) THEN (x * (1)) ELSE (x * y) ENDIF IN LET tmp = IF ((y + (1)) <= (-5)) THEN (x * y) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y + 1 \leq -5:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y + 1 \leq 2:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
if (+.f64 y #s(literal 1 binary64)) < -5 or 2 < (+.f64 y #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites51.3%
if -5 < (+.f64 y #s(literal 1 binary64)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites50.7%
(FPCore (x y) :precision binary64 :pre TRUE (* x y))
double code(double x, double y) {
return x * y;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * y
end function
public static double code(double x, double y) {
return x * y;
}
def code(x, y): return x * y
function code(x, y) return Float64(x * y) end
function tmp = code(x, y) tmp = x * y; end
code[x_, y_] := N[(x * y), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = x * y END code
x \cdot y
Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites51.3%
herbie shell --seed 2026092
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, B"
:precision binary64
(* x (+ y 1.0)))