Comments (20)
Thanks, this can be confirmed as a bug. The current implementation is naive and didn't consider negative cases. Will address it later.
from galgebra.
@mammalwong Hi, thanks for reporting these issues! Sorry that I just noticed them.
Which version of GAlgebra are you using? Are these bugs recent regression or they existed for a long time?
P.S. I wonder what are you using GAlgebra for? Physics, computer graphics, learning GA etc.?
from galgebra.
@utensil the version is 0.5.1. I was running the code on google colab, and it has to execute pip install galgebra whenever a new cloud machine is assigned to run my code. I have only start to use galgebra 2 days before I report this issue so I have no idea whether this issue is a recent regression or is a long existing issue.
My background is computer science and I had personal studies of traditional vector algebra based computer graphics and physics (which are mostly physics for games which are discretely approximated to just "convince" the player), I had also self studied basic geometric algebra (no geometric calculus and only GA with a diagonal metric tensor with 1/-1/0 elements, and primarily Cl(3,0,1) which is 3d projective GA for games).
For what I am using galgebra for, I have implemented the methods in section 15 and 20 of https://www.cphysics.org/article/86175.pdf to generate matrix representation of non-degenerate GA, and extended it to also generate matrix rep of degenerate GA, I am using galgebra to crosscheck and validate whether the operations on matrix presentations are correct or not, and my main focus is to see how computational effective are GA compare to traditional vector algebra (which have lots of existing hardware optimization). Besides it, geometric algebra neural layer are also one of the raising topic in the deep-learning/AI field which relate to my profession.
I wonder if you will implement matrix representation of GA? as I found it is pretty easy to calculate fractional power and exponential of a multivector using its matrix rep with matrix exponential, and it is quite easy to inverse map a matrix rep back to its multivector form.
from galgebra.
Good to learn about Matrix Representations of Clifford Algebras, it would be nice to have matrix representations implemented but not a priority for me at present.
Would you be interested in discussing GA in a discord with many GA enthusiasts ? https://discord.gg/2tQZVYkD
from galgebra.
Thanks for the discord invitation, yeah I will join it, is it the discord of bivector.net?
By the way, do you interest in how am I extending the non-degenerate GA only matrix representation generation to include also degenerate GA?
from galgebra.
Yes, it is.
Yes, I'm also interested in degenerate GAs, and looking forwards to tests or new features in this direction.
from galgebra.
I extended the non-degenerate GA matrix rep generation to include also degenerate GA like this: for Cl(p,q,r), I generate the matrix rep of Cl( p+r, q+r, 0) instead, then for each positive negative extra r basis pair a and b, the degenerate basis can be created as either
I think you should know them already,
from galgebra.
@mammalwong Can you also post minimal working example for this issue? Thanks!
from galgebra.
here is an example to reproduce this issue:
ga = Ga('e', g=[1,1,1], coords=S.symbols(f"0:{3}", real=True), wedge=False)
ex,ey,ez = ga.mv()
ex**-1, ga.mv(1)/ex
returns:
1, e0
expected correct output:
e0, e0
from galgebra.
@mammalwong This should also be fixed in the branch now.
from galgebra.
@utensil I have tested this issue with the branch again, I can confirm this issue is fixed.
from galgebra.
Thanks, it's also added to the test cases as examples/issue-511.ipynb
to prevent future regression.
from galgebra.
@utensil, looks like the current implementation of __pow__
is having
def pow(x, y):
if y < 0:
x, y = 1/x, -y
rval = 1
y_int = int(y)
y_fractional = y - y_int
# y_fractional is always between 0 and 1
if y_fractional > 0:
rval *= x**y_fractional
y = y_int
while True:
if y & 1 != 0:
rval *= x
y >>= 1
if y == 0:
break
x = x * x
return rval
# test
X,Y = 2,5.5
pow(X, Y), X**Y
from galgebra.
Would the implementation also support non-integer powers of multivectors? It doesn't look correct to me in that part.
As a symbolic library, my personal take is to prefer simple readable implementation rather than over-optimized ones. I would also prefer to delegate such optimizations to low-level implementation in SymPy as much as possible and keep GAlgebra minimal.
Although in this case it's simple enough, but to adopt such an implementation, much more unit tests upon more GAs and more blades are required. Your test only verified numeric x, y so far.
from galgebra.
@utensil that implementation was copied from my previous code for other purpose, let me rewrite the code to compare with the current implementation of galgebra:
def __pow__(self, n): # Integer power operator
if not isinstance(n, int):
raise ValueError('!!!!Multivector power can only be to integer power!!!!')
x, y = self, n
if y < 0:
x, y = x.inv(), -y
# compute result = x**y
result = Mv(S.One, 'scalar', ga=self.Ga)
while True:
if y & 1 != 0:
result *= x
y >>= 1
if y == 0:
break
x = x * x
return result
This should be still simple compare to the current O(n) implementation in galgebra
from galgebra.
I'll be happy to take a PR to address this, with proper test coverage, and some investigation about the possibility to delegate such details to SymPy.
GAlgebra is built as a reference symbolic implementation and my usage of it relies on its correctness heavily. So I'll need to be very sure about the correctness (i.e. proper test coverage, or delegating to maintained dependencies e.g. SymPy which also breaks sometimes).
The implementation you are suggesting is simple and it's particularly good for GA, besides it's x*x
would be simplified a lot due to the quadratic form of GA.
But unfortunately I need to note that GAlgebra is in maintenance mode, as its maintainers are preoccupied from time to time, like I was in the last few years (when GAlgebra was almost idle, except for the changes being updated in #510 ). Lately I have more time to invest into it as I need it again for cross-library validations, so it will be actively maintained for a while.
Being in maintenance mode means that maintainers would accept PRs, fix bugs with their best effort, but will not be actively developing new features unless they need them themselves too.
In the case of the changes you're proposing, to ensure its correctness, I need 10x work to add the tests etc. for different GAs and blades, and it's not going to be a priority in weeks at least. Sorry.
from galgebra.
Understandable and thanks for the explanation of the situation 👍
from galgebra.
Thanks, and I've opened separate issues for them. This issue will be closed when the fixes of the original issues are merged into master.
from galgebra.
Thank you, @mammalwong , the fix should be in master now as #510 is now merged.
from galgebra.
@utensil thanks for the acknowledgement!
from galgebra.
Related Issues (20)
- Run tests on latest sympy HOT 1
- Extra `\cdot` since SymPy 1.10 HOT 2
- Broken `MatrixFunction` since SymPy 1.11 HOT 2
- Broken doc since #487 HOT 2
- Sync upstream updates HOT 2
- The sundial problem and a cheat sheet by Russell Goyder
- expression like 1/<Mv> raise exception HOT 2
- diff and pdiff method of class Mv throws exception when differentiate by a coordinate symbol HOT 4
- Mv.dual() method return wrong result HOT 7
- The wedge product operator ^ returns wrong result HOT 1
- Mv.grades return None under some situations HOT 1
- Mv.__pow__ is not returning Mv instance as return value when raise to power of zero HOT 5
- Make `__pow__` more performant
- Make `__pow__` support rational powers as well
- Sort out scattered LaTeX preambles HOT 1
- `norm` has no abs bar for even grades
- Improve doc on available GA operations in README
- Provide a kingdon-like interface, and run cross-library test cases
- Improve Migrating guide for readers of LAGA&VAGC
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from galgebra.