rr-pf 3.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rr_pf/__init__.py +6 -0
- rr_pf/core.py +258 -0
- rr_pf/oracle.py +186 -0
- rr_pf-3.1.0.dist-info/METADATA +324 -0
- rr_pf-3.1.0.dist-info/RECORD +8 -0
- rr_pf-3.1.0.dist-info/WHEEL +5 -0
- rr_pf-3.1.0.dist-info/licenses/LICENSE +201 -0
- rr_pf-3.1.0.dist-info/top_level.txt +1 -0
rr_pf/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""RR-PF: exact rational numbers and rational intervals that enclose them."""
|
|
2
|
+
from .core import MNE, as_fraction, kahan_sum
|
|
3
|
+
from .oracle import ExactCSR, csr_matvec_exact
|
|
4
|
+
|
|
5
|
+
__all__ = ["MNE", "as_fraction", "kahan_sum", "ExactCSR", "csr_matvec_exact"]
|
|
6
|
+
__version__ = "3.1.0"
|
rr_pf/core.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"""RR-PF core: exact rational numbers and rational intervals that enclose them.
|
|
2
|
+
|
|
3
|
+
Every value is a ``fractions.Fraction``. There is no hidden rounding: the
|
|
4
|
+
sum of exact rationals is exact, so Kahan summation is unnecessary here.
|
|
5
|
+
The class is still named ``MNE`` for API stability with earlier versions.
|
|
6
|
+
|
|
7
|
+
Notes on behaviour (kept from v3):
|
|
8
|
+
- ``MNE(x)`` interprets str/Decimal/float by their decimal representation:
|
|
9
|
+
``MNE(0.1)`` is 1/10. ``MNE.from_float(0.1)`` is the exact binary value.
|
|
10
|
+
- ``sqrt`` is exact for rationals whose numerator and denominator are both
|
|
11
|
+
perfect squares; otherwise it returns a rational enclosure with
|
|
12
|
+
``10**-digits`` width.
|
|
13
|
+
- ``a / b`` raises ZeroDivisionError when the divisor's interval contains 0.
|
|
14
|
+
|
|
15
|
+
The mathematical correspondence between these intervals and the Lean model
|
|
16
|
+
in ``lean/RRPF`` is documented in ``docs/CORRESPONDENCE.md``.
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from fractions import Fraction
|
|
21
|
+
from decimal import Decimal
|
|
22
|
+
from math import isqrt
|
|
23
|
+
import re
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def as_fraction(value):
|
|
27
|
+
if isinstance(value, Fraction):
|
|
28
|
+
return value
|
|
29
|
+
if isinstance(value, int):
|
|
30
|
+
return Fraction(value)
|
|
31
|
+
return Fraction(str(value))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _is_square(n: int):
|
|
35
|
+
if n < 0:
|
|
36
|
+
return None
|
|
37
|
+
r = isqrt(n)
|
|
38
|
+
return r if r * r == n else None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class MNE:
|
|
42
|
+
"""Valor racional exacto o intervalo racional que lo acota."""
|
|
43
|
+
|
|
44
|
+
__slots__ = ("_lo", "_hi")
|
|
45
|
+
|
|
46
|
+
def __init__(self, value, err=0):
|
|
47
|
+
if isinstance(value, MNE):
|
|
48
|
+
radius = as_fraction(err)
|
|
49
|
+
if radius < 0:
|
|
50
|
+
raise ValueError("err debe ser no negativo")
|
|
51
|
+
self._lo = value._lo - radius
|
|
52
|
+
self._hi = value._hi + radius
|
|
53
|
+
return
|
|
54
|
+
center = as_fraction(value)
|
|
55
|
+
radius = as_fraction(err)
|
|
56
|
+
if radius < 0:
|
|
57
|
+
raise ValueError("err debe ser no negativo")
|
|
58
|
+
self._lo = center - radius
|
|
59
|
+
self._hi = center + radius
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def from_float(cls, x: float) -> "MNE":
|
|
63
|
+
"""El valor binario real del float, exacto como Fraction.
|
|
64
|
+
|
|
65
|
+
Distinto de MNE(0.1), que es el decimal 1/10 por la regla
|
|
66
|
+
documentada de as_fraction. Aqui no se esconde nada:
|
|
67
|
+
from_float(0.1) = 3602879701896397/36028797018963968.
|
|
68
|
+
"""
|
|
69
|
+
obj = object.__new__(cls)
|
|
70
|
+
f = Fraction(x)
|
|
71
|
+
obj._lo = f
|
|
72
|
+
obj._hi = f
|
|
73
|
+
return obj
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def _from_bounds(cls, lo, hi):
|
|
77
|
+
if lo > hi:
|
|
78
|
+
raise ValueError("intervalo inválido")
|
|
79
|
+
obj = object.__new__(cls)
|
|
80
|
+
obj._lo = lo
|
|
81
|
+
obj._hi = hi
|
|
82
|
+
return obj
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def parse(cls, text):
|
|
86
|
+
"""Acepta enteros, decimales, fracciones, periodicos [ ], ( )
|
|
87
|
+
y ... ; tambien ".5"."""
|
|
88
|
+
t = str(text).strip()
|
|
89
|
+
if "/" in t:
|
|
90
|
+
return cls(Fraction(t))
|
|
91
|
+
if "(" in t and ")" in t:
|
|
92
|
+
t = t.replace("(", "[").replace(")", "]")
|
|
93
|
+
if t.endswith("..."):
|
|
94
|
+
base = t[:-3]
|
|
95
|
+
if "." not in base:
|
|
96
|
+
raise ValueError(f"No se puede inferir periodo de {text!r}")
|
|
97
|
+
entero, dec = base.split(".", 1)
|
|
98
|
+
if len(dec) < 2 or dec[-1] != dec[-2]:
|
|
99
|
+
raise ValueError(f"No se puede inferir periodo de {text!r}")
|
|
100
|
+
digito = dec[-1]
|
|
101
|
+
i = len(dec)
|
|
102
|
+
while i > 0 and dec[i - 1] == digito:
|
|
103
|
+
i -= 1
|
|
104
|
+
no_per = dec[: i + 1] if i < len(dec) else dec
|
|
105
|
+
if set(dec) == {digito}:
|
|
106
|
+
no_per = ""
|
|
107
|
+
t = f"{entero}.{no_per}[{digito}]" if no_per else f"{entero}.[{digito}]"
|
|
108
|
+
|
|
109
|
+
match = re.fullmatch(r"([+-]?)(\d*)(?:\.(\d*))?(?:\[(\d+)\])?", t)
|
|
110
|
+
if not match:
|
|
111
|
+
raise ValueError(f"Formato no válido: {text!r}")
|
|
112
|
+
sign_text, whole, finite, repeat = match.groups()
|
|
113
|
+
if whole == "" and finite == "" and repeat is None:
|
|
114
|
+
raise ValueError(f"Formato no válido: {text!r}")
|
|
115
|
+
sign = -1 if sign_text == "-" else 1
|
|
116
|
+
whole = whole or "0"
|
|
117
|
+
finite = finite or ""
|
|
118
|
+
if repeat is None:
|
|
119
|
+
digits = whole + finite
|
|
120
|
+
denominator = 10 ** len(finite)
|
|
121
|
+
return cls(sign * Fraction(int(digits), denominator))
|
|
122
|
+
if "." not in t:
|
|
123
|
+
raise ValueError("Un período debe seguir al punto decimal")
|
|
124
|
+
prefix = int(whole + finite)
|
|
125
|
+
full = int(whole + finite + repeat)
|
|
126
|
+
denominator = 10 ** len(finite) * (10 ** len(repeat) - 1)
|
|
127
|
+
return cls(sign * Fraction(full - prefix, denominator))
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def exact(self):
|
|
131
|
+
return self._lo if self._lo == self._hi else None
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def center(self):
|
|
135
|
+
return (self._lo + self._hi) / 2
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def radius(self):
|
|
139
|
+
return (self._hi - self._lo) / 2
|
|
140
|
+
|
|
141
|
+
def bounds(self):
|
|
142
|
+
return self._lo, self._hi
|
|
143
|
+
|
|
144
|
+
def contains(self, value) -> bool:
|
|
145
|
+
# Real containment. For a scalar (or an exact value) this is the
|
|
146
|
+
# endpoint check lo <= v <= hi. For an interval argument, checking
|
|
147
|
+
# only its center is wrong: an interval can be centered inside
|
|
148
|
+
# while sticking out on either side. The whole interval must lie
|
|
149
|
+
# inside: lo <= value._lo and value._hi <= hi.
|
|
150
|
+
if isinstance(value, MNE):
|
|
151
|
+
return self._lo <= value._lo and value._hi <= self._hi
|
|
152
|
+
return self._lo <= as_fraction(value) <= self._hi
|
|
153
|
+
|
|
154
|
+
def __add__(self, other):
|
|
155
|
+
other = other if isinstance(other, MNE) else MNE(other)
|
|
156
|
+
return self._from_bounds(self._lo + other._lo, self._hi + other._hi)
|
|
157
|
+
|
|
158
|
+
__radd__ = __add__
|
|
159
|
+
|
|
160
|
+
def __neg__(self):
|
|
161
|
+
return self._from_bounds(-self._hi, -self._lo)
|
|
162
|
+
|
|
163
|
+
def __sub__(self, other):
|
|
164
|
+
other = other if isinstance(other, MNE) else MNE(other)
|
|
165
|
+
return self + (-other)
|
|
166
|
+
|
|
167
|
+
def __rsub__(self, other):
|
|
168
|
+
return MNE(other) - self
|
|
169
|
+
|
|
170
|
+
def __mul__(self, other):
|
|
171
|
+
other = other if isinstance(other, MNE) else MNE(other)
|
|
172
|
+
products = (self._lo * other._lo, self._lo * other._hi,
|
|
173
|
+
self._hi * other._lo, self._hi * other._hi)
|
|
174
|
+
return self._from_bounds(min(products), max(products))
|
|
175
|
+
|
|
176
|
+
__rmul__ = __mul__
|
|
177
|
+
|
|
178
|
+
def __truediv__(self, other):
|
|
179
|
+
other = other if isinstance(other, MNE) else MNE(other)
|
|
180
|
+
if other._lo <= 0 <= other._hi:
|
|
181
|
+
raise ZeroDivisionError("El divisor contiene cero en su intervalo")
|
|
182
|
+
reciprocals = (1 / other._lo, 1 / other._hi)
|
|
183
|
+
reciprocal = self._from_bounds(min(reciprocals), max(reciprocals))
|
|
184
|
+
return self * reciprocal
|
|
185
|
+
|
|
186
|
+
def __rtruediv__(self, other):
|
|
187
|
+
# Reflected division: `1 / MNE(2)`, `Fraction(1, 3) / MNE(2)`.
|
|
188
|
+
# Without this, only MNE-on-the-left divided; anything on the
|
|
189
|
+
# left raised TypeError even though __radd__/__rmul__/__rsub__
|
|
190
|
+
# already exist. Delegates to __truediv__, so a divisor whose
|
|
191
|
+
# interval contains zero still raises ZeroDivisionError.
|
|
192
|
+
return MNE(other) / self
|
|
193
|
+
|
|
194
|
+
@staticmethod
|
|
195
|
+
def _sqrt_bounds(value, digits):
|
|
196
|
+
if value < 0:
|
|
197
|
+
raise ValueError("raíz de número negativo")
|
|
198
|
+
scale = 10 ** digits
|
|
199
|
+
k = isqrt((value.numerator * scale * scale) // value.denominator)
|
|
200
|
+
lower = Fraction(k, scale)
|
|
201
|
+
if lower * lower == value:
|
|
202
|
+
return lower, lower
|
|
203
|
+
return lower, Fraction(k + 1, scale)
|
|
204
|
+
|
|
205
|
+
def sqrt(self, digits=50):
|
|
206
|
+
if not isinstance(digits, int) or digits < 0:
|
|
207
|
+
raise ValueError("digits debe ser un entero no negativo")
|
|
208
|
+
if self._lo < 0:
|
|
209
|
+
raise ValueError("El intervalo incluye valores negativos")
|
|
210
|
+
# CORRECCION 1: exactitud por cuadrados perfectos, antes
|
|
211
|
+
# de acotar por digitos. Asi sqrt(4/9) = 2/3 exacto.
|
|
212
|
+
if self.exact is not None:
|
|
213
|
+
num_r = _is_square(self.exact.numerator)
|
|
214
|
+
den_r = _is_square(self.exact.denominator)
|
|
215
|
+
if num_r is not None and den_r is not None:
|
|
216
|
+
return MNE(Fraction(num_r, den_r))
|
|
217
|
+
lower, _ = self._sqrt_bounds(self._lo, digits)
|
|
218
|
+
_, upper = self._sqrt_bounds(self._hi, digits)
|
|
219
|
+
return self._from_bounds(lower, upper)
|
|
220
|
+
|
|
221
|
+
def __eq__(self, other):
|
|
222
|
+
if isinstance(other, MNE):
|
|
223
|
+
return self._lo == other._lo and self._hi == other._hi
|
|
224
|
+
try:
|
|
225
|
+
return self.exact is not None and self.exact == as_fraction(other)
|
|
226
|
+
except Exception:
|
|
227
|
+
return NotImplemented
|
|
228
|
+
|
|
229
|
+
def __hash__(self):
|
|
230
|
+
# Defining __eq__ without __hash__ made MNE unhashable
|
|
231
|
+
# (Python sets __hash__ to None), so values could not be used
|
|
232
|
+
# in sets or as dict keys. The hash must agree with __eq__:
|
|
233
|
+
# an exact value hashes like the Fraction it equals, so
|
|
234
|
+
# hash(MNE(1, 3)) == hash(Fraction(1, 3)) and equal values
|
|
235
|
+
# stay interchangeable as keys; an interval (never equal to
|
|
236
|
+
# a non-MNE) hashes from its bounds, which is what __eq__
|
|
237
|
+
# compares for two intervals.
|
|
238
|
+
if self.exact is not None:
|
|
239
|
+
return hash(self.exact)
|
|
240
|
+
return hash((self._lo, self._hi))
|
|
241
|
+
|
|
242
|
+
def __str__(self):
|
|
243
|
+
if self.exact is not None:
|
|
244
|
+
return str(self.exact)
|
|
245
|
+
return f"[{self._lo}, {self._hi}]"
|
|
246
|
+
|
|
247
|
+
def __repr__(self):
|
|
248
|
+
return f"MNE({self})"
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def kahan_sum(values):
|
|
252
|
+
"""Suma de valores como MNE. Con racionales exactos es exacta,
|
|
253
|
+
asi que no necesita compensacion: ese es el punto.
|
|
254
|
+
Acepta MNE, Fraction, Decimal, int, float y str."""
|
|
255
|
+
total = MNE(0)
|
|
256
|
+
for v in values:
|
|
257
|
+
total = total + (v if isinstance(v, MNE) else MNE(v))
|
|
258
|
+
return total
|
rr_pf/oracle.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Exact sparse matrix-vector product over ``Fraction``: a test oracle.
|
|
2
|
+
|
|
3
|
+
Intended as a slow, obviously-correct reference for other projects' test
|
|
4
|
+
suites (HBAG, MORPH): feed it a small CSR matrix and a vector, compare
|
|
5
|
+
against the implementation under test.
|
|
6
|
+
|
|
7
|
+
Entries are converted only through exact paths: ``int``, ``Fraction``,
|
|
8
|
+
``str`` (e.g. ``"1/10"``, ``"0.1"``) and ``Decimal``. ``float`` is rejected
|
|
9
|
+
on purpose: ``float(0.1)`` is a binary value, and silently choosing either
|
|
10
|
+
reading of it would hide the very class of error this oracle is for.
|
|
11
|
+
Convert floats explicitly, e.g. ``Fraction(0.1)``, if you mean the binary value.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import math
|
|
16
|
+
from decimal import Decimal
|
|
17
|
+
from fractions import Fraction
|
|
18
|
+
from typing import Iterable, NamedTuple, Sequence
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def exact(value) -> Fraction:
|
|
22
|
+
"""Convert one entry to Fraction without rounding. Rejects float."""
|
|
23
|
+
if isinstance(value, Fraction):
|
|
24
|
+
return value
|
|
25
|
+
if isinstance(value, bool):
|
|
26
|
+
raise TypeError("bool is not a matrix entry")
|
|
27
|
+
if isinstance(value, int):
|
|
28
|
+
return Fraction(value)
|
|
29
|
+
if isinstance(value, Decimal):
|
|
30
|
+
return Fraction(value)
|
|
31
|
+
if isinstance(value, str):
|
|
32
|
+
return Fraction(value.strip())
|
|
33
|
+
if isinstance(value, float):
|
|
34
|
+
raise TypeError(
|
|
35
|
+
"float rejected by the oracle; pass Fraction(x) for the binary value "
|
|
36
|
+
"or a str/Decimal for the decimal one"
|
|
37
|
+
)
|
|
38
|
+
raise TypeError(f"unsupported entry type: {type(value).__name__}")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ExactCSR:
|
|
42
|
+
"""CSR matrix with Fraction entries. Validated on construction."""
|
|
43
|
+
|
|
44
|
+
__slots__ = ("shape", "indptr", "indices", "data")
|
|
45
|
+
|
|
46
|
+
def __init__(self, shape, indptr, indices, data):
|
|
47
|
+
nrows, ncols = (int(shape[0]), int(shape[1]))
|
|
48
|
+
if nrows < 0 or ncols < 0:
|
|
49
|
+
raise ValueError("shape must be non-negative")
|
|
50
|
+
indptr = tuple(int(p) for p in indptr)
|
|
51
|
+
indices = tuple(int(j) for j in indices)
|
|
52
|
+
data = tuple(exact(v) for v in data)
|
|
53
|
+
if len(indptr) != nrows + 1:
|
|
54
|
+
raise ValueError(f"indptr must have length nrows+1 = {nrows + 1}")
|
|
55
|
+
if indptr[0] != 0:
|
|
56
|
+
raise ValueError("indptr[0] must be 0")
|
|
57
|
+
if any(b < a for a, b in zip(indptr, indptr[1:])):
|
|
58
|
+
raise ValueError("indptr must be non-decreasing")
|
|
59
|
+
nnz = indptr[-1]
|
|
60
|
+
if len(indices) != nnz or len(data) != nnz:
|
|
61
|
+
raise ValueError("indices and data must have length indptr[-1]")
|
|
62
|
+
if any(not (0 <= j < ncols) for j in indices):
|
|
63
|
+
raise ValueError("column index out of range")
|
|
64
|
+
self.shape = (nrows, ncols)
|
|
65
|
+
self.indptr = indptr
|
|
66
|
+
self.indices = indices
|
|
67
|
+
self.data = data
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def from_dense(cls, rows: Sequence[Sequence]) -> "ExactCSR":
|
|
71
|
+
"""Build from a list of rows; zero entries are not stored."""
|
|
72
|
+
nrows = len(rows)
|
|
73
|
+
ncols = len(rows[0]) if nrows else 0
|
|
74
|
+
if any(len(r) != ncols for r in rows):
|
|
75
|
+
raise ValueError("ragged rows")
|
|
76
|
+
indptr, indices, data = [0], [], []
|
|
77
|
+
for row in rows:
|
|
78
|
+
for j, v in enumerate(row):
|
|
79
|
+
fv = exact(v)
|
|
80
|
+
if fv != 0:
|
|
81
|
+
indices.append(j)
|
|
82
|
+
data.append(fv)
|
|
83
|
+
indptr.append(len(indices))
|
|
84
|
+
return cls((nrows, ncols), indptr, indices, data)
|
|
85
|
+
|
|
86
|
+
def matvec(self, x: Iterable) -> list[Fraction]:
|
|
87
|
+
"""Exact y = A @ x. Returns a list of Fraction of length nrows."""
|
|
88
|
+
xs = [exact(v) for v in x]
|
|
89
|
+
if len(xs) != self.shape[1]:
|
|
90
|
+
raise ValueError(f"x must have length {self.shape[1]}, got {len(xs)}")
|
|
91
|
+
y: list[Fraction] = []
|
|
92
|
+
for i in range(self.shape[0]):
|
|
93
|
+
acc = Fraction(0)
|
|
94
|
+
for k in range(self.indptr[i], self.indptr[i + 1]):
|
|
95
|
+
acc += self.data[k] * xs[self.indices[k]]
|
|
96
|
+
y.append(acc)
|
|
97
|
+
return y
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def spmm(self, B: Sequence[Sequence]) -> list[list[Fraction]]:
|
|
101
|
+
"""Exact Y = A @ B for a dense B of shape (ncols, K).
|
|
102
|
+
|
|
103
|
+
Returns nrows lists of K Fractions. Entries of B go through ``exact``,
|
|
104
|
+
so floats are rejected here as well.
|
|
105
|
+
"""
|
|
106
|
+
rows = [[exact(v) for v in row] for row in B]
|
|
107
|
+
if len(rows) != self.shape[1]:
|
|
108
|
+
raise ValueError(f"B must have {self.shape[1]} rows, got {len(rows)}")
|
|
109
|
+
K = len(rows[0]) if rows else 0
|
|
110
|
+
if any(len(r) != K for r in rows):
|
|
111
|
+
raise ValueError("ragged B")
|
|
112
|
+
Y: list[list[Fraction]] = []
|
|
113
|
+
for i in range(self.shape[0]):
|
|
114
|
+
acc = [Fraction(0)] * K
|
|
115
|
+
for k in range(self.indptr[i], self.indptr[i + 1]):
|
|
116
|
+
a = self.data[k]
|
|
117
|
+
brow = rows[self.indices[k]]
|
|
118
|
+
for j in range(K):
|
|
119
|
+
acc[j] += a * brow[j]
|
|
120
|
+
Y.append(acc)
|
|
121
|
+
return Y
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def csr_matvec_exact(shape, indptr, indices, data, x) -> list[Fraction]:
|
|
125
|
+
"""Convenience wrapper: validate a CSR matrix and return exact A @ x."""
|
|
126
|
+
return ExactCSR(shape, indptr, indices, data).matvec(x)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class Violation(NamedTuple):
|
|
130
|
+
"""One entry outside its bound. ``error`` is None when approx is not finite."""
|
|
131
|
+
|
|
132
|
+
row: int
|
|
133
|
+
col: int
|
|
134
|
+
approx: object
|
|
135
|
+
expected: Fraction
|
|
136
|
+
error: Fraction | None
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _approx_fraction(value) -> Fraction | None:
|
|
140
|
+
"""Exact value of an approximation: floats as their binary value
|
|
141
|
+
(``Fraction(x)``), other types through ``exact``. None if not finite."""
|
|
142
|
+
if isinstance(value, float):
|
|
143
|
+
if not math.isfinite(value):
|
|
144
|
+
return None
|
|
145
|
+
return Fraction(value)
|
|
146
|
+
return exact(value)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def check_bounds(approx, expected, bound) -> list[Violation]:
|
|
150
|
+
"""Per-entry check: every |approx[i][j] - expected[i][j]| must be <= bound.
|
|
151
|
+
|
|
152
|
+
``expected`` is an exact matrix (e.g. the output of ``ExactCSR.spmm``).
|
|
153
|
+
``approx`` may hold floats, read as their binary values. ``bound`` goes
|
|
154
|
+
through ``exact``, so a float bound is rejected. Returns the violations;
|
|
155
|
+
an empty list means every entry is within bound.
|
|
156
|
+
"""
|
|
157
|
+
tol = exact(bound)
|
|
158
|
+
if tol < 0:
|
|
159
|
+
raise ValueError("bound must be non-negative")
|
|
160
|
+
if len(approx) != len(expected):
|
|
161
|
+
raise ValueError(f"approx has {len(approx)} rows, expected {len(expected)}")
|
|
162
|
+
out: list[Violation] = []
|
|
163
|
+
for i, (arow, erow) in enumerate(zip(approx, expected)):
|
|
164
|
+
if len(arow) != len(erow):
|
|
165
|
+
raise ValueError(f"row {i}: approx has {len(arow)} entries, expected {len(erow)}")
|
|
166
|
+
for j, (a, e) in enumerate(zip(arow, erow)):
|
|
167
|
+
fe = exact(e)
|
|
168
|
+
fa = _approx_fraction(a)
|
|
169
|
+
if fa is None:
|
|
170
|
+
out.append(Violation(i, j, a, fe, None))
|
|
171
|
+
continue
|
|
172
|
+
err = abs(fa - fe)
|
|
173
|
+
if err > tol:
|
|
174
|
+
out.append(Violation(i, j, a, fe, err))
|
|
175
|
+
return out
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def assert_within_bounds(approx, expected, bound) -> None:
|
|
179
|
+
"""Test helper: raise AssertionError listing the first violations, if any."""
|
|
180
|
+
bad = check_bounds(approx, expected, bound)
|
|
181
|
+
if bad:
|
|
182
|
+
shown = "; ".join(
|
|
183
|
+
f"[{v.row},{v.col}] approx={v.approx!r} expected={v.expected} error={v.error}"
|
|
184
|
+
for v in bad[:5]
|
|
185
|
+
)
|
|
186
|
+
raise AssertionError(f"{len(bad)} entries outside bound {bound}: {shown}")
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rr-pf
|
|
3
|
+
Version: 3.1.0
|
|
4
|
+
Summary: Exact rational numbers and rational enclosures, with a Fraction-based test oracle and a Lean 4 correspondence.
|
|
5
|
+
License: Apache License
|
|
6
|
+
Version 2.0, January 2004
|
|
7
|
+
http://www.apache.org/licenses/
|
|
8
|
+
|
|
9
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
10
|
+
|
|
11
|
+
1. Definitions.
|
|
12
|
+
|
|
13
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
14
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
15
|
+
|
|
16
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
17
|
+
the copyright owner that is granting the License.
|
|
18
|
+
|
|
19
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
20
|
+
other entities that control, are controlled by, or are under common
|
|
21
|
+
control with that entity. For the purposes of this definition,
|
|
22
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
23
|
+
direction or management of such entity, whether by contract or
|
|
24
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
25
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
26
|
+
|
|
27
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
28
|
+
exercising permissions granted by this License.
|
|
29
|
+
|
|
30
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
31
|
+
including but not limited to software source code, documentation
|
|
32
|
+
source, and configuration files.
|
|
33
|
+
|
|
34
|
+
"Object" form shall mean any form resulting from mechanical
|
|
35
|
+
transformation or translation of a Source form, including but
|
|
36
|
+
not limited to compiled object code, generated documentation,
|
|
37
|
+
and conversions to other media types.
|
|
38
|
+
|
|
39
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
40
|
+
Object form, made available under the License, as indicated by a
|
|
41
|
+
copyright notice that is included in or attached to the work
|
|
42
|
+
(an example is provided in the Appendix below).
|
|
43
|
+
|
|
44
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
45
|
+
form, that is based on (or derived from) the Work and for which the
|
|
46
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
47
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
48
|
+
of this License, Derivative Works shall not include works that remain
|
|
49
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
50
|
+
the Work and Derivative Works thereof.
|
|
51
|
+
|
|
52
|
+
"Contribution" shall mean any work of authorship, including
|
|
53
|
+
the original version of the Work and any modifications or additions
|
|
54
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
55
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
56
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
57
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
58
|
+
means any form of electronic, verbal, or written communication sent
|
|
59
|
+
to the Licensor or its representatives, including but not limited to
|
|
60
|
+
communication on electronic mailing lists, source code control systems,
|
|
61
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
62
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
63
|
+
excluding communication that is conspicuously marked or otherwise
|
|
64
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
65
|
+
|
|
66
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
67
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
68
|
+
subsequently incorporated within the Work.
|
|
69
|
+
|
|
70
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
74
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
75
|
+
Work and such Derivative Works in Source or Object form.
|
|
76
|
+
|
|
77
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
78
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
79
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
80
|
+
(except as stated in this section) patent license to make, have made,
|
|
81
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
82
|
+
where such license applies only to those patent claims licensable
|
|
83
|
+
by such Contributor that are necessarily infringed by their
|
|
84
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
85
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
86
|
+
institute patent litigation against any entity (including a
|
|
87
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
88
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
89
|
+
or contributory patent infringement, then any patent licenses
|
|
90
|
+
granted to You under this License for that Work shall terminate
|
|
91
|
+
as of the date such litigation is filed.
|
|
92
|
+
|
|
93
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
94
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
95
|
+
modifications, and in Source or Object form, provided that You
|
|
96
|
+
meet the following conditions:
|
|
97
|
+
|
|
98
|
+
(a) You must give any other recipients of the Work or
|
|
99
|
+
Derivative Works a copy of this License; and
|
|
100
|
+
|
|
101
|
+
(b) You must cause any modified files to carry prominent notices
|
|
102
|
+
stating that You changed the files; and
|
|
103
|
+
|
|
104
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
105
|
+
that You distribute, all copyright, patent, trademark, and
|
|
106
|
+
attribution notices from the Source form of the Work,
|
|
107
|
+
excluding those notices that do not pertain to any part of
|
|
108
|
+
the Derivative Works; and
|
|
109
|
+
|
|
110
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
111
|
+
distribution, then any Derivative Works that You distribute must
|
|
112
|
+
include a readable copy of the attribution notices contained
|
|
113
|
+
within such NOTICE file, excluding those notices that do not
|
|
114
|
+
pertain to any part of the Derivative Works, in at least one
|
|
115
|
+
of the following places: within a NOTICE text file distributed
|
|
116
|
+
as part of the Derivative Works; within the Source form or
|
|
117
|
+
documentation, if provided along with the Derivative Works; or,
|
|
118
|
+
within a display generated by the Derivative Works, if and
|
|
119
|
+
wherever such third-party notices normally appear. The contents
|
|
120
|
+
of the NOTICE file are for informational purposes only and
|
|
121
|
+
do not modify the License. You may add Your own attribution
|
|
122
|
+
notices within Derivative Works that You distribute, alongside
|
|
123
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
124
|
+
that such additional attribution notices cannot be construed
|
|
125
|
+
as modifying the License.
|
|
126
|
+
|
|
127
|
+
You may add Your own copyright statement to Your modifications and
|
|
128
|
+
may provide additional or different license terms and conditions
|
|
129
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
130
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
131
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
132
|
+
the conditions stated in this License.
|
|
133
|
+
|
|
134
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
135
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
136
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
137
|
+
this License, without any additional terms or conditions.
|
|
138
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
139
|
+
the terms of any separate license agreement you may have executed
|
|
140
|
+
with Licensor regarding such Contributions.
|
|
141
|
+
|
|
142
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
143
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
144
|
+
except as required for reasonable and customary use in describing the
|
|
145
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
146
|
+
|
|
147
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
148
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
149
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
150
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
151
|
+
implied, including, without limitation, any warranties or conditions
|
|
152
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
153
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
154
|
+
appropriateness of using or redistributing the Work and assume any
|
|
155
|
+
risks associated with Your exercise of permissions under this License.
|
|
156
|
+
|
|
157
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
158
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
159
|
+
unless required by applicable law (such as deliberate and grossly
|
|
160
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
161
|
+
liable to You for damages, including any direct, indirect, special,
|
|
162
|
+
incidental, or consequential damages of any character arising as a
|
|
163
|
+
result of this License or out of the use or inability to use the
|
|
164
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
165
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
166
|
+
other commercial damages or losses), even if such Contributor
|
|
167
|
+
has been advised of the possibility of such damages.
|
|
168
|
+
|
|
169
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
170
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
171
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
172
|
+
or other liability obligations and/or rights consistent with this
|
|
173
|
+
License. However, in accepting such obligations, You may act only
|
|
174
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
175
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
176
|
+
defend, and hold each Contributor harmless for any liability
|
|
177
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
178
|
+
of your accepting any such warranty or additional liability.
|
|
179
|
+
|
|
180
|
+
END OF TERMS AND CONDITIONS
|
|
181
|
+
|
|
182
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
183
|
+
|
|
184
|
+
To apply the Apache License to your work, attach the following
|
|
185
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
186
|
+
replaced with your own identifying information. (Don't include
|
|
187
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
188
|
+
comment syntax for the file format. We also recommend that a
|
|
189
|
+
file or class name and description of purpose be included on the
|
|
190
|
+
same "printed page" as the copyright notice for easier
|
|
191
|
+
identification within third-party archives.
|
|
192
|
+
|
|
193
|
+
Copyright [yyyy] [name of copyright owner]
|
|
194
|
+
|
|
195
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
196
|
+
you may not use this file except in compliance with the License.
|
|
197
|
+
You may obtain a copy of the License at
|
|
198
|
+
|
|
199
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
200
|
+
|
|
201
|
+
Unless required by applicable law or agreed to in writing, software
|
|
202
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
203
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
204
|
+
See the License for the specific language governing permissions and
|
|
205
|
+
limitations under the License.
|
|
206
|
+
|
|
207
|
+
Keywords: rational,interval arithmetic,exact arithmetic,testing,lean4
|
|
208
|
+
Classifier: Programming Language :: Python :: 3
|
|
209
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
210
|
+
Requires-Python: >=3.10
|
|
211
|
+
Description-Content-Type: text/markdown
|
|
212
|
+
License-File: LICENSE
|
|
213
|
+
Provides-Extra: test
|
|
214
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
215
|
+
Dynamic: license-file
|
|
216
|
+
|
|
217
|
+
# RR-PF
|
|
218
|
+
|
|
219
|
+
[](https://github.com/dcpracmatic-prog/RR-PF/actions/workflows/ci.yml)
|
|
220
|
+
[](https://github.com/dcpracmatic-prog/RR-PF/actions/workflows/dependabot/update-graph)
|
|
221
|
+
|
|
222
|
+
Exact rational numbers and rational intervals that enclose them, with a
|
|
223
|
+
`Fraction`-based test oracle and a Lean 4 model of the interval arithmetic.
|
|
224
|
+
|
|
225
|
+
Formerly published as `mne`; renamed because that name is taken on PyPI.
|
|
226
|
+
The main class is still called `MNE` for API stability.
|
|
227
|
+
|
|
228
|
+
## Install
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
pip install . # from a clone
|
|
232
|
+
pip install ".[test]" # with pytest
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Usage
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from fractions import Fraction
|
|
239
|
+
from rr_pf import MNE
|
|
240
|
+
|
|
241
|
+
MNE.parse("0.[3]") * 3 # 1
|
|
242
|
+
MNE.parse("0.1[6]") # 1/6
|
|
243
|
+
MNE.parse("0.[142857]") # 1/7
|
|
244
|
+
MNE.parse("-0.25") # -1/4
|
|
245
|
+
MNE(Fraction(4, 9)).sqrt() # 2/3
|
|
246
|
+
MNE.from_float(0.1) # exact binary value of the float
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`MNE(0.1)` is the decimal `1/10`, by documented rule.
|
|
250
|
+
`MNE.from_float(0.1)` is the binary value `3602879701896397/36028797018963968`.
|
|
251
|
+
|
|
252
|
+
Division by an interval that contains 0 raises `ZeroDivisionError`.
|
|
253
|
+
|
|
254
|
+
## Oracle
|
|
255
|
+
|
|
256
|
+
`rr_pf.oracle` provides an exact sparse matrix-vector product (`ExactCSR`,
|
|
257
|
+
`csr_matvec_exact`) for use as a slow reference in other projects' tests.
|
|
258
|
+
It rejects `float` entries on purpose, so that a binary/decimal ambiguity
|
|
259
|
+
cannot pass silently.
|
|
260
|
+
|
|
261
|
+
## Lean model
|
|
262
|
+
|
|
263
|
+
The formal side lives in [`lean/`](lean/). It defines bounded numbers
|
|
264
|
+
`(val, bound)` and interval operations over `ℝ`, and proves:
|
|
265
|
+
|
|
266
|
+
- `add_valid`, `mul_valid`, `sub_valid`, `div_valid`: the bounds are sound;
|
|
267
|
+
- `add_exact`, `mul_exact`, `div_exact`, `add_mono_bound`;
|
|
268
|
+
- `RInterval.toBN_add`, `toBN_sub`: the Python-style add and sub correspond exactly;
|
|
269
|
+
- `RInterval.mul_hull_sound`, `div_hull_sound`: the Python-style mul and div
|
|
270
|
+
results lie inside the Lean enclosure;
|
|
271
|
+
- `RRPF.Sqrt.pySqrt_enclosure`: Python's `sqrt` on an interval encloses `√x`
|
|
272
|
+
for every `x` in it; `RRPF.Literals.periodic_closed`: the closed form of a
|
|
273
|
+
repeating decimal; `RRPF.Literals.den_dyadic_pow_two`: `from_float`
|
|
274
|
+
denominators are powers of two.
|
|
275
|
+
|
|
276
|
+
`lean/RRPF/Cases.lean` is generated by `tools/export_cases.py` and checks 89
|
|
277
|
+
Python outputs against the Lean spec. CI fails if the committed file differs
|
|
278
|
+
from the generator's output.
|
|
279
|
+
|
|
280
|
+
No `sorry`. Each theorem depends only on `propext`, `Classical.choice`,
|
|
281
|
+
and `Quot.sound`.
|
|
282
|
+
|
|
283
|
+
[`docs/CORRESPONDENCE.md`](docs/CORRESPONDENCE.md) states, for every claim,
|
|
284
|
+
whether it is proven in Lean, only tested in Python, or out of scope, and in
|
|
285
|
+
which direction it holds (equality or containment).
|
|
286
|
+
|
|
287
|
+
## Tests
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
pip install ".[test]"
|
|
291
|
+
pytest -q
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
The suite has 44 tests. They cover the core arithmetic, the oracle, the
|
|
295
|
+
Lean-case generator, and a randomized correspondence check between the Python
|
|
296
|
+
code and the Lean formulas (fixed seed).
|
|
297
|
+
|
|
298
|
+
The oracle test suite includes a mutant that drops small terms. A
|
|
299
|
+
float-vs-float comparison misses it for some sizes; the exact oracle catches it.
|
|
300
|
+
|
|
301
|
+
## Lean build
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
cd lean
|
|
305
|
+
lake exe cache get # fetch the Mathlib cache
|
|
306
|
+
lake build # must end with "Build completed successfully"
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Toolchain: `leanprover/lean4:v4.14.0`, Mathlib `v4.14.0`.
|
|
310
|
+
|
|
311
|
+
## Continuous integration
|
|
312
|
+
|
|
313
|
+
`.github/workflows/ci.yml` runs `pytest` on Python and `lake build` on Lean,
|
|
314
|
+
checks the axiom list of the key theorems, and checks that the generated Lean
|
|
315
|
+
cases are up to date.
|
|
316
|
+
|
|
317
|
+
## Languages
|
|
318
|
+
|
|
319
|
+
- English: this file.
|
|
320
|
+
- Español: [README.es.md](README.es.md).
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rr_pf/__init__.py,sha256=-tLDQxCc0ocRNh3DSrA49Dt72iXU79upAL6VznVmYCE,272
|
|
2
|
+
rr_pf/core.py,sha256=QxU-mOuWDYgWtO1sw1NyR6uuHz5FrwTZZwnAa7YOb7g,9553
|
|
3
|
+
rr_pf/oracle.py,sha256=__Xn5nR8QO9By8-xui5JNteti7NnSRfz_QpbozihxIc,7283
|
|
4
|
+
rr_pf-3.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
rr_pf-3.1.0.dist-info/METADATA,sha256=_-AlIP4juGpuLWQyGx_KEqwp3ow2YbYcUlL9flB9fFY,17191
|
|
6
|
+
rr_pf-3.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
rr_pf-3.1.0.dist-info/top_level.txt,sha256=AhdM62XZioqTyYfiGZ1BPIZn0T0j8UGxOMB6qUe1l5A,6
|
|
8
|
+
rr_pf-3.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rr_pf
|