Representing a distance measure with math equation

I'm working on presenting a distance measure at a conference but don't have a publication quality math formula for representing what I'm doing in R. Below I have the problem laid out in it's simplest form and would like help representing this in a mathematical expression that would be of the type expected for publication (i.e., you can use LaTeX to show it).

I have data with two codes that run along a intervals across time as seen below in the dataframe and represented in the gantt plot as well:

Code:

code start end Start End variable
1 A 159 200 00:02:39 00:03:20
2 A 391 420 00:06:31 00:07:00
3 A 539 580 00:08:59 00:09:40
4 A 599 660 00:09:59 00:11:00
5 A 763 796 00:12:43 00:13:16
6 B 180 225 00:03:00 00:03:45
7 B 300 339 00:05:00 00:05:39
8 B 599 600 00:09:59 00:10:00
9 B 719 781 00:11:59 00:13:01

For every A interval (any location along A) we will find the nearest B interval (any location along B) and calculate the distance between them.

In this related post Bryan discusses interval arithmetic algebra but I'm not sure how to write in a journal specific way that I want for ever A code the minimum distance to the enarest B code.

Re: Representing a distance measure with math equation

@Vinux, I'm sorry I wasn't clear. I'm looking to make an equation not do it in R (I can do it with words and with computer code but not as an equation).

@BGM, I think that's it. Thank you. I'm looking at stuff online to learn more now. Thanks.

"If you torture the data long enough it will eventually confess."
-Ronald Harry Coase -

Re: Representing a distance measure with math equation

Not quite. Yours only gives a distance of 0 if any of the endpoints overlap. You could use your notation (although I think it's a little bit more complex with the subscripts than necessary) but consider using BGMs already defined distance.

I don't have emotions and sometimes that makes me very sad.

Re: Representing a distance measure with math equation

Originally Posted by Dason

You could try something like this:
Let be the jth interval in B then define

Now

One of the other methods might be better for your audience though?

Yeah I no longer got it I'm guessing BGM's is the most understandable to my audience. I had to look stuff up in vinu's approach and Dason's there are symbols I don't know yet (but will try to by the end of the day).

"If you torture the data long enough it will eventually confess."
-Ronald Harry Coase -