xref: /freebsd/contrib/arm-optimized-routines/pl/math/tools/erfcf.sollya (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
1// polynomial for approximating erfc(x)*exp(x*x)
2//
3// Copyright (c) 2022-2023, Arm Limited.
4// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
5
6deg = 15; // poly degree
7
8// interval bounds
9a = 0x1.0p-26;
10b = 2;
11
12f = proc(y) {
13  return erfc(y) * exp(y*y);
14};
15
16approx = proc(poly, d) {
17  return remez(1 - poly(x)/f(x), deg-d, [a;b], x^d/f(x), 1e-10);
18};
19
20poly = 0;
21for i from 0 to deg do {
22  p = roundcoefficients(approx(poly,i), [|D ...|]);
23  poly = poly + x^i*coeff(p,0);
24  print(i);
25};
26
27display = hexadecimal;
28print("rel error:", accurateinfnorm(1-poly(x)/f(x), [a;b], 30));
29print("in [",a,b,"]");
30print("coeffs:");
31for i from 0 to deg do coeff(poly,i);
32