Nontrivial types
A type is nontrivial if it contains at least two elements. This is useful in particular for rings (where it is equivalent to the fact that zero is different from one) and for vector spaces (where it is equivalent to the fact that the dimension is positive).
We introduce a typeclass nontrivial
formalizing this property.
- exists_pair_ne : ∃ (x y : α), x ≠ y
Predicate typeclass for expressing that a type is not reduced to a single element. In rings,
this is equivalent to 0 ≠ 1
. In vector spaces, this is equivalent to positive dimension.
Instances
- group_with_zero.to_nontrivial
- domain.to_nontrivial
- linear_ordered_semiring.to_nontrivial
- linear_ordered_ring.to_nontrivial
- division_ring.to_nontrivial
- field.to_nontrivial
- euclidean_domain.to_nontrivial
- infinite.nontrivial
- is_simple_lattice.to_nontrivial
- local_ring.to_nontrivial
- option.nontrivial
- nontrivial_prod_right
- nontrivial_prod_left
- pi.nontrivial
- function.nontrivial
- bool.nontrivial
- with_one.nontrivial
- with_zero.nontrivial
- with_top.nontrivial
- nat.nontrivial
- opposite.nontrivial
- int.nontrivial
- fin.nontrivial
- rat.nontrivial
- order_dual.nontrivial
- submonoid.nontrivial
- add_submonoid.nontrivial
- subgroup.nontrivial
- add_subgroup.nontrivial
- finsupp.nontrivial
- subsemiring.nontrivial
- subalgebra.nontrivial
- associates.nontrivial
- monoid_algebra.nontrivial
- add_monoid_algebra.nontrivial
- free_algebra.nontrivial
- polynomial.nontrivial
- field.direct_limit.nontrivial
- cardinal.nontrivial
- ordinal.nontrivial
- zmod.nontrivial
- real.nontrivial
- ennreal.nontrivial
- mv_power_series.nontrivial
- power_series.nontrivial
- filter.germ.nontrivial
- zsqrtd.nontrivial
- gaussian_int.nontrivial
- dihedral.nontrivial
- lucas_lehmer.X.nontrivial
- ring.fractional_ideal.nontrivial
- mod_p.nontrivial
An inhabited type is either nontrivial, or has a unique element.
Equations
- nontrivial_psum_unique α = dite (nontrivial α) (λ (h : nontrivial α), psum.inl h) (λ (h : ¬nontrivial α), psum.inr {to_inhabited := {default := default α _inst_1}, uniq := _})
A type is either a subsingleton or nontrivial.
Pushforward a nontrivial
instance along an injective function.
Pullback a nontrivial
instance along a surjective function.
An injective function from a nontrivial type has an argument at which it does not take a given value.
A pi type is nontrivial if it's nonempty everywhere and nontrivial somewhere.
As a convenience, provide an instance automatically if (f (default I))
is nontrivial.
If a different index has the non-trivial type, then use haveI := nontrivial_at that_index
.
Simp lemmas for nontriviality
tactic
Tries to generate a nontrivial α
instance by performing case analysis on
subsingleton_or_nontrivial α
,
attempting to discharge the subsingleton branch using lemmas with @[nontriviality]
attribute,
including subsingleton.le
and eq_iff_true_of_subsingleton
.
Tries to generate a nontrivial α
instance using nontrivial_of_ne
or nontrivial_of_lt
and local hypotheses.
Attempts to generate a nontrivial α
hypothesis.
The tactic first looks for an instance using apply_instance
.
If the goal is an (in)equality, the type α
is inferred from the goal.
Otherwise, the type needs to be specified in the tactic invocation, as nontriviality α
.
The nontriviality
tactic will first look for strict inequalities amongst the hypotheses,
and use these to derive the nontrivial
instance directly.
Otherwise, it will perform a case split on subsingleton α ∨ nontrivial α
, and attempt to discharge
the subsingleton
goal using simp [lemmas] with nontriviality
, where [lemmas]
is a list of
additional simp
lemmas that can be passed to nontriviality
using the syntax
nontriviality α using [lemmas]
.
example {R : Type} [ordered_ring R] {a : R} (h : 0 < a) : 0 < a :=
begin
nontriviality, -- There is now a `nontrivial R` hypothesis available.
assumption,
end
example {R : Type} [comm_ring R] {r s : R} : r * s = s * r :=
begin
nontriviality, -- There is now a `nontrivial R` hypothesis available.
apply mul_comm,
end
example {R : Type} [ordered_ring R] {a : R} (h : 0 < a) : (2 : ℕ) ∣ 4 :=
begin
nontriviality R, -- there is now a `nontrivial R` hypothesis available.
dec_trivial
end
def myeq {α : Type} (a b : α) : Prop := a = b
example {α : Type} (a b : α) (h : a = b) : myeq a b :=
begin
success_if_fail { nontriviality α }, -- Fails
nontriviality α using [myeq], -- There is now a `nontrivial α` hypothesis available
assumption
end