
(FPCore (x y) :precision binary64 :pre TRUE (+ (+ x y) x))
double code(double x, double y) {
return (x + y) + x;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) + x
end function
public static double code(double x, double y) {
return (x + y) + x;
}
def code(x, y): return (x + y) + x
function code(x, y) return Float64(Float64(x + y) + x) end
function tmp = code(x, y) tmp = (x + y) + x; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] + 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
\left(x + y\right) + x
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (+ (+ x y) x))
double code(double x, double y) {
return (x + y) + x;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) + x
end function
public static double code(double x, double y) {
return (x + y) + x;
}
def code(x, y): return (x + y) + x
function code(x, y) return Float64(Float64(x + y) + x) end
function tmp = code(x, y) tmp = (x + y) + x; end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] + 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
\left(x + y\right) + x
(FPCore (x y) :precision binary64 :pre TRUE (fma 2.0 x y))
double code(double x, double y) {
return fma(2.0, x, y);
}
function code(x, y) return fma(2.0, x, y) end
code[x_, y_] := N[(2.0 * x + y), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = ((2) * x) + y END code
\mathsf{fma}\left(2, x, y\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= y -1.1623226477154053e-26) (+ y x) (if (<= y 2.426229654520916e+48) (+ x x) (+ y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.1623226477154053e-26) {
tmp = y + x;
} else if (y <= 2.426229654520916e+48) {
tmp = x + x;
} else {
tmp = y + x;
}
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.1623226477154053d-26)) then
tmp = y + x
else if (y <= 2.426229654520916d+48) then
tmp = x + x
else
tmp = y + x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.1623226477154053e-26) {
tmp = y + x;
} else if (y <= 2.426229654520916e+48) {
tmp = x + x;
} else {
tmp = y + x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.1623226477154053e-26: tmp = y + x elif y <= 2.426229654520916e+48: tmp = x + x else: tmp = y + x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.1623226477154053e-26) tmp = Float64(y + x); elseif (y <= 2.426229654520916e+48) tmp = Float64(x + x); else tmp = Float64(y + x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.1623226477154053e-26) tmp = y + x; elseif (y <= 2.426229654520916e+48) tmp = x + x; else tmp = y + x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.1623226477154053e-26], N[(y + x), $MachinePrecision], If[LessEqual[y, 2.426229654520916e+48], N[(x + x), $MachinePrecision], N[(y + x), $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 <= (2426229654520915891643607200729785382101422440448)) THEN (x + x) ELSE (y + x) ENDIF IN LET tmp = IF (y <= (-11623226477154053309672337016807098596194572553602347814800057447127815991871901957210866385139524936676025390625e-138)) THEN (y + x) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -1.1623226477154053 \cdot 10^{-26}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;y \leq 2.426229654520916 \cdot 10^{+48}:\\
\;\;\;\;x + x\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
if y < -1.1623226477154053e-26 or 2.4262296545209159e48 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites58.0%
if -1.1623226477154053e-26 < y < 2.4262296545209159e48Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
Applied rewrites51.3%
(FPCore (x y) :precision binary64 :pre TRUE (if (<= y -3.7736488112764267e+33) y (if (<= y 2.426229654520916e+48) (+ x x) y)))
double code(double x, double y) {
double tmp;
if (y <= -3.7736488112764267e+33) {
tmp = y;
} else if (y <= 2.426229654520916e+48) {
tmp = x + x;
} else {
tmp = 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 <= (-3.7736488112764267d+33)) then
tmp = y
else if (y <= 2.426229654520916d+48) then
tmp = x + x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.7736488112764267e+33) {
tmp = y;
} else if (y <= 2.426229654520916e+48) {
tmp = x + x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.7736488112764267e+33: tmp = y elif y <= 2.426229654520916e+48: tmp = x + x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -3.7736488112764267e+33) tmp = y; elseif (y <= 2.426229654520916e+48) tmp = Float64(x + x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.7736488112764267e+33) tmp = y; elseif (y <= 2.426229654520916e+48) tmp = x + x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.7736488112764267e+33], y, If[LessEqual[y, 2.426229654520916e+48], N[(x + x), $MachinePrecision], y]]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = LET tmp_1 = IF (y <= (2426229654520915891643607200729785382101422440448)) THEN (x + x) ELSE y ENDIF IN LET tmp = IF (y <= (-3773648811276426676203284156383232)) THEN y ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -3.7736488112764267 \cdot 10^{+33}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.426229654520916 \cdot 10^{+48}:\\
\;\;\;\;x + x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
if y < -3.7736488112764267e33 or 2.4262296545209159e48 < y Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
Applied rewrites51.3%
Taylor expanded in x around 0
Applied rewrites50.2%
if -3.7736488112764267e33 < y < 2.4262296545209159e48Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
Applied rewrites51.3%
(FPCore (x y) :precision binary64 :pre TRUE y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = y END code
y
Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.3%
Applied rewrites51.3%
Taylor expanded in x around 0
Applied rewrites50.2%
herbie shell --seed 2026092
(FPCore (x y)
:name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, A"
:precision binary64
(+ (+ x y) x))