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

Question about multiplication #1

Open
folivetti opened this issue Oct 14, 2019 · 1 comment
Open

Question about multiplication #1

folivetti opened this issue Oct 14, 2019 · 1 comment

Comments

@folivetti
Copy link

levitate/src/Affine.hs

Lines 226 to 244 in 8dfcf39

(*@) :: Affine -> Affine -> AffineMonad Affine
(*@) Empty _ = return Empty
(*@) _ Empty = return Empty
(*@) RealLine _ = return RealLine
(*@) _ RealLine = return RealLine
(*@) x@(Affine cx _) y@(Affine cy _) = do
let rx = radius x
let ry = radius y
let δ = rx *↑ ry
let p = (Interval.make cx cx) *! (Interval.make cy cy)
let δ' = δ +↑ (Interval.radius p)
<- makeFreshAffine (-(Interval.midpoint p)) []
<- makeFreshAffine δ' []
a1 <- cy ·@ x
a2 <- cx ·@ y
a3 <- a1 +@ a2
a4 <- a3 +@
a5 <- a4 +@
return a5

Hi,

as I understand from this piece of code, for two affines

x = x0 + x1 . e1
y = y0 + y1 . e2

their multiplication are calculated as:

z = x0y0 + y0x0 - x0y0 + y0x1e1 + x0y1e2 + |x1||y1|
  = (x0y0 + |x1||y1|) + y0x1e1 + x0y1e2

But by reading Stolffi reference, it should be:

z = x0y0  + y0x1e1 + x0y1e2 + |x1||y1|e3

In my tests your implementation seems to lead to more accurate results. Do you have any reference for that?

@kevinclancy
Copy link
Owner

Hi. I'm a little rusty on affine arithmetic at the moment. I was hoping to do some review and get back to you with a fully satisfying answer, but I have been pretty busy lately. My implementation does seem different than the one described by Stolfi, but I recall thinking of this project as an implementation of parts of Stolfi's tutorial. I don't recall drawing from any other sources; perhaps I just made a mistake.

I've been hoping to review affine arithmetic in order to examine it from a category theoretic perspective, but I can't say when that will happen.

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

2 participants