Timings for int_abs.v
Require Import
HoTT.Classes.interfaces.naturals
HoTT.Classes.interfaces.abstract_algebra
HoTT.Classes.interfaces.orders
HoTT.Classes.orders.nat_int
HoTT.Classes.theory.integers
HoTT.Classes.theory.rings
HoTT.Classes.theory.groups
HoTT.Classes.orders.rings.
Generalizable Variables N Z Zle Zlt R f.
Context `{Funext} `{Univalence}.
Context `{Integers Z} `{Apart Z} `{!TrivialApart Z}
`{!FullPseudoSemiRingOrder Zle Zlt} `{Naturals N}.
(* Add Ring Z : (rings.stdlib_ring_theory Z). *)
Lemma int_abs_unique (a b : IntAbs Z N) (z : Z) :
int_abs Z N (ia:=a) z = int_abs Z N (ia:=b) z.
destruct (int_abs_sig Z N (IntAbs:=a) z) as [[n1 E1]|[n1 E1]];
destruct (int_abs_sig Z N (IntAbs:=b) z) as [[n2 E2]|[n2 E2]].
apply (injective (naturals_to_semiring N Z)).
assert (E : n1 + n2 = 0);[|path_via 0;[|symmetry];
apply (naturals.zero_sum _ _ E)].
apply (injective (naturals_to_semiring N Z)).
rewrite preserves_0,preserves_plus.
assert (E : n1 + n2 = 0);[|path_via 0;[|symmetry];
apply (naturals.zero_sum _ _ E)].
apply (injective (naturals_to_semiring N Z)).
rewrite preserves_0,preserves_plus.
apply (injective (naturals_to_semiring N Z)).
Context `{!IsSemiRingPreserving (f : N -> Z)}.
Lemma int_abs_spec x :
(0 ≤ x /\ f (int_abs Z N x) = x) |_| (x ≤ 0 /\ f (int_abs Z N x) = -x).
destruct (int_abs_sig Z N x) as [[n E]|[n E]].
eapply @to_semiring_nonneg;apply _.
apply (naturals.to_semiring_unique_alt _ _).
apply flip_nonpos_negate.
eapply @to_semiring_nonneg;apply _.
apply (naturals.to_semiring_unique_alt _ _).
Lemma int_abs_sig_alt x :
(sig (fun n : N => f n = x)) |_| (sig (fun n : N => f n = - x)).
destruct (int_abs_spec x) as [[??]|[??]]; eauto.
Lemma int_abs_nat n :
int_abs Z N (f n) = n.
destruct (int_abs_spec (f n)) as [[? E]|[? E]];trivial.
apply naturals.negate_to_ring.
Lemma int_abs_negate_nat n :
int_abs Z N (-f n) = n.
destruct (int_abs_spec (-f n)) as [[? E]|[? E]].
apply naturals.negate_to_ring.
Lemma int_abs_negate x :
int_abs Z N (-x) = int_abs Z N x.
destruct (int_abs_spec x) as [[_ E]|[_ E]].
path_via (int_abs Z N (- f (int_abs Z N x))).
apply int_abs_negate_nat.
Lemma int_abs_0_alt x : int_abs Z N x = 0 <-> x = 0.
destruct (int_abs_spec x) as [[_ E2]|[_ E2]];[|apply flip_negate_0];
rewrite <-E2, E1, (preserves_0 (f:=f)); trivial.
rewrite E1, <-(preserves_0 (f:=f)).
Lemma int_abs_ne_0 x : int_abs Z N x <> 0 <-> x <> 0.
destruct (int_abs_0_alt x).
Lemma int_abs_0 : int_abs Z N 0 = 0.
apply int_abs_0_alt;trivial.
Lemma int_abs_nonneg x :
0 ≤ x -> f (int_abs Z N x) = x.
destruct (int_abs_spec x) as [[n E2]|[n E2]];trivial.
apply (antisymmetry (<=));trivial.
rewrite Hrw,int_abs_0, (preserves_0 (f:=f)).
Lemma int_abs_nonpos x :
x ≤ 0 -> f (int_abs Z N x) = -x.
rewrite <-int_abs_negate, int_abs_nonneg; auto.
apply flip_nonpos_negate.
Lemma int_abs_1 : int_abs Z N 1 = 1.
rewrite (preserves_1 (f:=f)).
apply int_abs_nonneg; solve_propholds.
Lemma int_abs_nonneg_plus x y :
0 ≤ x -> 0 ≤ y -> int_abs Z N (x + y) = int_abs Z N x + int_abs Z N y.
rewrite (preserves_plus (f:=f)), !int_abs_nonneg;auto.
apply nonneg_plus_compat;trivial.
Lemma int_abs_mult x y :
int_abs Z N (x * y) = int_abs Z N x * int_abs Z N y.
rewrite (preserves_mult (f:=f)).
destruct (int_abs_spec x) as [[? Ex]|[? Ex]],
(int_abs_spec y) as [[? Ey]|[? Ey]]; rewrite Ex, Ey.
rewrite int_abs_nonneg;trivial.
apply nonneg_mult_compat;trivial.
apply negate_mult_distr_r.
apply nonneg_nonpos_mult;trivial.
apply negate_mult_distr_l.
apply nonpos_nonneg_mult;trivial.
symmetry;apply negate_mult_negate.
apply nonpos_mult;trivial.