interval API
用途
interval 是以 Binary 为端点的区间算术。Interval 是一个闭实数区间 (可以无界),或者空集;每个运算返回的区间都包含该运算作用于操作数中各点时的全部精确结果(即包含性质)。DecoratedInterval 增加了 IEEE 1788-2015 的装饰(decoration),IntervalContext 将结果舍入到目标二进制格式并报告 IntervalFlags。
虽然名字叫“球”,其存储表示却是端点对,而不是中点与半径:Interval::from_midpoint_radius(center, radius) 由中点–半径视图构造区间,midpoint() 和 radius() 则按 IEEE 1788-2015 12.12.8 的定义把它读回来。教程展示了典型用法;设计文档推导了相关公式并证明了包含性质。可能失败的管线包装为 interval_checked。
本页使用的约定:
- 和 分别向 和 舍入到 位有效二进制位。“向外舍入”是指下端点用 舍入、上端点用 舍入。
- 区间的精度是一个以位为单位的标记。运算会将结果向外舍入到其操作数中较大的那个精度;初等函数使用其参数的精度。
Binary端点的指数范围就是binary的实现范围:首位指数最大为 ,非零绝对值最小为 ,其中 。如需更窄的范围,请使用IntervalContext。- 区间的精度在 1 到
binary_precision_max(268,435,456)位之间,这是BinaryContext的上下限。返回值的构造函数在精度超出范围时中止并指明上下限;try_构造函数和 checked 层则返回错误。精度绝不会被悄悄替换(0.12 之前小于 1 的精度会变成 1)。 - Empty 表示空集,Entire 表示 。无界区间以 和/或 作为端点存储;这仅表示集合在该侧无界,绝不表示它包含无穷值。
- 目前代码会丢失部分输入集合、无谓地放宽结果,或对上下文结果舍入或置标志出错的少数输入,都在出现处注明并附上对应的跟踪 issue,并汇总在设计文档的已知局限中。
导入
在你的 moon.pkg 中添加该包及端点包:
import {
"Luna-Flow/floating/binary",
"Luna-Flow/floating/interval",
"Luna-Flow/arithmetic" @lf_arith,
}
示例中将这些包称为 @interval.、@binary. 和 @lf_arith.(对应 Luna-Flow/arithmetic,它定义了 ArithmeticError、RoundingMode 以及包络 trait)。示例使用两个辅助函数:iv(lo, hi) 构建端点为整数的 53 位区间;fmt(x) 将端点输出为六位十进制数,下端点向下舍入、上端点向上舍入,因此文本仍然包络所存储的集合。
///|
fn iv(lo : Int, hi : Int) -> @interval.Interval {
@interval.Interval::from_bounds(
@binary.Binary::from_int(lo, precision=53),
@binary.Binary::from_int(hi, precision=53),
)
}
///|
fn fmt(x : @interval.Interval) -> String {
if x.is_empty() {
return "[empty]"
}
let down = @binary.BinaryContext::new(
precision=53,
rounding=@binary.BinaryRoundingMode::RoundTowardNegative,
)
let up = @binary.BinaryContext::new(
precision=53,
rounding=@binary.BinaryRoundingMode::RoundTowardPositive,
)
"[" +
x.lower_bound().to_decimal_string_ctx(6, down).0 +
", " +
x.upper_bound().to_decimal_string_ctx(6, up).0 +
"]"
}
类型
Interval
Interval 是一个以 Binary 为端点并带有精度标记的闭区间。
pub struct Interval {
// private fields
} derive(Eq, @debug.Debug)
非空值满足 ,没有 NaN 端点,绝不会出现 或 ,且精度 。空集是一个单独的状态。字段是私有的;请使用构造中的函数构造值。== 是 IEEE 1788-2015 表 10.3 的 equal:它比较的是集合,而不是表示;参见 Interval::equal 和 Interval::identical。
DecoratedInterval
DecoratedInterval 是一个 Interval 与一个 IEEE 1788 Decoration 的组合,或者是特殊值 NaI(not an interval,非区间)。
pub struct DecoratedInterval {
// private fields
} derive(Eq)
装饰始终保持规范形式:空区间总是带有 Trv,无界区间绝不带有 Com,并且只有 DecoratedInterval::nai 带有 Ill。
Decoration
Decoration 是装饰区间的 IEEE 1788 装饰,其顺序为 Ill < Trv < Def < Dac < Com。
pub(all) enum Decoration {
Ill
Trv
Def
Dac
Com
} derive(Compare, Eq, @debug.Debug)
对于函数 在矩形 上求值所得的装饰结果 :
| 构造子 | 含义 |
|---|---|
Com | 非空且有界, 在 上有定义且连续,并且 有界 |
Dac | 非空, 在 上有定义,且其在 上的限制连续 |
Def | 非空,且 在 上有定义 |
Trv | 一无所知 |
Ill | 值为 NaI |
每个性质都蕴含其下方的性质,因此装饰是全序的;Decoration 按该顺序派生 Compare,所以 <、<=、> 和 >= 就是 IEEE 1788-2015 11.5.3 的装饰比较。Show 输出 IEEE 1788 的小写名称 com、dac、def、trv、ill。
OverlapState
OverlapState 是 overlap 的结果:IEEE 1788 对两个区间相对位置的分类。
#derive(Eq, @debug.Debug)
pub(all) enum OverlapState {
BothEmpty
FirstEmpty
SecondEmpty
Before
Meets
Overlaps
Starts
ContainedBy
Finishes
Equals
After
MetBy
OverlappedBy
StartedBy
Contains
FinishedBy
}
构造子就是 IEEE 1788-2015 表 10.7(10.6.4)的 16 个状态,名称与标准一致:bothEmpty、firstEmpty、secondEmpty、before、meets、overlaps、starts、containedBy、finishes、equals、after、metBy、overlappedBy、startedBy、contains 和 finishedBy。没有第 17 个状态:带装饰版本的 overlap 对 NaI 没有值(11.7.2),返回 None。
IntervalContext
IntervalContext 描述 IEEE 754-2019 3.3 的目标二进制格式:以位为单位的精度和指数范围 (e_min 是推导出来的,不是参数)。
pub struct IntervalContext {
// private fields
}
和 遵循 IEEE 754:满足 的有限非零值 ,当 时在范围内,当 时为正规数。参见上下文与标志。
IntervalFlags
IntervalFlags 记录将区间舍入到某个 IntervalContext 时触发的条件。
pub struct IntervalFlags {
// private fields
} derive(Eq)
当端点(对 midpoint_ctx 而言是中点)发生改变时设置 inexact;当其超出 时设置 overflow;当其为微小值且不精确时设置 underflow,与 IEEE 754 的定义一致(参见 Interval::apply_ctx)。字段为私有;每个标志都用同名访问器方法读取,这些方法列于 IntervalFlags::new 之下。
构造
Interval::from_midpoint_radius
Interval::from_midpoint_radius 由中心和半径构建区间 在 位格式中的包络(IEEE 1788-2015 12.12.7)。Interval::try_from_midpoint_radius 返回同样的区间,在 from_midpoint_radius 中止的地方则返回 ArithmeticError。
pub fn Interval::from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int) -> Self
pub fn Interval::try_from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
默认精度是 center 与 radius 精度中的较大者。记该精度为 ,则存储的区间为
即精确的 向下舍入、精确的 向上舍入,各舍入一次,在本库的指数范围内:两个端点都是该格式的数,且该区间是该格式中包含 的最紧区间(见设计页面)。当 center 或 radius 不是有限数、radius 为负,或 precision 超出 1..=binary_precision_max 时,from_midpoint_radius 中止,try_from_midpoint_radius 返回定义域错误。
当 至多有 位且 时,结果是单点集 。
Interval::from_string 与 DecoratedInterval::from_string
IEEE 1788-2015 textToInterval(10.5.8、12.12.7、13.2):把区间字面量 s 转成其值在 precision 位下的区间包。
pub let interval_literal_max_length : Int
pub fn Interval::from_string(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::from_string(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
接受 12.11 的可移植字面量,不区分大小写,除文法允许的括号内空格和制表符外不允许其他空白:
| 形式 | 示例 |
|---|---|
| 数字面量 | 3.56, 1.e-3, -0x1.3p-1, 2/3, inf, -Infinity |
| inf-sup 形式 | [1.5, 2.5]、[-Inf, 2/3]、[0x1.3p-1,](省略的端点为无穷)、[,](Entire) |
| 单点 | [3.56] |
不确定形式 m?rve | 3.56?1()、3.56?1e2()、3.560?2u、-10?(半个 ulp)、-10??u()、-10??(Entire) |
| 特殊形式 | [], [empty], [entire] |
| 带装饰 | [1,2]_com, 3.56?1_def, [nai] |
端点按精确值解析(十进制、十六进制与有理数的值,不确定形式的末位 ulp)并向外舍入:下端点向下,上端点向上。比较 由精确值判定,所以字面量不会因舍入而被拒绝或变空;超出范围的十进制或二进制指数由指数和数字个数判定,无需构造该值(超出范围的下端点是最大有限浮点数,上端点是 ;小于最小存储值时分别是 0 和最小正存储值)。只有两个不同基数的有限端点在工作规模上相等且指数超过 65,536 时无法排序;此时(12.12.7 情形 (b),PossiblyUndefinedOperation)结果包含两个端点。
Err 是标准中的失败调用(裸字面量的结果为 Empty,装饰字面量为 NaI,并发出异常 UndefinedOperation)。它是解析类的 ArithmeticError,消息指明被违反的规则(例如“下端点大于上端点(要求 l <= u)”“有理数字面量:分母必须是正自然数”“装饰 com 需要有界区间(11.4)”)。对 Interval::from_string 而言,裸字面量中带装饰或 [nai] 就是这样的失败。DecoratedInterval::from_string 接受裸字面量(由 newDec 装饰:有界为 com,否则为 dac)、bare_dec 和 [nai](即 Ok(NaI));对该值不允许的装饰(11.4:Empty 只允许 trv,com 只用于有界区间)是 Err,有界字面量舍入后溢出时 com 变为 dac。长于 interval_literal_max_length(65,536 个字符)的字符串不被解析:12.11.5 允许实现“限制对某些输入字符串(过长的字符串或含有理数字面量的字符串)的支持”,并要求构造函数“必须始终返回一个包含 Level 1 区间的 Level 2 区间(这种情况下可以是 Entire)”,所以结果是 Entire(装饰版本为 dac,或字符串所带的 trv、def)。
///|
test "from_string" {
// 3.56?1 is [3.55, 3.57]: each bound is rounded outward
let u = @interval.Interval::from_string("3.56?1").unwrap()
assert_true(u.lower_bound().compare(@binary.Binary::from_double(3.55)) <= 0)
// [0x1.3p-1,] is [19/32, +inf), exact
let r = @interval.Interval::from_string("[0x1.3p-1,]").unwrap()
assert_true(r.lower_bound().compare(@binary.Binary::from_double(19.0 / 32.0)) == 0)
// the failed call is an Err that names the rule
assert_true(@interval.Interval::from_string("[2,1]") is Err(_))
// [nai] is NaI for the decorated form
assert_true(@interval.DecoratedInterval::from_string("[nai]").unwrap().is_nai())
}
Interval::from_bounds 与 Interval::try_from_bounds
Interval::from_bounds 由端点构建区间 ,并向外舍入到所请求的精度。
pub fn Interval::from_bounds(@binary.Binary, @binary.Binary, precision? : Int) -> Self
pub fn Interval::try_from_bounds(@binary.Binary, @binary.Binary, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
默认精度是两个端点精度中的较大者。无穷端点构建无界区间:from_bounds(-inf, +inf) 即 Entire。当某个端点为 NaN、下端点为 、上端点为 或 时,输入无效;此时 from_bounds 中止,try_from_bounds 返回定义域错误。无法由端点构建 Empty;请使用 Interval::empty。
///|
test "from_bounds" {
let two = @binary.Binary::from_int(2, precision=53)
let three = @binary.Binary::from_int(3, precision=53)
inspect(fmt(@interval.Interval::from_bounds(two, three)), content="[2.00000e+0, 3.00000e+0]")
inspect(@interval.Interval::try_from_bounds(three, two) is Err(_), content="true")
}
Interval::exact 与 Interval::try_exact
Interval::exact 构建有限 Binary 的单点集 。
pub fn Interval::exact(@binary.Binary, precision? : Int) -> Self
pub fn Interval::try_exact(@binary.Binary, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
默认精度为 x 的精度。当 x 的有效位数多于所请求的精度时,单点集会向外舍入为两点区间 。非有限的 x 会使 exact 中止,并使 try_exact 返回定义域错误。
Interval::from_int 与 Interval::from_coefficient
Interval::from_int 和 Interval::from_coefficient 构建整数的包络。
pub fn Interval::from_int(Int, precision~ : Int) -> Self
pub fn Interval::from_coefficient(@binary.BinCoeff, precision? : Int, negative? : Bool) -> Self
from_int 的精度是必需的,按位计(原来默认是 53)。from_coefficient 接受一个非负的 BinCoeff 绝对值和一个单独的符号。整数先被精确转换为 Binary,再传给 exact,因此当 能用 位表示时结果为单点集 ,否则为两点区间 。无论哪种情况结果都包含 。要得到单点集,请传入不小于该整数位长的精度。
Interval::from_double、Interval::try_from_double、Interval::from_float 和 Interval::try_from_float
这些函数构建 Double 或 Float 的精确二进制值的单点集。
pub fn Interval::from_double(Double, precision? : Int) -> Self
pub fn Interval::try_from_double(Double, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::from_float(Float, precision? : Int) -> Self
pub fn Interval::try_from_float(Float, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
默认精度分别为 53 和 24。到 Binary 的转换是精确的;若请求的精度更小,则单点集会向外舍入。NaN 和无穷会使普通形式中止,对 try_ 形式则是定义域错误。结果包络的是二进制值,而不是书写时的十进制字面量:from_double(0.1) 不包含 。
Interval::entire 与 Interval::empty
Interval::entire 返回 Entire,Interval::empty 返回 Empty。
pub fn Interval::entire(precision? : Int) -> Self
pub fn Interval::empty(precision? : Int) -> Self
默认精度为 53。
观察函数
Interval::lower_bound 与 Interval::upper_bound
lower_bound 和 upper_bound 是 IEEE 1788-2015 12.12.8 的 inf 和 sup:它们返回端点。
pub fn Interval::lower_bound(Self) -> @binary.Binary
pub fn Interval::upper_bound(Self) -> @binary.Binary
在无界的一侧,端点是无穷。对于 Empty,二者分别返回 和 ,因此请先检查 is_empty。
零的符号遵循 12.12.8:在有符号零的格式中,Level 1 的值 0 由 lower_bound 返回为 ,由该子条款的其他所有函数(upper_bound、midpoint、radius、width、magnitude、mignitude 及其带上下文的形式)返回为 。所以 [0, 1] 的下界是 ,[-1, 0] 的上界是 ,不论区间由哪种符号的零构造;[0, 0] 的代表是 。区间是一个集合:存储的零的符号不是它的一部分。Binary 的 == 与 compare 一致(-0 == +0);identical 区分这两个零。
每个端点都是 位格式的数(至多 位有效位,落在 位的网格上,包括范围下限以下的区段)或无穷,其标签 endpoint.precision() 就是区间的精度 。Binary 的 == 与 compare 一致,并忽略标签(Binary::identical 会比较标签),因此对同一个数的值 y,x.lower_bound() == y 成立;Interval 自身的 == 与 identical 按值比较端点,从不读取标签。所存储零的符号不属于区间:由访问器决定,如上一段所述。
Interval::midpoint 与 Interval::radius
midpoint 即 IEEE 1788-2015 12.12.8 的 mid,radius 即其 rad(mid、rad、wid、inf、sup、mag 和 mig 这些名字在此用全称拼写;标准的短名字会与 Binary::inf 并列,所以长名字是有记录的例外)。
pub fn Interval::midpoint(Self) -> @binary.Binary
pub fn Interval::radius(Self) -> @binary.Binary
两者都是全函数,没有一个会中止。midpoint 对 Empty 返回 NaN,对 Entire 返回 0,对半无界区间返回该格式(区间的精度、Binary 最宽的指数范围)的最大有限数,符号与无界的一侧相同,其余情形返回精确中点按就近舍入(偶数优先)到区间精度的值。midpoint_ctx 是以给定的 IntervalContext 为结果格式的同一个观测量。radius 对 Empty 返回 NaN,对每个无界区间返回 ,其余情形返回满足 的该精度下最小的数 ,其中 是 midpoint 返回的值:即 与 中较大者,向上舍入。它是从舍入后的中点而不是精确中心量起的,所以 [midpoint - radius, midpoint + radius] 总是包含该区间(0.12 之前半径是半宽,最多可能比某个端点少半个 ulp)。对于 53 位下的 ,中点为 ,半径为 。
Interval::width
width 返回 ,是精确宽度的上界。对 Empty 为 NaN,对无界区间为 。
Interval::magnitude 与 Interval::mignitude
magnitude 返回 ,mignitude 返回 。
pub fn Interval::magnitude(Self) -> @binary.Binary
pub fn Interval::mignitude(Self) -> @binary.Binary
对于非空区间,
这是因为 是凸函数,其在区间上的最大值位于端点处,并且它在 0 的两侧各自单调。二者都是精确的。Empty 对二者都给出 NaN(12.12.8);无界区间的 magnitude 为 。
///|
test "observers" {
let x = iv(-3, 5)
inspect(x.midpoint().to_string(), content="1p0")
inspect(x.radius().to_string(), content="1p2")
inspect(x.width().to_string(), content="1p3")
inspect(x.magnitude().to_string(), content="5p0")
inspect(x.mignitude().to_string(), content="0")
inspect(iv(2, 7).mignitude().to_string(), content="1p1")
}
Interval::precision
precision 返回精度标记。
pub fn Interval::precision(Self) -> Int
Interval::is_empty, Interval::is_entire, Interval::is_common_interval, Interval::is_singleton
这些谓词检测集合的形状。
pub fn Interval::is_empty(Self) -> Bool
pub fn Interval::is_entire(Self) -> Bool
pub fn Interval::is_common_interval(Self) -> Bool
pub fn Interval::is_singleton(Self) -> Bool
当区间非空且两个端点都是有限数时,is_common_interval 成立(IEEE 1788-2015 10.6.3)。当 时,is_singleton 成立。要询问一个区间是否包含 0,请对零使用 is_member。
精度
Interval::with_precision
with_precision 将区间重新舍入到新的精度,且不会使其缩小。
pub fn Interval::with_precision(Self, Int) -> Self
端点向外取整:下界朝 ,上界朝 ,因为向外取整是唯一能让结果保持为包络的方向;没有舍入模式参数。Empty 仍为 Empty,并带上新精度。
///|
test "with_precision keeps the endpoints" {
let one = @binary.Binary::one(precision=53)
let next = @binary.Binary::make(
@binary.BinCoeff::from_uint64((1UL << 52) + 1UL),
-52,
53,
)
let x = @interval.Interval::from_bounds(one, next)
let y = x.with_precision(53)
inspect(y.lower_bound().to_string(), content="1p0")
inspect(y.upper_bound().to_string(), content="4503599627370497p-52")
inspect(y.equal(x), content="true")
// `normalized` keeps the endpoints too.
inspect(x.normalized().equal(x), content="true")
}
Interval::normalized
normalized 规范化两个端点(Binary::normalized 去掉末尾的零位),并以区间的精度存储它们。
pub fn Interval::normalized(Self) -> Self
存储的端点在该精度下本就可表示,因此结果与输入是同一个集合:53 位下 的 normalized 就是 。Empty 仍为 Empty。
集合运算
Interval::intersection 与 Interval::convex_hull
intersection 返回 ,convex_hull 返回包含 的最小区间。
pub fn Interval::intersection(Self, Self) -> Self
pub fn Interval::convex_hull(Self, Self) -> Self
对于非空操作数,二者都通过端点的 max/min 计算( 和 ),除最后向外舍入到较大精度外都是精确的。不相交的区间求交得到 Empty,有 Empty 操作数时交集为 Empty。当 convex_hull 的一个操作数为 Empty 时,结果是另一个操作数在两个精度中较大者下的值,这是精确的(参见 Interval::with_precision 下的说明)。
Interval::cancel_plus 与 Interval::cancel_minus
cancel_minus(x, y) 是 IEEE 1788 的消去减法:在精确算术下,它返回满足 的区间 ,从而撤销先前的求和;cancel_plus(x, y) 即 cancel_minus(x, -y)。
pub fn Interval::cancel_plus(Self, Self) -> Self
pub fn Interval::cancel_minus(Self, Self) -> Self
对于有界操作数,cancel_minus 为 。事实上 ,因此 迫使 且 ,而它恰在 时是一个区间。由于向外舍入,计算所得的 满足 。当 、有操作数无界或仅 为空时,结果为 Entire。 为空且 有界或为空时,结果为 Empty。
///|
test "set operations" {
inspect(fmt(iv(0, 4).intersection(iv(2, 9))), content="[2.00000e+0, 4.00000e+0]")
inspect(iv(0, 1).intersection(iv(2, 3)).is_empty(), content="true")
inspect(fmt(iv(0, 1).convex_hull(iv(5, 6))), content="[-0.00000e+0, 6.00000e+0]")
// (x + y) - y widens, cancel_minus recovers x.
let x = iv(1, 2)
let y = iv(10, 20)
inspect(fmt(x + y - y), content="[-9.00000e+0, 1.20000e+1]")
inspect(fmt((x + y).cancel_minus(y)), content="[1.00000e+0, 2.00000e+0]")
}
关系
所有关系都是 IEEE 1788 的集合关系;它们都不是全序。它们从不中止。
Interval::is_member
is_member 检测一个点是否属于该区间。
pub fn Interval::is_member(Self, @binary.Binary) -> Bool
对 Empty 和非有限的点,它返回假(无界区间包含所有足够大的实数,但不包含 或 NaN)。trait 方法 @lf_arith.Contains::contains 则接受两个区间并检测包含关系;参见包络关系。
Interval::subset, Interval::interior, Interval::equal, Interval::disjoint
这些函数检测集合的包含、内部包含、相等与不相交。
pub fn Interval::subset(Self, Self) -> Bool
pub fn Interval::interior(Self, Self) -> Bool
pub fn Interval::equal(Self, Self) -> Bool
pub fn Interval::disjoint(Self, Self) -> Bool
x.subset(y) 即 ,也就是 且 。x.interior(y) 即 :每个端点比较都是严格的,但两个相等的无穷端点视为位于内部( 的内部为 ,因此 Entire 在其自身内部)。Empty 是任何区间的子集、位于任何区间内部,并且与任何区间不相交。equal 是 Eq 实现的方法,所以 x == y 就是 x.equal(y):两个区间是同一个集合(两个空区间相等),与它们的精度标记和端点的表示方式无关(IEEE 1788-2015 12.3 和 12.12.9)。
Interval::identical
identical 比较的是数据本身,而不只是集合(12.3):同一个集合且精度标记相同。
pub fn Interval::identical(Self, Self) -> Bool
24 位和 113 位下的同一个区间是 == 的,但不是 identical 的;当精度很重要时,例如要检查结果是否具有所要求的精度,请使用 identical。两个空区间在精度相等时是 identical 的。
区间格式的其他任何部分,若以后的版本加入(754 兼容类型的可选指数范围,issue 232),同理:格式不属于 == 或 compare;只有 identical 可以查看它。
Interval::less, Interval::strict_less, Interval::precedes, Interval::strict_precedes
这些是 IEEE 1788 的序关系。
pub fn Interval::less(Self, Self) -> Bool
pub fn Interval::strict_less(Self, Self) -> Bool
pub fn Interval::precedes(Self, Self) -> Bool
pub fn Interval::strict_precedes(Self, Self) -> Bool
对于非空操作数:
| 关系 | 集合定义 | 条件 |
|---|---|---|
less | 且 | 且 |
strict_less | 同上,改用 | (或二者均为 )且 (或二者均为 ) |
precedes | ||
strict_precedes |
涉及 Empty 时:less 和 strict_less 仅当两者均为 Empty 时成立;precedes 和 strict_precedes 在任一者为 Empty 时成立。
Interval::overlap
overlap 对两个区间的相对位置进行分类。
pub fn Interval::overlap(Self, Self) -> OverlapState
结果是 OverlapState 的十六种状态之一;它由四个端点之间的比较计算得出,并先检测相等的端点,因此与另一区间某个端点重合的单点集会按 IEEE 1788 的要求给出 Starts、Finishes、StartedBy 或 FinishedBy,而不是 Meets 或 MetBy。
///|
test "relations" {
let a = iv(1, 3)
let b = iv(3, 6)
inspect(a.precedes(b), content="true")
inspect(a.strict_precedes(b), content="false")
inspect(@lf_arith.DefinitelyLe::definitely_le(a, b), content="true")
inspect(@lf_arith.MaybeEq::maybe_eq(a, b), content="true")
inspect(iv(2, 3).interior(iv(1, 6)), content="true")
inspect(iv(1, 3).interior(iv(1, 6)), content="false")
debug_inspect(a.overlap(b), content="Meets")
debug_inspect(iv(1, 6).overlap(iv(2, 3)), content="Contains")
}
算术
Interval::add, Interval::sub, Interval::mul, Interval::div
四则基本运算返回 向外舍入后的包;它们也可以通过运算符 +、-、*、/ 使用。
pub fn Interval::add(Self, Self) -> Self
pub fn Interval::sub(Self, Self) -> Self
pub fn Interval::mul(Self, Self) -> Self
pub fn Interval::div(Self, Self) -> Self
结果精度为操作数中较大的精度;有 Empty 操作数时结果为 Empty。端点公式如下:
其中在 中将 取为 0(零端点乘以无界的一侧贡献 0)。各和与积都精确构造,并只舍入一次。对于有界操作数,由符号选出可能取极值的乘积:两个操作数符号都不变时取两个,任一操作数在内部含 0 时取四个( 与 的最小值, 与 的最大值)。设计文档证明了符号情形表。
除法遵循 IEEE 1788: 是 的包。
| 除数 | 结果 |
|---|---|
| ,其中 取遍端点之商 | |
| Empty | |
| Entire,除非 | |
| 或 | 半无界(见下文),当 时为 Entire |
当除数在一端触及 0 时,商在一侧无界:例如 ,。被除数等于 时,对除 以外的任何除数都得到 。每个选出的商都在结果精度下通过一次定向除法计算。
///|
test "basic arithmetic" {
let x = iv(1, 2)
let y = iv(-3, 5)
inspect(fmt(x + y), content="[-2.00000e+0, 7.00000e+0]")
inspect(fmt(x - y), content="[-4.00000e+0, 5.00000e+0]")
inspect(fmt(x * y), content="[-6.00000e+0, 1.00000e+1]")
inspect((x / y).is_entire(), content="true")
inspect(fmt(x / iv(0, 4)), content="[2.50000e-1, inf]")
inspect((x / iv(0, 0)).is_empty(), content="true")
}
Interval::neg 与 Interval::abs
neg 返回 ,abs 返回 。
pub fn Interval::neg(Self) -> Self
pub fn Interval::abs(Self) -> Self
当 时 abs 为 ,当 时为 ,否则为 。二者都是精确的。neg 也是一元运算符 -。
Interval::recip
recip 按上述除法规则返回 。
pub fn Interval::recip(Self) -> Self
Interval::sqr 与 Interval::pown
sqr 返回 ,pown 对整数指数 返回 。
pub fn Interval::sqr(Self) -> Self
pub fn Interval::pown(Self, Int) -> Self
与 x * x 不同,这些函数两次使用的是同一个点,因此 [-1, 2].sqr() 为 (而 x * x 为 ):sqr 为 。pown 以定向舍入在端点处计算 的各单调分段:奇数正次幂递增;偶数正次幂先减后增,当 时最小值为 0;负次幂在 0 处有极点。对每个非空的 x,pown(x, 0) 为 ;Empty 仍为 Empty。当 时,pown(x, n) 对 返回 Empty,当 0 为端点时返回半无界区间,当 0 位于内部时返回 Entire( 为奇数)或 ( 为偶数)。作为捷径,当 且 0 位于内部时,即使 为偶数也返回 Entire;这是一个有效但不紧的包络。
///|
test "powers" {
let x = iv(-1, 2)
inspect(fmt(x.sqr()), content="[-0.00000e+0, 4.00000e+0]")
inspect(fmt(x.pown(3)), content="[-1.00000e+0, 8.00000e+0]")
inspect(fmt(x.pown(-2)), content="[2.50000e-1, inf]")
inspect(x.pown(-1).is_entire(), content="true")
inspect(fmt(iv(0, 2).pown(-1)), content="[5.00000e-1, inf]")
}
Interval::fma
fma(x, y, z) 以单次向外舍入返回 的一个包络。
pub fn Interval::fma(Self, Self, Self) -> Self
精确的乘积界按 mul 的方式计算,并在最终舍入之前加到 的端点上,因此结果绝不会比 x * y + z 更宽。
Interval::min 和 Interval::max
min 和 max 分别返回 和 。
pub fn Interval::min(Self, Self) -> Self
pub fn Interval::max(Self, Self) -> Self
min 为 ,max 则是将其中的 min 换成 max 的类似形式: 关于每个参数都是递增的。有 Empty 操作数时结果为 Empty。
Interval::sign, Interval::ceil, Interval::floor, Interval::trunc, Interval::round_ties_to_even, Interval::round_ties_to_away
IEEE 1788-2015 表 9.1 的整数函数。sign 按点的符号取 、 或 ;ceil 与 floor 分别给出不小于和不大于该点的最小、最大整数;trunc 给出朝零方向最近的整数;round_ties_to_even 与 round_ties_to_away 给出最近的整数,平局时分别取偶数或远离零的整数(这两个名称对应 754 的 roundTiesToEven 与 roundTiesToAway)。
pub fn Interval::sign(Self) -> Self
pub fn Interval::ceil(Self) -> Self
pub fn Interval::floor(Self) -> Self
pub fn Interval::trunc(Self) -> Self
pub fn Interval::round_ties_to_even(Self) -> Self
pub fn Interval::round_ties_to_away(Self) -> Self
每个函数 都是非递减的,因此结果为 。取值是整数(或 、、),所以结果是精确的:不做任何舍入,精度标记保持不变,零端点存为 。 的函数值为 (sign 为 )。空操作数给出空集。没有 try_ 形式:任何输入都不会失败。
///|
test "integer functions" {
let x = @interval.Interval::from_bounds(
@binary.Binary::from_double(1.1),
@binary.Binary::from_double(2.0),
)
assert_true(x.ceil() == iv(2, 2))
assert_true(x.floor() == iv(1, 2))
let d = @interval.DecoratedInterval::new(x)
assert_eq(d.ceil().decoration(), @interval.Decoration::Dac)
assert_eq(d.floor().decoration(), @interval.Decoration::Def)
}
Interval::sqr_rev、Interval::abs_rev、Interval::pown_rev 与 Interval::cosh_rev
IEEE 1788-2015 10.5.4 与表 10.1。每个函数都是自然反向扩展:即 的区间包,其中 是接收者,先验 是可选的最后一个参数(默认 Entire)。区间包是在原像与 相交之后取的,而不是之前:对 ,sqr_rev 为 ,给定先验 时为 ,而 。
pub fn Interval::sqr_rev(Self, x? : Self) -> Self
pub fn Interval::abs_rev(Self, x? : Self) -> Self
pub fn Interval::pown_rev(Self, Int, x? : Self) -> Self
pub fn Interval::cosh_rev(Self, x? : Self) -> Self
pown_rev(c, p, x?) 对应标准的 pownRev(c, x, p):幂在可选的先验之前。各函数:
| 函数 | 的原像 |
|---|---|
sqr_rev | ,根的端点向外舍入 |
abs_rev | ,精确 |
cosh_rev | |
pown_rev, | 若 则为 ,否则为空(对每个 都有 ) |
pown_rev, 为正偶数 | |
pown_rev, 为正奇数 | ,一个区间(:) |
pown_rev, 为负偶数 | 且 : 的 次根的 , 的上端从下方约束 ,下端从上方约束 |
pown_rev, 为负奇数 | 的正部分给出正的 ,负部分给出负的 ,各自通过 计算,并排除极点 0 |
空的 ,或位于函数值域之外的 (sqr_rev 为负,cosh_rev 小于 1),给出 Empty。根的端点是对精确点的定向舍入,所以结果在该类型中是最紧的。对于负幂,值 不在定义域内,因此止于 0 的分量(偶数 且 上方无界,或到达极点时)在该处为开:当 、 时集合为 ,先验 给出 Empty。结果精度取各操作数精度中的最大值。
///|
test "sqr_rev and pown_rev" {
let c = iv(1, 4)
inspect(c.sqr_rev().lower_bound().to_string() + " " + c.sqr_rev().upper_bound().to_string(), content="-1p1 1p1")
assert_true(c.sqr_rev(x=iv(0, 1)) == iv(1, 1))
assert_true(iv(16, 81).pown_rev(4, x=iv(0, 5)) == iv(2, 3))
assert_true(iv(1, 4).pown_rev(0) == @interval.Interval::entire())
}
Interval::sin_rev、Interval::cos_rev 与 Interval::tan_rev
IEEE 1788-2015 10.5.4 与表 10.1。每个函数都是 的区间包,其中 是接收者,先验 可省略(默认 Entire)。
pub fn Interval::sin_rev(Self, x? : Self) -> Self
pub fn Interval::cos_rev(Self, x? : Self) -> Self
pub fn Interval::tan_rev(Self, x? : Self) -> Self
原像是区间的周期性并集。令 、、,则 sin_rev 的原像为 ;cos_rev 与 tan_rev 类似(tan_rev:,位于 的端点给出极点 ,它不在定义域内)。使用默认先验时,只要 与函数的值域相交,结果就是 Entire;对 sin_rev 与 cos_rev, 在 之外给出 Empty,而 (tan_rev: Entire)直接返回先验本身。对有界先验,只有与之相交的第一个和最后一个片段起作用,因此开销与先验跨越多少个周期无关。
结果是该类型中真实集合的区间包:每次先验端点与片段端点的比较都被精确判定,来自片段的结果端点是该片段端点的精确定向舍入(下端取 RD,上端取 RU)。这是最紧的结果,可以比留有一个 ulp 余量的参考值更窄。例如 sin_rev([0, 0], x = [RU(pi), 7]) 是 ,而 sin_rev([0, 0], x = [RU(pi), 6]) 为 Empty。各端点如何判定见设计页面。唯一的限制与前向三角函数相同:先验的端点若其量级不小于 ,则原样保留(有效,但不紧),该判定在做任何工作之前完成,所有有限端点都在限制之外的先验直接原样返回。对限制之内量级为 的先验端点,开销随 增长,与trigonometric functions section中前向函数的开销相同,工作精度随 增加。
///|
test "sin_rev with a prior" {
let rd_pi = @binary.Binary::from_double(3.141592653589793)
let ru_pi = @binary.Binary::from_double(3.1415926535897936)
let c = iv(0, 0)
// the multiples of pi in [3, 4]: only pi, which is not a float
let r = c.sin_rev(x=iv(3, 4))
assert_true(r.lower_bound().compare(rd_pi) == 0)
assert_true(r.upper_bound().compare(ru_pi) == 0)
// the prior starts above pi and ends before 2 pi: nothing
let six = @binary.Binary::from_int(6)
let beyond = @interval.Interval::from_bounds(ru_pi, six)
assert_true(c.sin_rev(x=beyond).is_empty())
// the default prior
assert_true(c.sin_rev().is_entire())
}
Interval::pow_rev1
IEEE 1788-2015 表 10.1。b.pow_rev1(c, x?) 是 的区间包,其中先验 可省略(默认 Entire);接收者是指数区间 。 对 有定义,对 且 时也有定义(值为 0)。
pub fn Interval::pow_rev1(Self, Self, x? : Self) -> Self
对 , 意味着 ,因此该集合是 ,其中 ,即 mul_rev 的集合除法在对数坐标下的形式;当 且 含有正点时,再加上点 0。每个片段的端点是 、0、1 或无穷。未达到的端点为开:0(来自 ,除非零部分使其闭合)与 1(被无界 除所得商的极限);只触及这样端点的先验不与该集合相交。例如 pow_rev1([1, +inf), [2, +inf)) 是 ,所以给定先验 时结果为 Empty,而 pow_rev1([-1, 1], [0.5, 2]) 是 ,所以给定先验 时结果为 Empty。
结果是该类型中的区间包:先验端点与片段端点的每次比较都是精确的,写入结果的端点是 的精确定向舍入。 的精确值依据 与 的结构分类(不做乘方):可能是浮点数的(二进制有限小数)、非浮点数的有理数(例如 )、或无理数,最后一类由像 sin_rev 那样提高工作精度的循环判定。分类、预算及其开销见设计页面。该集合在最大有限浮点数之上的端点,若是上端点则写成 ,若是下端点则写成结果精度下的最大有限浮点数;在最小正存储值之下的端点,若是下端点则写成 0,若是上端点则写成最小正存储值;两者之间(包括非正规数范围)的端点是通常的定向舍入。量级为 的指数可立即判定,因为 的符号是精确的。
///|
test "pow_rev1" {
// x^2 in [4, 4] with x > 0: x = 2
assert_true(iv(2, 2).pow_rev1(iv(4, 4)) == iv(2, 2))
// x^beta in [1, 1] for beta in [-4, -2] with the prior x = [1, 1]: x = 1
let r = iv(-4, -2).pow_rev1(iv(1, 1), x=iv(1, 1))
assert_true(r == iv(1, 1))
// 0^beta = 0 for beta > 0
assert_true(iv(1, 2).pow_rev1(iv(0, 0)) == iv(0, 0))
}
Interval::pow_rev2
IEEE 1788-2015 表 10.1。a.pow_rev2(c, x?) 是 的区间包,其中 为可选先验区间(默认 Entire);接收者是底数区间 ,未知量是指数。 在 时有定义,在 且 时也有定义(值为 0)。
pub fn Interval::pow_rev2(Self, Self, x? : Self) -> Self
对 , 意味着 ,因此该集合是 ,其中 ,,即 mul_rev 的集合除法在对数坐标下的形式,再加上当 且 时的 (底数 0)。底数 1 是“除数含 ”的分支:若 且 ,则每个指数都满足;若 且 ,则没有解。每个片段的端点是 、0 或无穷。取不到的端点是开的:无穷,以及当 0 是被无界的 除所得商的极限(且 )时的 0;只碰到这样一个端点的先验区间不与该集合相交。例如 pow_rev2([2, +inf), [2, 4]) 是 ,所以先验区间取 时结果为 Empty,而 时端点 0 可取到,结果为 。
结果是该类型中的区间包:先验端点与片段端点的每次比较都是精确的,写入结果的端点是片段端点的精确定向舍入。端点的值 按 和 的结构分类:当且仅当 与 在乘法意义下相关时它是有理数,这由对奇部的乘法欧几里得算法判定(除法不整除就证明无关)。有理数当且仅当其约分后的分母是 2 的幂时是浮点数,否则是不为浮点数的有理数(例如 );其余端点是无理数,由一个像 sin_rev 那样提高工作精度的循环判定。设计页面给出了各类别、预算及其代价。离 1 只差一个单位的底数会给出很大的商,首个工作精度随其量级而定。
///|
test "pow_rev2" {
// 2^beta in [8, 8] gives beta = 3
assert_true(iv(2, 2).pow_rev2(iv(8, 8)) == iv(3, 3))
// 2^beta in [1, 1] gives beta = 0
assert_true(iv(2, 2).pow_rev2(iv(1, 1)) == iv(0, 0))
// a prior restricts the result: 2^beta = 4 has the only solution beta = 2
assert_true(iv(2, 2).pow_rev2(iv(4, 4), x=iv(0, 5)) == iv(2, 2))
}
Interval::atan2_rev1 与 Interval::atan2_rev2
IEEE 1788-2015 表 10.1,10.5.4 的式 (6) 与 (7)。b.atan2_rev1(c, x?) 是 的区间包:接收者是横坐标区间 ,未知量是纵坐标 。a.atan2_rev2(c, x?) 是 的区间包:接收者是纵坐标区间 ,未知量是横坐标 。可选的先验区间 默认为 Entire。
pub fn Interval::atan2_rev1(Self, Self, x? : Self) -> Self
pub fn Interval::atan2_rev2(Self, Self, x? : Self) -> Self
在去掉原点的平面上有定义,值域为 (表 9.1 脚注 f):角度 在半直线 、 上取到, 永远取不到。记 ,该集合是扇形 在未知量坐标轴上的投影,并受给定操作数所在带形的限制。设计页面给出了按角度区域与操作数符号划分的情形表、开端点、分支切割和原点。当 在 中没有点(例如 )、某个操作数或先验区间为 Empty 时,集合为空;当横坐标 (Rev1)或纵坐标 (Rev2)且 错过角度 (Rev1)或 与 (Rev2)时也为空;原点从不属于该集合。
结果是该类型中的区间包:先验端点与片段端点的每次比较都是精确的,写入结果的端点是片段端点的精确定向舍入。精确的端点是 0 和无穷;其余端点是非零浮点数的 (Rev1)或 (Rev2),它们是无理数(非零代数数的正切是超越数),所以与每个浮点数都不同,由一个像 sin_rev 那样提高工作精度的循环判定。 的端点位于 的某个倍数之下还是之上是精确判定的( 是无理数,所以浮点数永远不等于这样的倍数)。
///|
test "atan2_rev1 and atan2_rev2" {
// the angle 0 with a positive abscissa: the ordinate is 0
assert_true(iv(1, 1).atan2_rev1(iv(0, 0)) == iv(0, 0))
// c = [4, 5] has no point in (-pi, pi]: Empty; so has the origin
assert_true(iv(1, 1).atan2_rev1(iv(4, 5)).is_empty())
assert_true(iv(0, 0).atan2_rev1(iv(0, 0)).is_empty())
// the angle 0 with the ordinate {0} and a prior x0 in [1, 2]: the abscissa interval of the prior
assert_true(iv(0, 0).atan2_rev2(iv(0, 0), x=iv(1, 2)) == iv(1, 2))
}
Interval::mul_rev_to_pair 与 Interval::mul_rev
IEEE 1788-2015 10.5.5 与表 10.1。对区间 与 ,集合
有零个、一个或两个连通分量,且并不总是闭集()。mul_rev_to_pair 以有序二元组返回各分量的闭包;mul_rev 返回该集合落在先验区间 x 内的部分的区间包。
pub fn Interval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn Interval::mul_rev(Self, Self, x? : Self) -> Self
没有分量时 mul_rev_to_pair(b, c) 为 (Empty, Empty),一个分量时为 (u, Empty),两个分量时为 (u, v) 且 。两个闭包可以共享一个端点: 给出 ([-inf, 0], [0, +inf])。空操作数给出 (Empty, Empty)。接收者是 ,参数是 ,与标准的 mulRevToPair(b, c) 一致。
mul_rev(b, c, x?) 是 ,默认 Entire。区间包取自该集合本身,而不是它的闭包,也不是 x 与该集合区间包的交:当 、、 时结果为 Empty,而该集合的区间包是 Entire。作为被无界 除所得商的未达到的极限的端点 0 视为开端点,因此 mul_rev([1, +inf), [1, 1], x=[-1, 0]) 为 Empty(该集合是 ),而 时结果为 。各分量的端点是向外舍入的商,所以结果在该类型中是最紧的。结果精度取各操作数精度中的最大值。
///|
test "mul_rev_to_pair and mul_rev" {
let b = @interval.Interval::from_bounds(
@binary.Binary::from_int(-1),
@binary.Binary::from_int(1),
)
let (u, v) = b.mul_rev_to_pair(iv(1, 1))
// (-inf, -1] and [1, +inf)
inspect(u.upper_bound().to_string() + " " + v.lower_bound().to_string(), content="-1p0 1p0")
assert_true(b.mul_rev(iv(1, 1), x=iv(0, 0)).is_empty())
}
初等函数
每个函数 返回一个包含 的区间,其中 是 的定义域; 中位于 之外的点被忽略,当 为空时结果为 Empty。结果精度为参数的精度。
函数有两种形式,且只有一个内核。try_ 形式(try_exp 等)用 binary 中对应的 try_*_ctx 函数分别对每个端点求值,下端点向 舍入,上端点向 舍入;当该求值耗尽其工作预算时,返回带认证失败详情(说明运算、阶段和原因)的 Err(ArithmeticError)。全函数形式(exp、sin 等)就是带回退的 try_ 形式:只要 try_ 形式成功,它就返回相同的区间,否则返回该函数在其定义域上的值域(回退见下文),这是有效但较宽的包络。全函数形式在类型接受的任何精度下都不会中止;定义域错误不是失败(结果为 Empty),因此定义域之外的参数与认证失败给出不同的结果。没有任何东西被计算两次:全函数形式只调用一次 try_ 形式。
Interval::sqrt
sqrt 返回 。
pub fn Interval::sqrt(Self) -> Self
端点是区间精度下向下和向上舍入的平方根。当 时为 Empty。没有 try_ 形式:平方根从不失败。
Interval::exp, Interval::exp2, Interval::exp10, Interval::expm1, Interval::try_exp, Interval::try_exp2, Interval::try_exp10, Interval::try_expm1
这些函数分别返回 、、 和 的包络。
pub fn Interval::exp(Self) -> Self
pub fn Interval::exp2(Self) -> Self
pub fn Interval::exp10(Self) -> Self
pub fn Interval::expm1(Self) -> Self
pub fn Interval::try_exp(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_expm1(Self) -> Result[Self, @arithmetic.ArithmeticError]
四者都是递增的,因此结果为 。当 时,四者的包络都是 ;当 时,exp、exp2 和 exp10 的包络是 ,expm1 的是 ,因为 刚好在 之上。前者成立,是因为在任何精度下 都超过 ;后者成立,是因为 低于最小的正 Binary。对于幂在区间精度下可表示的整数端点,exp2 和 exp10 返回精确的幂( 的 exp2 为 , 的 exp10 为 );超出指数范围的整数端点保留向外舍入的包络,因此 的 exp2 为 , 的结果为 。全函数形式的回退对 exp、exp2 和 exp10 为 ,对 expm1 为 。
Interval::ln, Interval::log2, Interval::log10, Interval::log1p, Interval::try_ln, Interval::try_log2, Interval::try_log10, Interval::try_log1p
这些函数分别在其定义域 和 上返回 、、 和 的包络。
pub fn Interval::ln(Self) -> Self
pub fn Interval::log2(Self) -> Self
pub fn Interval::log10(Self) -> Self
pub fn Interval::log1p(Self) -> Self
pub fn Interval::try_ln(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log1p(Self) -> Result[Self, @arithmetic.ArithmeticError]
当区间到达定义域边界(,对 log1p 为 )时,下端点为 ;当区间完全位于定义域之外(,对 log1p 为 )时,结果为 Empty。log10 在端点 ()处返回精确整数。全函数形式的回退为 Entire(端点位于定义域边界或其外在内核运行之前就已判定,不算失败)。
///|
test "exponentials and logarithms" {
inspect(fmt(iv(0, 1).exp()), content="[1.00000e+0, 2.71829e+0]")
inspect(fmt(iv(-1, 10).exp2()), content="[5.00000e-1, 1.02400e+3]")
inspect(fmt(iv(0, 4).ln()), content="[-inf, 1.38630e+0]")
inspect(fmt(iv(1, 1000).log10()), content="[-0.00000e+0, 3.00000e+0]")
inspect(iv(-2, -1).ln().is_empty(), content="true")
// Integer endpoints outside the exponent range keep the outward-rounded enclosure.
let below = @interval.Interval::from_int(-1073742000, precision=53).exp2()
inspect(below.lower_bound().to_string(), content="-0")
inspect(below.upper_bound().to_string(), content="1p-1073741874")
let above = @interval.Interval::from_int(1 << 30, precision=53).exp2()
inspect(above.lower_bound().to_string(), content="9007199254740991p1073741771")
inspect(above.upper_bound().to_string(), content="inf")
}
Interval::pow 和 Interval::try_pow
pow(x, y) 在 IEEE 1788 中 pow 的定义域(,或 且 )上返回 的包络。
pub fn Interval::pow(Self, Self) -> Self
pub fn Interval::try_pow(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
底数的负值部分被忽略(负底数请使用 pown 或 rootn)。由于 ,且 关于 是双线性的,在 的矩形上极值位于四个角点。当底数到达 0 时,对 有 ,对 则 ,因此结果相应地扩展到 0 或 。当底数区间包含 1 或指数区间包含 0 时,代码还会加入值 1;该值本已位于角点值之间,因此这不会改变任何东西,但也无害。 时的 被排除,因此当 时 pow([0, 0], y) 为 Empty。结果精度为操作数中较大的精度。若某个角点的幂在结果精度下可表示(例如 ),则精确给出该幂。全函数形式回退为 。
Interval::rootn 与 Interval::try_rootn
rootn(x, n) 返回实 次方根 的包络: 为偶数时在 上, 为奇数时在全体实数上, 为负时取方根的倒数。
pub fn Interval::rootn(Self, Int) -> Self
pub fn Interval::try_rootn(Self, Int) -> Result[Self, @arithmetic.ArithmeticError]
rootn(x, 0) 和 rootn(x, Int min) 为 Empty;try_rootn(x, 0) 为定义域错误。rootn(x, 1) 即 x,rootn(x, 2) 即 sqrt。全函数形式就是带回退的 try_rootn(偶次为 ,奇次为 Entire)。当 为负且奇次方根的参数包含 0 时,try_rootn 返回 Entire。对任何次数,精确根都会被精确返回,因此 try_rootn({8}, -3) 为 。
///|
test "exact powers and roots" {
let three_quarters = @interval.Interval::exact(
@binary.Binary::make(@binary.BinCoeff::from_uint64(3UL), -2, 53),
)
let p = iv(16, 16).pow(three_quarters)
inspect(p.lower_bound().to_string() + " " + p.upper_bound().to_string(), content="1p3 1p3")
let r = iv(8, 8).try_rootn(-3).unwrap()
inspect(r.lower_bound().to_string() + " " + r.upper_bound().to_string(), content="1p-1 1p-1")
}
Interval::hypot 与 Interval::try_hypot
hypot 返回 的包络。
pub fn Interval::hypot(Self, Self) -> Self
pub fn Interval::try_hypot(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
该函数关于 和 递增,因此结果为 ,在 abs(x) 与 abs(y) 的端点处求值。全函数形式回退为 sqrt(sqr(x) + sqr(y))。
Interval::sin, Interval::cos, Interval::tan, Interval::try_sin, Interval::try_cos, Interval::try_tan
这些函数返回 、 和 在区间上(以弧度计)的包络。
pub fn Interval::sin(Self) -> Self
pub fn Interval::cos(Self) -> Self
pub fn Interval::tan(Self) -> Self
pub fn Interval::try_sin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tan(Self) -> Result[Self, @arithmetic.ArithmeticError]
两种形式都在端点(点区间)或在端点和临界点处对 binary 的函数求值。区间内的临界点 贡献 sin/cos 的极值 (sin 在 处取 ,在 处取 ;cos 在 处取 ,在 处取 );对于 tan,区间内若有 的奇数倍(极点),结果为 Entire。候选下标 的集合由 的包络计算得出,只可能偏大,这只会使结果变宽而绝不会使其失效。无界参数给出 (对 tan 为 Entire)。当较大端点的绝对值至少为 时,try_ 形式不经求值直接返回资源限制错误;全函数形式返回 (tan 为 Entire),当认证预算(12 个工作精度)耗尽时也使用同样的回退。
Interval::sinpi, Interval::cospi, Interval::tanpi, Interval::try_sinpi, Interval::try_cospi, Interval::try_tanpi
这些函数返回 、 和 的包络。
pub fn Interval::sinpi(Self) -> Self
pub fn Interval::cospi(Self) -> Self
pub fn Interval::tanpi(Self) -> Self
pub fn Interval::try_sinpi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cospi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanpi(Self) -> Result[Self, @arithmetic.ArithmeticError]
此处临界点是精确的半整数 ,由二进有理数端点直接定位,无需近似 。当极点恰好是端点且区间内没有其他极点时,tanpi 返回半无界区间(例如 给出 ,其上界为 0,由 upper_bound 读作 (IEEE 1788-2015 12.12.8); 在 IEEE 754-2019 9.2 中为 ,但存储的零的符号不属于区间);对极点的单点集返回 Empty;当极点位于区间内部时返回 Entire。无界参数和回退给出 (对 tanpi 为 Entire)。
///|
test "trigonometric functions" {
inspect(fmt(iv(0, 4).sin()), content="[-7.56803e-1, 1.00000e+0]")
inspect(fmt(iv(0, 4).cos()), content="[-1.00000e+0, 1.00000e+0]")
inspect(iv(1, 2).tan().is_entire(), content="true")
let half = @binary.Binary::make(@binary.BinCoeff::one(), -1, 53)
let x = @interval.Interval::from_bounds(half, @binary.Binary::one(precision=53))
inspect(fmt(x.sinpi()), content="[-0.00000e+0, 1.00000e+0]")
inspect(fmt(x.tanpi()), content="[-inf, 0.00000e+0]")
}
Interval::asin, Interval::acos, Interval::atan, Interval::try_asin, Interval::try_acos, Interval::try_atan
这些函数返回 、(在 上)和 的包络。
pub fn Interval::asin(Self) -> Self
pub fn Interval::acos(Self) -> Self
pub fn Interval::atan(Self) -> Self
pub fn Interval::try_asin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_acos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atan(Self) -> Result[Self, @arithmetic.ArithmeticError]
asin 和 atan 递增,acos 递减,因此只需对端点求值。无穷端点的 atan 为 。全函数形式的回退对 atan 和 asin 为 ,对 acos 为 ,其中 取自至多 64 位的常数并向外舍入到区间的精度,因此回退本身不会失败。
Interval::atan2 和 Interval::try_atan2
y.atan2(x) 返回矩形 中各点 的辐角 的包络。
pub fn Interval::atan2(Self, Self) -> Self
pub fn Interval::try_atan2(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
接收者是纵坐标。结果是四个角点以及矩形与坐标轴交点处的辐角的包。当矩形跨越分支切割线( 且 )时,结果为 。矩形 给出 Empty。全函数形式回退为 。
Interval::sinh, Interval::cosh, Interval::tanh, Interval::asinh, Interval::acosh, Interval::atanh, Interval::try_sinh, Interval::try_cosh, Interval::try_tanh, Interval::try_asinh, Interval::try_acosh, Interval::try_atanh
这些函数在各自定义域上(acosh 为 ,atanh 为 )返回双曲函数及其反函数的包络。
pub fn Interval::sinh(Self) -> Self
pub fn Interval::cosh(Self) -> Self
pub fn Interval::tanh(Self) -> Self
pub fn Interval::asinh(Self) -> Self
pub fn Interval::acosh(Self) -> Self
pub fn Interval::atanh(Self) -> Self
pub fn Interval::try_sinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_asinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_acosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atanh(Self) -> Result[Self, @arithmetic.ArithmeticError]
cosh 在 0 处取最小值 1,其余函数单调。到达 的 atanh 区间在该侧无界;若区间在定义域闭包中唯一的点是 或 ,则结果为 Empty。全函数形式的回退对 sinh、asinh 和 atanh 为 Entire,对 tanh 为 ,对 cosh 为 ,对 acosh 为 。
全函数形式对很小的参数也保持相对精度,因为它们就是 binary 的内核:在 53 位下, 的 sinh 是两个 ulp 宽的区间 。
///|
test "inverse and hyperbolic functions" {
let unit = iv(-1, 1)
inspect(fmt(unit.asin()), content="[-1.57080e+0, 1.57080e+0]")
inspect(fmt(iv(-2, 2).acos()), content="[-0.00000e+0, 3.14160e+0]")
inspect(fmt(iv(1, 1).atan2(iv(1, 1))), content="[7.85398e-1, 7.85399e-1]")
inspect(fmt(unit.cosh()), content="[1.00000e+0, 1.54309e+0]")
inspect(fmt(unit.atanh()), content="[-inf, inf]")
}
上下文与标志
IntervalContext::new 与 IntervalContext::try_new
IntervalContext::new 由精度和最大指数 e_max 构建上下文;e_min 为 1 - e_max(IEEE 754-2019 3.3)。
pub fn IntervalContext::new(precision? : Int, e_max? : Int) -> Self
pub fn IntervalContext::try_new(precision? : Int, e_max? : Int) -> Result[Self, @arithmetic.ArithmeticError]
默认精度为 53,e_max 的默认值为 binary 的实现上限 binary_value_e_max,与只给出精度的 BinaryContext::new 相同(所以 IntervalContext::new() 不是 binary64:要 binary64 请用 binary64())。这一对参数是否合法由 BinaryContext::try_new 决定,因此 binary 与 interval 对格式只有一个定义:精度在 1 到 binary_precision_max 之间,e_max 至少为 1。非法的参数对使 new 中止并指明参数,对 try_new 则是定义域错误。0.12 之前 e_min 是参数,任何满足 e_min <= e_max 的对都被接受,精度也没有上限。
IntervalContext::with_precision 与 IntervalContext::with_e_max
它们返回精度不同、或最大指数不同(同时 e_min = 1 - e_max)的同一种格式;结果不合法时中止。
pub fn IntervalContext::with_precision(Self, Int) -> Self
pub fn IntervalContext::with_e_max(Self, Int) -> Self
IntervalContext::binary16, IntervalContext::binary32, IntervalContext::binary64, IntervalContext::binary128
它们返回 IEEE 754 交换格式的上下文:binary16(,)、binary32(,)、binary64(,)和 binary128(,)。
pub fn IntervalContext::binary16() -> Self
pub fn IntervalContext::binary32() -> Self
pub fn IntervalContext::binary64() -> Self
pub fn IntervalContext::binary128() -> Self
IntervalContext::precision, IntervalContext::e_min, IntervalContext::e_max
它们返回上下文的参数。
pub fn IntervalContext::precision(Self) -> Int
pub fn IntervalContext::e_min(Self) -> Int
pub fn IntervalContext::e_max(Self) -> Int
IntervalFlags::new, IntervalFlags::combine, IntervalFlags::inexact, IntervalFlags::overflow, IntervalFlags::underflow
IntervalFlags::new 返回未触发任何条件的标志;combine 求二者的并;访问器读取各字段。
pub fn IntervalFlags::new() -> Self
pub fn IntervalFlags::combine(Self, Self) -> Self
pub fn IntervalFlags::inexact(Self) -> Bool
pub fn IntervalFlags::overflow(Self) -> Bool
pub fn IntervalFlags::underflow(Self) -> Bool
Interval::apply_ctx
apply_ctx 将区间向外舍入到上下文中并报告标志。
pub fn Interval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)
每个有限非零端点都向外舍入到上下文精度。舍入后指数超过 的端点发生上溢:若它是负的下端点或正的上端点,则变为 ;否则变为相应符号的最大有限值(正的下端点变为最大有限值,仍低于原值)。随后,低于正规范围的端点在次正规网格 上向外舍入,因此极小的正上端点会变为最小次正规数而不是 0。同一方向的两次舍入等于一次舍入到较粗的网格上,因此所得端点就是所存储端点的定向舍入。零和无穷保持不变。Empty 给出 Empty 且不设任何标志。结果具有上下文精度。
underflow 遵循 IEEE 754,并在舍入之后检测微小性:当端点不精确,且其在指数范围无界时舍入到 位的结果低于 时引发,无论丢失位数的是两步中的哪一步。在 、 时,下端点 变为 ,它已在次正规网格上,并同时引发 inexact 和 underflow。精确的微小端点不引发任何标志。
没有 add_ctx 或 exp_ctx:运算与上下文是组合起来的,即 (x + y).apply_ctx(ctx)。当操作数的精度不低于上下文精度时,这种两次舍入得到的端点与一次向外舍入到上下文所得的端点相同(参见设计文档)。
Interval::midpoint_ctx
midpoint_ctx 是以上下文为结果格式的 IEEE 1788 mid 运算。
pub fn Interval::midpoint_ctx(Self, IntervalContext) -> (@binary.Binary, IntervalFlags)
按照 IEEE 1788-2015 §12.12.8,Empty 给出 NaN,Entire 给出 ,仅上方无界的区间给出上下文的最大有限值 ,仅下方无界的区间给出其相反数;这些情形都不引发标志。有界区间给出其精确中心一次性按就近舍入(平局取偶)到上下文网格(包括次正规网格 )上的值,因此在 、 时,中心 给出 。零中心给出 。结果与中心不同时设置 inexact,若同时为微小值则设置 underflow,与 apply_ctx 相同。舍入后超出 的中心溢出为同号的无穷,并设置 overflow 和 inexact:在 IEEE 754 中就近舍入将其映射为 ,而 IEEE 1788 在有界情形下使用的正是这种舍入。只有端点本身就超出上下文范围的区间才会出现这种情况。
///|
test "contexts" {
let ctx = @interval.IntervalContext::new(precision=8, e_max=10)
let (third, flags) = (iv(1, 1) / iv(3, 3)).apply_ctx(ctx)
inspect(third.lower_bound().to_string(), content="85p-8")
inspect(third.upper_bound().to_string(), content="171p-9")
inspect(flags.inexact(), content="true")
let (big, big_flags) = iv(5000, 5000).apply_ctx(ctx)
inspect(fmt(big), content="[2.04000e+3, inf]")
inspect(big_flags.overflow(), content="true")
let merged = flags.combine(big_flags)
inspect(merged.overflow() && merged.inexact(), content="true")
}
装饰区间
装饰运算计算裸结果以及装饰 ,其中 是操作数的装饰, 是该运算在这些操作数上的装饰(当函数在整个输入矩形上有定义且连续时为 Com,当输入超出定义域时为 Trv,如下文所列)。随后将该最小值规范化(Empty → Trv,无界且为 Com → Dac)。任何 NaI 操作数都给出 NaI。
DecoratedInterval::new
DecoratedInterval::new 为裸区间添加装饰。
pub fn DecoratedInterval::new(Interval, decoration? : Decoration) -> Self
默认装饰为 Com。new 就是 IEEE 1788-2015 第 11.5.2 条的 setDec:装饰 Ill 对任何区间(无论是否为空)都给出 NaI(精度与该区间相同,因此结果等于 DecoratedInterval::nai);否则装饰会被规范化,所以 new(entire()) 的装饰为 Dac,new(empty()) 的装饰为 Trv,与 IEEE 1788 的 newDec 一致。
DecoratedInterval::nai 与 DecoratedInterval::is_nai
nai 返回 NaI,即无效装饰构造的结果;is_nai 检测它。
pub fn DecoratedInterval::nai(precision? : Int) -> Self
pub fn DecoratedInterval::is_nai(Self) -> Bool
NaI 的装饰为 Ill,区间为 Empty(默认精度 53),但它不是 Empty:对 NaI,is_empty 为假。
DecoratedInterval::interval 与 DecoratedInterval::decoration
它们返回裸区间和装饰。
pub fn DecoratedInterval::interval(Self) -> Interval
pub fn DecoratedInterval::decoration(Self) -> Decoration
DecoratedInterval::is_empty, DecoratedInterval::is_entire, DecoratedInterval::is_common_interval, DecoratedInterval::is_singleton, DecoratedInterval::is_member
这些谓词将相应的裸谓词作用于区间,对 NaI 返回假。
pub fn DecoratedInterval::is_empty(Self) -> Bool
pub fn DecoratedInterval::is_entire(Self) -> Bool
pub fn DecoratedInterval::is_common_interval(Self) -> Bool
pub fn DecoratedInterval::is_singleton(Self) -> Bool
pub fn DecoratedInterval::is_member(Self, @binary.Binary) -> Bool
DecoratedInterval::equal, DecoratedInterval::identical, DecoratedInterval::subset, DecoratedInterval::interior, DecoratedInterval::disjoint, DecoratedInterval::less, DecoratedInterval::strict_less, DecoratedInterval::precedes, DecoratedInterval::strict_precedes, DecoratedInterval::overlap
这些关系将相应的裸关系作用于区间,当有操作数为 NaI 时返回假,但 identical 除外,它是数据本身的相等(IEEE 1788-2015 12.3):两个 NaI 时为真,NaI 与任何其他值比较时为假。
pub fn DecoratedInterval::equal(Self, Self) -> Bool
pub fn DecoratedInterval::identical(Self, Self) -> Bool
pub fn DecoratedInterval::subset(Self, Self) -> Bool
pub fn DecoratedInterval::interior(Self, Self) -> Bool
pub fn DecoratedInterval::disjoint(Self, Self) -> Bool
pub fn DecoratedInterval::less(Self, Self) -> Bool
pub fn DecoratedInterval::strict_less(Self, Self) -> Bool
pub fn DecoratedInterval::precedes(Self, Self) -> Bool
pub fn DecoratedInterval::strict_precedes(Self, Self) -> Bool
pub fn DecoratedInterval::overlap(Self, Self) -> OverlapState?
当某个操作数为 NaI 时,overlap 返回 None,因为对非区间值的运算,NaI 没有值(IEEE 1788-2015 11.7.2);否则返回 Some(state)。
DecoratedInterval::intersection, DecoratedInterval::convex_hull, DecoratedInterval::cancel_plus, DecoratedInterval::cancel_minus
这些函数应用裸运算,并总是将装饰降为 Trv(集合运算不是逐点函数,因此无法对其结果断言函数的任何性质)。
pub fn DecoratedInterval::intersection(Self, Self) -> Self
pub fn DecoratedInterval::convex_hull(Self, Self) -> Self
pub fn DecoratedInterval::cancel_plus(Self, Self) -> Self
pub fn DecoratedInterval::cancel_minus(Self, Self) -> Self
DecoratedInterval::add, DecoratedInterval::sub, DecoratedInterval::mul, DecoratedInterval::div, DecoratedInterval::pos, DecoratedInterval::neg, DecoratedInterval::abs, DecoratedInterval::recip, DecoratedInterval::sqr, DecoratedInterval::pown, DecoratedInterval::fma, DecoratedInterval::min, DecoratedInterval::max
算术运算应用裸运算;除表中另有说明外,其运算装饰为 Com。
pub fn DecoratedInterval::add(Self, Self) -> Self
pub fn DecoratedInterval::sub(Self, Self) -> Self
pub fn DecoratedInterval::mul(Self, Self) -> Self
pub fn DecoratedInterval::div(Self, Self) -> Self
pub fn DecoratedInterval::pos(Self) -> Self
pub fn DecoratedInterval::neg(Self) -> Self
pub fn DecoratedInterval::abs(Self) -> Self
pub fn DecoratedInterval::recip(Self) -> Self
pub fn DecoratedInterval::sqr(Self) -> Self
pub fn DecoratedInterval::pown(Self, Int) -> Self
pub fn DecoratedInterval::fma(Self, Self, Self) -> Self
pub fn DecoratedInterval::min(Self, Self) -> Self
pub fn DecoratedInterval::max(Self, Self) -> Self
| 操作 | 运算装饰 |
|---|---|
div, recip | 除数包含 0 时为 Trv |
pown(x, n) | 当 且 时为 Trv |
pos | 恒等(IEEE 1788 pos) |
| 其他 | Com |
DecoratedInterval::sqrt, DecoratedInterval::exp, DecoratedInterval::exp2, DecoratedInterval::exp10, DecoratedInterval::expm1, DecoratedInterval::ln, DecoratedInterval::log2, DecoratedInterval::log10, DecoratedInterval::log1p, DecoratedInterval::pow, DecoratedInterval::rootn, DecoratedInterval::hypot
装饰初等函数应用裸的全函数形式(没有装饰版的 try_ 形式),并在输入超出函数定义域时降低装饰,具体见本组末尾的表格。
这些是装饰版的平方根、指数函数、对数函数、幂函数以及 hypot。
pub fn DecoratedInterval::sqrt(Self) -> Self
pub fn DecoratedInterval::exp(Self) -> Self
pub fn DecoratedInterval::exp2(Self) -> Self
pub fn DecoratedInterval::exp10(Self) -> Self
pub fn DecoratedInterval::expm1(Self) -> Self
pub fn DecoratedInterval::ln(Self) -> Self
pub fn DecoratedInterval::log2(Self) -> Self
pub fn DecoratedInterval::log10(Self) -> Self
pub fn DecoratedInterval::log1p(Self) -> Self
pub fn DecoratedInterval::pow(Self, Self) -> Self
pub fn DecoratedInterval::rootn(Self, Int) -> Self
pub fn DecoratedInterval::hypot(Self, Self) -> Self
DecoratedInterval::sign, DecoratedInterval::ceil, DecoratedInterval::floor, DecoratedInterval::trunc, DecoratedInterval::round_ties_to_even, DecoratedInterval::round_ties_to_away
区间部分是裸结果。操作装饰是 11.2 中该函数在输入盒上的最强装饰,结果是它与输入装饰的最小值(11.6,式 18):
| 输入盒 | 运算装饰 |
|---|---|
| Empty | Trv |
| 函数在 上不是常数 | Def |
| 为常数,且 无界 | Dac |
| 为常数、有界,且 含有该函数在实数轴上的一个不连续点 | Dac |
| 为常数、有界,且 中没有这样的点 | Com |
这些函数取整数值,因此它们在 上的限制连续当且仅当为常数(dac 要求限制连续,com 要求在 的每个点处连续)。不连续点:ceil 和 floor 为整数,trunc 为非零整数,sign 为 ,两个舍入函数为半整数。例如盒 的 ceil 为 ,装饰为 Dac:限制是常数,但 是 ceil 的不连续点。同一个盒的 floor 为 ,装饰为 Def。NaI 给出 NaI。
pub fn DecoratedInterval::sign(Self) -> Self
pub fn DecoratedInterval::ceil(Self) -> Self
pub fn DecoratedInterval::floor(Self) -> Self
pub fn DecoratedInterval::trunc(Self) -> Self
pub fn DecoratedInterval::round_ties_to_even(Self) -> Self
pub fn DecoratedInterval::round_ties_to_away(Self) -> Self
DecoratedInterval::sqr_rev、DecoratedInterval::abs_rev、DecoratedInterval::pown_rev 与 DecoratedInterval::cosh_rev
反向模式运算采用 11.7.1 的平凡装饰版本:任一输入(区间或先验)为 NaI 则为 NaI,否则为装饰 Trv 的裸结果。
pub fn DecoratedInterval::sqr_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::abs_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::pown_rev(Self, Int, x? : Self) -> Self
pub fn DecoratedInterval::cosh_rev(Self, x? : Self) -> Self
DecoratedInterval::sin_rev、DecoratedInterval::cos_rev 与 DecoratedInterval::tan_rev
11.7.1 的平凡装饰版本:任一输入(区间或先验)为 NaI 则为 NaI,否则为装饰 Trv 的裸结果。
pub fn DecoratedInterval::sin_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::cos_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::tan_rev(Self, x? : Self) -> Self
DecoratedInterval::pow_rev1
11.7.1 的平凡装饰版本:任一输入为 NaI 则为 NaI,否则为装饰 Trv 的裸结果。
pub fn DecoratedInterval::pow_rev1(Self, Self, x? : Self) -> Self
DecoratedInterval::mul_rev_to_pair 与 DecoratedInterval::mul_rev
mul_rev_to_pair 遵循 12.12.3。任一输入为 NaI 时两个输出都是 NaI。否则,当两者非空且 时,第一个输出是带装饰的商 (装饰与 / 相同),第二个输出是装饰为 Trv 的 Empty。其他所有输出,无论是否为空,都装饰为 Trv。mul_rev 是反向模式运算,采用 11.7.1 的平凡装饰版本:任一输入为 NaI 则为 NaI,否则为装饰 Trv 的裸结果。
pub fn DecoratedInterval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn DecoratedInterval::mul_rev(Self, Self, x? : Self) -> Self
DecoratedInterval::sin, DecoratedInterval::cos, DecoratedInterval::tan, DecoratedInterval::sinpi, DecoratedInterval::cospi, DecoratedInterval::tanpi, DecoratedInterval::asin, DecoratedInterval::acos, DecoratedInterval::atan, DecoratedInterval::atan2
这些是装饰版的三角函数及其反函数。
pub fn DecoratedInterval::sin(Self) -> Self
pub fn DecoratedInterval::cos(Self) -> Self
pub fn DecoratedInterval::tan(Self) -> Self
pub fn DecoratedInterval::sinpi(Self) -> Self
pub fn DecoratedInterval::cospi(Self) -> Self
pub fn DecoratedInterval::tanpi(Self) -> Self
pub fn DecoratedInterval::asin(Self) -> Self
pub fn DecoratedInterval::acos(Self) -> Self
pub fn DecoratedInterval::atan(Self) -> Self
pub fn DecoratedInterval::atan2(Self, Self) -> Self
DecoratedInterval::sinh, DecoratedInterval::cosh, DecoratedInterval::tanh, DecoratedInterval::asinh, DecoratedInterval::acosh, DecoratedInterval::atanh
这些是装饰版的双曲函数及其反函数。
pub fn DecoratedInterval::sinh(Self) -> Self
pub fn DecoratedInterval::cosh(Self) -> Self
pub fn DecoratedInterval::tanh(Self) -> Self
pub fn DecoratedInterval::asinh(Self) -> Self
pub fn DecoratedInterval::acosh(Self) -> Self
pub fn DecoratedInterval::atanh(Self) -> Self
| 函数 | 运算装饰为 Trv 的条件 |
|---|---|
sqrt | (或输入为 Empty) |
ln, log2, log10 | |
log1p | |
asin, acos | |
acosh | |
atanh | 或 |
rootn(x, n) | ,或 为偶数且 ,或 且 |
pow(x, y) | ,或 且 ,或结果为 Empty |
tan | 结果为 Entire(内部可能有极点) |
tanpi | 结果无界(参数中含有极点,可能位于端点) |
atan2 | 两个操作数都包含 0 |
其他所有函数的运算装饰均为 Com。对于 y.atan2(x),当矩形跨越分支切割线(,:限制函数从 跳到 )时装饰为 Def,当它从上方触及切割线(,:限制函数连续,但 atan2 本身在这些点不连续)时装饰为 Dac。
DecoratedInterval::apply_ctx
apply_ctx 将 Interval::apply_ctx 应用于区间并保留装饰(会再次规范化,因此发生上溢的 Com 变为 Dac)。
pub fn DecoratedInterval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)
NaI 仍为 NaI,并带上上下文精度。
///|
test "decorated intervals" {
let x = @interval.DecoratedInterval::new(iv(-1, 4))
inspect(x.sqrt().decoration(), content="trv")
inspect(x.exp().decoration(), content="com")
inspect((x / x).decoration(), content="trv")
inspect(@interval.DecoratedInterval::new(iv(0, 4)).rootn(-2).decoration(), content="trv")
let half = @binary.Binary::make(@binary.BinCoeff::one(), -1, 53)
let pole = @interval.DecoratedInterval::new(
@interval.Interval::from_bounds(half, @binary.Binary::one(precision=53)),
)
inspect(pole.tanpi().decoration(), content="trv")
let unbounded = @interval.DecoratedInterval::new(@interval.Interval::entire())
inspect(unbounded.decoration(), content="dac")
let nai = @interval.DecoratedInterval::nai()
inspect((x + nai).to_string(), content="[nai]")
debug_inspect(nai.overlap(x), content="None")
}
trait 实现
Interval 和 DecoratedInterval 的 Add、Sub、Mul、Div 和 Neg
Interval 实现了 Add、Sub、Mul、Div 和 Neg;DecoratedInterval 实现了 Add、Sub、Mul 和 Div。这些运算符调用同名方法。
pub impl Add for Interval
pub impl Sub for Interval
pub impl Mul for Interval
pub impl Div for Interval
pub impl Neg for Interval
pub impl Add for DecoratedInterval
pub impl Sub for DecoratedInterval
pub impl Mul for DecoratedInterval
pub impl Div for DecoratedInterval
Interval::to_string, Interval::output, DecoratedInterval::to_string, DecoratedInterval::output, Decoration::to_string, Decoration::output
Show 把区间写成 IEEE 1788-2015 13.3(intervalToText)的可移植 inf-sup 字面量:即 from_string 能读入的文本。
pub impl Show for Interval
pub fn Interval::to_string(Self) -> String
pub fn Interval::output(Self, &Logger) -> Unit
pub impl Show for DecoratedInterval
pub fn DecoratedInterval::to_string(Self) -> String
pub fn DecoratedInterval::output(Self, &Logger) -> Unit
pub impl Show for Decoration
pub fn Decoration::to_string(Self) -> String
pub fn Decoration::output(Self, &Logger) -> Unit
非空的有界或半有界区间写成 [l, u],空区间写成 [empty],全集写成 [entire];带装饰的区间在其后追加 _ 与装饰,NaI 写成 [nai]。每个端点是向外舍入的十进制数(下端点向下、上端点向上),因此该文本是包含该值的区间的字面量(13.3)。所用位数是使端点距所存端点不超过区间精度下一个末位单位的最少位数,所以 from_string(text, precision=x.precision()) 包含 x,且两端至多各宽一个末位单位。二进制指数的绝对值超过 4096 的端点用十六进制书写(0x3p1073741000),因为它的十进制展开需要那么大的十的幂;十六进制端点是精确的,也是合法的字面量。零端点写成 0,不带符号,无论它带什么符号: 的字面量不携带 lower_bound 与 upper_bound 返回的符号( 与 ,12.12.8),13.3 也不要求。
///|
test "show" {
inspect(iv(1, 2).to_string(), content="[1, 2]")
inspect(@interval.Interval::entire().to_string(), content="[entire]")
inspect(@interval.DecoratedInterval::new(iv(1, 2)).to_string(), content="[1, 2]_com")
}
Interval::to_exact_string, Interval::from_exact_string, DecoratedInterval::to_exact_string, DecoratedInterval::from_exact_string
IEEE 1788-2015 13.4 的 intervalToExact 与 exactToInterval:指明区间本身的文本。
pub fn Interval::to_exact_string(Self) -> String
pub fn Interval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::to_exact_string(Self) -> String
pub fn DecoratedInterval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
文本是 [empty]、[entire] 或 [l, u],端点写成十六进制数(0x1fffffp-3;无穷端点写 inf 与 -inf),带装饰的区间再加 _ 与装饰(NaI 为 [nai])。这些端点就是所存储的端点,所以 from_exact_string(x.to_exact_string(), precision=x.precision()) 与 x identical(不写带符号的零,13.4)。from_exact_string 按文本精确读入,绝不变宽。文本中的端点必须是 precision 位格式的数,与每个存储的端点一样:有效位多于 precision 的端点(0x1.00000000000001p0 有 57 位,与文本里有几个尾随的零无关,在 precision=57 下可读,在 53 下被拒绝)、超出本库指数范围的端点,或比范围下限以下 precision 位的网格更细的端点,会被拒绝并给出说明原因的解析错误;十进制或格式错误的端点、下端点大于上端点同样被拒绝。哪些端点能被表示由 IEEE 754-2019 5.12.3 的转换器决定(Binary::from_hex_ctx 报告 inexact),而不是数文本的位数,因此带小数部分的尾数(0x1.8p0、0x.8p1)、前导与尾随的零位以及大写都能读入。0.12 之前更宽的端点会被接受,并带有它自身位数的标签,因为该类型当时可以持有这样的端点;现在不能了。
///|
test "exact text" {
let x = iv(1, 2)
inspect(x.to_exact_string(), content="[0x1p0, 0x1p1]")
let back = @interval.Interval::from_exact_string(x.to_exact_string()).unwrap()
assert_true(x.identical(back))
}
Interval::to_midpoint_radius_string, DecoratedInterval::to_midpoint_radius_string
中点–半径视图,midpoint +/- radius:IEEE 1788-2015 12.12.8 的两个函数(Interval::midpoint 与 Interval::radius),是该区间格式中的数,以 Binary 记法写出(3p-1 即 )。半径以中点为中心,覆盖两个端点,所以打印出的这一对包含该区间。0.12 之前 Show 打印该视图;此后它供阅读,不是字面量(from_string 不读它),其代价不依赖指数范围:端点指数相差十亿的区间也只写 位的数。有无穷端点的区间按二进制数 [l, u] 打印,Empty 打印为 [empty];带装饰的区间追加 _ 与装饰。0.12 的这一改动之前,文本打印精确的中心与半宽,对相距超过 65,536 位的端点则打印约 65,000 位的数。
pub fn Interval::to_midpoint_radius_string(Self) -> String
pub fn DecoratedInterval::to_midpoint_radius_string(Self) -> String
Interval::equal, Interval::not_equal, Interval::to_repr, DecoratedInterval::equal, DecoratedInterval::not_equal, IntervalFlags::equal, IntervalFlags::not_equal
这些是各结构体派生的 Eq 和 Debug 方法。
pub fn Interval::equal(Self, Self) -> Bool
pub fn Interval::not_equal(Self, Self) -> Bool
pub fn Interval::to_repr(Self) -> @debug.Repr
pub fn DecoratedInterval::equal(Self, Self) -> Bool
pub fn DecoratedInterval::not_equal(Self, Self) -> Bool
pub fn IntervalFlags::equal(Self, Self) -> Bool
pub fn IntervalFlags::not_equal(Self, Self) -> Bool
Decoration::equal, Decoration::not_equal, Decoration::to_repr, OverlapState::equal, OverlapState::not_equal, OverlapState::to_repr
这些是各枚举派生的 Eq 和 Debug 方法。
pub fn Decoration::equal(Self, Self) -> Bool
pub fn Decoration::not_equal(Self, Self) -> Bool
pub fn Decoration::to_repr(Self) -> @debug.Repr
pub fn OverlapState::equal(Self, Self) -> Bool
pub fn OverlapState::not_equal(Self, Self) -> Bool
pub fn OverlapState::to_repr(Self) -> @debug.Repr
Interval 和 DecoratedInterval 的 Eq 实现是 IEEE 1788-2015(12.12.9)的 equal 关系,而不是表示的相等:== 比较集合,忽略精度标记;在带装饰的区间上,只要有一个操作数是 NaI 它就为假,所以 NaI 不等于它自己(NaN 同理),并且装饰被忽略。identical 是数据本身的相等。to_repr 给出结构化的 Debug 形式。Decoration 和 OverlapState 的 Eq 是各变体的相等。
@arithmetic.Contains, @arithmetic.Overlaps, @arithmetic.DefinitelyLt, @arithmetic.DefinitelyLe, @arithmetic.MaybeEq
Interval 实现了 Luna-Flow/arithmetic 的包络关系 trait。
pub impl @arithmetic.Contains for Interval
pub impl @arithmetic.Overlaps for Interval
pub impl @arithmetic.DefinitelyLt for Interval
pub impl @arithmetic.DefinitelyLe for Interval
pub impl @arithmetic.MaybeEq for Interval
Contains::contains(x, y) 即 y.subset(x)(集合的包含,而不是接受点的那个方法)。Overlaps::overlaps(x, y) 为 ,即 ,MaybeEq::maybe_eq 是同一关系,读作“两个未知的点可能相等”。DefinitelyLt::definitely_lt(x, y) 为 ,DefinitelyLe::definitely_le(x, y) 为 :它们在对每一对点该序都成立时成立。四者在某个操作数为 Empty 时都为假。这与 disjoint、precedes 和 strict_precedes 不同,后三者在操作数为 Empty 时为真(IEEE 1788-2015 表 10.4):overlaps 为假之处 disjoint 为真,definitely_lt 为假之处 strict_precedes 为真,因此这些 trait 返回 true 时总有至少一对点作为依据。它们是 Luna-Flow/arithmetic 的通用接口;区间包用 disjoint、precedes 和 strict_precedes 来拼写标准关系。
Interval::div_checked, Interval::pow_nat_checked, Interval::pow_int_checked
Interval 实现了 DivChecked、PowNatChecked 和 PowIntChecked;它们的方法被提升为该类型的方法。
pub impl @arithmetic.DivChecked for Interval
pub impl @arithmetic.PowNatChecked for Interval
pub impl @arithmetic.PowIntChecked for Interval
pub fn Interval::div_checked(Self, Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
只使用 ctx.precision:操作数先用 with_precision 重新舍入到该精度,再应用运算,然后将结果向外重新舍入(参见 Interval::with_precision)。在操作数自身的精度下,结果与普通运算相同;在更低的精度下结果可能更宽。它们总是返回 Ok。div_checked 遵循上述除法规则(除数包含 0 时给出无界结果,而不是错误)。pow_int_checked 使用 pown。pow_nat_checked 通过重复的区间乘法进行二进制求幂,这会把各因子视为相互独立:对于包含 0 的参数,其结果比 pown 更宽。与 pown 一样,Empty 底数对任何指数(包括 0)都给出 Empty。
///|
test "checked capabilities" {
let ctx = @lf_arith.ArithmeticContext::new(53)
let x = iv(-1, 2)
inspect(fmt(x.pow_int_checked(2, ctx).unwrap()), content="[-0.00000e+0, 4.00000e+0]")
inspect(fmt(x.pow_nat_checked(2U, ctx).unwrap()), content="[-2.00000e+0, 4.00000e+0]")
inspect(x.div_checked(iv(-1, 1), ctx).unwrap().is_entire(), content="true")
inspect(@lf_arith.Contains::contains(iv(0, 9), iv(1, 2)), content="true")
}
完整公共接口
此快照是该包生成的 pkg.generated.mbti。当正文与接口不一致时,以接口为准。
// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating/interval"
import {
"Luna-Flow/arithmetic",
"Luna-Flow/floating/binary",
"moonbitlang/core/debug",
}
// Values
pub let interval_literal_max_length : Int32
// Errors
// Types and methods
pub struct DecoratedInterval {
// private fields
}
pub fn DecoratedInterval::abs(Self) -> Self
pub fn DecoratedInterval::abs_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::acos(Self) -> Self
pub fn DecoratedInterval::acosh(Self) -> Self
pub fn DecoratedInterval::add(Self, Self) -> Self
pub fn DecoratedInterval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)
pub fn DecoratedInterval::asin(Self) -> Self
pub fn DecoratedInterval::asinh(Self) -> Self
pub fn DecoratedInterval::atan(Self) -> Self
pub fn DecoratedInterval::atan2(Self, Self) -> Self
pub fn DecoratedInterval::atan2_rev1(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::atan2_rev2(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::atanh(Self) -> Self
pub fn DecoratedInterval::cancel_minus(Self, Self) -> Self
pub fn DecoratedInterval::cancel_plus(Self, Self) -> Self
pub fn DecoratedInterval::ceil(Self) -> Self
pub fn DecoratedInterval::convex_hull(Self, Self) -> Self
pub fn DecoratedInterval::cos(Self) -> Self
pub fn DecoratedInterval::cos_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::cosh(Self) -> Self
pub fn DecoratedInterval::cosh_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::cospi(Self) -> Self
pub fn DecoratedInterval::decoration(Self) -> Decoration
pub fn DecoratedInterval::disjoint(Self, Self) -> Bool
pub fn DecoratedInterval::div(Self, Self) -> Self
pub fn DecoratedInterval::equal(Self, Self) -> Bool
pub fn DecoratedInterval::exp(Self) -> Self
pub fn DecoratedInterval::exp10(Self) -> Self
pub fn DecoratedInterval::exp2(Self) -> Self
pub fn DecoratedInterval::expm1(Self) -> Self
pub fn DecoratedInterval::floor(Self) -> Self
pub fn DecoratedInterval::fma(Self, Self, Self) -> Self
pub fn DecoratedInterval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::from_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::hypot(Self, Self) -> Self
pub fn DecoratedInterval::identical(Self, Self) -> Bool
pub fn DecoratedInterval::interior(Self, Self) -> Bool
pub fn DecoratedInterval::intersection(Self, Self) -> Self
pub fn DecoratedInterval::interval(Self) -> Interval
pub fn DecoratedInterval::is_common_interval(Self) -> Bool
pub fn DecoratedInterval::is_empty(Self) -> Bool
pub fn DecoratedInterval::is_entire(Self) -> Bool
pub fn DecoratedInterval::is_member(Self, @binary.Binary) -> Bool
pub fn DecoratedInterval::is_nai(Self) -> Bool
pub fn DecoratedInterval::is_singleton(Self) -> Bool
pub fn DecoratedInterval::less(Self, Self) -> Bool
pub fn DecoratedInterval::ln(Self) -> Self
pub fn DecoratedInterval::log10(Self) -> Self
pub fn DecoratedInterval::log1p(Self) -> Self
pub fn DecoratedInterval::log2(Self) -> Self
pub fn DecoratedInterval::max(Self, Self) -> Self
pub fn DecoratedInterval::min(Self, Self) -> Self
pub fn DecoratedInterval::mul(Self, Self) -> Self
pub fn DecoratedInterval::mul_rev(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn DecoratedInterval::nai(precision? : Int32) -> Self
pub fn DecoratedInterval::neg(Self) -> Self
pub fn DecoratedInterval::new(Interval, decoration? : Decoration) -> Self
pub fn DecoratedInterval::not_equal(Self, Self) -> Bool
pub fn DecoratedInterval::output(Self, &Logger) -> Unit
pub fn DecoratedInterval::overlap(Self, Self) -> OverlapState?
pub fn DecoratedInterval::pos(Self) -> Self
pub fn DecoratedInterval::pow(Self, Self) -> Self
pub fn DecoratedInterval::pow_rev1(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::pow_rev2(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::pown(Self, Int32) -> Self
pub fn DecoratedInterval::pown_rev(Self, Int32, x? : Self) -> Self
pub fn DecoratedInterval::precedes(Self, Self) -> Bool
pub fn DecoratedInterval::recip(Self) -> Self
pub fn DecoratedInterval::rootn(Self, Int32) -> Self
pub fn DecoratedInterval::round_ties_to_away(Self) -> Self
pub fn DecoratedInterval::round_ties_to_even(Self) -> Self
pub fn DecoratedInterval::sign(Self) -> Self
pub fn DecoratedInterval::sin(Self) -> Self
pub fn DecoratedInterval::sin_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::sinh(Self) -> Self
pub fn DecoratedInterval::sinpi(Self) -> Self
pub fn DecoratedInterval::sqr(Self) -> Self
pub fn DecoratedInterval::sqr_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::sqrt(Self) -> Self
pub fn DecoratedInterval::strict_less(Self, Self) -> Bool
pub fn DecoratedInterval::strict_precedes(Self, Self) -> Bool
pub fn DecoratedInterval::sub(Self, Self) -> Self
pub fn DecoratedInterval::subset(Self, Self) -> Bool
pub fn DecoratedInterval::tan(Self) -> Self
pub fn DecoratedInterval::tan_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::tanh(Self) -> Self
pub fn DecoratedInterval::tanpi(Self) -> Self
pub fn DecoratedInterval::to_exact_string(Self) -> String
pub fn DecoratedInterval::to_midpoint_radius_string(Self) -> String
pub fn DecoratedInterval::to_string(Self) -> String
pub fn DecoratedInterval::trunc(Self) -> Self
pub impl Add for DecoratedInterval
pub impl Div for DecoratedInterval
pub impl Eq for DecoratedInterval
pub impl Mul for DecoratedInterval
pub impl Show for DecoratedInterval
pub impl Sub for DecoratedInterval
#derive(Compare, Eq, @debug.Debug)
pub(all) enum Decoration {
Ill
Trv
Def
Dac
Com
}
pub fn Decoration::equal(Self, Self) -> Bool
pub fn Decoration::not_equal(Self, Self) -> Bool
pub fn Decoration::output(Self, &Logger) -> Unit
pub fn Decoration::to_repr(Self) -> @debug.Repr
pub fn Decoration::to_string(Self) -> String
pub impl Show for Decoration
#derive(@debug.Debug)
pub struct Interval {
// private fields
}
pub fn Interval::abs(Self) -> Self
pub fn Interval::abs_rev(Self, x? : Self) -> Self
pub fn Interval::acos(Self) -> Self
pub fn Interval::acosh(Self) -> Self
pub fn Interval::add(Self, Self) -> Self
pub fn Interval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)
pub fn Interval::asin(Self) -> Self
pub fn Interval::asinh(Self) -> Self
pub fn Interval::atan(Self) -> Self
pub fn Interval::atan2(Self, Self) -> Self
pub fn Interval::atan2_rev1(Self, Self, x? : Self) -> Self
pub fn Interval::atan2_rev2(Self, Self, x? : Self) -> Self
pub fn Interval::atanh(Self) -> Self
pub fn Interval::cancel_minus(Self, Self) -> Self
pub fn Interval::cancel_plus(Self, Self) -> Self
pub fn Interval::ceil(Self) -> Self
pub fn Interval::convex_hull(Self, Self) -> Self
pub fn Interval::cos(Self) -> Self
pub fn Interval::cos_rev(Self, x? : Self) -> Self
pub fn Interval::cosh(Self) -> Self
pub fn Interval::cosh_rev(Self, x? : Self) -> Self
pub fn Interval::cospi(Self) -> Self
pub fn Interval::disjoint(Self, Self) -> Bool
pub fn Interval::div(Self, Self) -> Self
pub fn Interval::div_checked(Self, Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::empty(precision? : Int32) -> Self
pub fn Interval::entire(precision? : Int32) -> Self
pub fn Interval::equal(Self, Self) -> Bool
pub fn Interval::exact(@binary.Binary, precision? : Int32) -> Self
pub fn Interval::exp(Self) -> Self
pub fn Interval::exp10(Self) -> Self
pub fn Interval::exp2(Self) -> Self
pub fn Interval::expm1(Self) -> Self
pub fn Interval::floor(Self) -> Self
pub fn Interval::fma(Self, Self, Self) -> Self
pub fn Interval::from_bounds(@binary.Binary, @binary.Binary, precision? : Int32) -> Self
pub fn Interval::from_coefficient(@binary.BinCoeff, precision? : Int32, negative? : Bool) -> Self
pub fn Interval::from_double(Double, precision? : Int32) -> Self
pub fn Interval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::from_float(Float, precision? : Int32) -> Self
pub fn Interval::from_int(Int32, precision~ : Int32) -> Self
pub fn Interval::from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int32) -> Self
pub fn Interval::from_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::hypot(Self, Self) -> Self
pub fn Interval::identical(Self, Self) -> Bool
pub fn Interval::interior(Self, Self) -> Bool
pub fn Interval::intersection(Self, Self) -> Self
pub fn Interval::is_common_interval(Self) -> Bool
pub fn Interval::is_empty(Self) -> Bool
pub fn Interval::is_entire(Self) -> Bool
pub fn Interval::is_member(Self, @binary.Binary) -> Bool
pub fn Interval::is_singleton(Self) -> Bool
pub fn Interval::less(Self, Self) -> Bool
pub fn Interval::ln(Self) -> Self
pub fn Interval::log10(Self) -> Self
pub fn Interval::log1p(Self) -> Self
pub fn Interval::log2(Self) -> Self
pub fn Interval::lower_bound(Self) -> @binary.Binary
pub fn Interval::magnitude(Self) -> @binary.Binary
pub fn Interval::max(Self, Self) -> Self
pub fn Interval::midpoint(Self) -> @binary.Binary
pub fn Interval::midpoint_ctx(Self, IntervalContext) -> (@binary.Binary, IntervalFlags)
pub fn Interval::mignitude(Self) -> @binary.Binary
pub fn Interval::min(Self, Self) -> Self
pub fn Interval::mul(Self, Self) -> Self
pub fn Interval::mul_rev(Self, Self, x? : Self) -> Self
pub fn Interval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn Interval::neg(Self) -> Self
pub fn Interval::normalized(Self) -> Self
pub fn Interval::not_equal(Self, Self) -> Bool
pub fn Interval::output(Self, &Logger) -> Unit
pub fn Interval::overlap(Self, Self) -> OverlapState
pub fn Interval::pow(Self, Self) -> Self
pub fn Interval::pow_int_checked(Self, Int32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_nat_checked(Self, UInt32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_rev1(Self, Self, x? : Self) -> Self
pub fn Interval::pow_rev2(Self, Self, x? : Self) -> Self
pub fn Interval::pown(Self, Int32) -> Self
pub fn Interval::pown_rev(Self, Int32, x? : Self) -> Self
pub fn Interval::precedes(Self, Self) -> Bool
pub fn Interval::precision(Self) -> Int32
pub fn Interval::radius(Self) -> @binary.Binary
pub fn Interval::recip(Self) -> Self
pub fn Interval::rootn(Self, Int32) -> Self
pub fn Interval::round_ties_to_away(Self) -> Self
pub fn Interval::round_ties_to_even(Self) -> Self
pub fn Interval::sign(Self) -> Self
pub fn Interval::sin(Self) -> Self
pub fn Interval::sin_rev(Self, x? : Self) -> Self
pub fn Interval::sinh(Self) -> Self
pub fn Interval::sinpi(Self) -> Self
pub fn Interval::sqr(Self) -> Self
pub fn Interval::sqr_rev(Self, x? : Self) -> Self
pub fn Interval::sqrt(Self) -> Self
pub fn Interval::strict_less(Self, Self) -> Bool
pub fn Interval::strict_precedes(Self, Self) -> Bool
pub fn Interval::sub(Self, Self) -> Self
pub fn Interval::subset(Self, Self) -> Bool
pub fn Interval::tan(Self) -> Self
pub fn Interval::tan_rev(Self, x? : Self) -> Self
pub fn Interval::tanh(Self) -> Self
pub fn Interval::tanpi(Self) -> Self
pub fn Interval::to_exact_string(Self) -> String
pub fn Interval::to_midpoint_radius_string(Self) -> String
pub fn Interval::to_repr(Self) -> @debug.Repr
pub fn Interval::to_string(Self) -> String
pub fn Interval::trunc(Self) -> Self
pub fn Interval::try_acos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_acosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_asin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_asinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atan(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atan2(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atanh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cospi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exact(@binary.Binary, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_expm1(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_bounds(@binary.Binary, @binary.Binary, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_double(Double, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_float(Float, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_hypot(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_ln(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log1p(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_pow(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_rootn(Self, Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_sin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_sinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_sinpi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tan(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanpi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::upper_bound(Self) -> @binary.Binary
pub fn Interval::width(Self) -> @binary.Binary
pub fn Interval::with_precision(Self, Int32) -> Self
pub impl @arithmetic.Contains for Interval
pub impl @arithmetic.DefinitelyLe for Interval
pub impl @arithmetic.DefinitelyLt for Interval
pub impl @arithmetic.DivChecked for Interval
pub impl @arithmetic.MaybeEq for Interval
pub impl @arithmetic.Overlaps for Interval
pub impl @arithmetic.PowIntChecked for Interval
pub impl @arithmetic.PowNatChecked for Interval
pub impl Add for Interval
pub impl Div for Interval
pub impl Eq for Interval
pub impl Mul for Interval
pub impl Neg for Interval
pub impl Show for Interval
pub impl Sub for Interval
pub struct IntervalContext {
// private fields
}
pub fn IntervalContext::binary128() -> Self
pub fn IntervalContext::binary16() -> Self
pub fn IntervalContext::binary32() -> Self
pub fn IntervalContext::binary64() -> Self
pub fn IntervalContext::e_max(Self) -> Int32
pub fn IntervalContext::e_min(Self) -> Int32
pub fn IntervalContext::new(precision? : Int32, e_max? : Int32) -> Self
pub fn IntervalContext::precision(Self) -> Int32
pub fn IntervalContext::try_new(precision? : Int32, e_max? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn IntervalContext::with_e_max(Self, Int32) -> Self
pub fn IntervalContext::with_precision(Self, Int32) -> Self
#derive(Eq)
pub struct IntervalFlags {
// private fields
}
pub fn IntervalFlags::combine(Self, Self) -> Self
pub fn IntervalFlags::equal(Self, Self) -> Bool
pub fn IntervalFlags::inexact(Self) -> Bool
pub fn IntervalFlags::new() -> Self
pub fn IntervalFlags::not_equal(Self, Self) -> Bool
pub fn IntervalFlags::overflow(Self) -> Bool
pub fn IntervalFlags::underflow(Self) -> Bool
#derive(Eq, @debug.Debug)
pub(all) enum OverlapState {
BothEmpty
FirstEmpty
SecondEmpty
Before
Meets
Overlaps
Starts
ContainedBy
Finishes
Equals
After
MetBy
OverlappedBy
StartedBy
Contains
FinishedBy
}
pub fn OverlapState::equal(Self, Self) -> Bool
pub fn OverlapState::not_equal(Self, Self) -> Bool
pub fn OverlapState::to_repr(Self) -> @debug.Repr
// Type aliases
// Traits