| 1 | #ifndef _ExtendedReal_h_ |
| 2 | #define _ExtendedReal_h_ |
| 3 | /* ExtendedReal.h |
| 4 | * |
| 5 | * Copyright (C) 2025 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | We extend the set of real numbers into a non-Archimedian ordered field by adding infinitesimals. |
| 23 | A positive infinitesimal number eps is smaller than any positive real number. |
| 24 | The predicate a < b, where a and b are reals, is affected by adding infinitesimals in the following way: |
| 25 | The test might become a + eps**2**i) < b + eps**2**j (a**b**c is shorthand notation for power (a, power (b,c))). |
| 26 | Assume without loss of generality that 0 < i <j. |
| 27 | If a != b, then if a < b is true, then also a + eps**i < b + eps**j. Adding the infinitesimal didn't |
| 28 | change the result. However, if a == b than the infinitisimals breaks the tie. |
| 29 | So adding infinitesimals to a and b we need to change the predicate from (a < b) to (if a!=b ? a < b : i > j). |
| 30 | |
| 31 | Our simple implementation is the ExtendedReal with consists of the struct {double real; integer extension;} |
| 32 | 'extension' represent the infinitesimal power (eps, power (2,extension)). |
| 33 | |
| 34 | An ExtendedReal can be copied but should not be saved in a file. |
| 35 | */ |
| 36 | |
| 37 | #include "Data.h" |
| 38 | |
| 39 | #include "ExtendedReal_def.h" |
| 40 | |
| 41 | template <typename structT> |
| 42 | autoVEC vector_to_VEC (vector<structT> v); |
| 43 | |
| 44 | /* |
| 45 | Put the kth smallest element at position k |
| 46 | */ |
| 47 | template <typename structT> |
| 48 | void NUMselect (vector<structT> const& v, integer kth_asIfSorted); |
| 49 | |
| 50 | structExtendedReal& NUMget_kth_inplace (vector<structExtendedReal> const& v, integer kth_asIfSorted); |
| 51 | structExtendedReal& NUMget_kth (constvectorview<structExtendedReal> const& v, integer kth_asIfSorted); |
| 52 | |
| 53 | structExtendedReal& NUMquantile (constvectorview<structExtendedReal> const& v, double factor); |
| 54 | structExtendedReal& NUMquantile_inplace (vector<structExtendedReal> const& v, double factor); |
| 55 | |
| 56 | #endif /* _ExtendedReal_h_ */ |