2014-11-28 12:06:46 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Module: algebra.function
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
|
|
|
|
General operations on functions.
|
|
|
|
-/
|
2014-07-24 23:29:39 +00:00
|
|
|
namespace function
|
|
|
|
|
2014-10-10 23:33:58 +00:00
|
|
|
variables {A : Type} {B : Type} {C : Type} {D : Type} {E : Type}
|
2014-07-24 23:29:39 +00:00
|
|
|
|
2014-10-10 23:33:58 +00:00
|
|
|
definition compose [reducible] (f : B → C) (g : A → B) : A → C :=
|
|
|
|
λx, f (g x)
|
2014-07-24 23:29:39 +00:00
|
|
|
|
2014-10-10 23:33:58 +00:00
|
|
|
definition id [reducible] (a : A) : A :=
|
|
|
|
a
|
2014-07-24 23:29:39 +00:00
|
|
|
|
2015-02-17 02:52:41 +00:00
|
|
|
definition on_fun [reducible] (f : B → B → C) (g : A → B) : A → A → C :=
|
2014-10-10 23:33:58 +00:00
|
|
|
λx y, f (g x) (g y)
|
2014-07-24 23:29:39 +00:00
|
|
|
|
2015-02-17 02:52:41 +00:00
|
|
|
definition combine [reducible] (f : A → B → C) (op : C → D → E) (g : A → B → D) : A → B → E :=
|
2014-10-10 23:33:58 +00:00
|
|
|
λx y, op (f x y) (g x y)
|
2014-07-24 23:29:39 +00:00
|
|
|
|
2015-02-17 02:52:41 +00:00
|
|
|
definition const [reducible] (B : Type) (a : A) : B → A :=
|
2014-07-29 02:58:57 +00:00
|
|
|
λx, a
|
2014-07-28 04:01:59 +00:00
|
|
|
|
2015-02-17 02:52:41 +00:00
|
|
|
definition dcompose [reducible] {B : A → Type} {C : Π {x : A}, B x → Type}
|
2014-11-28 12:06:46 +00:00
|
|
|
(f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) :=
|
2014-07-29 02:58:57 +00:00
|
|
|
λx, f (g x)
|
2014-07-24 23:29:39 +00:00
|
|
|
|
2015-02-17 02:52:41 +00:00
|
|
|
definition flip [reducible] {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y :=
|
2014-07-29 02:58:57 +00:00
|
|
|
λy x, f x y
|
2014-07-24 23:29:39 +00:00
|
|
|
|
2015-02-17 02:52:41 +00:00
|
|
|
definition app [reducible] {B : A → Type} (f : Πx, B x) (x : A) : B x :=
|
2014-07-29 02:58:57 +00:00
|
|
|
f x
|
2014-07-24 23:29:39 +00:00
|
|
|
|
|
|
|
precedence `∘'`:60
|
|
|
|
precedence `on`:1
|
|
|
|
precedence `$`:1
|
|
|
|
|
|
|
|
infixr ∘ := compose
|
|
|
|
infixr ∘' := dcompose
|
|
|
|
infixl on := on_fun
|
|
|
|
infixr $ := app
|
|
|
|
notation f `-[` op `]-` g := combine f op g
|
|
|
|
|
2015-04-03 22:43:44 +00:00
|
|
|
lemma left_inv_eq {finv : B → A} {f : A → B} (linv : finv ∘ f = id) : ∀ x, finv (f x) = x :=
|
|
|
|
take x, show (finv ∘ f) x = x, by rewrite linv
|
|
|
|
|
|
|
|
definition injective (f : A → B) : Prop := ∃ finv : B → A, finv ∘ f = id
|
|
|
|
|
|
|
|
lemma injective_def {f : A → B} (h : injective f) : ∀ a b, f a = f b → a = b :=
|
|
|
|
take a b, assume faeqfb,
|
|
|
|
obtain (finv : B → A) (inv : finv ∘ f = id), from h,
|
|
|
|
calc a = finv (f a) : by rewrite (left_inv_eq inv)
|
|
|
|
... = finv (f b) : faeqfb
|
|
|
|
... = b : by rewrite (left_inv_eq inv)
|
|
|
|
|
2014-08-07 23:59:08 +00:00
|
|
|
end function
|
2015-02-17 02:52:41 +00:00
|
|
|
|
|
|
|
-- copy reducible annotations to top-level
|
|
|
|
export [reduce-hints] function
|