2014-12-12 18:19:23 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
|
|
|
|
|
|
General operations on functions.
|
|
|
|
|
-/
|
2015-02-26 18:19:54 +00:00
|
|
|
|
|
2014-12-12 18:19:23 +00:00
|
|
|
|
prelude
|
2015-05-01 03:14:00 +00:00
|
|
|
|
import init.reserved_notation .types
|
|
|
|
|
|
|
|
|
|
open prod
|
2014-12-12 18:19:23 +00:00
|
|
|
|
|
|
|
|
|
namespace function
|
|
|
|
|
|
2015-04-24 22:51:16 +00:00
|
|
|
|
variables {A B C D E : Type}
|
2014-12-12 18:19:23 +00:00
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition compose [reducible] [unfold-f] (f : B → C) (g : A → B) : A → C :=
|
2014-12-12 18:19:23 +00:00
|
|
|
|
λx, f (g x)
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition compose_right [reducible] [unfold-f] (f : B → B → B) (g : A → B) : B → A → B :=
|
2015-05-01 03:14:00 +00:00
|
|
|
|
λ b a, f b (g a)
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition compose_left [reducible] [unfold-f] (f : B → B → B) (g : A → B) : A → B → B :=
|
2015-05-01 03:14:00 +00:00
|
|
|
|
λ a b, f (g a) b
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition id [reducible] [unfold-f] (a : A) : A :=
|
2014-12-12 18:19:23 +00:00
|
|
|
|
a
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition on_fun [reducible] [unfold-f] (f : B → B → C) (g : A → B) : A → A → C :=
|
2014-12-12 18:19:23 +00:00
|
|
|
|
λx y, f (g x) (g y)
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition combine [reducible] [unfold-f] (f : A → B → C) (op : C → D → E) (g : A → B → D)
|
|
|
|
|
: A → B → E :=
|
2014-12-12 18:19:23 +00:00
|
|
|
|
λx y, op (f x y) (g x y)
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition const [reducible] [unfold-f] (B : Type) (a : A) : B → A :=
|
2014-12-12 18:19:23 +00:00
|
|
|
|
λx, a
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition dcompose [reducible] [unfold-f] {B : A → Type} {C : Π {x : A}, B x → Type}
|
2014-12-12 18:19:23 +00:00
|
|
|
|
(f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) :=
|
|
|
|
|
λx, f (g x)
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition flip [reducible] [unfold-f] {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y :=
|
2014-12-12 18:19:23 +00:00
|
|
|
|
λy x, f x y
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition app [reducible] [unfold-f] {B : A → Type} (f : Πx, B x) (x : A) : B x :=
|
2014-12-12 18:19:23 +00:00
|
|
|
|
f x
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition curry [reducible] [unfold-f] : (A × B → C) → A → B → C :=
|
2015-05-01 03:14:00 +00:00
|
|
|
|
λ f a b, f (a, b)
|
|
|
|
|
|
2015-05-07 05:23:39 +00:00
|
|
|
|
definition uncurry [reducible] [unfold-c 5] : (A → B → C) → (A × B → C) :=
|
2015-05-01 03:14:00 +00:00
|
|
|
|
λ f p, match p with (a, b) := f a b end
|
|
|
|
|
|
2014-12-12 18:19:23 +00:00
|
|
|
|
precedence `∘'`:60
|
|
|
|
|
precedence `on`:1
|
|
|
|
|
precedence `$`:1
|
|
|
|
|
|
|
|
|
|
|
2014-12-16 20:10:12 +00:00
|
|
|
|
infixr ∘ := compose
|
2014-12-12 18:19:23 +00:00
|
|
|
|
infixr ∘' := dcompose
|
|
|
|
|
infixl on := on_fun
|
|
|
|
|
infixr $ := app
|
|
|
|
|
notation f `-[` op `]-` g := combine f op g
|
|
|
|
|
|
|
|
|
|
end function
|
2015-02-17 02:52:41 +00:00
|
|
|
|
|
|
|
|
|
-- copy reducible annotations to top-level
|
2015-05-07 05:23:39 +00:00
|
|
|
|
export [reduce-hints] [unfold-hints] function
|