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

transform kform objects #19

Closed
RobinHankin opened this issue Apr 27, 2019 · 1 comment
Closed

transform kform objects #19

RobinHankin opened this issue Apr 27, 2019 · 1 comment

Comments

@RobinHankin
Copy link
Owner

RobinHankin commented Apr 27, 2019

I asked a question on wikipedia (mathematics helpdesk, 24 April 2019), about transforming kform objects to another coordinate system. The question asked how to express a kform like dx_1 ^ dx_2 ^ dx_3 in terms of dy_1,dy_2,dy_3 where we have linear relationships like dx_1=M[1,1]dy_1 + M[1,2]dy_2 + M[1,3]dy_3. I wanted to know if there was a conceptually pleasant way of doing this.

Well the best I can do is this:

f <-  function(omega,M){
Reduce(`+`,sapply(seq_along(value(omega)),function(i){do.call("wedge",apply(M[index(omega)[i,,drop=FALSE],,drop=FALSE],1,as.1form))*value(omega)[i]},simplify=FALSE))
}

which is pretty dense idiom. But:

> (omega <- rform())
           val
 2 4 6  =   -1
 1 5 6  =   -1
 2 5 7  =    1
 1 4 6  =    2
 1 3 6  =   -1
 1 2 6  =   -1
 2 3 7  =   -1
 2 3 4  =    1
> (M <- matrix(round(rnorm(49),2),7,7))
      [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]
[1,] -0.75 -0.92 -1.30 -0.80 -0.10 -0.56 -0.39
[2,]  0.83 -0.76 -2.33 -1.80  0.12  1.54  0.56
[3,]  1.00 -1.47  0.09  0.22 -0.47  1.92  0.77
[4,]  0.72 -1.27 -0.31  0.74 -0.92 -0.43  0.43
[5,]  0.89 -0.36  2.49  1.35 -0.26  0.68  0.94
[6,] -0.03 -0.80 -0.37  0.03  0.73  0.65  0.39
[7,] -0.48 -1.77 -1.81  1.77  0.31 -0.37  1.92
> f(omega,M)
                 val
 1 2 3  =   0.080255
 1 3 6  =  -6.201454
 1 2 6  =   2.450020
 4 5 7  =  -4.005752
 2 4 7  =   3.807063
[snip]

and indeed we can transform and then transform back to the original coordinates with only small numerical error:

> max(abs(value(omega %>% f(M) %>% f(solve(M)) - omega)))
[1] 5.77316e-15
> 

But this takes a very long time to run and I can't help thinking that there might be some factorization or other trick or technique that would make the code run faster, and perhaps more transparently.

@RobinHankin
Copy link
Owner Author

RobinHankin commented Apr 28, 2019

but there is a bug in f():

> omega <- as.1form(1:7)
> f(omega,M)
Error in inherits(F2, "kform") : 
  argument "F2" is missing, with no default
>

This is because wedge() expects at least two arguments, I will deal with this separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant