
(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 6 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 (* 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}
Initial program 99.6%
Final simplification99.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (/ 1.0 (* y y)) -1.0))
(t_1 (- 1.0 (* y y)))
(t_2 (* x (* y y))))
(if (<= (* y y) 2e+42)
(+ x t_2)
(if (<= (* y y) 1e+296)
(+
(* (/ x t_0) (/ t_0 t_1))
(* (* t_2 (+ (* y y) -1.0)) (/ (/ (* y y) t_1) t_1)))
t_2))))
double code(double x, double y) {
double t_0 = (1.0 / (y * y)) + -1.0;
double t_1 = 1.0 - (y * y);
double t_2 = x * (y * y);
double tmp;
if ((y * y) <= 2e+42) {
tmp = x + t_2;
} else if ((y * y) <= 1e+296) {
tmp = ((x / t_0) * (t_0 / t_1)) + ((t_2 * ((y * y) + -1.0)) * (((y * y) / t_1) / t_1));
} else {
tmp = t_2;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = (1.0d0 / (y * y)) + (-1.0d0)
t_1 = 1.0d0 - (y * y)
t_2 = x * (y * y)
if ((y * y) <= 2d+42) then
tmp = x + t_2
else if ((y * y) <= 1d+296) then
tmp = ((x / t_0) * (t_0 / t_1)) + ((t_2 * ((y * y) + (-1.0d0))) * (((y * y) / t_1) / t_1))
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = (1.0 / (y * y)) + -1.0;
double t_1 = 1.0 - (y * y);
double t_2 = x * (y * y);
double tmp;
if ((y * y) <= 2e+42) {
tmp = x + t_2;
} else if ((y * y) <= 1e+296) {
tmp = ((x / t_0) * (t_0 / t_1)) + ((t_2 * ((y * y) + -1.0)) * (((y * y) / t_1) / t_1));
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y): t_0 = (1.0 / (y * y)) + -1.0 t_1 = 1.0 - (y * y) t_2 = x * (y * y) tmp = 0 if (y * y) <= 2e+42: tmp = x + t_2 elif (y * y) <= 1e+296: tmp = ((x / t_0) * (t_0 / t_1)) + ((t_2 * ((y * y) + -1.0)) * (((y * y) / t_1) / t_1)) else: tmp = t_2 return tmp
function code(x, y) t_0 = Float64(Float64(1.0 / Float64(y * y)) + -1.0) t_1 = Float64(1.0 - Float64(y * y)) t_2 = Float64(x * Float64(y * y)) tmp = 0.0 if (Float64(y * y) <= 2e+42) tmp = Float64(x + t_2); elseif (Float64(y * y) <= 1e+296) tmp = Float64(Float64(Float64(x / t_0) * Float64(t_0 / t_1)) + Float64(Float64(t_2 * Float64(Float64(y * y) + -1.0)) * Float64(Float64(Float64(y * y) / t_1) / t_1))); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y) t_0 = (1.0 / (y * y)) + -1.0; t_1 = 1.0 - (y * y); t_2 = x * (y * y); tmp = 0.0; if ((y * y) <= 2e+42) tmp = x + t_2; elseif ((y * y) <= 1e+296) tmp = ((x / t_0) * (t_0 / t_1)) + ((t_2 * ((y * y) + -1.0)) * (((y * y) / t_1) / t_1)); else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - N[(y * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * y), $MachinePrecision], 2e+42], N[(x + t$95$2), $MachinePrecision], If[LessEqual[N[(y * y), $MachinePrecision], 1e+296], N[(N[(N[(x / t$95$0), $MachinePrecision] * N[(t$95$0 / t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$2 * N[(N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(y * y), $MachinePrecision] / t$95$1), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{y \cdot y} + -1\\
t_1 := 1 - y \cdot y\\
t_2 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{+42}:\\
\;\;\;\;x + t_2\\
\mathbf{elif}\;y \cdot y \leq 10^{+296}:\\
\;\;\;\;\frac{x}{t_0} \cdot \frac{t_0}{t_1} + \left(t_2 \cdot \left(y \cdot y + -1\right)\right) \cdot \frac{\frac{y \cdot y}{t_1}}{t_1}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if (*.f64 y y) < 2.00000000000000009e42Initial program 99.3%
Taylor expanded in y around 0 94.0%
unpow294.0%
Simplified94.0%
if 2.00000000000000009e42 < (*.f64 y y) < 9.99999999999999981e295Initial program 100.0%
Taylor expanded in y around 0 26.6%
unpow226.6%
Simplified26.6%
flip-+24.9%
div-sub24.9%
associate-/l*29.2%
associate-/l*3.2%
frac-sub33.3%
Applied egg-rr33.3%
div-sub33.3%
div-inv33.3%
cancel-sign-sub-inv33.3%
Applied egg-rr56.7%
if 9.99999999999999981e295 < (*.f64 y y) Initial program 100.0%
Taylor expanded in y around 0 100.0%
unpow2100.0%
Simplified100.0%
flip-+0.0%
div-sub0.0%
associate-/l*0.0%
associate-/l*0.0%
frac-sub0.0%
Applied egg-rr0.0%
Taylor expanded in y around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification88.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ 1.0 (* y y))) (t_1 (* x (* y y))))
(if (<= (* y y) 2e+42)
(+ x t_1)
(if (<= (* y y) 5e+249)
(/
1.0
(/
(- x (* y (* x y)))
(/
x
(/
(+ t_0 -1.0)
(* x (+ t_0 (+ -1.0 (* (* y y) (+ (* y y) -1.0)))))))))
(+ x (* t_1 2.0))))))
double code(double x, double y) {
double t_0 = 1.0 / (y * y);
double t_1 = x * (y * y);
double tmp;
if ((y * y) <= 2e+42) {
tmp = x + t_1;
} else if ((y * y) <= 5e+249) {
tmp = 1.0 / ((x - (y * (x * y))) / (x / ((t_0 + -1.0) / (x * (t_0 + (-1.0 + ((y * y) * ((y * y) + -1.0))))))));
} else {
tmp = x + (t_1 * 2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 1.0d0 / (y * y)
t_1 = x * (y * y)
if ((y * y) <= 2d+42) then
tmp = x + t_1
else if ((y * y) <= 5d+249) then
tmp = 1.0d0 / ((x - (y * (x * y))) / (x / ((t_0 + (-1.0d0)) / (x * (t_0 + ((-1.0d0) + ((y * y) * ((y * y) + (-1.0d0)))))))))
else
tmp = x + (t_1 * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 / (y * y);
double t_1 = x * (y * y);
double tmp;
if ((y * y) <= 2e+42) {
tmp = x + t_1;
} else if ((y * y) <= 5e+249) {
tmp = 1.0 / ((x - (y * (x * y))) / (x / ((t_0 + -1.0) / (x * (t_0 + (-1.0 + ((y * y) * ((y * y) + -1.0))))))));
} else {
tmp = x + (t_1 * 2.0);
}
return tmp;
}
def code(x, y): t_0 = 1.0 / (y * y) t_1 = x * (y * y) tmp = 0 if (y * y) <= 2e+42: tmp = x + t_1 elif (y * y) <= 5e+249: tmp = 1.0 / ((x - (y * (x * y))) / (x / ((t_0 + -1.0) / (x * (t_0 + (-1.0 + ((y * y) * ((y * y) + -1.0)))))))) else: tmp = x + (t_1 * 2.0) return tmp
function code(x, y) t_0 = Float64(1.0 / Float64(y * y)) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (Float64(y * y) <= 2e+42) tmp = Float64(x + t_1); elseif (Float64(y * y) <= 5e+249) tmp = Float64(1.0 / Float64(Float64(x - Float64(y * Float64(x * y))) / Float64(x / Float64(Float64(t_0 + -1.0) / Float64(x * Float64(t_0 + Float64(-1.0 + Float64(Float64(y * y) * Float64(Float64(y * y) + -1.0))))))))); else tmp = Float64(x + Float64(t_1 * 2.0)); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 / (y * y); t_1 = x * (y * y); tmp = 0.0; if ((y * y) <= 2e+42) tmp = x + t_1; elseif ((y * y) <= 5e+249) tmp = 1.0 / ((x - (y * (x * y))) / (x / ((t_0 + -1.0) / (x * (t_0 + (-1.0 + ((y * y) * ((y * y) + -1.0)))))))); else tmp = x + (t_1 * 2.0); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 / N[(y * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * y), $MachinePrecision], 2e+42], N[(x + t$95$1), $MachinePrecision], If[LessEqual[N[(y * y), $MachinePrecision], 5e+249], N[(1.0 / N[(N[(x - N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x / N[(N[(t$95$0 + -1.0), $MachinePrecision] / N[(x * N[(t$95$0 + N[(-1.0 + N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(t$95$1 * 2.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{y \cdot y}\\
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{+42}:\\
\;\;\;\;x + t_1\\
\mathbf{elif}\;y \cdot y \leq 5 \cdot 10^{+249}:\\
\;\;\;\;\frac{1}{\frac{x - y \cdot \left(x \cdot y\right)}{\frac{x}{\frac{t_0 + -1}{x \cdot \left(t_0 + \left(-1 + \left(y \cdot y\right) \cdot \left(y \cdot y + -1\right)\right)\right)}}}}\\
\mathbf{else}:\\
\;\;\;\;x + t_1 \cdot 2\\
\end{array}
\end{array}
if (*.f64 y y) < 2.00000000000000009e42Initial program 99.3%
Taylor expanded in y around 0 94.0%
unpow294.0%
Simplified94.0%
if 2.00000000000000009e42 < (*.f64 y y) < 4.9999999999999996e249Initial program 100.0%
Taylor expanded in y around 0 18.5%
unpow218.5%
Simplified18.5%
flip-+26.7%
div-sub26.7%
associate-/l*3.1%
frac-sub26.7%
Applied egg-rr26.7%
clear-num26.7%
inv-pow26.7%
metadata-eval26.7%
sqr-pow10.8%
Applied egg-rr18.1%
pow-sqr36.4%
metadata-eval36.4%
unpow-136.4%
associate-*r*36.4%
associate-/l*36.4%
Simplified36.4%
Taylor expanded in x around 0 51.0%
sub-neg51.0%
unpow251.0%
metadata-eval51.0%
+-commutative51.0%
unpow251.0%
unpow251.0%
unpow251.0%
Simplified51.0%
if 4.9999999999999996e249 < (*.f64 y y) Initial program 100.0%
Taylor expanded in y around 0 97.6%
unpow297.6%
Simplified97.6%
flip-+1.3%
div-sub1.3%
associate-/l*1.3%
associate-/l*0.1%
frac-sub2.5%
Applied egg-rr2.5%
Taylor expanded in y around 0 2.5%
unpow22.5%
Simplified2.5%
Taylor expanded in y around 0 97.6%
unpow297.6%
Simplified97.6%
Final simplification88.4%
(FPCore (x y) :precision binary64 (if (<= (* y y) 0.0002) x (* x (* y y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 0.0002) {
tmp = x;
} else {
tmp = x * (y * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 0.0002d0) then
tmp = x
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 0.0002) {
tmp = x;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 0.0002: tmp = x else: tmp = x * (y * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 0.0002) tmp = x; else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 0.0002) tmp = x; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 0.0002], x, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 0.0002:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 2.0000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0 99.5%
if 2.0000000000000001e-4 < (*.f64 y y) Initial program 99.3%
Taylor expanded in y around 0 67.0%
unpow267.0%
Simplified67.0%
flip-+9.3%
div-sub9.3%
associate-/l*10.9%
associate-/l*1.3%
frac-sub12.4%
Applied egg-rr12.4%
Taylor expanded in y around inf 67.0%
unpow267.0%
Simplified67.0%
Final simplification83.2%
(FPCore (x y) :precision binary64 (+ x (* x (* y y))))
double code(double x, double y) {
return x + (x * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (x * (y * y))
end function
public static double code(double x, double y) {
return x + (x * (y * y));
}
def code(x, y): return x + (x * (y * y))
function code(x, y) return Float64(x + Float64(x * Float64(y * y))) end
function tmp = code(x, y) tmp = x + (x * (y * y)); end
code[x_, y_] := N[(x + N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \left(y \cdot y\right)
\end{array}
Initial program 99.6%
Taylor expanded in y around 0 83.3%
unpow283.3%
Simplified83.3%
Final simplification83.3%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.6%
Taylor expanded in y around 0 51.5%
Final simplification51.5%
(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 2023297
(FPCore (x y)
:name "Data.Number.Erf:$dmerfcx from erf-2.0.0.0"
:precision binary64
:herbie-target
(* x (pow (exp y) y))
(* x (exp (* y y))))