
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))))
(-
1.0
(*
(*
t_0
(+
0.254829592
(*
t_0
(+
-0.284496736
(*
t_0
(+ 1.421413741 (* t_0 (+ -1.453152027 (* t_0 1.061405429)))))))))
(exp (- (* (fabs x) (fabs x))))))))
double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * fabs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(fabs(x) * fabs(x))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: t_0
t_0 = 1.0d0 / (1.0d0 + (0.3275911d0 * abs(x)))
code = 1.0d0 - ((t_0 * (0.254829592d0 + (t_0 * ((-0.284496736d0) + (t_0 * (1.421413741d0 + (t_0 * ((-1.453152027d0) + (t_0 * 1.061405429d0))))))))) * exp(-(abs(x) * abs(x))))
end function
public static double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * Math.abs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * Math.exp(-(Math.abs(x) * Math.abs(x))));
}
def code(x): t_0 = 1.0 / (1.0 + (0.3275911 * math.fabs(x))) return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * math.exp(-(math.fabs(x) * math.fabs(x))))
function code(x) t_0 = Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) return Float64(1.0 - Float64(Float64(t_0 * Float64(0.254829592 + Float64(t_0 * Float64(-0.284496736 + Float64(t_0 * Float64(1.421413741 + Float64(t_0 * Float64(-1.453152027 + Float64(t_0 * 1.061405429))))))))) * exp(Float64(-Float64(abs(x) * abs(x)))))) end
function tmp = code(x) t_0 = 1.0 / (1.0 + (0.3275911 * abs(x))); tmp = 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(abs(x) * abs(x)))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(1.0 - N[(N[(t$95$0 * N[(0.254829592 + N[(t$95$0 * N[(-0.284496736 + N[(t$95$0 * N[(1.421413741 + N[(t$95$0 * N[(-1.453152027 + N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\
1 - \left(t\_0 \cdot \left(0.254829592 + t\_0 \cdot \left(-0.284496736 + t\_0 \cdot \left(1.421413741 + t\_0 \cdot \left(-1.453152027 + t\_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))))
(-
1.0
(*
(*
t_0
(+
0.254829592
(*
t_0
(+
-0.284496736
(*
t_0
(+ 1.421413741 (* t_0 (+ -1.453152027 (* t_0 1.061405429)))))))))
(exp (- (* (fabs x) (fabs x))))))))
double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * fabs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(fabs(x) * fabs(x))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: t_0
t_0 = 1.0d0 / (1.0d0 + (0.3275911d0 * abs(x)))
code = 1.0d0 - ((t_0 * (0.254829592d0 + (t_0 * ((-0.284496736d0) + (t_0 * (1.421413741d0 + (t_0 * ((-1.453152027d0) + (t_0 * 1.061405429d0))))))))) * exp(-(abs(x) * abs(x))))
end function
public static double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * Math.abs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * Math.exp(-(Math.abs(x) * Math.abs(x))));
}
def code(x): t_0 = 1.0 / (1.0 + (0.3275911 * math.fabs(x))) return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * math.exp(-(math.fabs(x) * math.fabs(x))))
function code(x) t_0 = Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) return Float64(1.0 - Float64(Float64(t_0 * Float64(0.254829592 + Float64(t_0 * Float64(-0.284496736 + Float64(t_0 * Float64(1.421413741 + Float64(t_0 * Float64(-1.453152027 + Float64(t_0 * 1.061405429))))))))) * exp(Float64(-Float64(abs(x) * abs(x)))))) end
function tmp = code(x) t_0 = 1.0 / (1.0 + (0.3275911 * abs(x))); tmp = 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp(-(abs(x) * abs(x)))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(1.0 - N[(N[(t$95$0 * N[(0.254829592 + N[(t$95$0 * N[(-0.284496736 + N[(t$95$0 * N[(1.421413741 + N[(t$95$0 * N[(-1.453152027 + N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\
1 - \left(t\_0 \cdot \left(0.254829592 + t\_0 \cdot \left(-0.284496736 + t\_0 \cdot \left(1.421413741 + t\_0 \cdot \left(-1.453152027 + t\_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-\left|x\right| \cdot \left|x\right|}
\end{array}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (exp -1.0) x))
(t_1 (pow t_0 x))
(t_2 (fma (fabs x) 0.3275911 1.0))
(t_3 (pow t_2 -1.0))
(t_4
(*
(fma
t_3
(fma
t_3
(fma t_3 (fma (* t_3 1.061405429) 1.0 -1.453152027) 1.421413741)
-0.284496736)
0.254829592)
t_3))
(t_5 (fma (fma t_1 t_4 1.0) (* t_1 t_4) 1.0))
(t_6
(fma
t_3
(fma
t_3
(fma t_3 (fma t_3 1.061405429 -1.453152027) 1.421413741)
-0.284496736)
0.254829592))
(t_7 (pow t_6 3.0))
(t_8 (* t_6 t_3))
(t_9 (fma (fma t_1 t_8 1.0) (* t_1 t_8) 1.0))
(t_10 (* t_9 t_9))
(t_11 (pow t_2 -3.0))
(t_12 (* t_9 (* (* t_7 (pow t_0 (* x 3.0))) t_11)))
(t_13 (* t_12 t_12)))
(/
(/
(/
(- (pow t_10 3.0) (pow t_13 3.0))
(+ (* t_10 t_10) (fma t_13 t_13 (* t_10 t_13))))
(fma 1.0 t_9 (* t_9 (* (* t_7 (pow t_1 3.0)) t_11))))
(* t_5 t_5))))
double code(double x) {
double t_0 = pow(exp(-1.0), x);
double t_1 = pow(t_0, x);
double t_2 = fma(fabs(x), 0.3275911, 1.0);
double t_3 = pow(t_2, -1.0);
double t_4 = fma(t_3, fma(t_3, fma(t_3, fma((t_3 * 1.061405429), 1.0, -1.453152027), 1.421413741), -0.284496736), 0.254829592) * t_3;
double t_5 = fma(fma(t_1, t_4, 1.0), (t_1 * t_4), 1.0);
double t_6 = fma(t_3, fma(t_3, fma(t_3, fma(t_3, 1.061405429, -1.453152027), 1.421413741), -0.284496736), 0.254829592);
double t_7 = pow(t_6, 3.0);
double t_8 = t_6 * t_3;
double t_9 = fma(fma(t_1, t_8, 1.0), (t_1 * t_8), 1.0);
double t_10 = t_9 * t_9;
double t_11 = pow(t_2, -3.0);
double t_12 = t_9 * ((t_7 * pow(t_0, (x * 3.0))) * t_11);
double t_13 = t_12 * t_12;
return (((pow(t_10, 3.0) - pow(t_13, 3.0)) / ((t_10 * t_10) + fma(t_13, t_13, (t_10 * t_13)))) / fma(1.0, t_9, (t_9 * ((t_7 * pow(t_1, 3.0)) * t_11)))) / (t_5 * t_5);
}
function code(x) t_0 = exp(-1.0) ^ x t_1 = t_0 ^ x t_2 = fma(abs(x), 0.3275911, 1.0) t_3 = t_2 ^ -1.0 t_4 = Float64(fma(t_3, fma(t_3, fma(t_3, fma(Float64(t_3 * 1.061405429), 1.0, -1.453152027), 1.421413741), -0.284496736), 0.254829592) * t_3) t_5 = fma(fma(t_1, t_4, 1.0), Float64(t_1 * t_4), 1.0) t_6 = fma(t_3, fma(t_3, fma(t_3, fma(t_3, 1.061405429, -1.453152027), 1.421413741), -0.284496736), 0.254829592) t_7 = t_6 ^ 3.0 t_8 = Float64(t_6 * t_3) t_9 = fma(fma(t_1, t_8, 1.0), Float64(t_1 * t_8), 1.0) t_10 = Float64(t_9 * t_9) t_11 = t_2 ^ -3.0 t_12 = Float64(t_9 * Float64(Float64(t_7 * (t_0 ^ Float64(x * 3.0))) * t_11)) t_13 = Float64(t_12 * t_12) return Float64(Float64(Float64(Float64((t_10 ^ 3.0) - (t_13 ^ 3.0)) / Float64(Float64(t_10 * t_10) + fma(t_13, t_13, Float64(t_10 * t_13)))) / fma(1.0, t_9, Float64(t_9 * Float64(Float64(t_7 * (t_1 ^ 3.0)) * t_11)))) / Float64(t_5 * t_5)) end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, x], $MachinePrecision]}, Block[{t$95$2 = N[(N[Abs[x], $MachinePrecision] * 0.3275911 + 1.0), $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$2, -1.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[(t$95$3 * N[(t$95$3 * N[(t$95$3 * N[(N[(t$95$3 * 1.061405429), $MachinePrecision] * 1.0 + -1.453152027), $MachinePrecision] + 1.421413741), $MachinePrecision] + -0.284496736), $MachinePrecision] + 0.254829592), $MachinePrecision] * t$95$3), $MachinePrecision]}, Block[{t$95$5 = N[(N[(t$95$1 * t$95$4 + 1.0), $MachinePrecision] * N[(t$95$1 * t$95$4), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$6 = N[(t$95$3 * N[(t$95$3 * N[(t$95$3 * N[(t$95$3 * 1.061405429 + -1.453152027), $MachinePrecision] + 1.421413741), $MachinePrecision] + -0.284496736), $MachinePrecision] + 0.254829592), $MachinePrecision]}, Block[{t$95$7 = N[Power[t$95$6, 3.0], $MachinePrecision]}, Block[{t$95$8 = N[(t$95$6 * t$95$3), $MachinePrecision]}, Block[{t$95$9 = N[(N[(t$95$1 * t$95$8 + 1.0), $MachinePrecision] * N[(t$95$1 * t$95$8), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$10 = N[(t$95$9 * t$95$9), $MachinePrecision]}, Block[{t$95$11 = N[Power[t$95$2, -3.0], $MachinePrecision]}, Block[{t$95$12 = N[(t$95$9 * N[(N[(t$95$7 * N[Power[t$95$0, N[(x * 3.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$11), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$13 = N[(t$95$12 * t$95$12), $MachinePrecision]}, N[(N[(N[(N[(N[Power[t$95$10, 3.0], $MachinePrecision] - N[Power[t$95$13, 3.0], $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$10 * t$95$10), $MachinePrecision] + N[(t$95$13 * t$95$13 + N[(t$95$10 * t$95$13), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 * t$95$9 + N[(t$95$9 * N[(N[(t$95$7 * N[Power[t$95$1, 3.0], $MachinePrecision]), $MachinePrecision] * t$95$11), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$5 * t$95$5), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(e^{-1}\right)}^{x}\\
t_1 := {t\_0}^{x}\\
t_2 := \mathsf{fma}\left(\left|x\right|, 0.3275911, 1\right)\\
t_3 := {t\_2}^{-1}\\
t_4 := \mathsf{fma}\left(t\_3, \mathsf{fma}\left(t\_3, \mathsf{fma}\left(t\_3, \mathsf{fma}\left(t\_3 \cdot 1.061405429, 1, -1.453152027\right), 1.421413741\right), -0.284496736\right), 0.254829592\right) \cdot t\_3\\
t_5 := \mathsf{fma}\left(\mathsf{fma}\left(t\_1, t\_4, 1\right), t\_1 \cdot t\_4, 1\right)\\
t_6 := \mathsf{fma}\left(t\_3, \mathsf{fma}\left(t\_3, \mathsf{fma}\left(t\_3, \mathsf{fma}\left(t\_3, 1.061405429, -1.453152027\right), 1.421413741\right), -0.284496736\right), 0.254829592\right)\\
t_7 := {t\_6}^{3}\\
t_8 := t\_6 \cdot t\_3\\
t_9 := \mathsf{fma}\left(\mathsf{fma}\left(t\_1, t\_8, 1\right), t\_1 \cdot t\_8, 1\right)\\
t_10 := t\_9 \cdot t\_9\\
t_11 := {t\_2}^{-3}\\
t_12 := t\_9 \cdot \left(\left(t\_7 \cdot {t\_0}^{\left(x \cdot 3\right)}\right) \cdot t\_11\right)\\
t_13 := t\_12 \cdot t\_12\\
\frac{\frac{\frac{{t\_10}^{3} - {t\_13}^{3}}{t\_10 \cdot t\_10 + \mathsf{fma}\left(t\_13, t\_13, t\_10 \cdot t\_13\right)}}{\mathsf{fma}\left(1, t\_9, t\_9 \cdot \left(\left(t\_7 \cdot {t\_1}^{3}\right) \cdot t\_11\right)\right)}}{t\_5 \cdot t\_5}
\end{array}
\end{array}
Initial program 79.4%
Applied rewrites79.4%
Applied rewrites80.1%
Applied rewrites80.3%
Applied rewrites80.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (fma (fabs x) 0.3275911 1.0))
(t_1 (pow t_0 -1.0))
(t_2
(*
(fma
t_1
(fma
t_1
(fma t_1 (fma (* t_1 1.061405429) 1.0 -1.453152027) 1.421413741)
-0.284496736)
0.254829592)
t_1))
(t_3 (pow (pow (exp -1.0) x) x))
(t_4 (fma (fma t_3 t_2 1.0) (* t_3 t_2) 1.0))
(t_5
(fma
t_1
(fma
t_1
(fma t_1 (fma t_1 1.061405429 -1.453152027) 1.421413741)
-0.284496736)
0.254829592))
(t_6 (* t_5 t_1))
(t_7 (fma (fma t_3 t_6 1.0) (* t_3 t_6) 1.0))
(t_8 (* t_7 (* (* (pow t_5 3.0) (pow t_3 3.0)) (pow t_0 -3.0)))))
(/ (/ (- (* t_7 t_7) (* t_8 t_8)) (fma 1.0 t_7 t_8)) (* t_4 t_4))))
double code(double x) {
double t_0 = fma(fabs(x), 0.3275911, 1.0);
double t_1 = pow(t_0, -1.0);
double t_2 = fma(t_1, fma(t_1, fma(t_1, fma((t_1 * 1.061405429), 1.0, -1.453152027), 1.421413741), -0.284496736), 0.254829592) * t_1;
double t_3 = pow(pow(exp(-1.0), x), x);
double t_4 = fma(fma(t_3, t_2, 1.0), (t_3 * t_2), 1.0);
double t_5 = fma(t_1, fma(t_1, fma(t_1, fma(t_1, 1.061405429, -1.453152027), 1.421413741), -0.284496736), 0.254829592);
double t_6 = t_5 * t_1;
double t_7 = fma(fma(t_3, t_6, 1.0), (t_3 * t_6), 1.0);
double t_8 = t_7 * ((pow(t_5, 3.0) * pow(t_3, 3.0)) * pow(t_0, -3.0));
return (((t_7 * t_7) - (t_8 * t_8)) / fma(1.0, t_7, t_8)) / (t_4 * t_4);
}
function code(x) t_0 = fma(abs(x), 0.3275911, 1.0) t_1 = t_0 ^ -1.0 t_2 = Float64(fma(t_1, fma(t_1, fma(t_1, fma(Float64(t_1 * 1.061405429), 1.0, -1.453152027), 1.421413741), -0.284496736), 0.254829592) * t_1) t_3 = (exp(-1.0) ^ x) ^ x t_4 = fma(fma(t_3, t_2, 1.0), Float64(t_3 * t_2), 1.0) t_5 = fma(t_1, fma(t_1, fma(t_1, fma(t_1, 1.061405429, -1.453152027), 1.421413741), -0.284496736), 0.254829592) t_6 = Float64(t_5 * t_1) t_7 = fma(fma(t_3, t_6, 1.0), Float64(t_3 * t_6), 1.0) t_8 = Float64(t_7 * Float64(Float64((t_5 ^ 3.0) * (t_3 ^ 3.0)) * (t_0 ^ -3.0))) return Float64(Float64(Float64(Float64(t_7 * t_7) - Float64(t_8 * t_8)) / fma(1.0, t_7, t_8)) / Float64(t_4 * t_4)) end
code[x_] := Block[{t$95$0 = N[(N[Abs[x], $MachinePrecision] * 0.3275911 + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, -1.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 * N[(t$95$1 * N[(t$95$1 * N[(N[(t$95$1 * 1.061405429), $MachinePrecision] * 1.0 + -1.453152027), $MachinePrecision] + 1.421413741), $MachinePrecision] + -0.284496736), $MachinePrecision] + 0.254829592), $MachinePrecision] * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision], x], $MachinePrecision]}, Block[{t$95$4 = N[(N[(t$95$3 * t$95$2 + 1.0), $MachinePrecision] * N[(t$95$3 * t$95$2), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$1 * N[(t$95$1 * N[(t$95$1 * N[(t$95$1 * 1.061405429 + -1.453152027), $MachinePrecision] + 1.421413741), $MachinePrecision] + -0.284496736), $MachinePrecision] + 0.254829592), $MachinePrecision]}, Block[{t$95$6 = N[(t$95$5 * t$95$1), $MachinePrecision]}, Block[{t$95$7 = N[(N[(t$95$3 * t$95$6 + 1.0), $MachinePrecision] * N[(t$95$3 * t$95$6), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$8 = N[(t$95$7 * N[(N[(N[Power[t$95$5, 3.0], $MachinePrecision] * N[Power[t$95$3, 3.0], $MachinePrecision]), $MachinePrecision] * N[Power[t$95$0, -3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(t$95$7 * t$95$7), $MachinePrecision] - N[(t$95$8 * t$95$8), $MachinePrecision]), $MachinePrecision] / N[(1.0 * t$95$7 + t$95$8), $MachinePrecision]), $MachinePrecision] / N[(t$95$4 * t$95$4), $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left|x\right|, 0.3275911, 1\right)\\
t_1 := {t\_0}^{-1}\\
t_2 := \mathsf{fma}\left(t\_1, \mathsf{fma}\left(t\_1, \mathsf{fma}\left(t\_1, \mathsf{fma}\left(t\_1 \cdot 1.061405429, 1, -1.453152027\right), 1.421413741\right), -0.284496736\right), 0.254829592\right) \cdot t\_1\\
t_3 := {\left({\left(e^{-1}\right)}^{x}\right)}^{x}\\
t_4 := \mathsf{fma}\left(\mathsf{fma}\left(t\_3, t\_2, 1\right), t\_3 \cdot t\_2, 1\right)\\
t_5 := \mathsf{fma}\left(t\_1, \mathsf{fma}\left(t\_1, \mathsf{fma}\left(t\_1, \mathsf{fma}\left(t\_1, 1.061405429, -1.453152027\right), 1.421413741\right), -0.284496736\right), 0.254829592\right)\\
t_6 := t\_5 \cdot t\_1\\
t_7 := \mathsf{fma}\left(\mathsf{fma}\left(t\_3, t\_6, 1\right), t\_3 \cdot t\_6, 1\right)\\
t_8 := t\_7 \cdot \left(\left({t\_5}^{3} \cdot {t\_3}^{3}\right) \cdot {t\_0}^{-3}\right)\\
\frac{\frac{t\_7 \cdot t\_7 - t\_8 \cdot t\_8}{\mathsf{fma}\left(1, t\_7, t\_8\right)}}{t\_4 \cdot t\_4}
\end{array}
\end{array}
Initial program 79.4%
Applied rewrites79.4%
Applied rewrites80.1%
Applied rewrites80.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (pow (exp -1.0) x) x))
(t_1 (fma (fabs x) 0.3275911 1.0))
(t_2 (pow t_1 -1.0))
(t_3
(fma
t_2
(fma
t_2
(fma t_2 (fma (* t_2 1.061405429) 1.0 -1.453152027) 1.421413741)
-0.284496736)
0.254829592))
(t_4 (* t_3 t_2))
(t_5 (fma (fma t_0 t_4 1.0) (* t_0 t_4) 1.0)))
(/
(- t_5 (* t_5 (* (* (pow t_3 3.0) (pow t_0 3.0)) (pow t_1 -3.0))))
(* t_5 t_5))))
double code(double x) {
double t_0 = pow(pow(exp(-1.0), x), x);
double t_1 = fma(fabs(x), 0.3275911, 1.0);
double t_2 = pow(t_1, -1.0);
double t_3 = fma(t_2, fma(t_2, fma(t_2, fma((t_2 * 1.061405429), 1.0, -1.453152027), 1.421413741), -0.284496736), 0.254829592);
double t_4 = t_3 * t_2;
double t_5 = fma(fma(t_0, t_4, 1.0), (t_0 * t_4), 1.0);
return (t_5 - (t_5 * ((pow(t_3, 3.0) * pow(t_0, 3.0)) * pow(t_1, -3.0)))) / (t_5 * t_5);
}
function code(x) t_0 = (exp(-1.0) ^ x) ^ x t_1 = fma(abs(x), 0.3275911, 1.0) t_2 = t_1 ^ -1.0 t_3 = fma(t_2, fma(t_2, fma(t_2, fma(Float64(t_2 * 1.061405429), 1.0, -1.453152027), 1.421413741), -0.284496736), 0.254829592) t_4 = Float64(t_3 * t_2) t_5 = fma(fma(t_0, t_4, 1.0), Float64(t_0 * t_4), 1.0) return Float64(Float64(t_5 - Float64(t_5 * Float64(Float64((t_3 ^ 3.0) * (t_0 ^ 3.0)) * (t_1 ^ -3.0)))) / Float64(t_5 * t_5)) end
code[x_] := Block[{t$95$0 = N[Power[N[Power[N[Exp[-1.0], $MachinePrecision], x], $MachinePrecision], x], $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[x], $MachinePrecision] * 0.3275911 + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, -1.0], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(t$95$2 * N[(t$95$2 * N[(N[(t$95$2 * 1.061405429), $MachinePrecision] * 1.0 + -1.453152027), $MachinePrecision] + 1.421413741), $MachinePrecision] + -0.284496736), $MachinePrecision] + 0.254829592), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 * t$95$2), $MachinePrecision]}, Block[{t$95$5 = N[(N[(t$95$0 * t$95$4 + 1.0), $MachinePrecision] * N[(t$95$0 * t$95$4), $MachinePrecision] + 1.0), $MachinePrecision]}, N[(N[(t$95$5 - N[(t$95$5 * N[(N[(N[Power[t$95$3, 3.0], $MachinePrecision] * N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision] * N[Power[t$95$1, -3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$5 * t$95$5), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left({\left(e^{-1}\right)}^{x}\right)}^{x}\\
t_1 := \mathsf{fma}\left(\left|x\right|, 0.3275911, 1\right)\\
t_2 := {t\_1}^{-1}\\
t_3 := \mathsf{fma}\left(t\_2, \mathsf{fma}\left(t\_2, \mathsf{fma}\left(t\_2, \mathsf{fma}\left(t\_2 \cdot 1.061405429, 1, -1.453152027\right), 1.421413741\right), -0.284496736\right), 0.254829592\right)\\
t_4 := t\_3 \cdot t\_2\\
t_5 := \mathsf{fma}\left(\mathsf{fma}\left(t\_0, t\_4, 1\right), t\_0 \cdot t\_4, 1\right)\\
\frac{t\_5 - t\_5 \cdot \left(\left({t\_3}^{3} \cdot {t\_0}^{3}\right) \cdot {t\_1}^{-3}\right)}{t\_5 \cdot t\_5}
\end{array}
\end{array}
Initial program 79.4%
Applied rewrites79.4%
Applied rewrites80.1%
Final simplification80.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (exp -1.0) (* x x)))
(t_1 (fma (* (fabs x) 0.3275911) 1.0 1.0))
(t_2 (pow t_1 -1.0))
(t_3
(fma
(fma
(fma (fma (* t_2 1.061405429) 1.0 -1.453152027) t_2 1.421413741)
t_2
-0.284496736)
t_2
0.254829592))
(t_4 (* t_0 t_2))
(t_5 (fma t_4 t_3 1.0))
(t_6 (* (pow (fma (fabs x) 0.3275911 1.0) -1.0) 1.061405429)))
(-
(/ 1.0 (fma (* t_4 t_3) t_5 1.0))
(/
(* (pow (pow (pow t_1 2.0) 1.5) -1.0) (pow (* t_3 t_0) 3.0))
(fma
(*
t_4
(fma
(fma
(fma
(/
(+ (pow t_6 3.0) -3.0685496600615605)
(fma t_6 t_6 (- 2.111650813574209 (* t_6 -1.453152027))))
t_2
1.421413741)
t_2
-0.284496736)
t_2
0.254829592))
t_5
1.0)))))
double code(double x) {
double t_0 = pow(exp(-1.0), (x * x));
double t_1 = fma((fabs(x) * 0.3275911), 1.0, 1.0);
double t_2 = pow(t_1, -1.0);
double t_3 = fma(fma(fma(fma((t_2 * 1.061405429), 1.0, -1.453152027), t_2, 1.421413741), t_2, -0.284496736), t_2, 0.254829592);
double t_4 = t_0 * t_2;
double t_5 = fma(t_4, t_3, 1.0);
double t_6 = pow(fma(fabs(x), 0.3275911, 1.0), -1.0) * 1.061405429;
return (1.0 / fma((t_4 * t_3), t_5, 1.0)) - ((pow(pow(pow(t_1, 2.0), 1.5), -1.0) * pow((t_3 * t_0), 3.0)) / fma((t_4 * fma(fma(fma(((pow(t_6, 3.0) + -3.0685496600615605) / fma(t_6, t_6, (2.111650813574209 - (t_6 * -1.453152027)))), t_2, 1.421413741), t_2, -0.284496736), t_2, 0.254829592)), t_5, 1.0));
}
function code(x) t_0 = exp(-1.0) ^ Float64(x * x) t_1 = fma(Float64(abs(x) * 0.3275911), 1.0, 1.0) t_2 = t_1 ^ -1.0 t_3 = fma(fma(fma(fma(Float64(t_2 * 1.061405429), 1.0, -1.453152027), t_2, 1.421413741), t_2, -0.284496736), t_2, 0.254829592) t_4 = Float64(t_0 * t_2) t_5 = fma(t_4, t_3, 1.0) t_6 = Float64((fma(abs(x), 0.3275911, 1.0) ^ -1.0) * 1.061405429) return Float64(Float64(1.0 / fma(Float64(t_4 * t_3), t_5, 1.0)) - Float64(Float64((((t_1 ^ 2.0) ^ 1.5) ^ -1.0) * (Float64(t_3 * t_0) ^ 3.0)) / fma(Float64(t_4 * fma(fma(fma(Float64(Float64((t_6 ^ 3.0) + -3.0685496600615605) / fma(t_6, t_6, Float64(2.111650813574209 - Float64(t_6 * -1.453152027)))), t_2, 1.421413741), t_2, -0.284496736), t_2, 0.254829592)), t_5, 1.0))) end
code[x_] := Block[{t$95$0 = N[Power[N[Exp[-1.0], $MachinePrecision], N[(x * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Abs[x], $MachinePrecision] * 0.3275911), $MachinePrecision] * 1.0 + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, -1.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(t$95$2 * 1.061405429), $MachinePrecision] * 1.0 + -1.453152027), $MachinePrecision] * t$95$2 + 1.421413741), $MachinePrecision] * t$95$2 + -0.284496736), $MachinePrecision] * t$95$2 + 0.254829592), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$0 * t$95$2), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$4 * t$95$3 + 1.0), $MachinePrecision]}, Block[{t$95$6 = N[(N[Power[N[(N[Abs[x], $MachinePrecision] * 0.3275911 + 1.0), $MachinePrecision], -1.0], $MachinePrecision] * 1.061405429), $MachinePrecision]}, N[(N[(1.0 / N[(N[(t$95$4 * t$95$3), $MachinePrecision] * t$95$5 + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[N[Power[N[Power[t$95$1, 2.0], $MachinePrecision], 1.5], $MachinePrecision], -1.0], $MachinePrecision] * N[Power[N[(t$95$3 * t$95$0), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$4 * N[(N[(N[(N[(N[(N[Power[t$95$6, 3.0], $MachinePrecision] + -3.0685496600615605), $MachinePrecision] / N[(t$95$6 * t$95$6 + N[(2.111650813574209 - N[(t$95$6 * -1.453152027), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2 + 1.421413741), $MachinePrecision] * t$95$2 + -0.284496736), $MachinePrecision] * t$95$2 + 0.254829592), $MachinePrecision]), $MachinePrecision] * t$95$5 + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(e^{-1}\right)}^{\left(x \cdot x\right)}\\
t_1 := \mathsf{fma}\left(\left|x\right| \cdot 0.3275911, 1, 1\right)\\
t_2 := {t\_1}^{-1}\\
t_3 := \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(t\_2 \cdot 1.061405429, 1, -1.453152027\right), t\_2, 1.421413741\right), t\_2, -0.284496736\right), t\_2, 0.254829592\right)\\
t_4 := t\_0 \cdot t\_2\\
t_5 := \mathsf{fma}\left(t\_4, t\_3, 1\right)\\
t_6 := {\left(\mathsf{fma}\left(\left|x\right|, 0.3275911, 1\right)\right)}^{-1} \cdot 1.061405429\\
\frac{1}{\mathsf{fma}\left(t\_4 \cdot t\_3, t\_5, 1\right)} - \frac{{\left({\left({t\_1}^{2}\right)}^{1.5}\right)}^{-1} \cdot {\left(t\_3 \cdot t\_0\right)}^{3}}{\mathsf{fma}\left(t\_4 \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{{t\_6}^{3} + -3.0685496600615605}{\mathsf{fma}\left(t\_6, t\_6, 2.111650813574209 - t\_6 \cdot -1.453152027\right)}, t\_2, 1.421413741\right), t\_2, -0.284496736\right), t\_2, 0.254829592\right), t\_5, 1\right)}
\end{array}
\end{array}
Initial program 79.4%
Applied rewrites79.4%
Applied rewrites79.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (fma (* (fabs x) 0.3275911) 1.0 1.0) -1.0))
(t_1
(fma
(fma (fma (* t_0 1.061405429) 1.0 -1.453152027) t_0 1.421413741)
t_0
-0.284496736))
(t_2 (* t_1 t_0)))
(+
1.0
(*
(*
(/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))
(/
(+ (* (* t_2 t_1) t_0) (* -1.0 0.06493812095888646))
(+ t_2 (* -1.0 0.254829592))))
(* -1.0 (exp (* -1.0 (* x x))))))))
double code(double x) {
double t_0 = pow(fma((fabs(x) * 0.3275911), 1.0, 1.0), -1.0);
double t_1 = fma(fma(fma((t_0 * 1.061405429), 1.0, -1.453152027), t_0, 1.421413741), t_0, -0.284496736);
double t_2 = t_1 * t_0;
return 1.0 + (((1.0 / (1.0 + (0.3275911 * fabs(x)))) * ((((t_2 * t_1) * t_0) + (-1.0 * 0.06493812095888646)) / (t_2 + (-1.0 * 0.254829592)))) * (-1.0 * exp((-1.0 * (x * x)))));
}
function code(x) t_0 = fma(Float64(abs(x) * 0.3275911), 1.0, 1.0) ^ -1.0 t_1 = fma(fma(fma(Float64(t_0 * 1.061405429), 1.0, -1.453152027), t_0, 1.421413741), t_0, -0.284496736) t_2 = Float64(t_1 * t_0) return Float64(1.0 + Float64(Float64(Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) * Float64(Float64(Float64(Float64(t_2 * t_1) * t_0) + Float64(-1.0 * 0.06493812095888646)) / Float64(t_2 + Float64(-1.0 * 0.254829592)))) * Float64(-1.0 * exp(Float64(-1.0 * Float64(x * x)))))) end
code[x_] := Block[{t$95$0 = N[Power[N[(N[(N[Abs[x], $MachinePrecision] * 0.3275911), $MachinePrecision] * 1.0 + 1.0), $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[(t$95$0 * 1.061405429), $MachinePrecision] * 1.0 + -1.453152027), $MachinePrecision] * t$95$0 + 1.421413741), $MachinePrecision] * t$95$0 + -0.284496736), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$0), $MachinePrecision]}, N[(1.0 + N[(N[(N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(t$95$2 * t$95$1), $MachinePrecision] * t$95$0), $MachinePrecision] + N[(-1.0 * 0.06493812095888646), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 + N[(-1.0 * 0.254829592), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 * N[Exp[N[(-1.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\mathsf{fma}\left(\left|x\right| \cdot 0.3275911, 1, 1\right)\right)}^{-1}\\
t_1 := \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(t\_0 \cdot 1.061405429, 1, -1.453152027\right), t\_0, 1.421413741\right), t\_0, -0.284496736\right)\\
t_2 := t\_1 \cdot t\_0\\
1 + \left(\frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \frac{\left(t\_2 \cdot t\_1\right) \cdot t\_0 + -1 \cdot 0.06493812095888646}{t\_2 + -1 \cdot 0.254829592}\right) \cdot \left(-1 \cdot e^{-1 \cdot \left(x \cdot x\right)}\right)
\end{array}
\end{array}
Initial program 79.4%
Applied rewrites79.4%
Final simplification79.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))))
(-
1.0
(*
(*
t_0
(+
0.254829592
(*
t_0
(+
-0.284496736
(*
t_0
(+ 1.421413741 (* t_0 (+ -1.453152027 (* t_0 1.061405429)))))))))
(exp (* -1.0 (* x x)))))))
double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * fabs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp((-1.0 * (x * x))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: t_0
t_0 = 1.0d0 / (1.0d0 + (0.3275911d0 * abs(x)))
code = 1.0d0 - ((t_0 * (0.254829592d0 + (t_0 * ((-0.284496736d0) + (t_0 * (1.421413741d0 + (t_0 * ((-1.453152027d0) + (t_0 * 1.061405429d0))))))))) * exp(((-1.0d0) * (x * x))))
end function
public static double code(double x) {
double t_0 = 1.0 / (1.0 + (0.3275911 * Math.abs(x)));
return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * Math.exp((-1.0 * (x * x))));
}
def code(x): t_0 = 1.0 / (1.0 + (0.3275911 * math.fabs(x))) return 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * math.exp((-1.0 * (x * x))))
function code(x) t_0 = Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) return Float64(1.0 - Float64(Float64(t_0 * Float64(0.254829592 + Float64(t_0 * Float64(-0.284496736 + Float64(t_0 * Float64(1.421413741 + Float64(t_0 * Float64(-1.453152027 + Float64(t_0 * 1.061405429))))))))) * exp(Float64(-1.0 * Float64(x * x))))) end
function tmp = code(x) t_0 = 1.0 / (1.0 + (0.3275911 * abs(x))); tmp = 1.0 - ((t_0 * (0.254829592 + (t_0 * (-0.284496736 + (t_0 * (1.421413741 + (t_0 * (-1.453152027 + (t_0 * 1.061405429))))))))) * exp((-1.0 * (x * x)))); end
code[x_] := Block[{t$95$0 = N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(1.0 - N[(N[(t$95$0 * N[(0.254829592 + N[(t$95$0 * N[(-0.284496736 + N[(t$95$0 * N[(1.421413741 + N[(t$95$0 * N[(-1.453152027 + N[(t$95$0 * 1.061405429), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(-1.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{1 + 0.3275911 \cdot \left|x\right|}\\
1 - \left(t\_0 \cdot \left(0.254829592 + t\_0 \cdot \left(-0.284496736 + t\_0 \cdot \left(1.421413741 + t\_0 \cdot \left(-1.453152027 + t\_0 \cdot 1.061405429\right)\right)\right)\right)\right) \cdot e^{-1 \cdot \left(x \cdot x\right)}
\end{array}
\end{array}
Initial program 79.4%
Final simplification79.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (fma (* (fabs x) 0.3275911) 1.0 1.0)) (t_1 (pow t_0 2.0)))
(+
1.0
(*
(*
(/ 1.0 (+ 1.0 (* 0.3275911 (fabs x))))
(-
(+
(fma
(* (pow t_1 -1.0) 1.421413741)
1.0
(* (pow (pow t_0 4.0) -1.0) 1.061405429))
0.254829592)
(fma (/ 1.453152027 (pow t_1 1.5)) 1.0 (* 0.284496736 (pow t_0 -1.0)))))
(* -1.0 (exp (* -1.0 (* x x))))))))
double code(double x) {
double t_0 = fma((fabs(x) * 0.3275911), 1.0, 1.0);
double t_1 = pow(t_0, 2.0);
return 1.0 + (((1.0 / (1.0 + (0.3275911 * fabs(x)))) * ((fma((pow(t_1, -1.0) * 1.421413741), 1.0, (pow(pow(t_0, 4.0), -1.0) * 1.061405429)) + 0.254829592) - fma((1.453152027 / pow(t_1, 1.5)), 1.0, (0.284496736 * pow(t_0, -1.0))))) * (-1.0 * exp((-1.0 * (x * x)))));
}
function code(x) t_0 = fma(Float64(abs(x) * 0.3275911), 1.0, 1.0) t_1 = t_0 ^ 2.0 return Float64(1.0 + Float64(Float64(Float64(1.0 / Float64(1.0 + Float64(0.3275911 * abs(x)))) * Float64(Float64(fma(Float64((t_1 ^ -1.0) * 1.421413741), 1.0, Float64(((t_0 ^ 4.0) ^ -1.0) * 1.061405429)) + 0.254829592) - fma(Float64(1.453152027 / (t_1 ^ 1.5)), 1.0, Float64(0.284496736 * (t_0 ^ -1.0))))) * Float64(-1.0 * exp(Float64(-1.0 * Float64(x * x)))))) end
code[x_] := Block[{t$95$0 = N[(N[(N[Abs[x], $MachinePrecision] * 0.3275911), $MachinePrecision] * 1.0 + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 2.0], $MachinePrecision]}, N[(1.0 + N[(N[(N[(1.0 / N[(1.0 + N[(0.3275911 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[Power[t$95$1, -1.0], $MachinePrecision] * 1.421413741), $MachinePrecision] * 1.0 + N[(N[Power[N[Power[t$95$0, 4.0], $MachinePrecision], -1.0], $MachinePrecision] * 1.061405429), $MachinePrecision]), $MachinePrecision] + 0.254829592), $MachinePrecision] - N[(N[(1.453152027 / N[Power[t$95$1, 1.5], $MachinePrecision]), $MachinePrecision] * 1.0 + N[(0.284496736 * N[Power[t$95$0, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(-1.0 * N[Exp[N[(-1.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left|x\right| \cdot 0.3275911, 1, 1\right)\\
t_1 := {t\_0}^{2}\\
1 + \left(\frac{1}{1 + 0.3275911 \cdot \left|x\right|} \cdot \left(\left(\mathsf{fma}\left({t\_1}^{-1} \cdot 1.421413741, 1, {\left({t\_0}^{4}\right)}^{-1} \cdot 1.061405429\right) + 0.254829592\right) - \mathsf{fma}\left(\frac{1.453152027}{{t\_1}^{1.5}}, 1, 0.284496736 \cdot {t\_0}^{-1}\right)\right)\right) \cdot \left(-1 \cdot e^{-1 \cdot \left(x \cdot x\right)}\right)
\end{array}
\end{array}
Initial program 79.4%
Taylor expanded in x around 0
Applied rewrites77.7%
Final simplification77.7%
herbie shell --seed 2025065
(FPCore (x)
:name "Jmat.Real.erf"
:precision binary64
(- 1.0 (* (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ 0.254829592 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ -0.284496736 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ 1.421413741 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) (+ -1.453152027 (* (/ 1.0 (+ 1.0 (* 0.3275911 (fabs x)))) 1.061405429))))))))) (exp (- (* (fabs x) (fabs x)))))))