
(FPCore (x y) :precision binary64 (* x (exp (* y y))))
double code(double x, double y) {
return x * exp((y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * exp((y * y))
end function
public static double code(double x, double y) {
return x * Math.exp((y * y));
}
def code(x, y): return x * math.exp((y * y))
function code(x, y) return Float64(x * exp(Float64(y * y))) end
function tmp = code(x, y) tmp = x * exp((y * y)); end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (exp (* y y))))
double code(double x, double y) {
return x * exp((y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * exp((y * y))
end function
public static double code(double x, double y) {
return x * Math.exp((y * y));
}
def code(x, y): return x * math.exp((y * y))
function code(x, y) return Float64(x * exp(Float64(y * y))) end
function tmp = code(x, y) tmp = x * exp((y * y)); end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot y}
\end{array}
(FPCore (x y) :precision binary64 (* (exp (* y y)) x))
double code(double x, double y) {
return exp((y * y)) * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp((y * y)) * x
end function
public static double code(double x, double y) {
return Math.exp((y * y)) * x;
}
def code(x, y): return math.exp((y * y)) * x
function code(x, y) return Float64(exp(Float64(y * y)) * x) end
function tmp = code(x, y) tmp = exp((y * y)) * x; end
code[x_, y_] := N[(N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
e^{y \cdot y} \cdot x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= (exp (* y y)) 2.0) (* (fma y y 1.0) x) (* (* (* (fma 0.16666666666666666 y 0.5) y) y) x)))
double code(double x, double y) {
double tmp;
if (exp((y * y)) <= 2.0) {
tmp = fma(y, y, 1.0) * x;
} else {
tmp = ((fma(0.16666666666666666, y, 0.5) * y) * y) * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (exp(Float64(y * y)) <= 2.0) tmp = Float64(fma(y, y, 1.0) * x); else tmp = Float64(Float64(Float64(fma(0.16666666666666666, y, 0.5) * y) * y) * x); end return tmp end
code[x_, y_] := If[LessEqual[N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision], 2.0], N[(N[(y * y + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(0.16666666666666666 * y + 0.5), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{y \cdot y} \leq 2:\\
\;\;\;\;\mathsf{fma}\left(y, y, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(0.16666666666666666, y, 0.5\right) \cdot y\right) \cdot y\right) \cdot x\\
\end{array}
\end{array}
if (exp.f64 (*.f64 y y)) < 2Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6499.8
Applied rewrites99.8%
if 2 < (exp.f64 (*.f64 y y)) Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites49.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6441.4
Applied rewrites41.4%
Taylor expanded in y around inf
Applied rewrites41.4%
Taylor expanded in y around inf
Applied rewrites41.4%
Final simplification70.8%
(FPCore (x y) :precision binary64 (if (<= (exp (* y y)) 2.0) (* (fma y y 1.0) x) (* (* (* 0.16666666666666666 y) (* y y)) x)))
double code(double x, double y) {
double tmp;
if (exp((y * y)) <= 2.0) {
tmp = fma(y, y, 1.0) * x;
} else {
tmp = ((0.16666666666666666 * y) * (y * y)) * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (exp(Float64(y * y)) <= 2.0) tmp = Float64(fma(y, y, 1.0) * x); else tmp = Float64(Float64(Float64(0.16666666666666666 * y) * Float64(y * y)) * x); end return tmp end
code[x_, y_] := If[LessEqual[N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision], 2.0], N[(N[(y * y + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(0.16666666666666666 * y), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{y \cdot y} \leq 2:\\
\;\;\;\;\mathsf{fma}\left(y, y, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(\left(0.16666666666666666 \cdot y\right) \cdot \left(y \cdot y\right)\right) \cdot x\\
\end{array}
\end{array}
if (exp.f64 (*.f64 y y)) < 2Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6499.8
Applied rewrites99.8%
if 2 < (exp.f64 (*.f64 y y)) Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites49.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6441.4
Applied rewrites41.4%
Taylor expanded in y around inf
Applied rewrites41.4%
Taylor expanded in y around inf
Applied rewrites41.4%
Final simplification70.8%
(FPCore (x y) :precision binary64 (if (<= (exp (* y y)) 2.0) (* 1.0 x) (* (* y y) x)))
double code(double x, double y) {
double tmp;
if (exp((y * y)) <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = (y * y) * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (exp((y * y)) <= 2.0d0) then
tmp = 1.0d0 * x
else
tmp = (y * y) * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (Math.exp((y * y)) <= 2.0) {
tmp = 1.0 * x;
} else {
tmp = (y * y) * x;
}
return tmp;
}
def code(x, y): tmp = 0 if math.exp((y * y)) <= 2.0: tmp = 1.0 * x else: tmp = (y * y) * x return tmp
function code(x, y) tmp = 0.0 if (exp(Float64(y * y)) <= 2.0) tmp = Float64(1.0 * x); else tmp = Float64(Float64(y * y) * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (exp((y * y)) <= 2.0) tmp = 1.0 * x; else tmp = (y * y) * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision], 2.0], N[(1.0 * x), $MachinePrecision], N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{y \cdot y} \leq 2:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot y\right) \cdot x\\
\end{array}
\end{array}
if (exp.f64 (*.f64 y y)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites99.5%
if 2 < (exp.f64 (*.f64 y y)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6467.1
Applied rewrites67.1%
Taylor expanded in y around inf
Applied rewrites67.1%
Final simplification83.4%
(FPCore (x y) :precision binary64 (* (exp y) x))
double code(double x, double y) {
return exp(y) * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp(y) * x
end function
public static double code(double x, double y) {
return Math.exp(y) * x;
}
def code(x, y): return math.exp(y) * x
function code(x, y) return Float64(exp(y) * x) end
function tmp = code(x, y) tmp = exp(y) * x; end
code[x_, y_] := N[(N[Exp[y], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
e^{y} \cdot x
\end{array}
Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites74.5%
Final simplification74.5%
(FPCore (x y)
:precision binary64
(if (<= (* y y) 1e+120)
(fma (fma 0.5 (* (* y y) x) x) (* y y) x)
(*
(/
(* (fma 0.027777777777777776 (* y y) -0.25) (* y y))
(fma 0.16666666666666666 y -0.5))
x)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 1e+120) {
tmp = fma(fma(0.5, ((y * y) * x), x), (y * y), x);
} else {
tmp = ((fma(0.027777777777777776, (y * y), -0.25) * (y * y)) / fma(0.16666666666666666, y, -0.5)) * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 1e+120) tmp = fma(fma(0.5, Float64(Float64(y * y) * x), x), Float64(y * y), x); else tmp = Float64(Float64(Float64(fma(0.027777777777777776, Float64(y * y), -0.25) * Float64(y * y)) / fma(0.16666666666666666, y, -0.5)) * x); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 1e+120], N[(N[(0.5 * N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision] + x), $MachinePrecision] * N[(y * y), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(N[(0.027777777777777776 * N[(y * y), $MachinePrecision] + -0.25), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision] / N[(0.16666666666666666 * y + -0.5), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 10^{+120}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, \left(y \cdot y\right) \cdot x, x\right), y \cdot y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.027777777777777776, y \cdot y, -0.25\right) \cdot \left(y \cdot y\right)}{\mathsf{fma}\left(0.16666666666666666, y, -0.5\right)} \cdot x\\
\end{array}
\end{array}
if (*.f64 y y) < 9.9999999999999998e119Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6486.5
Applied rewrites86.5%
Applied rewrites86.5%
Taylor expanded in y around 0
Applied rewrites86.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6488.5
Applied rewrites88.5%
if 9.9999999999999998e119 < (*.f64 y y) Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites51.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6448.3
Applied rewrites48.3%
Taylor expanded in y around inf
Applied rewrites48.3%
Applied rewrites50.9%
Final simplification72.9%
(FPCore (x y) :precision binary64 (* (fma (* 0.16666666666666666 (* y y)) y 1.0) x))
double code(double x, double y) {
return fma((0.16666666666666666 * (y * y)), y, 1.0) * x;
}
function code(x, y) return Float64(fma(Float64(0.16666666666666666 * Float64(y * y)), y, 1.0) * x) end
code[x_, y_] := N[(N[(N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision] * y + 1.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.16666666666666666 \cdot \left(y \cdot y\right), y, 1\right) \cdot x
\end{array}
Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites74.5%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6470.4
Applied rewrites70.4%
Taylor expanded in y around inf
Applied rewrites70.7%
Final simplification70.7%
(FPCore (x y) :precision binary64 (if (<= (* y y) 2e-6) (* 1.0 x) (* y x)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e-6) {
tmp = 1.0 * x;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 2d-6) then
tmp = 1.0d0 * x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 2e-6) {
tmp = 1.0 * x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 2e-6: tmp = 1.0 * x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e-6) tmp = Float64(1.0 * x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 2e-6) tmp = 1.0 * x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e-6], N[(1.0 * x), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{-6}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (*.f64 y y) < 1.99999999999999991e-6Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites99.5%
if 1.99999999999999991e-6 < (*.f64 y y) Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites49.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6417.6
Applied rewrites17.6%
Taylor expanded in y around inf
Applied rewrites17.6%
Final simplification58.9%
(FPCore (x y) :precision binary64 (* (fma y y 1.0) x))
double code(double x, double y) {
return fma(y, y, 1.0) * x;
}
function code(x, y) return Float64(fma(y, y, 1.0) * x) end
code[x_, y_] := N[(N[(y * y + 1.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, y, 1\right) \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6483.6
Applied rewrites83.6%
Final simplification83.6%
(FPCore (x y) :precision binary64 (fma y x x))
double code(double x, double y) {
return fma(y, x, x);
}
function code(x, y) return fma(y, x, x) end
code[x_, y_] := N[(y * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, x\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites74.5%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6458.6
Applied rewrites58.6%
(FPCore (x y) :precision binary64 (* y x))
double code(double x, double y) {
return y * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * x
end function
public static double code(double x, double y) {
return y * x;
}
def code(x, y): return y * x
function code(x, y) return Float64(y * x) end
function tmp = code(x, y) tmp = y * x; end
code[x_, y_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
lift-*.f64N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
*-rgt-identityN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-outN/A
div-invN/A
div-invN/A
+-inversesN/A
difference-of-squaresN/A
+-inversesN/A
flip-+N/A
count-2N/A
Applied rewrites74.5%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6458.6
Applied rewrites58.6%
Taylor expanded in y around inf
Applied rewrites11.1%
(FPCore (x y) :precision binary64 (* x (pow (exp y) y)))
double code(double x, double y) {
return x * pow(exp(y), y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (exp(y) ** y)
end function
public static double code(double x, double y) {
return x * Math.pow(Math.exp(y), y);
}
def code(x, y): return x * math.pow(math.exp(y), y)
function code(x, y) return Float64(x * (exp(y) ^ y)) end
function tmp = code(x, y) tmp = x * (exp(y) ^ y); end
code[x_, y_] := N[(x * N[Power[N[Exp[y], $MachinePrecision], y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot {\left(e^{y}\right)}^{y}
\end{array}
herbie shell --seed 2024270
(FPCore (x y)
:name "Data.Number.Erf:$dmerfcx from erf-2.0.0.0"
:precision binary64
:alt
(! :herbie-platform default (* x (pow (exp y) y)))
(* x (exp (* y y))))