<commit_before>module prelude.complex

import builtins


------------------------------ General

infix 6 :+
data Complex a = (:+) a a

realPart : Complex a -> a
realPart (r:+i) = r

imagPart : Complex a -> a
imagPart (r:+i) = i


------------------------------ Polarform

mkPolar : Float -> Float -> Complex Float
mkPolar radius angle = radius * cos angle :+ radius * sin angle

cis : Float -> Complex Float
cis angle = cos angle :+ sin angle

magnitude : Complex Float -> Float
magnitude (r:+i) = sqrt (r*r+i*i)

phase : Complex Float -> Float
phase (x:+y) = atan2 y x<commit_msg>added instance declarations of complex a for class eq and show<commit_after>module prelude.complex

import builtins


------------------------------ General

infix 6 :+
data Complex a = (:+) a a

realPart : Complex a -> a
realPart (r:+i) = r

imagPart : Complex a -> a
imagPart (r:+i) = i


------------------------------ Instances

instance Eq a => Eq (Complex a) where
    (==) a b = realPart a == realPart b && imagPart a == imagPart b

instance Show a => Show (Complex a) where
    show (r:+i) = "("++show r++":+"++show i++")"

------------------------------ Polarform

mkPolar : Float -> Float -> Complex Float
mkPolar radius angle = radius * cos angle :+ radius * sin angle

cis : Float -> Complex Float
cis angle = cos angle :+ sin angle

magnitude : Complex Float -> Float
magnitude (r:+i) = sqrt (r*r+i*i)

phase : Complex Float -> Float
phase (x:+y) = atan2 y x
{'fraction_non_alphanumeric': 0.22038567493112948, 'fraction_numerical': 0.0027548209366391185, 'mean_word_length': 2.2947845804988662, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '776820', 'n_tokens_mistral': 474, 'n_tokens_neox': 450, 'n_words': 175}