Skip to main content
Commonmark migration
Source Link

Jelly,  23 22  18 bytes

-4 bytes thanks to miles (use of { and } while using their formula.

;I}ÆẠP+ÆSP${ÆA×⁽£ġ

A dyadic function accepting [ϕ1, ϕ2,] on the left and [λ1, λ2] on the right in radians that returns the result (as floating point).

Try it online!


Mine... (also saved a byte here by using a {)

,IÆẠCH;ÆẠ{Ḣ+PƊ½ÆṢ×⁽µṣ

Try it online

Jelly,  23 22  18 bytes

-4 bytes thanks to miles (use of { and } while using their formula.

;I}ÆẠP+ÆSP${ÆA×⁽£ġ

A dyadic function accepting [ϕ1, ϕ2,] on the left and [λ1, λ2] on the right in radians that returns the result (as floating point).

Try it online!


Mine... (also saved a byte here by using a {)

,IÆẠCH;ÆẠ{Ḣ+PƊ½ÆṢ×⁽µṣ

Try it online

Jelly,  23 22  18 bytes

-4 bytes thanks to miles (use of { and } while using their formula.

;I}ÆẠP+ÆSP${ÆA×⁽£ġ

A dyadic function accepting [ϕ1, ϕ2,] on the left and [λ1, λ2] on the right in radians that returns the result (as floating point).

Try it online!


Mine... (also saved a byte here by using a {)

,IÆẠCH;ÆẠ{Ḣ+PƊ½ÆṢ×⁽µṣ

Try it online

deleted 1373 characters in body
Source Link
Jonathan Allan
  • 115.9k
  • 8
  • 69
  • 294

Jelly,  23 22  2218 bytes

-4 bytes thanks to miles (use of { and } while using their formula.

,IÆẠCH;⁸ÆẠ¤Ḣ+PƊ½ÆṢ×⁽µṣ;I}ÆẠP+ÆSP${ÆA×⁽£ġ

Try it online!Try it online!

How?

,IÆẠCH;⁸ÆẠ¤Ḣ+PƊ½ÆṢ×⁽µṣ - Link: [ϕ1, ϕ2]; [λ1, λ2]
,                      - pair = [[ϕ1, ϕ2], [λ1, λ2]]
 I                     - incremental differences = [ϕ2-ϕ1, λ2-λ1]
  ÆẠ                   - cosine = [cos(ϕ2-ϕ1), cos(λ2-λ1)]
    C                  - complement = [1-cos(ϕ2-ϕ1), 1-cos(λ2-λ1)]
     H                 - halve = [sin²((ϕ2-ϕ1)/2), sin²((λ2-λ1)/2)]
          ¤            - nilad followed by links as a nilad:
       ⁸               -   chain's left argument = [ϕ1, ϕ2]
        ÆẠ             -   cosine = [cos(ϕ1), cos(ϕ2)]
      ;                - concatenate = [sin²((ϕ2-ϕ1)/2), sin²((λ2-λ1)/2), cos(ϕ1), cos(ϕ2)]
              Ɗ        - last three links as a monad:
           Ḣ           -   remove head and yield = sin²((ϕ2-ϕ1)/2)
             P         -   product = sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)
            +          -   add = sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)
               ½       - square-root = √(sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2))
                ÆṢ     - arcsine = asin(√(sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)))
                   ⁽µṣ - literal 3474
                  ×    - multiply = 3474×asin(√(sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)))

GolfingMine... (miles') alternate form,also saved a byte here by using a r × acos(sin(ϕ1) × sin(ϕ2) + cos(ϕ1) × cos(ϕ2) × cos(λ2 - λ1)){, I got this 23 byter:)

ÆSżÆẠƊP;⁹IÆẠ¤Ḣ+PƊÆA×⁽£ġ,IÆẠCH;ÆẠ{Ḣ+PƊ½ÆṢ×⁽µṣ

Try it onlineTry it online

Jelly,  23  22 bytes

,IÆẠCH;⁸ÆẠ¤Ḣ+PƊ½ÆṢ×⁽µṣ

Try it online!

How?

,IÆẠCH;⁸ÆẠ¤Ḣ+PƊ½ÆṢ×⁽µṣ - Link: [ϕ1, ϕ2]; [λ1, λ2]
,                      - pair = [[ϕ1, ϕ2], [λ1, λ2]]
 I                     - incremental differences = [ϕ2-ϕ1, λ2-λ1]
  ÆẠ                   - cosine = [cos(ϕ2-ϕ1), cos(λ2-λ1)]
    C                  - complement = [1-cos(ϕ2-ϕ1), 1-cos(λ2-λ1)]
     H                 - halve = [sin²((ϕ2-ϕ1)/2), sin²((λ2-λ1)/2)]
          ¤            - nilad followed by links as a nilad:
       ⁸               -   chain's left argument = [ϕ1, ϕ2]
        ÆẠ             -   cosine = [cos(ϕ1), cos(ϕ2)]
      ;                - concatenate = [sin²((ϕ2-ϕ1)/2), sin²((λ2-λ1)/2), cos(ϕ1), cos(ϕ2)]
              Ɗ        - last three links as a monad:
           Ḣ           -   remove head and yield = sin²((ϕ2-ϕ1)/2)
             P         -   product = sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)
            +          -   add = sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)
               ½       - square-root = √(sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2))
                ÆṢ     - arcsine = asin(√(sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)))
                   ⁽µṣ - literal 3474
                  ×    - multiply = 3474×asin(√(sin²((ϕ2-ϕ1)/2) + sin²((λ2-λ1)/2) × cos(ϕ1) × cos(ϕ2)))

Golfing (miles') alternate form, r × acos(sin(ϕ1) × sin(ϕ2) + cos(ϕ1) × cos(ϕ2) × cos(λ2 - λ1)), I got this 23 byter:

ÆSżÆẠƊP;⁹IÆẠ¤Ḣ+PƊÆA×⁽£ġ

Try it online

Jelly,  23 22  18 bytes

-4 bytes thanks to miles (use of { and } while using their formula.

;I}ÆẠP+ÆSP${ÆA×⁽£ġ

Try it online!

Mine... (also saved a byte here by using a {)

,IÆẠCH;ÆẠ{Ḣ+PƊ½ÆṢ×⁽µṣ

Try it online

added 407 characters in body
Source Link
Jonathan Allan
  • 115.9k
  • 8
  • 69
  • 294

Golfing (miles') alternate form, r × acos(sin(ϕ1) × sin(ϕ2) + cos(ϕ1) × cos(ϕ2) × cos(λ2 - λ1)), I got this 23 byter:

ÆSżÆẠƊP;⁹IÆẠ¤Ḣ+PƊÆA×⁽£ġ

Try it online


Golfing (miles') alternate form, r × acos(sin(ϕ1) × sin(ϕ2) + cos(ϕ1) × cos(ϕ2) × cos(λ2 - λ1)), I got this 23 byter:

ÆSżÆẠƊP;⁹IÆẠ¤Ḣ+PƊÆA×⁽£ġ

Try it online

added 1354 characters in body
Source Link
Jonathan Allan
  • 115.9k
  • 8
  • 69
  • 294
Loading
Source Link
Jonathan Allan
  • 115.9k
  • 8
  • 69
  • 294
Loading