Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] New Design #8

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6645022
Draft the doc for new design
utensil Jul 12, 2020
27edad5
Add inspirations.lean
utensil Jul 12, 2020
f692a3e
Add operatrors.lean
utensil Jul 12, 2020
1ef4437
Add defs.lean
utensil Jul 12, 2020
456a95e
Fix typos found in review
utensil Jul 13, 2020
a9c56f7
Change universe symbols
utensil Jul 13, 2020
62cbbeb
Trying stop using old structure
utensil Jul 14, 2020
604ef0f
Experiment with bundled definitions
utensil Jul 14, 2020
56ba0af
Merge branch 'master' of https://github.com/pygae/lean-ga into utensi…
utensil Jul 14, 2020
5f8d3eb
Breakthrough: worked out stating theorems under variables
utensil Jul 15, 2020
a727f31
Update related inspirations.lean
utensil Jul 18, 2020
f7f09d6
Ignore local experiments
utensil Jul 18, 2020
8371f5d
Further explore unbundled v.s. (semi-)bundled
utensil Jul 18, 2020
f465714
Add equiv to inspirations
utensil Jul 18, 2020
487738a
Cl(V,Q) is a N-filtered algebra
utensil Jul 18, 2020
699cd14
Relation with Grassmann-Cayley Algebra
utensil Jul 21, 2020
d377450
leanproject up
utensil Jul 21, 2020
a388fbd
group, proof_demo, and unbundled GA for the talk
utensil Jul 28, 2020
724220b
Alternate proof formulation, maybe more readable? (#10)
eric-wieser Jul 29, 2020
8538cfc
General clean up and improve the proof doc
utensil Jul 29, 2020
948c9b4
Add bundled quadratic_form
utensil Jul 29, 2020
2a2c83a
Add unbundled_range
eric-wieser Jul 29, 2020
2f2dff1
Rewrite to calc
utensil Jul 29, 2020
1efb817
Merge branch 'master' of https://github.com/pygae/lean-ga into utensi…
utensil Jul 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions docs/misc/new_design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Rethinking the Design of Mathematical Theory Development in Lean

It turns out that we must have a design template in mind in order to carry on further designing of GA in Lean. This document will address this issue.

## Key Insight from Euclidean Geometry

Taking a step back, let's go back to geometry and look at https://github.com/vaibhavkarve/leanteach2020/blob/master/src/euclid.lean .

What's a point? How do we tell this concept to the computer? Do we draw a point? Or do we went to analytic geometry and give it a coordinate? It turns out we don't need to do either, the former is infeasible and the latter is the worst idea in formalizing.

```lean
constant Point : Type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I have a pointXY structure, and I want to apply the theorems about Point to it?

Copy link
Member Author

@utensil utensil Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph discusses how to do abstract reasoning without ever coming back to the concrete world. There was supposed to be a paragraph about what if we need to link back to the concrete world then that's where type classes come in. And I should also discuss using class v.s. structure (1:1 v.s. 1:n) as pointed out by Kevin Buzzard.

```

How about a line? Same.

```lean
constant Line : Type
```

How about the relations between points and lines?

```lean
constant lies_on : Point → Line → Prop
constant between : Point → Point → Point → Prop -- (between a b c) means "b is in between a and c"
constant congruent {A : Type} : A → A → Prop
constant distance : Point → Point → ℝ
```

How about axioms?

```lean
axiom distance_not_neg {p1 p2 : Point} : 0 ≤ distance p1 p2
axiom distance_pos {p1 p2 : Point} : p1 ≠ p2 ↔ 0 < distance p1 p2
```

And this keeps on and on. Then we have a lot of lemmas and theorems and we still don't need to know what exactly a point is, we don't even need to know how to compute a distance.

That's it. We don't need concrete types or computibility to reason about them. The semantic can end with their names and we don't need to know more underneath.

This is the key insight one must have before formalizing a piece of mathematics.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Add structure v.s. class here

## Compatibility with mathlib

A geometric product "contains" an inner product and an exterior product (or wedge product).

They're established mathematic. There's already inner product space in mathlib and there would definitely be Grassmann Algebra in mathlib one day. And obviously we can't escape the general Clifford Algebra too.

We must maintain compatibility with them, at least don't conflict with their existence.

It's not a duplication. The development of mathlib is driven by professional mathematitians, they struggle for math generity but we're working at an abstraction level close to applications.

We want to stand on such shoulders but we want good capsulation so that we don't want to worry about more abstract concepts and some too general cases. This would definitely leak, it might not be obvious in definitions but it would be very clear when you're proving something. For example, you have to deal with lattice and finsupp when proving things about linear algebra, and that should not be.

## Operators

We start with has_* that have absolutely no axioms with them, they don't have any properties and any behaviors. It's almost just a name. And we associate notations with them.

Just like in https://github.com/leanprover-community/lean/blob/master/library/init/core.lean#L321

```lean
class has_mul (α : Type u) := (mul : α → α → α)
```

we could just:

```lean
class has_wedge (α : Type u) := (wedge : α → α → α)
class has_inner (α : Type u) := (inner : α → α → α)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_inner assumes the result is real. It could be a more concrete instance of the general has_dot we have.

```

The latter presumably is already in mathlib and has a lot of structures and properties associated with it. We'll deal with that later.

As for geometric product, I'm thinking about the following short name instead of `geomprod`, `gp` etc.:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that gmul doesn't scale well, Scalar Product can't be smul because it's used by has_scalar which would be in our inheritance hierarchy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we have geometric_algebra.has_scalar_product.smul to distinguish from has_scalar.smul? Or do namespaces not work well here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old structure is flat, so no matter where smul comes from, as long as it's in our inheritance hierarchy, it conflicts.

Better avoid it anyway.


```lean
class has_gmul (α : Type u) := (gmul : α → α → α)
```

## Notations

Now we assoc notations with them:

```lean
-- \circ
infix ∘ := has_gmul.gmul
-- \wedge
infix ∧ := has_wedge.wedge
-- \cdot
infix ⋅ := has_inner.inner
```

We'll always use `local` notations waiting for to be `open_locale`ed. I expect conflicts with notations in mathlib and using this to avoid the conflicts as long as possible.

> TODO: describe how to use them even when there's a confliction.

## Defining without defining

There're really millions of products defined in GA and they're based on the geometric product. But the definition might not be the most efficient one or the most intuitive one.

So instead of using `def`, we should make these products just a product with a `Prop` asserting that they're equal to the definition based on gp and let the implementation prove it when intantiate the instance.

```lean
class has_ga_wedge (α : Type u) extends has_wedge :=
(defeq : ∀ a b : α, a ∧ b = (a ∘ b - b ∘ a) / 2)
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't happen yet.


The above ignore the fact this only works on vectors instead of multivectors.

So the true story is that we should define `has_sym_mul` and `has_asym_mul` first.

## The complication with mul

mul group diamond

C wrong

## ga extends has_gmul

## ga vs mv

## the standard template

import universe open variables

class with parameter

bundle

prio

marker forgetful_to

directory structure

## defs and lemmas

contains no lemma except for ... see groups/defs.lean

recover the usual for demo but never use them

## R V are not G0 G1

## G is vector space

## linear map

no `:G` or `coe`

## vector_contractible

non-metric

quadratic form?

functional?

induced topology

## attr

## universal algebra

## what to inherit and forget?

## Clifford and Grassmann

## graded comes later
67 changes: 67 additions & 0 deletions src/geometric_algebra/generic/defs.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/-
Copyright (c) 2020 lean-ga Team. All rights reserved.
Released under MIT license as described in the file LICENRE.
Authors: Utensil Rong
-/
import ring_theory.algebra
import linear_algebra.quadratic_form
import tactic
import tactic.lint

-- import geometric_algebra.generic.operators

universes ur uv ug

variables {R : Type ur} [field R]
variables {V : Type uv} [add_comm_group V] [vector_space R V]
variables {G : Type ug} [ring G]

section prio
-- set_option default_priority 200 -- see Note [default priority]
set_option default_priority 100
set_option old_structure_cmd true

/--
-/
@[ancestor algebra]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do that isn't covered by extends?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still trying to figure out the exact effect, it shows up in group.defs in mathlib

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've seen it before too, was hoping you'd worked out its meaning since I haven't yet...

class semi_geometric_algebra
(R : Type ur) [field R]
(V : Type uv) [add_comm_group V] [vector_space R V]
(G : Type ug) [ring G]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that I can't leave them to variables because that would cause failure to use either semi_geometric_algebra G or semi_geometric_algebra R V G. They still stick here.

extends algebra R G
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_geom_prod will return here. Haven't figure out how to and how it surves the purpose yet.


class weak_geometric_algebra
(R : Type ur) [field R]
(V : Type uv) [add_comm_group V] [vector_space R V]
(G : Type ug) [ring G]
extends semi_geometric_algebra R V G
:=
(fᵣ : R →+* G)
-- this follows normed_algebra in analysis.normed_space.basic
(fᵣ_algebra_map_eq : fᵣ = algebra_map R G)
(fᵥ : V →+ G)
-- this is the weaker form of the contraction rule for vectors
(vector_contract' : ∀ v, ∃ r, fᵥ v * fᵥ v = fᵣ r )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this weak form useful? Is there a way we can have lean infer it from the strong form?

Copy link
Member Author

@utensil utensil Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this can be proven by the strong form.

I'm leaving the weak layer here because I want to be explicit about three layers that: purely just an ordinary algebra, having something about the linear map (the weak form demonstrate the usefulness of the linear maps but it could also be not there), and bundling a quadratic form.

The real issue between choosing the weak form or the strong form, is whether we assume a metric at the beginning. There are literatures assumes no metric or assume a non-symmetric bilinear form, and this layer can be useful to them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more of a POC and I don't if we need them after some software engineering thinking. So far it can stay there and be in the way of nothing.


class geometric_algebra
(R : Type ur) [field R]
(V : Type uv) [add_comm_group V] [vector_space R V]
(G : Type ug) [ring G]
extends weak_geometric_algebra R V G
:=
(q : quadratic_form R V)
(vector_contract : ∀ v, fᵥ v * fᵥ v = fᵣ (q v) )

end prio

-- #print geometric_algebra

namespace geometric_algebra

variables [geometric_algebra R V G]

-- instance : inhabited (geometric_algebra R V G) := ⟨0⟩

end geometric_algebra

#lint
33 changes: 33 additions & 0 deletions src/geometric_algebra/generic/inspirations.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/-
Copyright (c) 2020 lean-ga Team. All rights reserved.
Released under MIT license as described in the file LICENSE.
Authors: Utensil Song

This file contains only imports which are just the lean files
that the authors draw inspirations from.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal here is a quick "jump to definition"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only that. Since this is a branch so I'm a little casual about file organization and leave it by the side of the files I'm working on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, just would like a comment in this file pointing out it it can be used this way :)

-/
import init.core

import algebra.group.defs
import algebra.group.hom
import algebra.module
import algebra.direct_limit
import ring_theory.algebra
import linear_algebra.quadratic_form

import data.real.basic
import data.complex.basic
import data.complex.module
import data.matrix.basic

import geometry.euclidean
import geometry.manifold.real_instances

import analysis.convex.cone
import analysis.normed_space.basic
import analysis.normed_space.real_inner_product

import tactic
import tactic.lint

#lint
51 changes: 51 additions & 0 deletions src/geometric_algebra/generic/operators.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/-
Copyright (c) 2020 lean-ga Team. All rights reserved.
Released under MIT license as described in the file LICENSE.
Authors: Utensil Song

This file defines operators with local notations and no axioms.
-/
import tactic.lint

universes u

namespace geometric_algebra

class has_dot (α : Type u) := (dot : α → α → α)
class has_wedge (α : Type u) := (wedge : α → α → α)

-- class has_geom_prod (α : Type u) := (geom_prod : α → α → α)

class has_scalar_prod (α : Type u) := (scalar_prod : α → α → α)

class has_symm_prod (α : Type u) := (symm_prod : α → α → α)
class has_asymm_prod (α : Type u) := (asymm_prod : α → α → α)

class has_left_contract (α : Type u) := (left_contract : α → α → α)
class has_right_contract (α : Type u) := (right_contract : α → α → α)

-- export has_dot (dot)
-- export has_wedge (wedge)
Comment on lines +27 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the idea behind these?

Copy link
Member Author

@utensil utensil Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exports a wedge function, without has_wedge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so I should read this as the python wedge = has_wedge.wedge?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the full extent of this, I saw this in code, check out what it seems to mean and commented it out because I thought it's not useful for our purpose.


local infix ⬝ := has_dot.dot
local infix ∧ := has_wedge.wedge
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A serious problem is that wedge is globally reserved to infixr which has right associativity and conflicts with our wedge. local only evaded the problem temporarily.

Copy link
Member

@eric-wieser eric-wieser Jul 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on why right-associativity is an issue with an example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it conflicts with logical AND


-- local infix ∘ := has_geom_prod.geom_prod

reserve infix ` ⊛ `:70
local infix ` ⊛ ` := has_scalar_prod.scalar_prod

reserve infix ` ⊙ `:70
reserve infix ` ⊠ `:70
local infix ` ⊙ ` := has_symm_prod.symm_prod
local infix ` ⊠ ` := has_asymm_prod.asymm_prod

reserve infix ` ⨼ `:70
reserve infix ` ⨽ `:70
local infix ⨼ := has_left_contract.left_contract
local infix ⨽ := has_right_contract.right_contract
Comment on lines +35 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorter and equivalent as:

Suggested change
reserve infix ` ⊛ `:70
local infix ` ⊛ ` := has_scalar_prod.scalar_prod
reserve infix ` ⊙ `:70
reserve infix ` ⊠ `:70
local infix ` ⊙ ` := has_symm_prod.symm_prod
local infix ` ⊠ ` := has_asymm_prod.asymm_prod
reserve infix ` ⨼ `:70
reserve infix ` ⨽ `:70
local infix ⨼ := has_left_contract.left_contract
local infix ⨽ := has_right_contract.right_contract
local infix ` ⊛ `:70 := has_scalar_prod.scalar_prod
local infix ` ⊙ `:70 := has_symm_prod.symm_prod
local infix ` ⊠ `:70 := has_asymm_prod.asymm_prod
local infix ` ⨼ `:70 := has_left_contract.left_contract
local infix ` ⨽ `:70 := has_right_contract.right_contract

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unless you know a difference that I don't)


end geometric_algebra

#lint