-
Notifications
You must be signed in to change notification settings - Fork 62
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
Features from meuns/galgebra: GA4CS examples, PGA, code-generation, and more #68
Open
meuns
wants to merge
87
commits into
pygae:master
Choose a base branch
from
meuns:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
2f925ff
remove and ignore pyc files
meuns c67ac34
leo dorst book chapter 2 drills
meuns 5fded26
ignore eclipe project files
meuns 216731c
leo dorst book chapter 2 exercices (in progress)
meuns cf9c50f
fix and test Mv.blade_coefs method
meuns 50509ff
leo dorst book chapter 2 exercices (in progress)
meuns dc779f2
remove and ignore pyc files
meuns d6ec574
leo dorst book chapter 2 drills
meuns 0b9b78f
ignore eclipe project files
meuns 8cd317b
leo dorst book chapter 2 exercices (in progress)
meuns d9f0d7b
leo dorst book chapter 2 exercices (in progress)
meuns 3af9f1e
merge after rebasing on brombo
meuns 1b1672a
leo dorst book chapter 2 exercices (in progress)
meuns 2f4aa45
cleanup path hack
meuns 539ef47
leo dorst book chapter 3 exercices (in progress)
meuns 4791c4d
remove and ignore pyc files
meuns 053cead
leo dorst book chapter 2 drills
meuns c10a4c9
ignore eclipe project files
meuns f908814
leo dorst book chapter 2 exercices (in progress)
meuns 93b9a83
fix and test Mv.blade_coefs method
meuns ff08a83
leo dorst book chapter 2 exercices (in progress)
meuns a9341b4
leo dorst book chapter 2 exercices (in progress)
meuns e46619f
leo dorst book chapter 2 exercices (in progress)
meuns 96b43a1
cleanup path hack
meuns 7923202
leo dorst book chapter 3 exercices (in progress)
meuns dd79887
merge branch 'master' of https://github.com/meuns/galgebra after reba…
meuns 47564c4
add I_inv method to Ga class
meuns 569a40c
remove Abs from Mv.norm2 method
meuns 5edaa64
leo dorst book chapter 3 exercices (in progress)
meuns 53f7af8
leo dorst book chapter 3 exercices (in progress)
meuns 0c33701
cleanup chapter 3 exercices
meuns 99e20e9
leo dorst book chapter 3 exercices (in progress)
meuns dcd1d45
leo dorst book chapter 3 exercices (in progress)
meuns 7803817
leo dorst book chapter 3 exercices (in progress)
meuns ca9c388
leo dorst book chapter 2 exercices (in progress)
meuns d5028e1
leo dorst book chapter 2 exercices (in progress)
meuns 0afad0b
compute grades using grade_decomposition instead of pure_grade, leo d…
meuns cef764f
leo dorst book chapter 3 exercices (in progress)
meuns 5d637bb
more about cross product
meuns ff8d2e8
leo dorst book chapter 3 exercices (in progress)
meuns 7b077f9
fix Mv.__mul__(A) when A is a scalar and self isn't
meuns e6d4291
leo dorst book chapter 6 exercices (in progress)
meuns 9d1b6d0
leo dorst book chapter 6 exercices (in progress)
meuns c1eb831
leo dorst book chapter 6 exercices (in progress)
meuns 99583d0
fix inv, norm2 and norm, enhance inverse test3_5_2
meuns 941a780
Mv.__init__ can make k-blades using the 'blade' factory, fix Mv.__xor…
meuns a233877
leo dorst book chapter 6 exercices (in progress)
meuns b6ee442
leo dorst book chapter 7 exercices (in progress)
meuns 5b124d9
Small fixes, cleanup and use don't use grade_decomposition if we alre…
meuns a94289b
Fix add missing parenthesis
meuns 7a7617f
leo dorst book chapter 10 exercises (in progress)
meuns c2634e8
Rename a file
meuns 080f6c0
Rename a file
meuns ff08cb6
leo dorst book chapter 11 exercises (in progress)
meuns 2f26ea4
leo dorst book chapter 11 exercises (in progress)
meuns cc0bb70
Revert mistake about inv, norm and norm2
meuns 1b41f89
A test about associativity of the outer product and calculating deter…
meuns f25281b
Generate some flat geometric algebra (like ganja.js)
meuns 7905e50
leo dorst book chapter 13 exercises (in progress)
meuns fd88288
first pga version
meuns e9a8d80
More pga tests
meuns 188aeb1
Generate flat pga
meuns 9697689
Change norm computation for pga tests
meuns f5d4d87
More pga tests and squared norm
meuns 1e2cda9
Cleanup, rotors and translators (work in progress)
meuns 229bd4e
implement custom basis (like enki) and add more tests
meuns 2fb10bb
implement custom basis (like enki) and add more tests
meuns 41dbbef
Merge remote-tracking branch 'origin/master'
meuns d59b69b
leo dorst book chapter 8 exercises (in progress)
meuns 9d4c5aa
Merge all brombo's commits until ae32af960f0525f42eff5b99f695b8e1a970…
meuns 43e0f66
Merge commits until Run included
meuns b07e3ff
Quick and easy fixes after migrating to python 3
meuns c358afe
Merge all utensil commits in 2018 21ed56db65fc57cf720cab5f3425a06469e…
meuns 634a4b0
Quick and easy fixes after merging utensil commits
meuns 685455c
Merge all release_0_4_4 commits
meuns 36df07f
Merge all pygae/master commits
meuns 06682cb
Fix test2_12_1_4
meuns 3722052
Refactor assertEquals, assertNotEquals and assertProjEquals and fix a…
meuns 7c2069e
Symbols are real
meuns 4fce49f
Fix PEP8
meuns 1043951
Use assertEqual, assertNotEqual and assertProjEqual
meuns e376c59
Move all tests to test
meuns 4689050
Merge pygae/master until commit 09ecbd1a4ad489fb3c579319faa2fd5ccfe77…
meuns c4693c8
Refactor chapter 13
meuns 3c4a5b8
chapter 13 exercises (in progress)
meuns 5fc94d2
Fix assertEqual for difficult expressions
meuns 3fea69f
chapter 13 exercises (in progress)
meuns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from sympy import Symbol | ||
|
||
from .ga import Ga | ||
from .mv import J, Jinv | ||
|
||
|
||
def create_multivector(GA, name): | ||
blades = [1] + GA.blades_lst | ||
mv = GA.mv(0, 'scalar') | ||
for blade_index, blade in enumerate(blades): | ||
mv += Symbol('{name}[{i}]'.format(name=name, i=blade_index)) * blade | ||
return mv | ||
|
||
|
||
_CLASS_TEMPLATE = '''# -*- coding: utf-8 -*- | ||
|
||
|
||
class FlatMv(object): | ||
def __init__(self, coefs): | ||
assert len(coefs) == {class_blade_count} | ||
self.coefs = coefs | ||
|
||
def __getitem__(self, index): | ||
return self.coefs[index] | ||
''' | ||
|
||
_BINARY_OPERATOR_TEMPLATE = ''' | ||
def __{op_name}__(self, other): | ||
x = self.coefs | ||
y = other.coefs | ||
return FlatMv([ | ||
{op_list} | ||
]) | ||
''' | ||
|
||
_UNARY_METHOD_TEMPLATE = ''' | ||
def {method_name}(self): | ||
x = self.coefs | ||
return FlatMv([ | ||
{method_list} | ||
]) | ||
''' | ||
|
||
_BINARY_METHOD_TEMPLATE = ''' | ||
def {method_name}(self, other): | ||
x = self.coefs | ||
y = other.coefs | ||
return FlatMv([ | ||
{method_list} | ||
]) | ||
''' | ||
|
||
|
||
def format_class(class_blade_count): | ||
return _CLASS_TEMPLATE.format(class_blade_count=class_blade_count) | ||
|
||
|
||
def format_op_name(name): | ||
return name | ||
|
||
|
||
def format_op_list(mv): | ||
return ',\n '.join(str(blade_coef) for blade_coef in mv.blade_coefs()) | ||
|
||
|
||
def format_binary_operator(name, mv): | ||
return _BINARY_OPERATOR_TEMPLATE.format(op_name=format_op_name(name), op_list=format_op_list(mv)) | ||
|
||
|
||
def format_method_name(name): | ||
return name | ||
|
||
|
||
def format_method_list(mv): | ||
return ',\n '.join(str(blade_coef) for blade_coef in mv.blade_coefs()) | ||
|
||
|
||
def format_unary_method(name, mv): | ||
return _UNARY_METHOD_TEMPLATE.format(method_name=format_method_name(name), method_list=format_method_list(mv)) | ||
|
||
|
||
def format_binary_method(name, mv): | ||
return _BINARY_METHOD_TEMPLATE.format(method_name=format_method_name(name), method_list=format_method_list(mv)) | ||
|
||
|
||
def format_geometric_algebra(GA): | ||
|
||
X = create_multivector(GA, 'x') | ||
Y = create_multivector(GA, 'y') | ||
|
||
flat_geometric_algebra = format_class(len(GA._all_blades_lst)) | ||
flat_geometric_algebra += format_binary_operator('add', X + Y) | ||
flat_geometric_algebra += format_binary_operator('sub', X - Y) | ||
flat_geometric_algebra += format_binary_operator('mul', X * Y) | ||
flat_geometric_algebra += format_binary_operator('and', Jinv(J(X) ^ J(Y))) | ||
flat_geometric_algebra += format_binary_operator('xor', X ^ Y) | ||
flat_geometric_algebra += format_binary_operator('lshift', X << Y) | ||
flat_geometric_algebra += format_binary_operator('rshift', X >> Y) | ||
flat_geometric_algebra += format_binary_method('meet', Jinv(J(X) ^ J(Y))) | ||
flat_geometric_algebra += format_binary_method('join', X ^ Y) | ||
flat_geometric_algebra += format_unary_method('rev', X.rev()) | ||
|
||
return flat_geometric_algebra | ||
|
||
|
||
def flatten(flat_ga_module, mv): | ||
return flat_ga_module.FlatMv([blade_coef for blade_coef in mv.blade_coefs()]) | ||
|
||
|
||
def expand(GA, flat_mv): | ||
assert len(flat_mv.coefs) == len(GA._all_blades_lst) | ||
mv = GA.mv(0, 'scalar') | ||
for blade_coef, blade in zip(flat_mv.coefs, GA._all_blades_lst): | ||
mv += blade_coef * blade | ||
return mv | ||
|
||
|
||
if __name__ == "__main__": | ||
GA = Ga('e*1|2|3', g=[1, 1, 1]) | ||
print(format_geometric_algebra(GA)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xref #215.
I think I understand the rough intent here, although it's not clear to me why a separate set of indices or signs are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a "canonical" way for building cobases (see John Browne's book) and PGA uses some kind of "tricky" way for building it (J and Jinv stuff). My implementation is probably not the best we can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@enkimute, is "cobase" consistent with the terminology you'd use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sign is for using the orthogonal wedge implementation provided by galgebra which needs a canonical basis. PGA basis isn't canonical too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you say the PGA basis isn't canonical, do you mean that the default is not to use lexicographically-order basis blades? Eg,
e132
is considered a "base" blade in that algebra, rather thane123
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This forum post captures the issue I assume?
https://discourse.bivector.net/t/dual-operator-disambiguation/59/45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to handle this might just be in the printing only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be very nice if you are able to run test_pga.py without adding the custom indexes and signs. I don't see how we can achieve this.