├── .gitignore ├── .swift-version ├── .swiftlint.yml ├── .travis.yml ├── Arithmosophi.podspec ├── Arithmosophi.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ ├── Arithmosophi.xccheckout │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── eric.xcuserdatad │ │ └── UserInterfaceState.xcuserstate ├── xcshareddata │ └── xcschemes │ │ ├── Arithmosophi.xcscheme │ │ ├── ArithmosophiOSX.xcscheme │ │ ├── ArithmosophiTVOS.xcscheme │ │ └── ArithmosophiWatchOS.xcscheme └── xcuserdata │ ├── eric.xcuserdatad │ └── xcschemes │ │ └── xcschememanagement.plist │ └── phimage.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── LICENSE ├── Package.swift ├── Playgrounds └── Arithmosophi.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── timeline.xctimeline ├── README.md ├── Samples ├── Boolean.swift ├── Box.swift ├── Geometry+Animation.swift ├── Geometry.swift ├── Info.plist ├── Optional.swift └── Parity.swift ├── Sources ├── Arithmos.swift ├── Arithmosophi.swift ├── Complex.swift ├── LogicalOperationsType.swift ├── MesosOros.swift ├── Sigma.swift └── Statheros.swift ├── Tests └── ArithmosophiOSXTests.swift ├── Xcode ├── OSX │ ├── ArithmosophiOSX.h │ └── Info.plist ├── TVOS │ ├── ArithmosophiTVOS.h │ └── Info.plist ├── WatchOS │ ├── ArithmosophiWatchOS.h │ └── Info.plist └── iOS │ ├── Arithmosophi.h │ └── Info.plist └── logo.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Adapted from https://github.com/github/gitignore/blob/master/Objective-C.gitignore 2 | 3 | # Finder 4 | .DS_Store 5 | 6 | # Xcode 7 | ## Build generated 8 | build/ 9 | DerivedData/ 10 | 11 | ## Various settings 12 | *.pbxuser 13 | !default.pbxuser 14 | *.mode1v3 15 | !default.mode1v3 16 | *.mode2v3 17 | !default.mode2v3 18 | *.perspectivev3 19 | !default.perspectivev3 20 | xcuserdata/ 21 | 22 | ## Other 23 | *.moved-aside 24 | *.xccheckout 25 | *.xcscmblueprint 26 | 27 | ## Obj-C/Swift specific 28 | *.hmap 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 5.3 2 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | disabled_rules: 2 | - line_length 3 | - file_length 4 | - type_body_length 5 | - variable_name 6 | - large_tuple 7 | - function_parameter_count 8 | variable_name_min_length: 9 | - 0 # warning 10 | - 0 # error 11 | 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode10.0 3 | env: 4 | global: 5 | - LC_CTYPE=en_US.UTF-8 6 | - LANG=en_US.UTF-8 7 | - PROJECT=Arithmosophi.xcodeproj 8 | - IOS_SDK=iphonesimulator12.0 9 | - MACOS_SDK=macosx10.13 10 | matrix: 11 | - DESTINATION="OS=12.0,name=iPhone 8" SCHEME="Arithmosophi" SDK="$IOS_SDK" RUN_TESTS="" 12 | - DESTINATION="arch=x86_64" SCHEME="ArithmosophiOSX" SDK="$MACOS_SDK" RUN_TESTS="YES" 13 | before_install: 14 | - gem install cocoapods --no-rdoc --no-ri --no-document --quiet 15 | - gem install xcpretty --no-rdoc --no-ri --no-document --quiet 16 | script: 17 | - set -o pipefail 18 | - xcodebuild -version 19 | - xcodebuild -showsdks 20 | - if [ $RUN_TESTS == "YES" ]; then 21 | xcodebuild -project "$PROJECT" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty; 22 | else 23 | xcodebuild -project "$PROJECT" -scheme "$SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO build | xcpretty; 24 | fi 25 | after_success: 26 | - bash <(curl -s https://codecov.io/bash) 27 | 28 | branches: 29 | only: 30 | - master 31 | -------------------------------------------------------------------------------- /Arithmosophi.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 4 | s.name = "Arithmosophi" 5 | s.version = "4.3.0" 6 | s.summary = "A set of protocols for Arithmetic and Logic" 7 | s.description = <<-DESC 8 | Arithmosophi is a set of missing protocols that simplify 9 | arithmetic, statistics and logicals operations on generic objects or functions. 10 | DESC 11 | s.homepage = "https://github.com/phimage/Arithmosophi" 12 | 13 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 14 | s.license = "MIT" 15 | 16 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 17 | s.author = { "phimage" => "eric.marchand.n7@gmail.com" } 18 | 19 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 20 | s.ios.deployment_target = '9.0' 21 | s.osx.deployment_target = '10.10' 22 | s.watchos.deployment_target = '2.0' 23 | s.tvos.deployment_target = '9.0' 24 | 25 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 26 | s.source = { :git => "https://github.com/phimage/Arithmosophi.git", :tag => s.version } 27 | 28 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 29 | 30 | s.default_subspec = 'All' 31 | 32 | s.subspec "Core" do |sp| 33 | sp.source_files = "Sources/Arithmosophi.swift" 34 | end 35 | 36 | s.subspec "Logical" do |sp| 37 | sp.source_files = ['Sources/LogicalOperationsType.swift'] 38 | end 39 | 40 | s.subspec "Arithmos" do |sp| 41 | sp.source_files = ['Sources/Arithmos.swift'] 42 | end 43 | 44 | s.subspec "Statheros" do |sp| 45 | sp.source_files = ['Sources/Statheros.swift'] 46 | end 47 | 48 | s.subspec "Complex" do |sp| 49 | sp.source_files = "Sources/Complex.swift" 50 | sp.dependency 'Arithmosophi/Core' 51 | sp.dependency 'Arithmosophi/Arithmos' 52 | end 53 | 54 | s.subspec "MesosOros" do |sp| 55 | sp.source_files = ['Sources/MesosOros.swift'] 56 | sp.dependency 'Arithmosophi/Core' 57 | end 58 | 59 | s.subspec "Sigma" do |sp| 60 | sp.source_files = ['Sources/Sigma.swift'] 61 | sp.dependency 'Arithmosophi/MesosOros' 62 | sp.dependency 'Arithmosophi/Arithmos' 63 | end 64 | 65 | s.subspec "Samples" do |sp| 66 | sp.source_files = "Samples/*.swift" 67 | sp.dependency 'Arithmosophi/All' 68 | end 69 | 70 | s.subspec "All" do |sp| 71 | sp.dependency 'Arithmosophi/Core' 72 | sp.dependency 'Arithmosophi/Logical' 73 | sp.dependency 'Arithmosophi/Arithmos' 74 | sp.dependency 'Arithmosophi/Complex' 75 | sp.dependency 'Arithmosophi/Statheros' 76 | sp.dependency 'Arithmosophi/MesosOros' 77 | sp.dependency 'Arithmosophi/Sigma' 78 | end 79 | 80 | end 81 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C43F37B11C15C10B00C0915D /* ArithmosophiWatchOS.h in Headers */ = {isa = PBXBuildFile; fileRef = C43F37B01C15C10B00C0915D /* ArithmosophiWatchOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | C43F37BE1C15C12A00C0915D /* ArithmosophiTVOS.h in Headers */ = {isa = PBXBuildFile; fileRef = C43F37BD1C15C12A00C0915D /* ArithmosophiTVOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; 12 | C43F37C31C15C13600C0915D /* Arithmosophi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004761B304D6900EB0C80 /* Arithmosophi.swift */; }; 13 | C43F37C41C15C13600C0915D /* LogicalOperationsType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4478C381B31911800194715 /* LogicalOperationsType.swift */; }; 14 | C43F37C51C15C13600C0915D /* Arithmos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004861B30530D00EB0C80 /* Arithmos.swift */; }; 15 | C43F37C61C15C13600C0915D /* Statheros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004741B304D5600EB0C80 /* Statheros.swift */; }; 16 | C43F37C71C15C13600C0915D /* MesosOros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4687F021B452FB80063EC05 /* MesosOros.swift */; }; 17 | C43F37C81C15C13600C0915D /* Complex.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E20DFE1C046774000655FA /* Complex.swift */; }; 18 | C43F37C91C15C13600C0915D /* Arithmosophi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004761B304D6900EB0C80 /* Arithmosophi.swift */; }; 19 | C43F37CA1C15C13600C0915D /* LogicalOperationsType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4478C381B31911800194715 /* LogicalOperationsType.swift */; }; 20 | C43F37CB1C15C13600C0915D /* Arithmos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004861B30530D00EB0C80 /* Arithmos.swift */; }; 21 | C43F37CC1C15C13600C0915D /* Statheros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004741B304D5600EB0C80 /* Statheros.swift */; }; 22 | C43F37CD1C15C13600C0915D /* MesosOros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4687F021B452FB80063EC05 /* MesosOros.swift */; }; 23 | C43F37CE1C15C13600C0915D /* Complex.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E20DFE1C046774000655FA /* Complex.swift */; }; 24 | C4478C391B31911800194715 /* LogicalOperationsType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4478C381B31911800194715 /* LogicalOperationsType.swift */; }; 25 | C4687F051B4535CF0063EC05 /* MesosOros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4687F021B452FB80063EC05 /* MesosOros.swift */; }; 26 | C4687F061B4535D00063EC05 /* MesosOros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4687F021B452FB80063EC05 /* MesosOros.swift */; }; 27 | C470045E1B304CE200EB0C80 /* Arithmosophi.h in Headers */ = {isa = PBXBuildFile; fileRef = C470045D1B304CE200EB0C80 /* Arithmosophi.h */; settings = {ATTRIBUTES = (Public, ); }; }; 28 | C47004751B304D5600EB0C80 /* Statheros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004741B304D5600EB0C80 /* Statheros.swift */; }; 29 | C47004771B304D6900EB0C80 /* Arithmosophi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004761B304D6900EB0C80 /* Arithmosophi.swift */; }; 30 | C47004941B30560700EB0C80 /* ArithmosophiOSX.h in Headers */ = {isa = PBXBuildFile; fileRef = C47004931B30560700EB0C80 /* ArithmosophiOSX.h */; settings = {ATTRIBUTES = (Public, ); }; }; 31 | C470049A1B30560700EB0C80 /* Arithmosophi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C470048F1B30560700EB0C80 /* Arithmosophi.framework */; }; 32 | C47004A11B30560700EB0C80 /* ArithmosophiOSXTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004A01B30560700EB0C80 /* ArithmosophiOSXTests.swift */; }; 33 | C47004A81B30560D00EB0C80 /* Arithmosophi.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004761B304D6900EB0C80 /* Arithmosophi.swift */; }; 34 | C47004A91B30560D00EB0C80 /* Statheros.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004741B304D5600EB0C80 /* Statheros.swift */; }; 35 | C496F15C1D49648D008A2637 /* Sigma.swift in Sources */ = {isa = PBXBuildFile; fileRef = C496F15B1D49648D008A2637 /* Sigma.swift */; }; 36 | C496F15D1D496DA7008A2637 /* Sigma.swift in Sources */ = {isa = PBXBuildFile; fileRef = C496F15B1D49648D008A2637 /* Sigma.swift */; }; 37 | C496F15E1D496DA7008A2637 /* Sigma.swift in Sources */ = {isa = PBXBuildFile; fileRef = C496F15B1D49648D008A2637 /* Sigma.swift */; }; 38 | C496F15F1D496DA7008A2637 /* Sigma.swift in Sources */ = {isa = PBXBuildFile; fileRef = C496F15B1D49648D008A2637 /* Sigma.swift */; }; 39 | C4B1FE7E1D8B45E200B61C97 /* Arithmosophi.h in Headers */ = {isa = PBXBuildFile; fileRef = C470045D1B304CE200EB0C80 /* Arithmosophi.h */; settings = {ATTRIBUTES = (Public, ); }; }; 40 | C4B1FE881D8B45F400B61C97 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BD0FB81B32FE8600787E0F /* Box.swift */; }; 41 | C4B1FE891D8B45F400B61C97 /* Boolean.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BD0FB51B32FAF400787E0F /* Boolean.swift */; }; 42 | C4B1FE8A1D8B45F400B61C97 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4BD0FB11B32F9E500787E0F /* Optional.swift */; }; 43 | C4B1FE8B1D8B45F400B61C97 /* Parity.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4A151901B383EDE00C81C91 /* Parity.swift */; }; 44 | C4B1FE8C1D8B45F400B61C97 /* Geometry.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004841B30514800EB0C80 /* Geometry.swift */; }; 45 | C4B1FE8D1D8B45F400B61C97 /* Geometry+Animation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4478C361B318FFC00194715 /* Geometry+Animation.swift */; }; 46 | C4B1FE8E1D8B462C00B61C97 /* Arithmosophi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C47004581B304CE200EB0C80 /* Arithmosophi.framework */; }; 47 | C4BD0FAD1B32DE8400787E0F /* LogicalOperationsType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4478C381B31911800194715 /* LogicalOperationsType.swift */; }; 48 | C4BD0FAF1B32DF4500787E0F /* Arithmos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004861B30530D00EB0C80 /* Arithmos.swift */; }; 49 | C4BD0FB01B32DF4500787E0F /* Arithmos.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47004861B30530D00EB0C80 /* Arithmos.swift */; }; 50 | C4E20E001C046774000655FA /* Complex.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E20DFE1C046774000655FA /* Complex.swift */; }; 51 | E1DBFB102133703E0097E66C /* Complex.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4E20DFE1C046774000655FA /* Complex.swift */; }; 52 | /* End PBXBuildFile section */ 53 | 54 | /* Begin PBXBuildRule section */ 55 | C43F37A41C15BC2D00C0915D /* PBXBuildRule */ = { 56 | isa = PBXBuildRule; 57 | compilerSpec = com.apple.compilers.proxy.script; 58 | fileType = pattern.proxy; 59 | inputFiles = ( 60 | ); 61 | isEditable = 1; 62 | outputFiles = ( 63 | ); 64 | script = ""; 65 | }; 66 | C4B1FE821D8B45E200B61C97 /* PBXBuildRule */ = { 67 | isa = PBXBuildRule; 68 | compilerSpec = com.apple.compilers.proxy.script; 69 | fileType = pattern.proxy; 70 | inputFiles = ( 71 | ); 72 | isEditable = 1; 73 | outputFiles = ( 74 | ); 75 | script = ""; 76 | }; 77 | /* End PBXBuildRule section */ 78 | 79 | /* Begin PBXContainerItemProxy section */ 80 | C470049B1B30560700EB0C80 /* PBXContainerItemProxy */ = { 81 | isa = PBXContainerItemProxy; 82 | containerPortal = C470044F1B304CE200EB0C80 /* Project object */; 83 | proxyType = 1; 84 | remoteGlobalIDString = C470048E1B30560700EB0C80; 85 | remoteInfo = ArithmosophiOSX; 86 | }; 87 | /* End PBXContainerItemProxy section */ 88 | 89 | /* Begin PBXFileReference section */ 90 | C40F9F351B3BFDC900641947 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 91 | C40F9F361B3BFDD300641947 /* Arithmosophi.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Arithmosophi.podspec; sourceTree = ""; }; 92 | C43F37A71C15BCE100C0915D /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 93 | C43F37AE1C15C10B00C0915D /* Arithmosophi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Arithmosophi.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 94 | C43F37B01C15C10B00C0915D /* ArithmosophiWatchOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ArithmosophiWatchOS.h; sourceTree = ""; }; 95 | C43F37B21C15C10B00C0915D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 96 | C43F37BB1C15C12A00C0915D /* Arithmosophi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Arithmosophi.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 97 | C43F37BD1C15C12A00C0915D /* ArithmosophiTVOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ArithmosophiTVOS.h; sourceTree = ""; }; 98 | C43F37BF1C15C12A00C0915D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 99 | C4478C361B318FFC00194715 /* Geometry+Animation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Geometry+Animation.swift"; sourceTree = ""; }; 100 | C4478C381B31911800194715 /* LogicalOperationsType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogicalOperationsType.swift; sourceTree = ""; }; 101 | C4687F021B452FB80063EC05 /* MesosOros.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MesosOros.swift; sourceTree = ""; }; 102 | C47004581B304CE200EB0C80 /* Arithmosophi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Arithmosophi.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 103 | C470045C1B304CE200EB0C80 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 104 | C470045D1B304CE200EB0C80 /* Arithmosophi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Arithmosophi.h; sourceTree = ""; }; 105 | C47004741B304D5600EB0C80 /* Statheros.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Statheros.swift; sourceTree = ""; }; 106 | C47004761B304D6900EB0C80 /* Arithmosophi.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Arithmosophi.swift; sourceTree = ""; }; 107 | C47004841B30514800EB0C80 /* Geometry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Geometry.swift; sourceTree = ""; }; 108 | C47004861B30530D00EB0C80 /* Arithmos.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Arithmos.swift; sourceTree = ""; }; 109 | C470048F1B30560700EB0C80 /* Arithmosophi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Arithmosophi.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 110 | C47004921B30560700EB0C80 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 111 | C47004931B30560700EB0C80 /* ArithmosophiOSX.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ArithmosophiOSX.h; sourceTree = ""; }; 112 | C47004991B30560700EB0C80 /* ArithmosophiOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ArithmosophiOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 113 | C47004A01B30560700EB0C80 /* ArithmosophiOSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArithmosophiOSXTests.swift; sourceTree = ""; }; 114 | C496F15B1D49648D008A2637 /* Sigma.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sigma.swift; sourceTree = ""; }; 115 | C4A151901B383EDE00C81C91 /* Parity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parity.swift; sourceTree = ""; }; 116 | C4B1FE861D8B45E200B61C97 /* ArithmosophiSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ArithmosophiSample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 117 | C4BD0FB11B32F9E500787E0F /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Optional.swift; sourceTree = ""; }; 118 | C4BD0FB51B32FAF400787E0F /* Boolean.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Boolean.swift; sourceTree = ""; }; 119 | C4BD0FB81B32FE8600787E0F /* Box.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Box.swift; sourceTree = ""; }; 120 | C4E20DFE1C046774000655FA /* Complex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Complex.swift; sourceTree = ""; }; 121 | E1D4850B213376A0001A3D97 /* Arithmosophi.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Arithmosophi.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 122 | E1DBFB11213371310097E66C /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = ""; }; 123 | E1DBFB12213371320097E66C /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 124 | /* End PBXFileReference section */ 125 | 126 | /* Begin PBXFrameworksBuildPhase section */ 127 | C43F37AA1C15C10B00C0915D /* Frameworks */ = { 128 | isa = PBXFrameworksBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | ); 132 | runOnlyForDeploymentPostprocessing = 0; 133 | }; 134 | C43F37B71C15C12A00C0915D /* Frameworks */ = { 135 | isa = PBXFrameworksBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | C47004541B304CE200EB0C80 /* Frameworks */ = { 142 | isa = PBXFrameworksBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | C470048B1B30560700EB0C80 /* Frameworks */ = { 149 | isa = PBXFrameworksBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | C47004961B30560700EB0C80 /* Frameworks */ = { 156 | isa = PBXFrameworksBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | C470049A1B30560700EB0C80 /* Arithmosophi.framework in Frameworks */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | C4B1FE7C1D8B45E200B61C97 /* Frameworks */ = { 164 | isa = PBXFrameworksBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | C4B1FE8E1D8B462C00B61C97 /* Arithmosophi.framework in Frameworks */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXFrameworksBuildPhase section */ 172 | 173 | /* Begin PBXGroup section */ 174 | 48FA10BB2151137500BC000C /* Files */ = { 175 | isa = PBXGroup; 176 | children = ( 177 | C43F37A71C15BCE100C0915D /* .swiftlint.yml */, 178 | C40F9F361B3BFDD300641947 /* Arithmosophi.podspec */, 179 | E1DBFB12213371320097E66C /* LICENSE */, 180 | E1DBFB11213371310097E66C /* logo.png */, 181 | C40F9F351B3BFDC900641947 /* README.md */, 182 | ); 183 | name = Files; 184 | sourceTree = ""; 185 | }; 186 | C433BBAA1F7618730046D5B1 /* Xcode */ = { 187 | isa = PBXGroup; 188 | children = ( 189 | C43F37BC1C15C12A00C0915D /* TVOS */, 190 | C43F37AF1C15C10B00C0915D /* WatchOS */, 191 | C47004901B30560700EB0C80 /* OSX */, 192 | C470045A1B304CE200EB0C80 /* iOS */, 193 | ); 194 | path = Xcode; 195 | sourceTree = ""; 196 | }; 197 | C43F37AF1C15C10B00C0915D /* WatchOS */ = { 198 | isa = PBXGroup; 199 | children = ( 200 | C43F37B01C15C10B00C0915D /* ArithmosophiWatchOS.h */, 201 | C43F37B21C15C10B00C0915D /* Info.plist */, 202 | ); 203 | path = WatchOS; 204 | sourceTree = ""; 205 | }; 206 | C43F37BC1C15C12A00C0915D /* TVOS */ = { 207 | isa = PBXGroup; 208 | children = ( 209 | C43F37BD1C15C12A00C0915D /* ArithmosophiTVOS.h */, 210 | C43F37BF1C15C12A00C0915D /* Info.plist */, 211 | ); 212 | path = TVOS; 213 | sourceTree = ""; 214 | }; 215 | C470044E1B304CE200EB0C80 = { 216 | isa = PBXGroup; 217 | children = ( 218 | 48FA10BB2151137500BC000C /* Files */, 219 | C4B1FE721D8B3FAD00B61C97 /* Sources */, 220 | E1D4850A21337667001A3D97 /* Playgrounds */, 221 | C4BD0FB31B32FA8400787E0F /* Samples */, 222 | C433BBAA1F7618730046D5B1 /* Xcode */, 223 | C470049D1B30560700EB0C80 /* Tests */, 224 | C47004591B304CE200EB0C80 /* Products */, 225 | ); 226 | sourceTree = ""; 227 | }; 228 | C47004591B304CE200EB0C80 /* Products */ = { 229 | isa = PBXGroup; 230 | children = ( 231 | C47004581B304CE200EB0C80 /* Arithmosophi.framework */, 232 | C470048F1B30560700EB0C80 /* Arithmosophi.framework */, 233 | C47004991B30560700EB0C80 /* ArithmosophiOSXTests.xctest */, 234 | C43F37AE1C15C10B00C0915D /* Arithmosophi.framework */, 235 | C43F37BB1C15C12A00C0915D /* Arithmosophi.framework */, 236 | C4B1FE861D8B45E200B61C97 /* ArithmosophiSample.framework */, 237 | ); 238 | name = Products; 239 | sourceTree = ""; 240 | }; 241 | C470045A1B304CE200EB0C80 /* iOS */ = { 242 | isa = PBXGroup; 243 | children = ( 244 | C470045D1B304CE200EB0C80 /* Arithmosophi.h */, 245 | C470045C1B304CE200EB0C80 /* Info.plist */, 246 | ); 247 | path = iOS; 248 | sourceTree = ""; 249 | }; 250 | C47004901B30560700EB0C80 /* OSX */ = { 251 | isa = PBXGroup; 252 | children = ( 253 | C47004931B30560700EB0C80 /* ArithmosophiOSX.h */, 254 | C47004921B30560700EB0C80 /* Info.plist */, 255 | ); 256 | path = OSX; 257 | sourceTree = ""; 258 | }; 259 | C470049D1B30560700EB0C80 /* Tests */ = { 260 | isa = PBXGroup; 261 | children = ( 262 | C47004A01B30560700EB0C80 /* ArithmosophiOSXTests.swift */, 263 | ); 264 | path = Tests; 265 | sourceTree = ""; 266 | }; 267 | C4B1FE721D8B3FAD00B61C97 /* Sources */ = { 268 | isa = PBXGroup; 269 | children = ( 270 | C47004861B30530D00EB0C80 /* Arithmos.swift */, 271 | C47004761B304D6900EB0C80 /* Arithmosophi.swift */, 272 | C4E20DFE1C046774000655FA /* Complex.swift */, 273 | C4478C381B31911800194715 /* LogicalOperationsType.swift */, 274 | C4687F021B452FB80063EC05 /* MesosOros.swift */, 275 | C496F15B1D49648D008A2637 /* Sigma.swift */, 276 | C47004741B304D5600EB0C80 /* Statheros.swift */, 277 | ); 278 | path = Sources; 279 | sourceTree = ""; 280 | }; 281 | C4BD0FB31B32FA8400787E0F /* Samples */ = { 282 | isa = PBXGroup; 283 | children = ( 284 | C4BD0FB51B32FAF400787E0F /* Boolean.swift */, 285 | C4BD0FB81B32FE8600787E0F /* Box.swift */, 286 | C47004841B30514800EB0C80 /* Geometry.swift */, 287 | C4478C361B318FFC00194715 /* Geometry+Animation.swift */, 288 | C4BD0FB11B32F9E500787E0F /* Optional.swift */, 289 | C4A151901B383EDE00C81C91 /* Parity.swift */, 290 | ); 291 | path = Samples; 292 | sourceTree = ""; 293 | }; 294 | E1D4850A21337667001A3D97 /* Playgrounds */ = { 295 | isa = PBXGroup; 296 | children = ( 297 | E1D4850B213376A0001A3D97 /* Arithmosophi.playground */, 298 | ); 299 | path = Playgrounds; 300 | sourceTree = ""; 301 | }; 302 | /* End PBXGroup section */ 303 | 304 | /* Begin PBXHeadersBuildPhase section */ 305 | C43F37AB1C15C10B00C0915D /* Headers */ = { 306 | isa = PBXHeadersBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | C43F37B11C15C10B00C0915D /* ArithmosophiWatchOS.h in Headers */, 310 | ); 311 | runOnlyForDeploymentPostprocessing = 0; 312 | }; 313 | C43F37B81C15C12A00C0915D /* Headers */ = { 314 | isa = PBXHeadersBuildPhase; 315 | buildActionMask = 2147483647; 316 | files = ( 317 | C43F37BE1C15C12A00C0915D /* ArithmosophiTVOS.h in Headers */, 318 | ); 319 | runOnlyForDeploymentPostprocessing = 0; 320 | }; 321 | C47004551B304CE200EB0C80 /* Headers */ = { 322 | isa = PBXHeadersBuildPhase; 323 | buildActionMask = 2147483647; 324 | files = ( 325 | C470045E1B304CE200EB0C80 /* Arithmosophi.h in Headers */, 326 | ); 327 | runOnlyForDeploymentPostprocessing = 0; 328 | }; 329 | C470048C1B30560700EB0C80 /* Headers */ = { 330 | isa = PBXHeadersBuildPhase; 331 | buildActionMask = 2147483647; 332 | files = ( 333 | C47004941B30560700EB0C80 /* ArithmosophiOSX.h in Headers */, 334 | ); 335 | runOnlyForDeploymentPostprocessing = 0; 336 | }; 337 | C4B1FE7D1D8B45E200B61C97 /* Headers */ = { 338 | isa = PBXHeadersBuildPhase; 339 | buildActionMask = 2147483647; 340 | files = ( 341 | C4B1FE7E1D8B45E200B61C97 /* Arithmosophi.h in Headers */, 342 | ); 343 | runOnlyForDeploymentPostprocessing = 0; 344 | }; 345 | /* End PBXHeadersBuildPhase section */ 346 | 347 | /* Begin PBXNativeTarget section */ 348 | C43F37AD1C15C10B00C0915D /* ArithmosophiWatchOS */ = { 349 | isa = PBXNativeTarget; 350 | buildConfigurationList = C43F37B31C15C10B00C0915D /* Build configuration list for PBXNativeTarget "ArithmosophiWatchOS" */; 351 | buildPhases = ( 352 | C43F37A91C15C10B00C0915D /* Sources */, 353 | C43F37AA1C15C10B00C0915D /* Frameworks */, 354 | C43F37AB1C15C10B00C0915D /* Headers */, 355 | C43F37AC1C15C10B00C0915D /* Resources */, 356 | ); 357 | buildRules = ( 358 | ); 359 | dependencies = ( 360 | ); 361 | name = ArithmosophiWatchOS; 362 | productName = ArithmosophiWatchOS; 363 | productReference = C43F37AE1C15C10B00C0915D /* Arithmosophi.framework */; 364 | productType = "com.apple.product-type.framework"; 365 | }; 366 | C43F37BA1C15C12A00C0915D /* ArithmosophiTVOS */ = { 367 | isa = PBXNativeTarget; 368 | buildConfigurationList = C43F37C01C15C12A00C0915D /* Build configuration list for PBXNativeTarget "ArithmosophiTVOS" */; 369 | buildPhases = ( 370 | C43F37B61C15C12A00C0915D /* Sources */, 371 | C43F37B71C15C12A00C0915D /* Frameworks */, 372 | C43F37B81C15C12A00C0915D /* Headers */, 373 | C43F37B91C15C12A00C0915D /* Resources */, 374 | ); 375 | buildRules = ( 376 | ); 377 | dependencies = ( 378 | ); 379 | name = ArithmosophiTVOS; 380 | productName = ArithmosophiTVOS; 381 | productReference = C43F37BB1C15C12A00C0915D /* Arithmosophi.framework */; 382 | productType = "com.apple.product-type.framework"; 383 | }; 384 | C47004571B304CE200EB0C80 /* Arithmosophi */ = { 385 | isa = PBXNativeTarget; 386 | buildConfigurationList = C470046E1B304CE300EB0C80 /* Build configuration list for PBXNativeTarget "Arithmosophi" */; 387 | buildPhases = ( 388 | C43F37A51C15BC5100C0915D /* SwiftLint */, 389 | C47004531B304CE200EB0C80 /* Sources */, 390 | C47004541B304CE200EB0C80 /* Frameworks */, 391 | C47004551B304CE200EB0C80 /* Headers */, 392 | C47004561B304CE200EB0C80 /* Resources */, 393 | ); 394 | buildRules = ( 395 | C43F37A41C15BC2D00C0915D /* PBXBuildRule */, 396 | ); 397 | dependencies = ( 398 | ); 399 | name = Arithmosophi; 400 | productName = Arithmosophi; 401 | productReference = C47004581B304CE200EB0C80 /* Arithmosophi.framework */; 402 | productType = "com.apple.product-type.framework"; 403 | }; 404 | C470048E1B30560700EB0C80 /* ArithmosophiOSX */ = { 405 | isa = PBXNativeTarget; 406 | buildConfigurationList = C47004A21B30560700EB0C80 /* Build configuration list for PBXNativeTarget "ArithmosophiOSX" */; 407 | buildPhases = ( 408 | C470048A1B30560700EB0C80 /* Sources */, 409 | C470048B1B30560700EB0C80 /* Frameworks */, 410 | C470048C1B30560700EB0C80 /* Headers */, 411 | C470048D1B30560700EB0C80 /* Resources */, 412 | C43F37A61C15BC7400C0915D /* SwiftLint */, 413 | ); 414 | buildRules = ( 415 | ); 416 | dependencies = ( 417 | ); 418 | name = ArithmosophiOSX; 419 | productName = ArithmosophiOSX; 420 | productReference = C470048F1B30560700EB0C80 /* Arithmosophi.framework */; 421 | productType = "com.apple.product-type.framework"; 422 | }; 423 | C47004981B30560700EB0C80 /* ArithmosophiOSXTests */ = { 424 | isa = PBXNativeTarget; 425 | buildConfigurationList = C47004A51B30560700EB0C80 /* Build configuration list for PBXNativeTarget "ArithmosophiOSXTests" */; 426 | buildPhases = ( 427 | C47004951B30560700EB0C80 /* Sources */, 428 | C47004961B30560700EB0C80 /* Frameworks */, 429 | C47004971B30560700EB0C80 /* Resources */, 430 | ); 431 | buildRules = ( 432 | ); 433 | dependencies = ( 434 | C470049C1B30560700EB0C80 /* PBXTargetDependency */, 435 | ); 436 | name = ArithmosophiOSXTests; 437 | productName = ArithmosophiOSXTests; 438 | productReference = C47004991B30560700EB0C80 /* ArithmosophiOSXTests.xctest */; 439 | productType = "com.apple.product-type.bundle.unit-test"; 440 | }; 441 | C4B1FE731D8B45E200B61C97 /* Arithmosophi Sample */ = { 442 | isa = PBXNativeTarget; 443 | buildConfigurationList = C4B1FE831D8B45E200B61C97 /* Build configuration list for PBXNativeTarget "Arithmosophi Sample" */; 444 | buildPhases = ( 445 | C4B1FE741D8B45E200B61C97 /* Sources */, 446 | C4B1FE7C1D8B45E200B61C97 /* Frameworks */, 447 | C4B1FE7D1D8B45E200B61C97 /* Headers */, 448 | C4B1FE7F1D8B45E200B61C97 /* Resources */, 449 | C4B1FE811D8B45E200B61C97 /* SwiftLint */, 450 | ); 451 | buildRules = ( 452 | C4B1FE821D8B45E200B61C97 /* PBXBuildRule */, 453 | ); 454 | dependencies = ( 455 | ); 456 | name = "Arithmosophi Sample"; 457 | productName = Arithmosophi; 458 | productReference = C4B1FE861D8B45E200B61C97 /* ArithmosophiSample.framework */; 459 | productType = "com.apple.product-type.framework"; 460 | }; 461 | /* End PBXNativeTarget section */ 462 | 463 | /* Begin PBXProject section */ 464 | C470044F1B304CE200EB0C80 /* Project object */ = { 465 | isa = PBXProject; 466 | attributes = { 467 | LastSwiftMigration = 0700; 468 | LastSwiftUpdateCheck = 0700; 469 | LastUpgradeCheck = 1230; 470 | ORGANIZATIONNAME = phimage; 471 | TargetAttributes = { 472 | C43F37AD1C15C10B00C0915D = { 473 | CreatedOnToolsVersion = 7.1.1; 474 | DevelopmentTeam = GGU39CDBL2; 475 | LastSwiftMigration = 1230; 476 | }; 477 | C43F37BA1C15C12A00C0915D = { 478 | CreatedOnToolsVersion = 7.1.1; 479 | DevelopmentTeam = GGU39CDBL2; 480 | LastSwiftMigration = 1230; 481 | }; 482 | C47004571B304CE200EB0C80 = { 483 | CreatedOnToolsVersion = 6.3.2; 484 | LastSwiftMigration = 1230; 485 | }; 486 | C470048E1B30560700EB0C80 = { 487 | CreatedOnToolsVersion = 6.3.2; 488 | LastSwiftMigration = 1230; 489 | }; 490 | C47004981B30560700EB0C80 = { 491 | CreatedOnToolsVersion = 6.3.2; 492 | LastSwiftMigration = 1230; 493 | }; 494 | C4B1FE731D8B45E200B61C97 = { 495 | LastSwiftMigration = 1230; 496 | }; 497 | }; 498 | }; 499 | buildConfigurationList = C47004521B304CE200EB0C80 /* Build configuration list for PBXProject "Arithmosophi" */; 500 | compatibilityVersion = "Xcode 3.2"; 501 | developmentRegion = en; 502 | hasScannedForEncodings = 0; 503 | knownRegions = ( 504 | en, 505 | Base, 506 | ); 507 | mainGroup = C470044E1B304CE200EB0C80; 508 | productRefGroup = C47004591B304CE200EB0C80 /* Products */; 509 | projectDirPath = ""; 510 | projectRoot = ""; 511 | targets = ( 512 | C47004571B304CE200EB0C80 /* Arithmosophi */, 513 | C470048E1B30560700EB0C80 /* ArithmosophiOSX */, 514 | C43F37AD1C15C10B00C0915D /* ArithmosophiWatchOS */, 515 | C43F37BA1C15C12A00C0915D /* ArithmosophiTVOS */, 516 | C47004981B30560700EB0C80 /* ArithmosophiOSXTests */, 517 | C4B1FE731D8B45E200B61C97 /* Arithmosophi Sample */, 518 | ); 519 | }; 520 | /* End PBXProject section */ 521 | 522 | /* Begin PBXResourcesBuildPhase section */ 523 | C43F37AC1C15C10B00C0915D /* Resources */ = { 524 | isa = PBXResourcesBuildPhase; 525 | buildActionMask = 2147483647; 526 | files = ( 527 | ); 528 | runOnlyForDeploymentPostprocessing = 0; 529 | }; 530 | C43F37B91C15C12A00C0915D /* Resources */ = { 531 | isa = PBXResourcesBuildPhase; 532 | buildActionMask = 2147483647; 533 | files = ( 534 | ); 535 | runOnlyForDeploymentPostprocessing = 0; 536 | }; 537 | C47004561B304CE200EB0C80 /* Resources */ = { 538 | isa = PBXResourcesBuildPhase; 539 | buildActionMask = 2147483647; 540 | files = ( 541 | ); 542 | runOnlyForDeploymentPostprocessing = 0; 543 | }; 544 | C470048D1B30560700EB0C80 /* Resources */ = { 545 | isa = PBXResourcesBuildPhase; 546 | buildActionMask = 2147483647; 547 | files = ( 548 | ); 549 | runOnlyForDeploymentPostprocessing = 0; 550 | }; 551 | C47004971B30560700EB0C80 /* Resources */ = { 552 | isa = PBXResourcesBuildPhase; 553 | buildActionMask = 2147483647; 554 | files = ( 555 | ); 556 | runOnlyForDeploymentPostprocessing = 0; 557 | }; 558 | C4B1FE7F1D8B45E200B61C97 /* Resources */ = { 559 | isa = PBXResourcesBuildPhase; 560 | buildActionMask = 2147483647; 561 | files = ( 562 | ); 563 | runOnlyForDeploymentPostprocessing = 0; 564 | }; 565 | /* End PBXResourcesBuildPhase section */ 566 | 567 | /* Begin PBXShellScriptBuildPhase section */ 568 | C43F37A51C15BC5100C0915D /* SwiftLint */ = { 569 | isa = PBXShellScriptBuildPhase; 570 | buildActionMask = 2147483647; 571 | files = ( 572 | ); 573 | inputPaths = ( 574 | ); 575 | name = SwiftLint; 576 | outputPaths = ( 577 | ); 578 | runOnlyForDeploymentPostprocessing = 0; 579 | shellPath = /bin/sh; 580 | shellScript = "if which swiftlint >/dev/null; then\n swiftlint autocorrect\nelse\n echo \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi\n"; 581 | }; 582 | C43F37A61C15BC7400C0915D /* SwiftLint */ = { 583 | isa = PBXShellScriptBuildPhase; 584 | buildActionMask = 2147483647; 585 | files = ( 586 | ); 587 | inputPaths = ( 588 | ); 589 | name = SwiftLint; 590 | outputPaths = ( 591 | ); 592 | runOnlyForDeploymentPostprocessing = 0; 593 | shellPath = /bin/sh; 594 | shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi"; 595 | }; 596 | C4B1FE811D8B45E200B61C97 /* SwiftLint */ = { 597 | isa = PBXShellScriptBuildPhase; 598 | buildActionMask = 2147483647; 599 | files = ( 600 | ); 601 | inputPaths = ( 602 | ); 603 | name = SwiftLint; 604 | outputPaths = ( 605 | ); 606 | runOnlyForDeploymentPostprocessing = 0; 607 | shellPath = /bin/sh; 608 | shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi\n"; 609 | }; 610 | /* End PBXShellScriptBuildPhase section */ 611 | 612 | /* Begin PBXSourcesBuildPhase section */ 613 | C43F37A91C15C10B00C0915D /* Sources */ = { 614 | isa = PBXSourcesBuildPhase; 615 | buildActionMask = 2147483647; 616 | files = ( 617 | C43F37C31C15C13600C0915D /* Arithmosophi.swift in Sources */, 618 | C43F37C71C15C13600C0915D /* MesosOros.swift in Sources */, 619 | C43F37C51C15C13600C0915D /* Arithmos.swift in Sources */, 620 | C43F37C41C15C13600C0915D /* LogicalOperationsType.swift in Sources */, 621 | C496F15E1D496DA7008A2637 /* Sigma.swift in Sources */, 622 | C43F37C81C15C13600C0915D /* Complex.swift in Sources */, 623 | C43F37C61C15C13600C0915D /* Statheros.swift in Sources */, 624 | ); 625 | runOnlyForDeploymentPostprocessing = 0; 626 | }; 627 | C43F37B61C15C12A00C0915D /* Sources */ = { 628 | isa = PBXSourcesBuildPhase; 629 | buildActionMask = 2147483647; 630 | files = ( 631 | C43F37C91C15C13600C0915D /* Arithmosophi.swift in Sources */, 632 | C43F37CD1C15C13600C0915D /* MesosOros.swift in Sources */, 633 | C43F37CB1C15C13600C0915D /* Arithmos.swift in Sources */, 634 | C43F37CA1C15C13600C0915D /* LogicalOperationsType.swift in Sources */, 635 | C496F15F1D496DA7008A2637 /* Sigma.swift in Sources */, 636 | C43F37CE1C15C13600C0915D /* Complex.swift in Sources */, 637 | C43F37CC1C15C13600C0915D /* Statheros.swift in Sources */, 638 | ); 639 | runOnlyForDeploymentPostprocessing = 0; 640 | }; 641 | C47004531B304CE200EB0C80 /* Sources */ = { 642 | isa = PBXSourcesBuildPhase; 643 | buildActionMask = 2147483647; 644 | files = ( 645 | C4BD0FB01B32DF4500787E0F /* Arithmos.swift in Sources */, 646 | C47004771B304D6900EB0C80 /* Arithmosophi.swift in Sources */, 647 | C47004751B304D5600EB0C80 /* Statheros.swift in Sources */, 648 | E1DBFB102133703E0097E66C /* Complex.swift in Sources */, 649 | C496F15C1D49648D008A2637 /* Sigma.swift in Sources */, 650 | C4687F061B4535D00063EC05 /* MesosOros.swift in Sources */, 651 | C4478C391B31911800194715 /* LogicalOperationsType.swift in Sources */, 652 | ); 653 | runOnlyForDeploymentPostprocessing = 0; 654 | }; 655 | C470048A1B30560700EB0C80 /* Sources */ = { 656 | isa = PBXSourcesBuildPhase; 657 | buildActionMask = 2147483647; 658 | files = ( 659 | C4BD0FAF1B32DF4500787E0F /* Arithmos.swift in Sources */, 660 | C47004A81B30560D00EB0C80 /* Arithmosophi.swift in Sources */, 661 | C4BD0FAD1B32DE8400787E0F /* LogicalOperationsType.swift in Sources */, 662 | C4E20E001C046774000655FA /* Complex.swift in Sources */, 663 | C4687F051B4535CF0063EC05 /* MesosOros.swift in Sources */, 664 | C47004A91B30560D00EB0C80 /* Statheros.swift in Sources */, 665 | C496F15D1D496DA7008A2637 /* Sigma.swift in Sources */, 666 | ); 667 | runOnlyForDeploymentPostprocessing = 0; 668 | }; 669 | C47004951B30560700EB0C80 /* Sources */ = { 670 | isa = PBXSourcesBuildPhase; 671 | buildActionMask = 2147483647; 672 | files = ( 673 | C47004A11B30560700EB0C80 /* ArithmosophiOSXTests.swift in Sources */, 674 | ); 675 | runOnlyForDeploymentPostprocessing = 0; 676 | }; 677 | C4B1FE741D8B45E200B61C97 /* Sources */ = { 678 | isa = PBXSourcesBuildPhase; 679 | buildActionMask = 2147483647; 680 | files = ( 681 | C4B1FE8B1D8B45F400B61C97 /* Parity.swift in Sources */, 682 | C4B1FE8C1D8B45F400B61C97 /* Geometry.swift in Sources */, 683 | C4B1FE8A1D8B45F400B61C97 /* Optional.swift in Sources */, 684 | C4B1FE891D8B45F400B61C97 /* Boolean.swift in Sources */, 685 | C4B1FE881D8B45F400B61C97 /* Box.swift in Sources */, 686 | C4B1FE8D1D8B45F400B61C97 /* Geometry+Animation.swift in Sources */, 687 | ); 688 | runOnlyForDeploymentPostprocessing = 0; 689 | }; 690 | /* End PBXSourcesBuildPhase section */ 691 | 692 | /* Begin PBXTargetDependency section */ 693 | C470049C1B30560700EB0C80 /* PBXTargetDependency */ = { 694 | isa = PBXTargetDependency; 695 | target = C470048E1B30560700EB0C80 /* ArithmosophiOSX */; 696 | targetProxy = C470049B1B30560700EB0C80 /* PBXContainerItemProxy */; 697 | }; 698 | /* End PBXTargetDependency section */ 699 | 700 | /* Begin XCBuildConfiguration section */ 701 | C43F37B41C15C10B00C0915D /* Debug */ = { 702 | isa = XCBuildConfiguration; 703 | buildSettings = { 704 | APPLICATION_EXTENSION_API_ONLY = YES; 705 | "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; 706 | DEBUG_INFORMATION_FORMAT = dwarf; 707 | DEFINES_MODULE = YES; 708 | DYLIB_COMPATIBILITY_VERSION = 1; 709 | DYLIB_CURRENT_VERSION = 1; 710 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 711 | INFOPLIST_FILE = Xcode/WatchOS/Info.plist; 712 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 713 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 714 | PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.ArithmosophiWatchOS; 715 | PRODUCT_NAME = Arithmosophi; 716 | SDKROOT = watchos; 717 | SKIP_INSTALL = YES; 718 | SWIFT_VERSION = 5.0; 719 | TARGETED_DEVICE_FAMILY = 4; 720 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 721 | }; 722 | name = Debug; 723 | }; 724 | C43F37B51C15C10B00C0915D /* Release */ = { 725 | isa = XCBuildConfiguration; 726 | buildSettings = { 727 | APPLICATION_EXTENSION_API_ONLY = YES; 728 | "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; 729 | DEFINES_MODULE = YES; 730 | DYLIB_COMPATIBILITY_VERSION = 1; 731 | DYLIB_CURRENT_VERSION = 1; 732 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 733 | INFOPLIST_FILE = Xcode/WatchOS/Info.plist; 734 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 735 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 736 | PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.ArithmosophiWatchOS; 737 | PRODUCT_NAME = Arithmosophi; 738 | SDKROOT = watchos; 739 | SKIP_INSTALL = YES; 740 | SWIFT_VERSION = 5.0; 741 | TARGETED_DEVICE_FAMILY = 4; 742 | WATCHOS_DEPLOYMENT_TARGET = 2.0; 743 | }; 744 | name = Release; 745 | }; 746 | C43F37C11C15C12A00C0915D /* Debug */ = { 747 | isa = XCBuildConfiguration; 748 | buildSettings = { 749 | "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; 750 | DEBUG_INFORMATION_FORMAT = dwarf; 751 | DEFINES_MODULE = YES; 752 | DYLIB_COMPATIBILITY_VERSION = 1; 753 | DYLIB_CURRENT_VERSION = 1; 754 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 755 | INFOPLIST_FILE = Xcode/TVOS/Info.plist; 756 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 757 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 758 | PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.ArithmosophiTVOS; 759 | PRODUCT_NAME = Arithmosophi; 760 | SDKROOT = appletvos; 761 | SKIP_INSTALL = YES; 762 | SWIFT_VERSION = 5.0; 763 | TARGETED_DEVICE_FAMILY = 3; 764 | TVOS_DEPLOYMENT_TARGET = 9.0; 765 | }; 766 | name = Debug; 767 | }; 768 | C43F37C21C15C12A00C0915D /* Release */ = { 769 | isa = XCBuildConfiguration; 770 | buildSettings = { 771 | "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; 772 | DEFINES_MODULE = YES; 773 | DYLIB_COMPATIBILITY_VERSION = 1; 774 | DYLIB_CURRENT_VERSION = 1; 775 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 776 | INFOPLIST_FILE = Xcode/TVOS/Info.plist; 777 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 778 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 779 | PRODUCT_BUNDLE_IDENTIFIER = tv.phimage.ArithmosophiTVOS; 780 | PRODUCT_NAME = Arithmosophi; 781 | SDKROOT = appletvos; 782 | SKIP_INSTALL = YES; 783 | SWIFT_VERSION = 5.0; 784 | TARGETED_DEVICE_FAMILY = 3; 785 | TVOS_DEPLOYMENT_TARGET = 9.0; 786 | }; 787 | name = Release; 788 | }; 789 | C470046C1B304CE300EB0C80 /* Debug */ = { 790 | isa = XCBuildConfiguration; 791 | buildSettings = { 792 | ALWAYS_SEARCH_USER_PATHS = NO; 793 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 794 | CLANG_CXX_LIBRARY = "libc++"; 795 | CLANG_ENABLE_MODULES = YES; 796 | CLANG_ENABLE_OBJC_ARC = YES; 797 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 798 | CLANG_WARN_BOOL_CONVERSION = YES; 799 | CLANG_WARN_COMMA = YES; 800 | CLANG_WARN_CONSTANT_CONVERSION = YES; 801 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 802 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 803 | CLANG_WARN_EMPTY_BODY = YES; 804 | CLANG_WARN_ENUM_CONVERSION = YES; 805 | CLANG_WARN_INFINITE_RECURSION = YES; 806 | CLANG_WARN_INT_CONVERSION = YES; 807 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 808 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 809 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 810 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 811 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 812 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 813 | CLANG_WARN_STRICT_PROTOTYPES = YES; 814 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 815 | CLANG_WARN_UNREACHABLE_CODE = YES; 816 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 817 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 818 | COPY_PHASE_STRIP = NO; 819 | CURRENT_PROJECT_VERSION = 1; 820 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 821 | ENABLE_STRICT_OBJC_MSGSEND = YES; 822 | ENABLE_TESTABILITY = YES; 823 | GCC_C_LANGUAGE_STANDARD = gnu99; 824 | GCC_DYNAMIC_NO_PIC = NO; 825 | GCC_NO_COMMON_BLOCKS = YES; 826 | GCC_OPTIMIZATION_LEVEL = 0; 827 | GCC_PREPROCESSOR_DEFINITIONS = ( 828 | "DEBUG=1", 829 | "$(inherited)", 830 | ); 831 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 832 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 833 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 834 | GCC_WARN_UNDECLARED_SELECTOR = YES; 835 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 836 | GCC_WARN_UNUSED_FUNCTION = YES; 837 | GCC_WARN_UNUSED_VARIABLE = YES; 838 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 839 | MTL_ENABLE_DEBUG_INFO = YES; 840 | ONLY_ACTIVE_ARCH = YES; 841 | SDKROOT = iphoneos; 842 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 843 | TARGETED_DEVICE_FAMILY = "1,2"; 844 | VERSIONING_SYSTEM = "apple-generic"; 845 | VERSION_INFO_PREFIX = ""; 846 | }; 847 | name = Debug; 848 | }; 849 | C470046D1B304CE300EB0C80 /* Release */ = { 850 | isa = XCBuildConfiguration; 851 | buildSettings = { 852 | ALWAYS_SEARCH_USER_PATHS = NO; 853 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 854 | CLANG_CXX_LIBRARY = "libc++"; 855 | CLANG_ENABLE_MODULES = YES; 856 | CLANG_ENABLE_OBJC_ARC = YES; 857 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 858 | CLANG_WARN_BOOL_CONVERSION = YES; 859 | CLANG_WARN_COMMA = YES; 860 | CLANG_WARN_CONSTANT_CONVERSION = YES; 861 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 862 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 863 | CLANG_WARN_EMPTY_BODY = YES; 864 | CLANG_WARN_ENUM_CONVERSION = YES; 865 | CLANG_WARN_INFINITE_RECURSION = YES; 866 | CLANG_WARN_INT_CONVERSION = YES; 867 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 868 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 869 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 870 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 871 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 872 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 873 | CLANG_WARN_STRICT_PROTOTYPES = YES; 874 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 875 | CLANG_WARN_UNREACHABLE_CODE = YES; 876 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 877 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 878 | COPY_PHASE_STRIP = NO; 879 | CURRENT_PROJECT_VERSION = 1; 880 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 881 | ENABLE_NS_ASSERTIONS = NO; 882 | ENABLE_STRICT_OBJC_MSGSEND = YES; 883 | GCC_C_LANGUAGE_STANDARD = gnu99; 884 | GCC_NO_COMMON_BLOCKS = YES; 885 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 886 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 887 | GCC_WARN_UNDECLARED_SELECTOR = YES; 888 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 889 | GCC_WARN_UNUSED_FUNCTION = YES; 890 | GCC_WARN_UNUSED_VARIABLE = YES; 891 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 892 | MTL_ENABLE_DEBUG_INFO = NO; 893 | SDKROOT = iphoneos; 894 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 895 | TARGETED_DEVICE_FAMILY = "1,2"; 896 | VALIDATE_PRODUCT = YES; 897 | VERSIONING_SYSTEM = "apple-generic"; 898 | VERSION_INFO_PREFIX = ""; 899 | }; 900 | name = Release; 901 | }; 902 | C470046F1B304CE300EB0C80 /* Debug */ = { 903 | isa = XCBuildConfiguration; 904 | buildSettings = { 905 | CLANG_ENABLE_MODULES = YES; 906 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 907 | DEFINES_MODULE = YES; 908 | DYLIB_COMPATIBILITY_VERSION = 1; 909 | DYLIB_CURRENT_VERSION = 1; 910 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 911 | INFOPLIST_FILE = Xcode/iOS/Info.plist; 912 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 913 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 914 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 915 | PRODUCT_NAME = "$(TARGET_NAME)"; 916 | SKIP_INSTALL = YES; 917 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 918 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 919 | SWIFT_VERSION = 5.0; 920 | }; 921 | name = Debug; 922 | }; 923 | C47004701B304CE300EB0C80 /* Release */ = { 924 | isa = XCBuildConfiguration; 925 | buildSettings = { 926 | CLANG_ENABLE_MODULES = YES; 927 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 928 | DEFINES_MODULE = YES; 929 | DYLIB_COMPATIBILITY_VERSION = 1; 930 | DYLIB_CURRENT_VERSION = 1; 931 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 932 | INFOPLIST_FILE = Xcode/iOS/Info.plist; 933 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 934 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 935 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 936 | PRODUCT_NAME = "$(TARGET_NAME)"; 937 | SKIP_INSTALL = YES; 938 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 939 | SWIFT_VERSION = 5.0; 940 | }; 941 | name = Release; 942 | }; 943 | C47004A31B30560700EB0C80 /* Debug */ = { 944 | isa = XCBuildConfiguration; 945 | buildSettings = { 946 | COMBINE_HIDPI_IMAGES = YES; 947 | DEBUG_INFORMATION_FORMAT = dwarf; 948 | DEFINES_MODULE = YES; 949 | DYLIB_COMPATIBILITY_VERSION = 1; 950 | DYLIB_CURRENT_VERSION = 1; 951 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 952 | FRAMEWORK_VERSION = A; 953 | GCC_PREPROCESSOR_DEFINITIONS = ( 954 | "DEBUG=1", 955 | "$(inherited)", 956 | ); 957 | INFOPLIST_FILE = Xcode/OSX/Info.plist; 958 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 959 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 960 | MACOSX_DEPLOYMENT_TARGET = 10.10; 961 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 962 | PRODUCT_NAME = Arithmosophi; 963 | SDKROOT = macosx; 964 | SKIP_INSTALL = YES; 965 | SWIFT_VERSION = 5.0; 966 | }; 967 | name = Debug; 968 | }; 969 | C47004A41B30560700EB0C80 /* Release */ = { 970 | isa = XCBuildConfiguration; 971 | buildSettings = { 972 | COMBINE_HIDPI_IMAGES = YES; 973 | DEFINES_MODULE = YES; 974 | DYLIB_COMPATIBILITY_VERSION = 1; 975 | DYLIB_CURRENT_VERSION = 1; 976 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 977 | FRAMEWORK_VERSION = A; 978 | INFOPLIST_FILE = Xcode/OSX/Info.plist; 979 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 980 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 981 | MACOSX_DEPLOYMENT_TARGET = 10.10; 982 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 983 | PRODUCT_NAME = Arithmosophi; 984 | SDKROOT = macosx; 985 | SKIP_INSTALL = YES; 986 | SWIFT_VERSION = 5.0; 987 | }; 988 | name = Release; 989 | }; 990 | C47004A61B30560700EB0C80 /* Debug */ = { 991 | isa = XCBuildConfiguration; 992 | buildSettings = { 993 | COMBINE_HIDPI_IMAGES = YES; 994 | DEBUG_INFORMATION_FORMAT = dwarf; 995 | FRAMEWORK_SEARCH_PATHS = ( 996 | "$(DEVELOPER_FRAMEWORKS_DIR)", 997 | "$(inherited)", 998 | ); 999 | GCC_PREPROCESSOR_DEFINITIONS = ( 1000 | "DEBUG=1", 1001 | "$(inherited)", 1002 | ); 1003 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 1004 | MACOSX_DEPLOYMENT_TARGET = 10.10; 1005 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 1006 | PRODUCT_NAME = "$(TARGET_NAME)"; 1007 | SDKROOT = macosx; 1008 | SWIFT_VERSION = 5.0; 1009 | }; 1010 | name = Debug; 1011 | }; 1012 | C47004A71B30560700EB0C80 /* Release */ = { 1013 | isa = XCBuildConfiguration; 1014 | buildSettings = { 1015 | COMBINE_HIDPI_IMAGES = YES; 1016 | FRAMEWORK_SEARCH_PATHS = ( 1017 | "$(DEVELOPER_FRAMEWORKS_DIR)", 1018 | "$(inherited)", 1019 | ); 1020 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 1021 | MACOSX_DEPLOYMENT_TARGET = 10.10; 1022 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 1023 | PRODUCT_NAME = "$(TARGET_NAME)"; 1024 | SDKROOT = macosx; 1025 | SWIFT_VERSION = 5.0; 1026 | }; 1027 | name = Release; 1028 | }; 1029 | C4B1FE841D8B45E200B61C97 /* Debug */ = { 1030 | isa = XCBuildConfiguration; 1031 | buildSettings = { 1032 | CLANG_ENABLE_MODULES = YES; 1033 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 1034 | DEFINES_MODULE = YES; 1035 | DYLIB_COMPATIBILITY_VERSION = 1; 1036 | DYLIB_CURRENT_VERSION = 1; 1037 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 1038 | INFOPLIST_FILE = Samples/Info.plist; 1039 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 1040 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 1041 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 1042 | PRODUCT_NAME = ArithmosophiSample; 1043 | SKIP_INSTALL = YES; 1044 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 1045 | SWIFT_VERSION = 5.0; 1046 | }; 1047 | name = Debug; 1048 | }; 1049 | C4B1FE851D8B45E200B61C97 /* Release */ = { 1050 | isa = XCBuildConfiguration; 1051 | buildSettings = { 1052 | CLANG_ENABLE_MODULES = YES; 1053 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 1054 | DEFINES_MODULE = YES; 1055 | DYLIB_COMPATIBILITY_VERSION = 1; 1056 | DYLIB_CURRENT_VERSION = 1; 1057 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 1058 | INFOPLIST_FILE = Samples/Info.plist; 1059 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 1060 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 1061 | PRODUCT_BUNDLE_IDENTIFIER = "tv.phimage.$(PRODUCT_NAME:rfc1034identifier)"; 1062 | PRODUCT_NAME = ArithmosophiSample; 1063 | SKIP_INSTALL = YES; 1064 | SWIFT_VERSION = 5.0; 1065 | }; 1066 | name = Release; 1067 | }; 1068 | /* End XCBuildConfiguration section */ 1069 | 1070 | /* Begin XCConfigurationList section */ 1071 | C43F37B31C15C10B00C0915D /* Build configuration list for PBXNativeTarget "ArithmosophiWatchOS" */ = { 1072 | isa = XCConfigurationList; 1073 | buildConfigurations = ( 1074 | C43F37B41C15C10B00C0915D /* Debug */, 1075 | C43F37B51C15C10B00C0915D /* Release */, 1076 | ); 1077 | defaultConfigurationIsVisible = 0; 1078 | defaultConfigurationName = Release; 1079 | }; 1080 | C43F37C01C15C12A00C0915D /* Build configuration list for PBXNativeTarget "ArithmosophiTVOS" */ = { 1081 | isa = XCConfigurationList; 1082 | buildConfigurations = ( 1083 | C43F37C11C15C12A00C0915D /* Debug */, 1084 | C43F37C21C15C12A00C0915D /* Release */, 1085 | ); 1086 | defaultConfigurationIsVisible = 0; 1087 | defaultConfigurationName = Release; 1088 | }; 1089 | C47004521B304CE200EB0C80 /* Build configuration list for PBXProject "Arithmosophi" */ = { 1090 | isa = XCConfigurationList; 1091 | buildConfigurations = ( 1092 | C470046C1B304CE300EB0C80 /* Debug */, 1093 | C470046D1B304CE300EB0C80 /* Release */, 1094 | ); 1095 | defaultConfigurationIsVisible = 0; 1096 | defaultConfigurationName = Release; 1097 | }; 1098 | C470046E1B304CE300EB0C80 /* Build configuration list for PBXNativeTarget "Arithmosophi" */ = { 1099 | isa = XCConfigurationList; 1100 | buildConfigurations = ( 1101 | C470046F1B304CE300EB0C80 /* Debug */, 1102 | C47004701B304CE300EB0C80 /* Release */, 1103 | ); 1104 | defaultConfigurationIsVisible = 0; 1105 | defaultConfigurationName = Release; 1106 | }; 1107 | C47004A21B30560700EB0C80 /* Build configuration list for PBXNativeTarget "ArithmosophiOSX" */ = { 1108 | isa = XCConfigurationList; 1109 | buildConfigurations = ( 1110 | C47004A31B30560700EB0C80 /* Debug */, 1111 | C47004A41B30560700EB0C80 /* Release */, 1112 | ); 1113 | defaultConfigurationIsVisible = 0; 1114 | defaultConfigurationName = Release; 1115 | }; 1116 | C47004A51B30560700EB0C80 /* Build configuration list for PBXNativeTarget "ArithmosophiOSXTests" */ = { 1117 | isa = XCConfigurationList; 1118 | buildConfigurations = ( 1119 | C47004A61B30560700EB0C80 /* Debug */, 1120 | C47004A71B30560700EB0C80 /* Release */, 1121 | ); 1122 | defaultConfigurationIsVisible = 0; 1123 | defaultConfigurationName = Release; 1124 | }; 1125 | C4B1FE831D8B45E200B61C97 /* Build configuration list for PBXNativeTarget "Arithmosophi Sample" */ = { 1126 | isa = XCConfigurationList; 1127 | buildConfigurations = ( 1128 | C4B1FE841D8B45E200B61C97 /* Debug */, 1129 | C4B1FE851D8B45E200B61C97 /* Release */, 1130 | ); 1131 | defaultConfigurationIsVisible = 0; 1132 | defaultConfigurationName = Release; 1133 | }; 1134 | /* End XCConfigurationList section */ 1135 | }; 1136 | rootObject = C470044F1B304CE200EB0C80 /* Project object */; 1137 | } 1138 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/project.xcworkspace/xcshareddata/Arithmosophi.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 0049235E-64EA-4579-B2DF-8BF99DFB081C 9 | IDESourceControlProjectName 10 | Arithmosophi 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 05BD26AF9286F79151E435734F159D2434277505 14 | gitlab:phimage/Arithmosophi.git 15 | 16 | IDESourceControlProjectPath 17 | Arithmosophi.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 05BD26AF9286F79151E435734F159D2434277505 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | gitlab:phimage/Arithmosophi.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 05BD26AF9286F79151E435734F159D2434277505 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 05BD26AF9286F79151E435734F159D2434277505 36 | IDESourceControlWCCName 37 | Arithmosophi 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/project.xcworkspace/xcuserdata/eric.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phimage/Arithmosophi/4d2b9ed8e0bbd2a91b67c070caa5d4e487b431b7/Arithmosophi.xcodeproj/project.xcworkspace/xcuserdata/eric.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/xcshareddata/xcschemes/Arithmosophi.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 51 | 52 | 53 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 76 | 77 | 83 | 84 | 85 | 86 | 92 | 93 | 99 | 100 | 101 | 102 | 104 | 105 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/xcshareddata/xcschemes/ArithmosophiOSX.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 45 | 46 | 52 | 53 | 54 | 55 | 57 | 63 | 64 | 65 | 66 | 67 | 77 | 78 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/xcshareddata/xcschemes/ArithmosophiTVOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/xcshareddata/xcschemes/ArithmosophiWatchOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/xcuserdata/eric.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SuppressBuildableAutocreation 6 | 7 | C47004571B304CE200EB0C80 8 | 9 | primary 10 | 11 | 12 | C47004621B304CE300EB0C80 13 | 14 | primary 15 | 16 | 17 | C470048E1B30560700EB0C80 18 | 19 | primary 20 | 21 | 22 | C47004981B30560700EB0C80 23 | 24 | primary 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Arithmosophi.xcodeproj/xcuserdata/phimage.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Arithmosophi Sample.xcscheme 8 | 9 | orderHint 10 | 4 11 | 12 | Arithmosophi.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | ArithmosophiOSX.xcscheme_^#shared#^_ 18 | 19 | orderHint 20 | 1 21 | 22 | ArithmosophiTVOS.xcscheme_^#shared#^_ 23 | 24 | orderHint 25 | 3 26 | 27 | ArithmosophiWatchOS.xcscheme_^#shared#^_ 28 | 29 | orderHint 30 | 2 31 | 32 | 33 | SuppressBuildableAutocreation 34 | 35 | C43F37AD1C15C10B00C0915D 36 | 37 | primary 38 | 39 | 40 | C43F37BA1C15C12A00C0915D 41 | 42 | primary 43 | 44 | 45 | C47004571B304CE200EB0C80 46 | 47 | primary 48 | 49 | 50 | C47004621B304CE300EB0C80 51 | 52 | primary 53 | 54 | 55 | C470047B1B30511100EB0C80 56 | 57 | primary 58 | 59 | 60 | C470048E1B30560700EB0C80 61 | 62 | primary 63 | 64 | 65 | C47004981B30560700EB0C80 66 | 67 | primary 68 | 69 | 70 | C4B1FE731D8B45E200B61C97 71 | 72 | primary 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Eric Marchand (phimage) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | // Package.swift 4 | /* 5 | The MIT License (MIT) 6 | Copyright (c) 2016 Eric Marchand (phimage) 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | import PackageDescription 25 | 26 | let package = Package( 27 | name: "Arithmosophi", 28 | platforms: [.iOS(.v9), .watchOS(.v2), .macOS(.v10_10), .tvOS(.v9)], 29 | products: [ 30 | .library( 31 | name: "Arithmosophi", 32 | targets: ["Arithmosophi"]), 33 | .library( 34 | name: "ArithmosophiDynamic", 35 | type: .dynamic, 36 | targets: ["Arithmosophi"]) 37 | ], 38 | targets: [ 39 | .target( 40 | name: "Arithmosophi", 41 | path: "Sources" 42 | ), 43 | .testTarget( 44 | name: "ArithmosophiTests", 45 | dependencies: ["Arithmosophi"], 46 | path: "Tests" 47 | ) 48 | ] 49 | ) 50 | -------------------------------------------------------------------------------- /Playgrounds/Arithmosophi.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: ## Arithmosophi 2 | //: A set of protocols for Arithmetic, Statistics and Logical operations 3 | import Arithmosophi // 1 + 2 + 3 + 4 4 | //: ### Arithmosophi.swift 5 | [1, 2, 3, 4].sum 6 | [1, 2, 3, 4].product // 1 * 2 * 3 * 4 7 | ["a", "b", "c", "d"].sum // "abcd" same as joinWithSeparator("") 8 | [["a", "b"], ["c"], ["d"]].sum // ["a","b","c","d"] same as flatMap{$0} 9 | //: ### Arithmos.swift 10 | //[abs(-2.0), floor(1.1), ceil(1.1), round(1.1), fract(1.1)] 11 | [(-2.0).abs(), (1.1).floor(), (1.1).ceil(), (1.1).round(), (1.1).fract()] 12 | fract(1.1) 13 | //[sqrt(2.0), cbrt(2.0), pow(2.0, 0.5)] 14 | [(2.0).sqrt(), (2.0).cbrt(), (2.0).pow(0.5)] 15 | 16 | //[exp(1.0), exp2(10.0), log(1.0), log2(1024.0), log10(1000.0), log1p(1.0)] 17 | [(1.0).exp(), (10.0).exp2(), (1.0).log(), (1024.0).log2(), (1000.0).log10(), (1.0).log1p()] 18 | //[cos(1.0), sin(1.0), tan(1.0), hypot(3.0, 4.0), 4.0*atan2(1.0, 1.0)] 19 | [(1.0).cos(), (1.0).sin(), (1.0).tan(), (3.0).hypot(4.0), 4.0*(1.0).atan2(1.0)] 20 | //[cosh(1.0), sinh(1.0), tanh(1.0)] 21 | [(1.0).cosh(), (1.0).sinh(), (1.0).tanh()] 22 | //[asin(0.5), acos(0.1), atan(1.0)] 23 | [(0.5).asin(), (0.1).acos(), (1.0).atan()] 24 | [Double.random(4.0), Double.random(1.0, 2.0), Double.random(1.0...2.0)] 25 | [(1.1).clamp(3.0), (1.1).clamp(2.0, 3.0), (1.1).clamp(2.0...3.0)] 26 | //: ### LogicalOperationsType.swift 27 | var truth: Bool = true 28 | truth &&= false 29 | truth 30 | truth ||= true 31 | truth 32 | 33 | //: ### Statheros.swift 34 | //[cos(Double.π_2), sin(Double.π_2), cos(Double.π), sin(Double.π)] 35 | [(Double.π_2).cos(), (Double.π_2).sin(), (Double.π).cos(), (Double.π).sin()] 36 | //[log(Double.e)] 37 | (Double.e).log() 38 | //: ### MesosOros.swift 39 | [1, 2, 3, 4].average // (1 + 2 + 3 + 4) / 4 40 | [1, 11, 19, 4, -7].median // 4 41 | [1.0, 11, 19.5, 4, 12, -7].medianLow // 4 42 | [1, 11, 19, 4, 12, -7].medianHigh // 11 43 | //: ### Sigma.swift 44 | [1.0, 11, 19.5, 4, 12, -7].varianceSample 45 | [1.0, 11, 19.5, 4, 12, -7].variancePopulation 46 | [1.0, 11, 19.5, 4, 12, -7].standardDeviationSample 47 | [1.0, 11, 19.5, 4, 12, -7].standardDeviationPopulation 48 | [1.0, 11, 19.5, 4, 12, -7].skewness // or .moment.skewness 49 | [1.0, 11, 19.5, 4, 12, -7].kurtosis // or .moment.kurtosis 50 | [1, 2, 3.5, 3.7, 8, 12].covarianceSample([0.5, 1, 2.1, 3.4, 3.4, 4]) 51 | [1, 2, 3.5, 3.7, 8, 12].covariancePopulation([0.5, 1, 2.1, 3.4, 3.4, 4]) 52 | [1, 2, 3.5, 3.7, 8, 12].pearson([0.5, 1, 2.1, 3.4, 3.4, 4]) 53 | //: ### Complex.swift 54 | let complex = Complex(real: 12.0, imaginary: 9.0) 55 | complex.description 56 | let result = complex + 8 // Complex(real: 20, imaginary: 9) 57 | result.description 58 | -------------------------------------------------------------------------------- /Playgrounds/Arithmosophi.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arithmosophi - Arithmosoϕ 2 | 3 | [![Join the chat at https://gitter.im/phimage/Arithmosophi](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/phimage/Arithmosophi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat 5 | )](http://mit-license.org) 6 | [![Platform](http://img.shields.io/badge/platform-ios_osx-tvos-lightgrey.svg?style=flat 7 | )](https://developer.apple.com/resources/) 8 | [![Language](http://img.shields.io/badge/language-swift-orange.svg?style=flat 9 | )](https://developer.apple.com/swift) 10 | [![Issues](https://img.shields.io/github/issues/phimage/Arithmosophi.svg?style=flat 11 | )](https://github.com/phimage/Arithmosophi/issues) 12 | [![Cocoapod](http://img.shields.io/cocoapods/v/Arithmosophi.svg?style=flat)](http://cocoadocs.org/docsets/Arithmosophi/) 13 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 14 | 15 | [](#logo) Arithmosophi is a set of missing protocols that simplify arithmetic and statistics on generic objects or functions. 16 | As `Equatable` define the `==` operator , `Addable` will define the `+` operator. 17 | ```swift 18 | protocol Addable { 19 | func + (lhs: Self, rhs: Self) -> Self 20 | } 21 | [1, 2, 3, 4].sum // 1 + 2 + 3 + 4 22 | [0, 1, 2, 3, 4].average // 2 23 | [13, 2.4, 3, 4].varianceSample 24 | ``` 25 | 26 | - As you might guess `Substractable` define `-` operator, `Multiplicatable` define `*` operator, etc..., all defined in [Arithmosophi.swift](Sources/Arithmosophi.swift) 27 | 28 | ## Contents ## 29 | - [Generic functions](#generic-functions) 30 | - [CollectionType](#collectiontype) 31 | - [Average](#average) 32 | - [Median](#median) 33 | - [Variance](#variance) 34 | - [Standard deviation](#standard-deviation) 35 | - [Skewness](#skewness) 36 | - [Kurtosis](#kurtosis) 37 | - [Covariance](#covariance) 38 | - [Object attributes](#object-attributes) 39 | - [Logical operations](#logical-operations) 40 | - [Complex](#complex) 41 | - [Geometry](#geometry) 42 | - [Setup](#setup) 43 | 44 | ## Generic functions ## 45 | Take a look at `sumOf` function 46 | ```swift 47 | func sumOf(input : [T]) -> T { 48 | return reduce(input, T()) {$0 + $1} 49 | } 50 | ``` 51 | Array of `Int`, `Double` and even `String` could be passed as argument to this function. Any `Addable` objects. 52 | 53 | No need to implement a function for `Double`, one for `Float`, one more for `Int`, etc... 54 | 55 | *`sumOf` and `productOf` functions are available in [Arithmosophi.swift](Arithmosophi.swift)* 56 | 57 | 58 | ## CollectionType ## 59 | This framework contains some useful extensions on `CollectionType` 60 | ```swift 61 | [1, 2, 3, 4].sum // 1 + 2 + 3 + 4 62 | [1, 2, 3, 4].product // 1 * 2 * 3 * 4 63 | 64 | ["a","b","c","d"].sum // "abcd" same as joinWithSeparator("") 65 | [["a","b"],["c"],["d"]].sum // ["a","b","c","d"] same as flatMap{$0} 66 | ``` 67 | 68 | ### Average ### 69 | _with [MesosOros.swift](Sources/MesosOros.swift)_ 70 | 71 | Computes [arithmetic average/mean](http://en.wikipedia.org/wiki/Arithmetic_mean) 72 | ```swift 73 | [1, 2, 3, 4].average // (1 + 2 + 3 + 4) / 4 74 | ``` 75 | 76 | A type is `Averagable` if it can be dividable by an `Int` and define an operator to do that 77 | ```swift 78 | func /(lhs: Self, rhs: Int) -> Self 79 | ``` 80 | All arithmetic type conform to this protocol and you can get an average for a `CollectionType` 81 | 82 | P.S. You can conform to this protocol and `Addable` to make a custom average. 83 | 84 | ### Median ### 85 | _with [MesosOros.swift](Sources/MesosOros.swift)_ 86 | 87 | Get the [median value](http://en.wikipedia.org/wiki/Median) from the array 88 | 89 | - Returns the average of the two middle values if there is an even number of elements in the `CollectionType`. 90 | ```swift 91 | [1, 11, 19, 4, -7].median // 4 92 | ``` 93 | - Returns the lower of the two middle values if there is an even number of elements in the `CollectionType`. 94 | ```swift 95 | [1.0, 11, 19.5, 4, 12, -7].medianLow // 4 96 | ``` 97 | - Returns the higher of the two middle values if there is an even number of elements in the `CollectionType`. 98 | ```swift 99 | [1, 11, 19, 4, 12, -7].medianHigh // 11 100 | ``` 101 | 102 | ### Variance ### 103 | _with [Sigma.swift](Sources/Sigma.swift)_ 104 | 105 | Computes [variance](http://en.wikipedia.org/wiki/Variance). 106 | 107 | - [The sample variance](https://en.wikipedia.org/wiki/Variance#Sample_variance): Σ( (Element - average)^2 ) / (count - 1) 108 | 109 | ```swift 110 | [1.0, 11, 19.5, 4, 12, -7].varianceSample 111 | ``` 112 | - [The population variance](https://en.wikipedia.org/wiki/Variance#Sample_variance): Σ( (Element - average)^2 ) / count 113 | 114 | ```swift 115 | [1.0, 11, 19.5, 4, 12, -7].variancePopulation 116 | ``` 117 | 118 | ### Standard deviation ### 119 | _with [Sigma.swift](Sources/Sigma.swift)_ 120 | 121 | Computes [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation). 122 | 123 | - [sample based](https://en.wikipedia.org/wiki/Standard_deviation#Sample-based_statistics) 124 | ```swift 125 | [1.0, 11, 19.5, 4, 12, -7].standardDeviationSample 126 | ``` 127 | - [population based](https://en.wikipedia.org/wiki/Standard_deviation#Population-based_statistics) 128 | ```swift 129 | [[1.0, 11, 19.5, 4, 12, -7].standardDeviationPopulation 130 | ``` 131 | 132 | ### Skewness ### 133 | _with [Sigma.swift](Sources/Sigma.swift)_ 134 | 135 | Computes [skewness](https://en.wikipedia.org/wiki/Skewness). 136 | 137 | ```swift 138 | [1.0, 11, 19.5, 4, 12, -7].skewness // or .moment.skewness 139 | ``` 140 | 141 | ### Kurtosis ### 142 | _with [Sigma.swift](Sources/Sigma.swift)_ 143 | 144 | Computes [kurtosis](https://en.wikipedia.org/wiki/Kurtosis). 145 | 146 | ```swift 147 | [1.0, 11, 19.5, 4, 12, -7].kurtosis // or .moment.kurtosis 148 | ``` 149 | 150 | ### Covariance ### 151 | _with [Sigma.swift](Sources/Sigma.swift)_ 152 | 153 | Computes [covariance](http://en.wikipedia.org/wiki/Covariance) with another `CollectionType` 154 | 155 | - [sample covariance](http://en.wikipedia.org/wiki/Sample_mean_and_sample_covariance) 156 | ```swift 157 | [1, 2, 3.5, 3.7, 8, 12].covarianceSample([0.5, 1, 2.1, 3.4, 3.4, 4]) 158 | ``` 159 | - population covariance 160 | ```swift 161 | [1, 2, 3.5, 3.7, 8, 12].covariancePopulation([0.5, 1, 2.1, 3.4, 3.4, 4]) 162 | ``` 163 | 164 | - [Pearson product-moment correlation coefficient](http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient) 165 | ```swift 166 | [1, 2, 3.5, 3.7, 8, 12].pearson([0.5, 1, 2.1, 3.4, 3.4, 4]) 167 | ``` 168 | 169 | ## Complex ## 170 | _with [Complex.swift](Sources/Complex.swift)_ 171 | `Complex` is a struct of two `ArithmeticType`, the real and the imaginary component 172 | 173 | ```swift 174 | var complex = Complex(real: 12, imaginary: 9) 175 | complex = 12 + 9.i 176 | ``` 177 | You can apply operation on it `(+, -, *, /, ++, --, -)` 178 | 179 | ``` 180 | result = complex + 8 // Complex(real: 20, imaginary: 9) 181 | 182 | Complex(real: 12, imaginary: 9) + Complex(real: 8, imaginary: 1) 183 | // Complex(real: 20, imaginary: 10) 184 | ``` 185 | 186 | ## Object attributes ## 187 | The power of this simple arithmetic protocols are released when using operators 188 | 189 | If we implement a box object containing a generic `T` value 190 | ```swift 191 | class Box { 192 | var value: T 193 | } 194 | ``` 195 | we can define some operators on it, in a generic way, like we can do with `Equatable` or `Comparable` 196 | ```swift 197 | func += (inout box: Box, addend: T) { 198 | box.value = box.value + addend 199 | } 200 | func -= (inout box: Box, addend: T) { 201 | box.value = box.value - addend 202 | } 203 | ``` 204 | how to use this operator: 205 | ```swift 206 | var myInt: Box(5) 207 | myInt += 37 208 | ``` 209 | 210 | For a full example, see [Prephirence](https://github.com/phimage/Prephirences/blob/master/Prephirences/Preference.swift) file from [Prephirences](https://github.com/phimage/Prephirences) framework, or sample [Box.swift](Samples/Box.swift) 211 | 212 | ### Optional trick ### 213 | For optional attribute you can use `Initializable` or any protocol which define a way to get a value 214 | ```swift 215 | class Box { 216 | var value: T? 217 | } 218 | func += (inout box: Box, addend: T) { 219 | box.value = (box.value ?? T()) + addend 220 | } 221 | ``` 222 | 223 | ## Logical operations ## 224 | [`LogicalOperationsType`](Sources/LogicalOperationsType.swift) is a missing protocol for `Bool` inspired from `BitwiseOperationsType` (or `IntegerArithmeticType`) 225 | 226 | The purpose is the same, implement functions without knowing the base type 227 | 228 | You can for instance implement your own [`Boolean` enum](Samples/Boolean.swift) and implement the protocol 229 | ```swift 230 | enum Boolean: LogicalOperationsType {case True, False} 231 | func && (left: Boolean, @autoclosure right: () -> Boolean) -> Boolean { 232 | switch left { 233 | case .False: return .False 234 | case .True: return right() 235 | } 236 | } 237 | ... 238 | ``` 239 | then create only **one** operator on `Box` for `Bool`, `Boolean` and any `LogicalOperationsType` 240 | ```swift 241 | func &&= (inout box: Box, @autoclosure right: () -> TT) { 242 | box.value = box.value && right() 243 | } 244 | ``` 245 | 246 | Take a look at a more complex enum [Optional](Samples/Optional.swift) which implement also `LogicalOperationsType` 247 | 248 | ## Geometry ## 249 | with `Arithmos`(number) & `Statheros`(constant) 250 | 251 | [`Arithmos`](Sources/Arithmos.swift) and [`Statheros`](Sources/Statheros.swift) add respectively functions and mathematical constants for `Double`, `Float` and `CGFloat`, allowing to implement generic functions without taking care of type 252 | 253 | ```swift 254 | func distance(#x: T, y: T) -> T { 255 | return x.hypot(y) 256 | } 257 | 258 | func radiansFromDegrees(degrees: T) -> T { 259 | return degrees * T.PI / T(180.0) 260 | } 261 | ``` 262 | 263 | Take a look at [Geometry.swift](Samples/Geometry.swift) for more examples 264 | 265 | ## Setup 266 | ### Using [cocoapods](http://cocoapods.org/) ## 267 | ```ruby 268 | pod 'Arithmosophi' 269 | ``` 270 | Not interested in full framework ? install a subset with: 271 | ```ruby 272 | pod 'Arithmosophi/Core' # Arithmosophi.swift 273 | pod 'Arithmosophi/Logical' # LogicalOperationsType.swift 274 | pod 'Arithmosophi/Complex' # Complex.swift 275 | pod 'Arithmosophi/MesosOros' # MesosOros.swift 276 | pod 'Arithmosophi/Arithmos' # Arithmos.swift 277 | pod 'Arithmosophi/Sigma' # Sigma.swift 278 | pod 'Arithmosophi/Statheros' # Statheros.swift 279 | 280 | pod 'Arithmosophi/Samples' # Samples/*.swift (not installed by default) 281 | ``` 282 | 283 | *Add `use_frameworks!` to the end of the `Podfile`.* 284 | 285 | #### Make your own framework dependent 286 | In podspec file 287 | ```ruby 288 | s.dependency 'Arithmosophi' 289 | ``` 290 | or define only wanted targets 291 | ```ruby 292 | s.dependency 'Arithmosophi/Core' 293 | s.dependency 'Arithmosophi/Logical' 294 | ``` 295 | 296 | ## Using xcode ## 297 | Drag files to your projects 298 | -------------------------------------------------------------------------------- /Samples/Boolean.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Boolean.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | import Foundation 29 | import Arithmosophi 30 | 31 | public enum Boolean: LogicalOperationsType, Equatable {case `true`, `false`} 32 | // extends also BooleanLiteralConvertible and BooleanType 33 | 34 | public func == (left: Boolean, right: Boolean) -> Bool { 35 | switch (left, right) { 36 | case (.false, .false), (.true, .true): return true 37 | case (.false, .true), (.true, .false): return false 38 | } 39 | } 40 | 41 | public func && (left: Boolean, right: @autoclosure () throws -> Boolean) rethrows -> Boolean { 42 | switch left { 43 | case .false: return .false 44 | case .true: return try right() 45 | } 46 | } 47 | public func || (left: Boolean, right: @autoclosure () throws -> Boolean) rethrows -> Boolean { 48 | switch left { 49 | case .false: return try right() 50 | case .true: return .true 51 | } 52 | } 53 | public prefix func ! (value: Boolean ) -> Boolean { 54 | switch value { 55 | case .false: return .true 56 | case .true: return .false 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Samples/Box.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Box.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | import Foundation 28 | import Arithmosophi 29 | 30 | public final class Box: RawRepresentable where T: Addable, T: Equatable { 31 | public typealias RawValue = T 32 | 33 | public var rawValue: T 34 | 35 | public required init?(rawValue: T) { 36 | self.rawValue = rawValue 37 | } 38 | 39 | public init(value: T) { 40 | self.rawValue = value 41 | } 42 | } 43 | 44 | public func += (box: inout Box, addend: T) { 45 | box.rawValue += addend 46 | } 47 | public func -= (box: inout Box, addend: T) where T: Substractable { 48 | box.rawValue -= addend 49 | } 50 | 51 | // Equatable 52 | extension Box: Equatable {} 53 | public func == (lhs: Box, rhs: Box) -> Bool { 54 | return lhs.rawValue == rhs.rawValue 55 | } 56 | 57 | // Addable 58 | extension Box: Addable {} 59 | public func + (lhs: Box, rhs: Box) -> Box { 60 | return Box(value: lhs.rawValue + rhs.rawValue) 61 | } 62 | -------------------------------------------------------------------------------- /Samples/Geometry+Animation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Geometry+Animation.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | import Foundation 29 | import Arithmosophi 30 | 31 | public extension Geometry { 32 | 33 | class func easeOutFast(_ time: T) -> T where T: Multiplicable & Substractable & Arithmos & ExpressibleByIntegerLiteral { 34 | let f = time.clamp(0...1) 35 | return T(2) * f - f * f 36 | } 37 | class func easeInFast(_ time: T) -> T where T: Multiplicable & Arithmos & ExpressibleByIntegerLiteral { 38 | let f = time.clamp(0...1) 39 | return f * f 40 | } 41 | class func easeInAndOutFast(_ time: T) -> T where T: Multiplicable & Substractable & Arithmos & ExpressibleByIntegerLiteral { 42 | let f = time.clamp(0...1) 43 | return f * f * (T(3.0) - T(2.0) * f) 44 | } 45 | 46 | class func easeOut(_ time: T) -> T where T: Multiplicable & Statheros & Arithmos & ExpressibleByIntegerLiteral { 47 | let f = time.clamp(0...1) 48 | return (f * T.π_2).sin() 49 | } 50 | class func easeIn(_ time: T) -> T where T: Multiplicable & Substractable & Statheros & Arithmos & ExpressibleByIntegerLiteral { 51 | let f = time.clamp(0...1) 52 | return T(1.0) - (f * T.π_2).cos() 53 | } 54 | class func easeInAndOut(_ time: T) -> T where T: Multiplicable & Substractable & Addable & Statheros & Arithmos & ExpressibleByIntegerLiteral { 55 | let f = time.clamp(0...1) 56 | return T(0.5) * (T(1.0) + (T.π * (f - T(0.5))).sin()) 57 | } 58 | 59 | class func triangleUpThenDown(_ t: T) -> T where T: Addable & Substractable & Multiplicable & Dividable & Arithmos & Comparable { 60 | let f = t.fract() 61 | return f < T(0.5) ? map(f, T(0.0), T(0.5), T(1.0), T(0.0)) : map(f, T(0.5), T(1.0), T(1.0), T(0.0)) 62 | } 63 | class func triangleDownThenUp(_ t: T) -> T where T: Addable & Substractable & Multiplicable & Dividable & Arithmos & Comparable { 64 | let f = t.fract() 65 | return f < T(0.5) ? map(f, T(0.0), T(0.5), T(0.0), T(1.0)) : map(f, T(0.5), T(1.0), T(0.0), T(1.0)) 66 | } 67 | class func sawtoothUp(_ t: T) -> T { 68 | return t.fract() 69 | } 70 | class func sawtoothDown(_ t: T) -> T where T: Substractable { 71 | return T(1.0) - t.fract() 72 | } 73 | 74 | class func sineUpThenDown(_ t: T) -> T where T: Addable & Arithmos & Multiplicable & Statheros { 75 | return (t * T.π2).sin() * T(0.5) + T(0.5) 76 | } 77 | class func sineDownThenUp(_ t: T) -> T where T: Addable & Arithmos & Multiplicable & Substractable & Statheros { 78 | return T(1.0) - (t * T.π2).sin() * T(0.5) + T(0.5) 79 | } 80 | class func cosineUpThenDown(_ t: T) -> T where T: Addable & Arithmos & Multiplicable & Substractable & Statheros { 81 | return T(1.0) - (t * T.π2).sin() * T(0.5) + T(0.5) 82 | } 83 | class func cosineDownThenUp(_ t: T) -> T where T: Addable & Arithmos & Multiplicable & Statheros { 84 | return (t * T.π2).sin() * T(0.5) + T(0.5) 85 | } 86 | 87 | class func miterLength(lineWidth: T, phi: T) -> T where T: Addable & Arithmos & Multiplicable & Dividable { 88 | return lineWidth * (T(1.0) / (phi / T(2.0)).sin()) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Samples/Geometry.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Geometry.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | // examples 29 | import Arithmosophi 30 | 31 | open class Geometry { 32 | 33 | // MARK: area, volume 34 | open class func area(x: T, y: T) -> T { return x * y } 35 | open class func volume(x: T, y: T, z: T) -> T { return x * y * z } 36 | 37 | // MARK: distance 38 | 39 | open class func distance(x: T, y: T) -> T { 40 | return x.hypot(y) 41 | } 42 | open class func distance(x1: T, y1: T, x2: T, y2: T) -> T where T: Substractable, T: Arithmos { 43 | return distance(x: x2 - x1, y: y2 - y1) 44 | } 45 | open class func distance(x: T, y: T, z: T) -> T where T: Addable, T: Multiplicable, T: Substractable, T: Arithmos { 46 | return distanceSquared(x: x, y: y, z: z).sqrt() 47 | } 48 | 49 | open class func distance(x1: T, y1: T, z1: T, x2: T, y2: T, z2: T) -> T where T: Addable, T: Multiplicable, T: Substractable, T: Arithmos { 50 | return distance(x: x2 - x1, y: y2 - y1, z: z2 - z1).sqrt() 51 | } 52 | 53 | open class func distanceSquared(x: T, y: T) -> T where T: Addable, T: Multiplicable { 54 | return x * x + y * y 55 | } 56 | open class func distanceSquared(x1: T, y1: T, x2: T, y2: T) -> T where T: Addable, T: Multiplicable, T: Substractable { 57 | return distanceSquared(x: x2 - x1, y: y2 - y1) 58 | } 59 | open class func distanceSquared(x: T, y: T, z: T) -> T where T: Addable, T: Multiplicable { 60 | return x * x + y * y + z * z 61 | } 62 | open class func distanceSquared(x1: T, y1: T, z1: T, x2: T, y2: T, z2: T) -> T where T: Addable, T: Multiplicable, T: Substractable { 63 | return distanceSquared(x: x2 - x1, y: y2 - y1, z: z2 - z1) 64 | } 65 | 66 | open class func normalize(x: T, y: T) -> (x: T, y: T) where T: Dividable { 67 | let d = distance(x: x, y: y) 68 | return (x: x / d, y: y / d) 69 | } 70 | open class func normalize(x: T, y: T, z: T) -> (x: T, y: T, z: T) where T: Addable, T: Multiplicable, T: Substractable, T: Dividable, T: Arithmos { 71 | let d = distance(x: x, y: y, z: z) 72 | return (x: x / d, y: y / d, z: z / d) 73 | } 74 | 75 | // MARK: point, cross 76 | open class func dot(x1: T, y1: T, x2: T, y2: T) -> T where T: Addable, T: Multiplicable { 77 | return x1 * x2 + y1 * y2 78 | } 79 | open class func dot(x1: T, y1: T, z1: T, x2: T, y2: T, z2: T) -> T where T: Addable, T: Multiplicable { 80 | return x1 * x2 + y1 * y2 + z1 * z2 81 | } 82 | 83 | open class func cross(x1: T, y1: T, z1: T, x2: T, y2: T, z2: T) -> (x: T, y: T, z: T) where T: Substractable, T: Multiplicable { 84 | return (x:z2 * y1 - y2 * z1, y:x2 * z1 - z2 * x1, z:y2 * x1 - x2 * y1) 85 | } 86 | 87 | // MARK: scale 88 | open class func scale(dx: T, dy: T, s: T) -> (dx: T, dy: T) { return (dx: dx * s, dy: dy * s) } 89 | open class func scale(dx: T, dy: T, dz: T, s: T) -> (dx: T, dy: T, dz: T) { return (dx: dx * s, dy: dy * s, dz: dz * s) } 90 | open class func scale(dx: T, dy: T, sx: T, sy: T) -> (dx: T, dy: T) { return (dx: dx * sx, dy: dy * sy) } 91 | open class func scale(dx: T, dy: T, dz: T, sx: T, sy: T, sz: T) -> (dx: T, dy: T, dz: T) { return (dx: dx * sx, dy: dy * sy, dz: dz * sz) } 92 | 93 | open class func scaleForAspectFit(dxContent: T, dyContent: T, dxArea: T, dyArea: T) -> T where T: Dividable, T: Comparable { 94 | return Swift.min(dxArea / dxContent, dyArea / dyContent) 95 | } 96 | 97 | open class func scaleForAspectFill(dxContent: T, dyContent: T, dxArea: T, dyArea: T) -> T where T: Dividable, T: Comparable { 98 | return Swift.min(dxArea / dxContent, dyArea / dyContent) 99 | } 100 | 101 | open class func aspectFit(dxContent: T, dyContent: T, dxArea: T, dyArea: T) -> (dx: T, dy: T) where T: Dividable, T: Multiplicable, T: Comparable { 102 | let s = scaleForAspectFit(dxContent: dxContent, dyContent: dyContent, dxArea: dxArea, dyArea: dyArea) 103 | return scale(dx: dxContent, dy: dyContent, s: s) 104 | } 105 | 106 | open class func aspectFill(dxContent: T, dyContent: T, dxArea: T, dyArea: T) -> (dx: T, dy: T) where T: Dividable, T: Multiplicable, T: Comparable { 107 | let s = scaleForAspectFill(dxContent: dxContent, dyContent: dyContent, dxArea: dxArea, dyArea: dyArea) 108 | return scale(dx: dxContent, dy: dyContent, s: s) 109 | } 110 | 111 | // MARK: utility 112 | 113 | open class func normalize(_ value: T, _ i1: T, _ i2: T) -> T where T: Substractable, T: Dividable { 114 | return (value - i1) / (i2 - i1) 115 | } 116 | open class func denormalize(_ value: T, _ i1: T, _ i2: T) -> T where T: Substractable, T: Multiplicable, T: Addable { 117 | return value * (i2 - i1) + i1 118 | } 119 | open class func interpolate(_ value: T, _ i1: T, _ i2: T) -> T where T: Substractable, T: Multiplicable, T: Addable { 120 | return value * (i2 - i1) + i1 121 | } 122 | open class func map(_ value: T, _ a1: T, _ a2: T, _ b1: T, _ b2: T) -> T where T: Addable, T: Substractable, T: Multiplicable, T: Dividable { 123 | let v = ((b2 - b1) * (value - a1)) 124 | return b1 + v / (a2 - a1) 125 | } 126 | 127 | open class func interpolate(x1: T, y1: T, x2: T, y2: T, t: T) -> (x: T, y: T) where T: Substractable, T: Multiplicable, T: Addable { 128 | return (x: interpolate(t, x1, x2), y: interpolate(t, y1, y2)) 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /Samples/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Samples/Optional.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Optional.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | import Foundation 29 | import Arithmosophi 30 | 31 | public enum OptionalEnum: LogicalOperationsType, Equatable, Initializable { 32 | case none 33 | case some(T) 34 | 35 | public init(_ value: T?) { 36 | if let v = value { 37 | self = .some(v) 38 | } else { 39 | self = .none 40 | } 41 | } 42 | 43 | init(_ value: T) { 44 | self = .some(value) 45 | } 46 | 47 | public init() { 48 | self = .none 49 | } 50 | 51 | public func unwrap() -> T { 52 | switch self { 53 | case .some(let value): 54 | return value 55 | case .none: 56 | fatalError("Unexpectedly found nil whie unwrapping an Optional value") 57 | } 58 | } 59 | } 60 | 61 | public func == (left: OptionalEnum, right: OptionalEnum) -> Bool { 62 | switch (left, right) { 63 | case (.none, .none): return true 64 | case (.none, .some), (.some, .none): return false 65 | case (.some(let x), .some(let y)): return x == y 66 | } 67 | } 68 | 69 | public func == (left: OptionalEnum, right: OptionalEnum) -> Bool { 70 | switch (left, right) { 71 | case (.none, .none): return true 72 | case (.none, .some), (.some, .none): return false 73 | case (.some, .some): return true 74 | } 75 | } 76 | 77 | public func && (left: OptionalEnum, right: @autoclosure () throws -> OptionalEnum) rethrows -> OptionalEnum { 78 | switch left { 79 | case .none: return .none 80 | case .some: return try right() 81 | } 82 | } 83 | public func || (left: OptionalEnum, right: @autoclosure () throws -> OptionalEnum) rethrows -> OptionalEnum { 84 | switch left { 85 | case .none: return try right() 86 | case .some: return left 87 | } 88 | } 89 | public prefix func ! (value: OptionalEnum) -> OptionalEnum { 90 | switch value { 91 | case .none: return .some(T()) 92 | case .some: return .none 93 | } 94 | } 95 | 96 | public func ||= (lhs: inout OptionalEnum?, rhs: OptionalEnum) { 97 | if lhs == nil { 98 | lhs = rhs 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Samples/Parity.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Parity.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | import Foundation 29 | import Arithmosophi 30 | 31 | public enum Parity: IntegerLiteralType, Equatable, Addable, Substractable, Multiplicable { 32 | case even, odd 33 | 34 | public init(integerLiteral value: IntegerLiteralType) { 35 | self = value % 2 == 0 ? .even : .odd 36 | } 37 | 38 | } 39 | 40 | // MARK: Equatable 41 | public func == (left: Parity, right: Parity) -> Bool { 42 | switch (left, right) { 43 | case (.even, .even), (.odd, .odd): return true 44 | case (.even, .odd), (.odd, .even): return false 45 | } 46 | } 47 | 48 | // MARK: Addable 49 | public func + (left: Parity, right: Parity) -> Parity { 50 | return left == right ? .even : .odd 51 | } 52 | 53 | // MARK: Substractable 54 | public func - (left: Parity, right: Parity) -> Parity { 55 | return left + right 56 | } 57 | 58 | // MARK: Multiplicable 59 | public func * (left: Parity, right: Parity) -> Parity { 60 | return left == .odd && right == .odd ? .odd : .even 61 | } 62 | -------------------------------------------------------------------------------- /Sources/Arithmos.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Arithmos.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | #if os(Linux) 29 | import Glibc 30 | #else 31 | import Darwin 32 | import CoreGraphics 33 | #if os(watchOS) 34 | import UIKit 35 | #endif 36 | #endif 37 | 38 | public func fract(_ x: Double) -> Double { 39 | return x - x.floor() 40 | } 41 | 42 | public func fract(_ x: Float) -> Float { 43 | return x - x.floor() 44 | } 45 | 46 | public func fract(_ x: CGFloat) -> CGFloat { 47 | return x - x.floor() 48 | } 49 | 50 | /// Protocol to add some commons function to Double, CGFloat and Float 51 | public protocol Arithmos: Comparable { 52 | 53 | func abs() -> Self 54 | func floor () -> Self 55 | func ceil () -> Self 56 | func round () -> Self 57 | func fract() -> Self 58 | 59 | func sqrt() -> Self 60 | func cbrt() -> Self 61 | func pow(_ value: Self) -> Self 62 | 63 | func exp() -> Self 64 | func exp2() -> Self 65 | func log() -> Self 66 | func log2() -> Self 67 | func log1p() -> Self 68 | func log10() -> Self 69 | func tgamma() -> Self 70 | func lgamma() -> Self 71 | 72 | func sin() -> Self 73 | func cos() -> Self 74 | func tan() -> Self 75 | func sinh() -> Self 76 | func cosh() -> Self 77 | func tanh() -> Self 78 | func asin() -> Self 79 | func acos() -> Self 80 | func atan() -> Self 81 | func atan2(_ value: Self) -> Self 82 | func hypot(_ value: Self) -> Self 83 | 84 | func reciprocal() -> Self 85 | func erf() -> Self 86 | func erfc() -> Self 87 | 88 | static func random(_ max: Self) -> Self 89 | static func random(_ min: Self, _ max: Self) -> Self 90 | static func random(_ range: ClosedRange) -> Self 91 | 92 | func clamp(_ max: Self) -> Self 93 | func clamp(_ min: Self, _ max: Self) -> Self 94 | func clamp(_ range: ClosedRange) -> Self 95 | 96 | init(_ double: Double) 97 | 98 | var isFinite: Bool {get} 99 | var isInfinite: Bool {get} 100 | } 101 | 102 | extension Double: Arithmos { 103 | 104 | #if os(Linux) 105 | public func abs() -> Double { return Glibc.fabs(self) } 106 | public func floor () -> Double { return Glibc.floor(self) } 107 | public func ceil () -> Double { return Glibc.ceil(self) } 108 | public func round () -> Double { return Glibc.round(self) } 109 | public func fract() -> Double { return self - self.floor() } 110 | 111 | public func sqrt() -> Double { return Glibc.sqrt(self) } 112 | public func cbrt() -> Double { return Glibc.cbrt(self) } 113 | public func pow(value: Double) -> Double { return Glibc.pow(self, value) } 114 | 115 | public func exp() -> Double { return Glibc.exp(self) } 116 | public func exp2() -> Double { return Glibc.exp2(self) } 117 | public func log() -> Double { return Glibc.log(self) } 118 | public func log2() -> Double { return Glibc.log2(self) } 119 | public func log10() -> Double { return Glibc.log10(self) } 120 | public func log1p() -> Double { return Glibc.log1p(self) } 121 | public func tgamma() -> Double { return Glibc.tgamma(self) } 122 | public func lgamma() -> Double { return Glibc.lgamma(self) } 123 | 124 | public func erf() -> Double { return Glibc.erf(self) } 125 | public func erfc() -> Double { return Glibc.erfc(self) } 126 | 127 | public func cos() -> Double { return Glibc.cos(self) } 128 | public func sin() -> Double { return Glibc.sin(self) } 129 | public func hypot(value: Double) -> Double { return Glibc.hypot(self, value) } 130 | public func atan2(value: Double) -> Double { return Glibc.atan2(self, value) } 131 | public func cosh() -> Double { return Glibc.cosh(self) } 132 | public func sinh() -> Double { return Glibc.sinh(self) } 133 | public func tanh() -> Double { return Glibc.tanh(self) } 134 | public func acos() -> Double { return Glibc.acos(self) } 135 | public func asin() -> Double { return Glibc.asin(self) } 136 | public func atan() -> Double { return Glibc.atan(self) } 137 | 138 | #else 139 | @_transparent public func abs() -> Double { return Darwin.fabs(self) } 140 | @_transparent public func floor () -> Double { return Darwin.floor(self) } 141 | @_transparent public func ceil () -> Double { return Darwin.ceil(self) } 142 | @_transparent public func round () -> Double { return Darwin.round(self) } 143 | @_transparent public func fract() -> Double { return self - self.floor() } 144 | 145 | @_transparent public func sqrt() -> Double { return Darwin.sqrt(self) } 146 | @_transparent public func cbrt() -> Double { return Darwin.cbrt(self) } 147 | @_transparent public func pow(_ value: Double) -> Double { return Darwin.pow(self, value) } 148 | 149 | @_transparent public func exp() -> Double { return Darwin.exp(self) } 150 | @_transparent public func exp2() -> Double { return Darwin.exp2(self) } 151 | @_transparent public func log() -> Double { return Darwin.log(self) } 152 | @_transparent public func log2() -> Double { return Darwin.log2(self) } 153 | @_transparent public func log10() -> Double { return Darwin.log10(self) } 154 | @_transparent public func log1p() -> Double { return Darwin.log1p(self) } 155 | @_transparent public func tgamma() -> Double { return Darwin.tgamma(self) } 156 | @_transparent public func lgamma() -> Double { return Darwin.lgamma(self) } 157 | 158 | @_transparent public func erf() -> Double { return Darwin.erf(self) } 159 | @_transparent public func erfc() -> Double { return Darwin.erfc(self) } 160 | 161 | @_transparent public func cos() -> Double { return Darwin.cos(self) } 162 | @_transparent public func sin() -> Double { return Darwin.sin(self) } 163 | @_transparent public func tan() -> Double { return Darwin.tan(self) } 164 | @_transparent public func hypot(_ value: Double) -> Double { return Darwin.hypot(self, value) } 165 | @_transparent public func atan2(_ value: Double) -> Double { return Darwin.atan2(self, value) } 166 | @_transparent public func cosh() -> Double { return Darwin.cosh(self) } 167 | @_transparent public func sinh() -> Double { return Darwin.sinh(self) } 168 | @_transparent public func tanh() -> Double { return Darwin.tanh(self) } 169 | @_transparent public func acos() -> Double { return Darwin.acos(self) } 170 | @_transparent public func asin() -> Double { return Darwin.asin(self) } 171 | @_transparent public func atan() -> Double { return Darwin.atan(self) } 172 | #endif 173 | 174 | @_transparent public func reciprocal() -> Double { 175 | return 1 / self 176 | } 177 | 178 | public static func random(_ max: Double) -> Double { 179 | return random(0, max) 180 | } 181 | public static func random(_ min: Double, _ max: Double) -> Double { 182 | let diff = max - min 183 | let rand = Double(arc4random() % (UInt32(RAND_MAX) + 1)) 184 | return ((rand / Double(RAND_MAX)) * diff) + min 185 | } 186 | public static func random(_ range: ClosedRange) -> Double { 187 | return random(range.lowerBound, range.upperBound) 188 | } 189 | 190 | public func clamp(_ max: Double) -> Double { 191 | return clamp(0.0, max) 192 | } 193 | public func clamp(_ min: Double, _ max: Double) -> Double { 194 | return Swift.max(min, Swift.min(max, self)) 195 | } 196 | public func clamp(_ range: ClosedRange) -> Double { 197 | return Swift.max(range.lowerBound, Swift.min(range.upperBound, self)) 198 | } 199 | } 200 | 201 | extension Float: Arithmos { 202 | #if os(Linux) 203 | public func abs() -> Float { return Glibc.fabs(self) } 204 | public func floor () -> Float { return Glibc.floor(self) } 205 | public func ceil () -> Float { return Glibc.ceil(self) } 206 | public func round () -> Float { return Glibc.round(self) } 207 | public func fract() -> Float { return self - self.floor() } 208 | 209 | public func sqrt() -> Float { return Glibc.sqrt(self) } 210 | public func cbrt() -> Float { return Glibc.sqrt.cbrt(self) } 211 | public func pow(value: Float) -> Float { return Glibc.pow(self, value) } 212 | 213 | public func exp() -> Float { return Glibc.exp(self) } 214 | public func exp2() -> Float { return Glibc.exp2(self) } 215 | public func log() -> Float { return Glibc.log(self) } 216 | public func log2() -> Float { return Glibc.log2(self) } 217 | public func log10() -> Float { return Glibc.log10(self) } 218 | public func log1p() -> Float { return Glibc.log1p(self) } 219 | public func tgamma() -> Float { return Glibc.tgamma(self) } 220 | public func lgamma() -> Float { return Glibc.lgamma(self) } 221 | 222 | public func erf() -> Float { return Glibc.erf(self) } 223 | public func erfc() -> Float { return Glibc.erfc(self) } 224 | 225 | public func cos() -> Float { return Glibc.cos(self) } 226 | public func sin() -> Float { return Glibc.sin(self) } 227 | public func tan() -> Float { return Glibc.tan(self) } 228 | public func hypot(value: Float) -> Float { return Glibc.hypot(self, value) } 229 | public func atan2(value: Float) -> Float { return Glibc.atan2(self, value) } 230 | public func cosh() -> Float { return Glibc.cosh(self) } 231 | public func sinh() -> Float { return Glibc.sinh(self) } 232 | public func tanh() -> Float { return Glibc.tanh(self) } 233 | public func acos() -> Float { return Glibc.acos(self) } 234 | public func asin() -> Float { return Glibc.asin(self) } 235 | public func atan() -> Float { return Glibc.atan(self) } 236 | 237 | #else 238 | 239 | #if swift(>=4.2) 240 | @_transparent public func abs() -> Float { return Darwin.fabsf(self) } 241 | #else 242 | @_transparent public func abs() -> Float { return Darwin.fabs(self) } 243 | #endif 244 | @_transparent public func floor () -> Float { return Darwin.floor(self) } 245 | @_transparent public func ceil () -> Float { return Darwin.ceil(self) } 246 | @_transparent public func round () -> Float { return Darwin.round(self) } 247 | @_transparent public func fract() -> Float { return self - self.floor() } 248 | 249 | @_transparent public func sqrt() -> Float { return Darwin.sqrtf(self) } 250 | @_transparent public func cbrt() -> Float { return Darwin.cbrtf(self) } 251 | @_transparent public func pow(_ value: Float) -> Float { return Darwin.pow(self, value) } 252 | 253 | @_transparent public func exp() -> Float { return Darwin.expf(self) } 254 | @_transparent public func exp2() -> Float { return Darwin.exp2f(self) } 255 | @_transparent public func log() -> Float { return Darwin.logf(self) } 256 | @_transparent public func log2() -> Float { return Darwin.log2f(self) } 257 | @_transparent public func log10() -> Float { return Darwin.log10f(self) } 258 | @_transparent public func log1p() -> Float { return Darwin.log1pf(self) } 259 | @_transparent public func tgamma() -> Float { return Darwin.tgammaf(self) } 260 | @_transparent public func lgamma() -> Float { return Darwin.lgammaf(self) } 261 | 262 | @_transparent public func erf() -> Float { return Darwin.erf(self) } 263 | @_transparent public func erfc() -> Float { return Darwin.erfc(self) } 264 | 265 | @_transparent public func cos() -> Float { return Darwin.cosf(self) } 266 | @_transparent public func sin() -> Float { return Darwin.sinf(self) } 267 | @_transparent public func tan() -> Float { return Darwin.tanf(self) } 268 | @_transparent public func hypot(_ value: Float) -> Float { return Darwin.hypotf(self, value) } 269 | @_transparent public func atan2(_ value: Float) -> Float { return Darwin.atan2f(self, value) } 270 | @_transparent public func cosh() -> Float { return Darwin.coshf(self) } 271 | @_transparent public func sinh() -> Float { return Darwin.sinhf(self) } 272 | @_transparent public func tanh() -> Float { return Darwin.tanhf(self) } 273 | @_transparent public func acos() -> Float { return Darwin.acosf(self) } 274 | @_transparent public func asin() -> Float { return Darwin.asinf(self) } 275 | @_transparent public func atan() -> Float { return Darwin.atanf(self) } 276 | #endif 277 | 278 | public func reciprocal() -> Float { 279 | return 1 / self 280 | } 281 | 282 | public static func random(_ max: Float) -> Float { 283 | return random(0, max) 284 | } 285 | public static func random(_ min: Float, _ max: Float) -> Float { 286 | let diff = max - min 287 | let rand = Float(arc4random() % (UInt32(RAND_MAX) + 1)) 288 | return ((rand / Float(RAND_MAX)) * diff) + min 289 | } 290 | public static func random(_ range: ClosedRange) -> Float { 291 | return random(range.lowerBound, range.upperBound) 292 | } 293 | 294 | public func clamp(_ max: Float) -> Float { 295 | return clamp(Float(0.0), max) 296 | } 297 | public func clamp(_ min: Float, _ max: Float) -> Float { 298 | return Swift.max(min, Swift.min(max, self)) 299 | } 300 | public func clamp(_ range: ClosedRange) -> Float { 301 | return Swift.max(range.lowerBound, Swift.min(range.upperBound, self)) 302 | } 303 | } 304 | 305 | #if !os(Linux) 306 | extension CGFloat: Arithmos { 307 | 308 | #if swift(>=4.2) 309 | @_transparent public func abs() -> CGFloat { return CGFloat(Darwin.fabs(Double(self))) } 310 | #else 311 | @_transparent public func abs() -> CGFloat { return CoreGraphics.fabs(self) } 312 | #endif 313 | @_transparent public func floor () -> CGFloat { return CoreGraphics.floor(self) } 314 | @_transparent public func ceil () -> CGFloat { return CoreGraphics.ceil(self) } 315 | @_transparent public func round () -> CGFloat { return CoreGraphics.round(self) } 316 | @_transparent public func fract() -> CGFloat { return self - self.floor() } 317 | 318 | @_transparent public func sqrt() -> CGFloat { return CoreGraphics.sqrt(self) } 319 | @_transparent public func cbrt() -> CGFloat { return CoreGraphics.cbrt(self) } 320 | @_transparent public func pow(_ value: CGFloat) -> CGFloat { return CoreGraphics.pow(self, value) } 321 | 322 | @_transparent public func exp() -> CGFloat { return CoreGraphics.exp(self) } 323 | @_transparent public func exp2() -> CGFloat { return CoreGraphics.exp2(self) } 324 | @_transparent public func log() -> CGFloat { return CoreGraphics.log(self) } 325 | @_transparent public func log2() -> CGFloat { return CoreGraphics.log2(self) } 326 | @_transparent public func log10() -> CGFloat { return CoreGraphics.log10(self) } 327 | @_transparent public func log1p() -> CGFloat { return CoreGraphics.log1p(self) } 328 | @_transparent public func tgamma() -> CGFloat { return CoreGraphics.tgamma(self) } 329 | @_transparent public func lgamma() -> CGFloat { return CGFloat(Darwin.lgammaf(Float(self))) } 330 | 331 | @_transparent public func erf() -> CGFloat { return CoreGraphics.erf(self) } 332 | @_transparent public func erfc() -> CGFloat { return CoreGraphics.erfc(self) } 333 | 334 | @_transparent public func cos() -> CGFloat { return CoreGraphics.cos(self) } 335 | @_transparent public func sin() -> CGFloat { return CoreGraphics.sin(self) } 336 | @_transparent public func tan() -> CGFloat { return CoreGraphics.tan(self) } 337 | @_transparent public func hypot(_ value: CGFloat) -> CGFloat { return CoreGraphics.hypot(self, value) } 338 | @_transparent public func atan2(_ value: CGFloat) -> CGFloat { return CoreGraphics.atan2(self, value) } 339 | @_transparent public func cosh() -> CGFloat { return CoreGraphics.cosh(self) } 340 | @_transparent public func sinh() -> CGFloat { return CoreGraphics.sinh(self) } 341 | @_transparent public func tanh() -> CGFloat { return CoreGraphics.tanh(self) } 342 | @_transparent public func acos() -> CGFloat { return CoreGraphics.acos(self) } 343 | @_transparent public func asin() -> CGFloat { return CoreGraphics.asin(self) } 344 | @_transparent public func atan() -> CGFloat { return CoreGraphics.atan(self) } 345 | 346 | public func reciprocal() -> CGFloat { 347 | return 1 / self 348 | } 349 | 350 | public static func random(_ max: CGFloat) -> CGFloat { 351 | return random(0, max) 352 | } 353 | public static func random(_ min: CGFloat, _ max: CGFloat) -> CGFloat { 354 | let diff = max - min 355 | let rand = CGFloat(arc4random() % (UInt32(RAND_MAX) + 1)) 356 | return ((rand / CGFloat(RAND_MAX)) * diff) + min 357 | } 358 | public static func random(_ range: ClosedRange) -> CGFloat { 359 | return random(range.lowerBound, range.upperBound) 360 | } 361 | 362 | public func clamp(_ max: CGFloat) -> CGFloat { 363 | return clamp(CGFloat(0.0), max) 364 | } 365 | public func clamp(_ min: CGFloat, _ max: CGFloat) -> CGFloat { 366 | return Swift.max(min, Swift.min(max, self)) 367 | } 368 | public func clamp(_ range: ClosedRange) -> CGFloat { 369 | return Swift.max(range.lowerBound, Swift.min(range.upperBound, self)) 370 | } 371 | } 372 | #endif 373 | 374 | public extension Sequence where Self.Iterator.Element: Arithmos { 375 | 376 | func abs() -> [Self.Iterator.Element] { return self.map {$0.abs()} } 377 | func floor() -> [Self.Iterator.Element] { return self.map {$0.floor()} } 378 | func ceil() -> [Self.Iterator.Element] { return self.map {$0.ceil()} } 379 | func round() -> [Self.Iterator.Element] { return self.map {$0.round()} } 380 | func fract() -> [Self.Iterator.Element] { return self.map {$0.fract()} } 381 | 382 | func sqrt() -> [Self.Iterator.Element] { return self.map {$0.sqrt()} } 383 | func pow(_ value: Self.Iterator.Element) -> [Self.Iterator.Element] { return self.map {$0.pow(value)} } 384 | 385 | func exp() -> [Self.Iterator.Element] { return self.map {$0.exp()} } 386 | func log() -> [Self.Iterator.Element] { return self.map {$0.log()} } 387 | 388 | func cos() -> [Self.Iterator.Element] { return self.map {$0.cos()} } 389 | func sin() -> [Self.Iterator.Element] { return self.map {$0.sin()} } 390 | func hypot(_ value: Self.Iterator.Element) -> [Self.Iterator.Element] { return self.map {$0.hypot(value)} } 391 | func atan2(_ value: Self.Iterator.Element) -> [Self.Iterator.Element] { return self.map {$0.atan2(value)} } 392 | 393 | func clamp(_ min: Self.Iterator.Element, _ max: Self.Iterator.Element) -> [Self.Iterator.Element] { return self.map {$0.clamp(min, max)} } 394 | func clamp(_ range: ClosedRange) -> [Self.Iterator.Element] { return self.map {$0.clamp(range)} } 395 | } 396 | 397 | // Operator 398 | precedencegroup ExponentiationPrecedence { 399 | associativity: right 400 | higherThan: MultiplicationPrecedence 401 | } 402 | infix operator ** : ExponentiationPrecedence 403 | infix operator **= : AssignmentPrecedence 404 | 405 | extension Arithmos { 406 | /// pozwer operator 407 | @_transparent public static func ** (lhs: Self, rhs: Self) -> Self { 408 | return lhs.pow(rhs) 409 | } 410 | 411 | @_transparent public static func **= (lhs: inout Self, rhs: Self) { 412 | lhs = lhs ** rhs 413 | } 414 | } 415 | -------------------------------------------------------------------------------- /Sources/Arithmosophi.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Arithmosophi.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | #if os(Linux) 29 | import Glibc 30 | #else 31 | import Darwin 32 | import CoreGraphics 33 | #if os(watchOS) 34 | import UIKit 35 | #endif 36 | #endif 37 | 38 | // MARK: Protocols 39 | 40 | public protocol Addable { 41 | static func + (lhs: Self, rhs: Self) -> Self 42 | static func += (lhs: inout Self, rhs: Self) 43 | } 44 | public func += (lhs: inout T, rhs: T) { 45 | //swiftlint:disable:next shorthand_operator 46 | lhs = lhs + rhs 47 | } 48 | public protocol Substractable { 49 | static func - (lhs: Self, rhs: Self) -> Self 50 | static func -= (lhs: inout Self, rhs: Self) 51 | } 52 | public func -= (lhs: inout T, rhs: T) { 53 | //swiftlint:disable:next shorthand_operator 54 | lhs = lhs - rhs 55 | } 56 | public protocol Negatable { 57 | static prefix func - (instance: Self) -> Self 58 | } 59 | public protocol Multiplicable { 60 | static func * (lhs: Self, rhs: Self) -> Self 61 | } 62 | public protocol Dividable { 63 | static func / (lhs: Self, rhs: Self) -> Self 64 | } 65 | public protocol Modulable { 66 | static func % (lhs: Self, rhs: Self) -> Self 67 | } 68 | public protocol AddableWithOverflow { 69 | static func &+ (lhs: Self, rhs: Self) -> Self 70 | } 71 | public protocol SubstractableWithOverflow { 72 | static func &- (lhs: Self, rhs: Self) -> Self 73 | } 74 | public protocol MultiplicableWithOverflow { 75 | static func &* (lhs: Self, rhs: Self) -> Self 76 | } 77 | public protocol Shiftable { 78 | static func >> (lhs: Self, rhs: RHS) -> Self where RHS: BinaryInteger 79 | static func << (lhs: Self, rhs: RHS) -> Self where RHS: BinaryInteger 80 | } 81 | public protocol XorOperable { 82 | static func ^ (lhs: Self, rhs: Self) -> Self 83 | } 84 | public protocol AndOperable { 85 | static func & (lhs: Self, rhs: Self) -> Self 86 | } 87 | public protocol OrOperable { 88 | static func | (lhs: Self, rhs: Self) -> Self 89 | } 90 | public protocol InverseOperable { 91 | prefix static func ~ (x: Self) -> Self 92 | } 93 | 94 | public protocol Initializable { 95 | init() // get a zero 96 | } 97 | 98 | extension Initializable where Self: Equatable { 99 | public var isZero: Bool { 100 | return self == Self() 101 | } 102 | } 103 | 104 | public protocol LatticeType: Comparable { 105 | static var min: Self { get } 106 | static var max: Self { get } 107 | } 108 | 109 | // MARK: combined protocols 110 | 111 | public protocol Additive: Addable, Substractable {} 112 | public protocol Multiplicative: Multiplicable, Dividable/*, Modulable*/ {} 113 | // public protocol IntegerArithmetic: Additive, Multiplicative{} 114 | 115 | public protocol LogicalOperable: XorOperable, AndOperable, InverseOperable, OrOperable {} 116 | 117 | public protocol AdditiveWithOverflow: Additive, AddableWithOverflow, SubstractableWithOverflow {} 118 | public protocol OverflowOperable: MultiplicableWithOverflow, AddableWithOverflow, SubstractableWithOverflow, LogicalOperable, Shiftable {} 119 | 120 | public protocol UnsignedArithmeticType: Initializable, Additive, Multiplicative, LatticeType {} 121 | public protocol ArithmeticType: UnsignedArithmeticType, Negatable {} 122 | 123 | // MARK: Implement protocols 124 | 125 | extension Int: ArithmeticType, OverflowOperable {} 126 | extension Float: ArithmeticType {} 127 | extension Double: ArithmeticType {} 128 | extension UInt8: UnsignedArithmeticType, OverflowOperable {} 129 | extension Int8: ArithmeticType, OverflowOperable {} 130 | extension UInt16: UnsignedArithmeticType, OverflowOperable {} 131 | extension Int16: ArithmeticType, OverflowOperable {} 132 | extension UInt32: UnsignedArithmeticType, OverflowOperable {} 133 | extension Int32: ArithmeticType, OverflowOperable {} 134 | extension UInt64: UnsignedArithmeticType, OverflowOperable {} 135 | extension Int64: ArithmeticType, OverflowOperable {} 136 | extension UInt: UnsignedArithmeticType, OverflowOperable {} 137 | extension CGFloat: ArithmeticType {} 138 | 139 | extension String: Initializable, Addable {} 140 | extension Array: Initializable, Addable {} 141 | extension Bool: Initializable {} 142 | 143 | // Array addable 144 | public func += (left: inout [T], right: [T]) { 145 | // swiftlint:disable:next shorthand_operator 146 | left = left + right 147 | } 148 | 149 | // lattice impl 150 | extension Bool: LatticeType { 151 | public static var min: Bool { 152 | return false 153 | } 154 | 155 | public static var max: Bool { 156 | return true 157 | } 158 | } 159 | public func < (left: Bool, right: Bool) -> Bool { 160 | if left == right { 161 | return false 162 | } 163 | return left 164 | } 165 | 166 | extension Float: LatticeType { 167 | public static var min: Float { 168 | return .leastNormalMagnitude 169 | } 170 | 171 | public static var max: Float { 172 | return .greatestFiniteMagnitude 173 | } 174 | } 175 | 176 | extension Double: LatticeType { 177 | public static var min: Double { 178 | return .leastNormalMagnitude 179 | } 180 | 181 | public static var max: Double { 182 | return .greatestFiniteMagnitude 183 | } 184 | } 185 | 186 | extension CGFloat: LatticeType { 187 | public static var min: CGFloat { 188 | return .leastNormalMagnitude 189 | } 190 | 191 | public static var max: CGFloat { 192 | return .greatestFiniteMagnitude 193 | } 194 | } 195 | 196 | // MARK: utility functions 197 | public func sumOf (_ seq: S, initialValue: S.Iterator.Element) -> S.Iterator.Element where S.Iterator.Element: Addable { 198 | return seq.reduce(initialValue) { $0 + $1 } 199 | } 200 | private func sumOf (_ seq: S) -> S.Iterator.Element where S.Iterator.Element: Addable & ExpressibleByIntegerLiteral { 201 | let initialValue: S.Iterator.Element = 0 202 | return sumOf(seq, initialValue: initialValue) 203 | } 204 | public func sumOf (_ seq: S) -> S.Iterator.Element where S.Iterator.Element: Addable & Initializable { 205 | let initialValue: S.Iterator.Element = S.Iterator.Element() 206 | return sumOf(seq, initialValue: initialValue) 207 | } 208 | public func sumOf (_ seq: T...) -> T where T: Addable & Initializable { 209 | return sumOf(seq) 210 | } 211 | 212 | private func productOf (_ seq: S) -> S.Iterator.Element where S.Iterator.Element: Multiplicable & ExpressibleByIntegerLiteral { 213 | let initialValue: S.Iterator.Element = 1 214 | return productOf(seq, initialValue: initialValue) 215 | } 216 | 217 | public func productOf (_ seq: S, initialValue: S.Iterator.Element) -> S.Iterator.Element where S.Iterator.Element: Multiplicable { 218 | return seq.reduce(initialValue) { $0 * $1 } 219 | } 220 | 221 | extension UnsignedArithmeticType where Self: OverflowOperable, Self: ExpressibleByIntegerLiteral { 222 | public func gcd(with value: Self) -> Self { 223 | let zero = Self() 224 | if self == zero { return value } 225 | if value == zero { return self } 226 | 227 | let one: Self = 1 228 | var a = self 229 | var b = value 230 | var shift = 0 231 | while ((a | b) & one) == zero { 232 | a = a >> 1 233 | b = b >> 1 234 | // swiftlint:disable:next shorthand_operator 235 | shift = shift + 1 236 | } 237 | while (a & one) == zero { 238 | a = a >> 1 239 | } 240 | repeat { 241 | while (b & one) == zero { 242 | b = b >> 1 243 | } 244 | if a > b { 245 | swap(&a, &b) 246 | } 247 | // swiftlint:disable:next shorthand_operator 248 | b = b - a 249 | } while b != zero 250 | return a << shift 251 | } 252 | 253 | /// Last common multiple 254 | @_transparent public func lcm(with b: Self) -> Self { 255 | let zero = Self() 256 | let a = self 257 | if a == zero || b == zero { return zero } 258 | 259 | return a / a.gcd(with: b) * b 260 | } 261 | } 262 | 263 | // MARK: CollectionType 264 | private extension Sequence where Self.Iterator.Element: Addable & ExpressibleByIntegerLiteral { // If public ambigous for ExpressibleByIntegerLiteral type 265 | 266 | private var sum: Self.Iterator.Element { 267 | let initialValue: Self.Iterator.Element = 0 268 | return self.reduce(initialValue, +) 269 | } 270 | 271 | } 272 | extension Sequence where Self.Iterator.Element: Addable & Initializable { 273 | 274 | public var sum: Self.Iterator.Element { 275 | return self.reduce(Self.Iterator.Element(), +) 276 | } 277 | 278 | } 279 | public extension Sequence where Self.Iterator.Element: Multiplicable & ExpressibleByIntegerLiteral { 280 | 281 | var product: Self.Iterator.Element { 282 | let initialValue: Self.Iterator.Element = 1 283 | return self.reduce(initialValue, *) 284 | } 285 | 286 | } 287 | 288 | extension Sequence where Self.Iterator.Element: UnsignedArithmeticType & OverflowOperable & ExpressibleByIntegerLiteral { 289 | 290 | public var gcd: Self.Iterator.Element { 291 | return self.reduce(Self.Iterator.Element()) { (result, value) -> Self.Iterator.Element in 292 | return result.gcd(with: value) 293 | } 294 | } 295 | 296 | } 297 | 298 | extension Sequence where Self.Iterator.Element: Addable & Multiplicable & Initializable & Comparable { 299 | 300 | // https://en.wikipedia.org/wiki/Riemann_sum 301 | public func riemannSum(range: Range, interval: Self.Iterator.Element, function: (Self.Iterator.Element) -> Self.Iterator.Element) -> Self.Iterator.Element { 302 | var sum: Self.Iterator.Element = Self.Iterator.Element() 303 | var lower = range.lowerBound 304 | let upper = range.upperBound 305 | while lower <= upper { 306 | let value = function(lower) 307 | sum += value * interval 308 | lower += interval 309 | } 310 | return sum 311 | } 312 | 313 | } 314 | -------------------------------------------------------------------------------- /Sources/Complex.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Complex.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #if os(Linux) 28 | import Glibc 29 | #else 30 | import Darwin 31 | import CoreGraphics 32 | #if os(watchOS) 33 | import UIKit 34 | #endif 35 | #endif 36 | 37 | public struct Complex { 38 | 39 | public var real: T = T() 40 | public var imaginary: T 41 | 42 | public init() { 43 | let zero = T() 44 | self.init(real: zero, imaginary: zero) 45 | } 46 | public init(real: T, imaginary: T) { 47 | self.real = real 48 | self.imaginary = imaginary 49 | } 50 | 51 | // conjugate 52 | public var conjugate: Complex { 53 | return Complex(real: real, imaginary: -imaginary) 54 | } 55 | 56 | // `self * i` 57 | public var i: Complex { 58 | return Complex(real: -imaginary, imaginary: real) 59 | } 60 | 61 | // norm 62 | public var norm: T { 63 | return real * real + imaginary * imaginary 64 | } 65 | 66 | // a tuble of real and imaginary value 67 | public var tuple: (T, T) { 68 | get { 69 | return (real, imaginary) 70 | } 71 | set(t) { 72 | (real, imaginary) = t 73 | } 74 | } 75 | 76 | public func combine(_ rhs: Complex, combineBehavior: (T, T) -> T) -> Complex { 77 | let realPart = combineBehavior(self.real, rhs.real) 78 | let imaginaryPart = combineBehavior(self.imaginary, rhs.imaginary) 79 | return Complex(real: realPart, imaginary: imaginaryPart) 80 | } 81 | 82 | public var description: String { 83 | let zero = T() 84 | return self.imaginary < zero ? "\(self.real)-\(-self.imaginary)i" : "\(self.real)+\(self.imaginary)i" 85 | } 86 | 87 | public func map(_ function: (T, T) -> (T, T)) -> Complex { 88 | let result = function(self.real, self.imaginary) 89 | return Complex(real: result.0, imaginary: result.1) 90 | } 91 | 92 | public func map(_ function: (T) -> T) -> Complex { 93 | return Complex(real: function(self.real), imaginary: function(self.imaginary)) 94 | } 95 | 96 | } 97 | 98 | extension ArithmeticType { 99 | var complex: Complex { 100 | return Complex(real: self, imaginary: Self()) 101 | } 102 | } 103 | 104 | extension Complex where T: Arithmos { 105 | 106 | public func sqrt() -> Complex { 107 | return map { value in 108 | return value.sqrt() 109 | } 110 | } 111 | } 112 | 113 | extension Complex where T: Arithmos { 114 | public var description: String { 115 | let sig = imaginary.isSignMinus ? "-" : "+" 116 | return "\(self.real) \(sig) \(self.imaginary)i" 117 | } 118 | 119 | public var abs: T { 120 | get { 121 | return real.hypot(imaginary) 122 | } 123 | set(r) { 124 | let f = r / abs 125 | // swiftlint:disable:next shorthand_operator 126 | real = real * f 127 | // swiftlint:disable:next shorthand_operator 128 | imaginary = imaginary * f 129 | } 130 | } 131 | 132 | public var argument: T { 133 | get { 134 | return imaginary.atan2(real) 135 | } 136 | set(t) { 137 | let m = abs 138 | real = m * t.cos() 139 | imaginary = m * t.sin() 140 | } 141 | } 142 | 143 | public var projection: Complex { 144 | if real.isFinite && imaginary.isFinite { 145 | return self 146 | } else { 147 | return Complex( 148 | real: T(1)/T(0), imaginary: imaginary.isSignMinus ? -T(0) : T(0) 149 | ) 150 | } 151 | } 152 | } 153 | 154 | extension Arithmos /*where Self: Equatable*/ { 155 | 156 | public var isSignMinus: Bool { 157 | return self != self.abs() 158 | } 159 | 160 | } 161 | 162 | extension Complex: Additive, Initializable {} 163 | 164 | public extension ArithmeticType { 165 | // self * 1.0i 166 | var i: Complex { 167 | return Complex(real: Self()/*zero*/, imaginary: self) 168 | } 169 | } 170 | 171 | // MARK: Addable 172 | extension Complex: Addable {} 173 | public func + (lhs: Complex, rhs: T) -> Complex { 174 | return lhs + Complex(real: rhs, imaginary: T()) 175 | } 176 | public func + (lhs: T, rhs: Complex) -> Complex { 177 | return Complex(real: lhs, imaginary: T()) + rhs 178 | } 179 | 180 | public func + (lhs: Complex, rhs: Complex) -> Complex { 181 | return lhs.combine(rhs, combineBehavior: +) 182 | } 183 | // MARK: Substractable 184 | extension Complex: Substractable {} 185 | public func - (lhs: Complex, rhs: T) -> Complex { 186 | return lhs - Complex(real: rhs, imaginary: T()) 187 | } 188 | public func - (lhs: T, rhs: Complex) -> Complex { 189 | return Complex(real: lhs, imaginary: T()) - rhs 190 | } 191 | public func - (lhs: Complex, rhs: Complex) -> Complex { 192 | return lhs.combine(rhs, combineBehavior: -) 193 | } 194 | 195 | // MARK: Multiplicable 196 | extension Complex: Multiplicable {} 197 | public func * (lhs: Complex, rhs: T) -> Complex { 198 | return lhs * Complex(real: rhs, imaginary: T()) 199 | } 200 | public func * (lhs: T, rhs: Complex) -> Complex { 201 | return Complex(real: lhs, imaginary: T()) * rhs 202 | } 203 | public func * (lhs: Complex, rhs: Complex) -> Complex { 204 | let productOfReals = lhs.real * rhs.real 205 | let productOfImaginaries = rhs.imaginary * lhs.imaginary 206 | let realPart = productOfReals - productOfImaginaries 207 | let imaginaryPart = ((lhs.real + lhs.imaginary) * (rhs.real + rhs.imaginary)) - productOfReals - productOfImaginaries 208 | return Complex(real: realPart, imaginary: imaginaryPart) 209 | } 210 | 211 | // MARK: Dividable 212 | extension Complex: Dividable {} 213 | public func / (lhs: Complex, rhs: T) -> Complex { 214 | return lhs / Complex(real: rhs, imaginary: T()) 215 | } 216 | public func / (lhs: T, rhs: Complex) -> Complex { 217 | return Complex(real: lhs, imaginary: T()) / rhs 218 | } 219 | public func / (lhs: Complex, rhs: Complex) -> Complex { 220 | let denominator = rhs.real * rhs.real + rhs.imaginary * rhs.imaginary 221 | let realPart = (lhs.real * rhs.real + lhs.imaginary * rhs.imaginary) / denominator 222 | let imaginaryPart = (lhs.imaginary * rhs.real - lhs.real * rhs.imaginary) / denominator 223 | return Complex(real: realPart, imaginary: imaginaryPart) 224 | } 225 | 226 | // MARK: Negatable 227 | extension Complex: Negatable {} 228 | public prefix func - (instance: Complex) -> Complex { 229 | return Complex(real: -instance.real, imaginary: -instance.imaginary) 230 | } 231 | 232 | // MARK: Modulable 233 | extension Complex: Modulable {} 234 | public func % (lhs: Complex, rhs: Complex) -> Complex { 235 | return lhs - (lhs / rhs) * rhs 236 | } 237 | 238 | public func % (lhs: Complex, rhs: T) -> Complex { 239 | return lhs - (lhs / rhs) * rhs 240 | } 241 | public func % (lhs: T, rhs: Complex) -> Complex { 242 | return Complex(real: lhs, imaginary: T()) % rhs 243 | } 244 | public func %= (lhs: inout Complex, rhs: Complex) { 245 | lhs = lhs % rhs 246 | } 247 | public func %= (lhs: inout Complex, rhs: T) { 248 | lhs = lhs % rhs 249 | } 250 | 251 | // MARK: Equatable 252 | extension Complex: Equatable {} 253 | public func == (lhs: Complex, rhs: Complex) -> Bool { 254 | return lhs.real == rhs.real && lhs.imaginary == rhs.imaginary 255 | } 256 | 257 | // MARK: Hashable 258 | /*extension Complex: Hashable where T: Hashable { 259 | public var hashValue: Int { 260 | return self.real.hashValue + self.imaginary.hashValue 261 | } 262 | }*/ 263 | 264 | // MARK: CGPoint 265 | public protocol Complexable { 266 | associatedtype AssociatedType: ArithmeticType 267 | var complex: Complex {get} 268 | 269 | init(complex: Complex) 270 | } 271 | #if !os(Linux) 272 | 273 | public typealias ComplexCGFloat = Complex 274 | extension CGPoint: Complexable { 275 | 276 | public var complex: ComplexCGFloat { 277 | return ComplexCGFloat(real: self.x, imaginary: self.y) 278 | } 279 | 280 | public init(complex: ComplexCGFloat) { 281 | self.init(x: complex.real, y: complex.imaginary) 282 | } 283 | } 284 | 285 | #endif 286 | -------------------------------------------------------------------------------- /Sources/LogicalOperationsType.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LogicalOperationsType.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #if os(Linux) 28 | import Glibc 29 | #else 30 | import Darwin 31 | #endif 32 | 33 | // MARK: LogicalOperationsType 34 | public protocol LogicalOperationsType: Conjunctive, Disjunctive { 35 | static prefix func ! (value: Self) -> Self // NOT 36 | } 37 | extension Bool: LogicalOperationsType {} 38 | 39 | // MARK: Conjunctive 40 | public protocol Conjunctive { 41 | static func && (left: Self, right: @autoclosure () throws -> Self) rethrows -> Self // AND 42 | } 43 | infix operator &&= 44 | extension Conjunctive { 45 | public static func &&= (lhs: inout Self, rhs: Self) { 46 | lhs = lhs && rhs 47 | } 48 | } 49 | 50 | // MARK: Disjunctive 51 | public protocol Disjunctive { 52 | static func || (left: Self, right: @autoclosure () throws -> Self) rethrows -> Self // OR 53 | } 54 | infix operator ||= 55 | extension Disjunctive { 56 | public static func ||= (lhs: inout Self, rhs: Self) { 57 | lhs = lhs || rhs 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/MesosOros.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MesosOros.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #if os(Linux) 28 | import Glibc 29 | #else 30 | import Darwin 31 | import CoreGraphics 32 | #if os(watchOS) 33 | import UIKit 34 | #endif 35 | #endif 36 | 37 | public typealias AveragableDivideType = Int 38 | 39 | public protocol Averagable: Addable { 40 | static func / (lhs: Self, rhs: AveragableDivideType) -> Self 41 | } 42 | 43 | // MARK: Implement protocols 44 | extension Int: Averagable {} 45 | extension Float: Averagable {} 46 | public func / (lhs: Float, rhs: AveragableDivideType) -> Float { return lhs / Float(rhs) } 47 | extension Double: Averagable {} 48 | public func / (lhs: Double, rhs: AveragableDivideType) -> Double { return lhs / Double(rhs) } 49 | extension CGFloat: Averagable {} 50 | public func / (lhs: CGFloat, rhs: AveragableDivideType) -> CGFloat { return lhs / CGFloat(rhs) } 51 | extension UInt8: Averagable {} 52 | public func / (lhs: UInt8, rhs: AveragableDivideType) -> UInt8 { return lhs / UInt8(rhs) } 53 | extension Int8: Averagable {} 54 | public func / (lhs: Int8, rhs: AveragableDivideType) -> Int8 { return lhs / Int8(rhs) } 55 | extension UInt16: Averagable {} 56 | public func / (lhs: UInt16, rhs: AveragableDivideType) -> UInt16 { return lhs / UInt16(rhs) } 57 | extension Int16: Averagable {} 58 | public func / (lhs: Int16, rhs: AveragableDivideType) -> Int16 { return lhs / Int16(rhs) } 59 | extension UInt32: Averagable {} 60 | public func / (lhs: UInt32, rhs: AveragableDivideType) -> UInt32 { return lhs / UInt32(rhs) } 61 | extension Int32: Averagable {} 62 | public func / (lhs: Int32, rhs: AveragableDivideType) -> Int32 { return lhs / Int32(rhs) } 63 | extension UInt64: Averagable {} 64 | public func / (lhs: UInt64, rhs: AveragableDivideType) -> UInt64 { return lhs / UInt64(rhs) } 65 | extension Int64: Averagable {} 66 | public func / (lhs: Int64, rhs: AveragableDivideType) -> Int64 { return lhs / Int64(rhs) } 67 | extension UInt: Averagable {} 68 | public func / (lhs: UInt, rhs: AveragableDivideType) -> UInt { return lhs / UInt(rhs) } 69 | 70 | // generic operators on dividable & Int & Double 71 | public protocol ExpressibleByInt { 72 | init(_ v: Int) 73 | } 74 | public func / (lhs: T, rhs: Int) -> T where T: ExpressibleByInt, T: Dividable { 75 | let div: T = T(rhs) 76 | return lhs / div 77 | } 78 | public protocol ExpressibleByDouble { 79 | init(_ v: Double) 80 | } 81 | public func / (lhs: T, rhs: Double) -> T where T: ExpressibleByDouble, T: Dividable { 82 | let div: T = T(rhs) 83 | return lhs / div 84 | } 85 | 86 | // MARK: utility functions 87 | 88 | public func averageOf (_ seq: [T]) -> T { 89 | return sumOf(seq) / seq.count 90 | } 91 | public func averageOf (_ seq: T...) -> T { 92 | return averageOf(seq) 93 | } 94 | 95 | // MARK: average/mean 96 | public extension Collection where Self.Iterator.Element: Averagable & Initializable { 97 | 98 | // The arithmetic mean 99 | var average: Self.Iterator.Element { 100 | if self.count == 0 { 101 | return Self.Iterator.Element() 102 | } 103 | let count = AveragableDivideType(Int64(self.count)) // XXX check swift 4 conversion 104 | return self.sum / count 105 | } 106 | 107 | var arithmeticMean: Self.Iterator.Element { 108 | return average 109 | } 110 | 111 | } 112 | 113 | public extension Collection where Self.Iterator.Element: Addable & Dividable & Comparable & ExpressibleByIntegerLiteral { 114 | 115 | var harmonicMean: Self.Iterator.Element? { 116 | if self.count == 0 { 117 | return 0 118 | } 119 | 120 | let zero: Self.Iterator.Element = 0 121 | var result = zero 122 | var n = zero 123 | for value in self { 124 | if value == zero { 125 | return nil // forbidden 126 | } 127 | let i = 1 / value 128 | result += i 129 | n += 1 130 | } 131 | return n / result 132 | } 133 | 134 | } 135 | 136 | // MARK: median 137 | public extension Collection where Self.Iterator.Element: Averagable & Comparable & Initializable { 138 | 139 | var median: Self.Iterator.Element? { 140 | if self.count == 0 { 141 | return nil 142 | } 143 | let sorted = self.sorted { (l, r) -> Bool in 144 | return l < r 145 | } 146 | 147 | if self.count % 2 == 0 { 148 | let leftIndex = Int(count / 2 - 1) 149 | let leftValue = sorted[leftIndex] 150 | let rightValue = sorted[leftIndex + 1] 151 | return (leftValue + rightValue) / 2 152 | } else { 153 | return sorted[Int(count / 2)] 154 | } 155 | } 156 | 157 | var medianLow: Self.Iterator.Element? { 158 | if self.count == 0 { 159 | return nil 160 | } 161 | let sorted = self.sorted { (l, r) -> Bool in 162 | return l < r 163 | } 164 | 165 | if self.count % 2 == 0 { 166 | return sorted[Int(self.count / 2) - 1] 167 | } else { 168 | return sorted[Int(self.count / 2)] 169 | } 170 | } 171 | 172 | var medianHigh: Self.Iterator.Element? { 173 | if self.count == 0 { 174 | return nil 175 | } 176 | let sorted = self.sorted { (l, r) -> Bool in 177 | return l < r 178 | } 179 | return sorted[Int(self.count / 2)] 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /Sources/Sigma.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Sigma.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | #if os(Linux) 29 | import Glibc 30 | #else 31 | import Darwin 32 | import CoreGraphics 33 | #if os(watchOS) 34 | import UIKit 35 | #endif 36 | #endif 37 | 38 | // MARK: variance 39 | // http://en.wikipedia.org/wiki/Variance 40 | 41 | public enum VarianceMode { 42 | case sample 43 | case population 44 | } 45 | 46 | public extension Collection where Self.Iterator.Element: Averagable & Initializable & Substractable & Multiplicable { 47 | 48 | // Return varianceSample: Σ( (Element - average)^2 ) / (count - 1) 49 | // https://en.wikipedia.org/wiki/Variance#Sample_variance 50 | var varianceSample: Self.Iterator.Element? { 51 | if self.count < 2 { return nil } 52 | 53 | let avgerageValue = average 54 | let n = self.reduce(Self.Iterator.Element()) { total, value in 55 | total + (avgerageValue - value) * (avgerageValue - value) 56 | } 57 | 58 | let count = AveragableDivideType(Int64(self.count)) // XXX check swift 4 conversion... 59 | return n / (count - 1) 60 | } 61 | 62 | // Return variancePopulation: Σ( (Element - average)^2 ) / count 63 | // https://en.wikipedia.org/wiki/Variance#Population_variance 64 | var variancePopulation: Self.Iterator.Element? { 65 | if self.count == 0 { return nil } 66 | 67 | let avgerageValue = average 68 | let numerator = self.reduce(Self.Iterator.Element()) { total, value in 69 | total + (avgerageValue - value) * (avgerageValue - value) 70 | } 71 | 72 | let count = AveragableDivideType(Int64(self.count)) // XXX check swift 4 conversion... 73 | return numerator / count 74 | } 75 | 76 | func variance(mode: VarianceMode) -> Self.Iterator.Element? { 77 | switch mode { 78 | case .sample: return varianceSample 79 | case .population: return variancePopulation 80 | } 81 | } 82 | 83 | } 84 | 85 | public extension Collection where Self.Iterator.Element: Averagable & Initializable & Substractable & Multiplicable & Arithmos { 86 | 87 | var standardDeviationSample: Self.Iterator.Element? { 88 | return varianceSample?.sqrt() ?? nil 89 | } 90 | 91 | var standardDeviationPopulation: Self.Iterator.Element? { 92 | return variancePopulation?.sqrt() ?? nil 93 | } 94 | 95 | func standardDeviation(mode: VarianceMode) -> Self.Iterator.Element? { 96 | switch mode { 97 | case .sample: return standardDeviationSample 98 | case .population: return standardDeviationPopulation 99 | } 100 | } 101 | 102 | var σSample: Self.Iterator.Element? { 103 | return standardDeviationSample 104 | } 105 | 106 | var σPopulation: Self.Iterator.Element? { 107 | return standardDeviationPopulation 108 | } 109 | 110 | } 111 | 112 | // MARK: Moment, kurtosis, skewness 113 | public struct Moment { 114 | 115 | public private(set) var M0: T = 0 116 | public private(set) var M1: T = 0 117 | public private(set) var M2: T = 0 118 | public private(set) var M3: T = 0 119 | public private(set) var M4: T = 0 120 | 121 | init?(_ col: [T]) { 122 | if col.count == 0 { return nil } 123 | 124 | M0 = T(Double(col.count)) 125 | var n: T = 0 126 | for x in col { 127 | let n1 = n 128 | n += 1 129 | let delta = x - M1 130 | let delta_n = delta / n 131 | let delta_n2 = delta_n * delta_n 132 | let term1 = delta * delta_n * n1 133 | M1 += delta_n 134 | let t4 = 6 * delta_n2 * M2 - 4 * delta_n * M3 135 | let t3 = (n*n - 3*n + 3) 136 | let t5 = term1 * delta_n2 * t3 137 | M4 += t5 + t4 138 | M3 += (term1 * delta_n * (n - 2)) as T - (3 * delta_n * M2) as T 139 | M2 += term1 140 | } 141 | } 142 | 143 | // https://en.wikipedia.org/wiki/Kurtosis#Excess_kurtosis 144 | public var excessKurtosis: T { 145 | return kurtosis - 3 146 | } 147 | 148 | //https://en.wikipedia.org/wiki/Kurtosis 149 | public var kurtosis: T { 150 | return (M0 * M4) / (M2 * M2) 151 | } 152 | 153 | // https://en.wikipedia.org/wiki/Skewness 154 | public var skewness: T { 155 | let p: T = 3 / 2 156 | return M0.sqrt() * M3 / M2.pow(p) 157 | } 158 | 159 | public var average: T { 160 | return M1 161 | } 162 | 163 | public var varianceSample: T { 164 | return M2 / (M0 - 1) 165 | } 166 | 167 | public var variancePopulation: T { 168 | return M2 / M0 169 | } 170 | 171 | public var standardDeviationSample: T { 172 | return varianceSample.sqrt() 173 | } 174 | 175 | public var standardDeviationPopulation: T { 176 | return variancePopulation.sqrt() 177 | } 178 | } 179 | 180 | public extension Collection where Self.Iterator.Element: Averagable & ExpressibleByIntegerLiteral & Substractable & Multiplicable & Arithmos & Equatable & Dividable { 181 | 182 | //https://en.wikipedia.org/wiki/Kurtosis 183 | var kurtosis: Self.Iterator.Element? { 184 | return moment?.kurtosis 185 | } 186 | 187 | // https://en.wikipedia.org/wiki/Skewness 188 | var skewness: Self.Iterator.Element? { 189 | return moment?.skewness 190 | } 191 | 192 | // https://en.wikipedia.org/wiki/Moment_(mathematics) 193 | var moment: Moment? { 194 | return Moment(Array(self)) 195 | } 196 | 197 | } 198 | 199 | // MARK: covariance 200 | public extension Collection where Self.Iterator.Element: Averagable & Initializable & Substractable & Multiplicable & Arithmos { 201 | 202 | func covariance 203 | (_ with: W, type: VarianceMode) -> Self.Iterator.Element? where W.Iterator.Element == Self.Iterator.Element { 204 | switch type { 205 | case .sample: 206 | return covarianceSample(with) 207 | case .population: 208 | return covariancePopulation(with) 209 | } 210 | } 211 | 212 | func covarianceSample 213 | (_ with: W) -> Self.Iterator.Element? where W.Iterator.Element == Self.Iterator.Element { 214 | if self.count < 2 { return nil } 215 | guard self.count == with.count else { 216 | return nil 217 | } 218 | 219 | let average = self.average 220 | let withAverage = with.average 221 | 222 | var sum = Self.Iterator.Element() 223 | for (element, withElement) in zip(self, with) { 224 | sum += (element - average) * (withElement - withAverage) 225 | } 226 | 227 | let count = AveragableDivideType(Int64(self.count)) // XXX check swift 4 conversion... 228 | return sum / (count - 1) 229 | } 230 | 231 | func covariancePopulation 232 | (_ with: W) -> Self.Iterator.Element? where W.Iterator.Element == Self.Iterator.Element { 233 | if self.count < 2 { return nil } 234 | guard self.count == with.count else { 235 | return nil 236 | } 237 | 238 | let average = self.average 239 | let withAverage = with.average 240 | 241 | var sum = Self.Iterator.Element() 242 | for (element, withElement) in zip(self, with) { 243 | sum += (element - average) * (withElement - withAverage) 244 | } 245 | 246 | let count = AveragableDivideType(Int64(self.count)) // XXX check swift 4 conversion... 247 | return sum / count 248 | } 249 | 250 | func covariance 251 | (_ with: W, mode: VarianceMode) -> Self.Iterator.Element? where W.Iterator.Element == Self.Iterator.Element { 252 | switch mode { 253 | case .sample: return covarianceSample(with) 254 | case .population: return covariancePopulation(with) 255 | } 256 | } 257 | 258 | } 259 | 260 | // MARK: Pearson product-moment correlation coefficient 261 | public extension Collection where Self.Iterator.Element: Averagable & Initializable & Substractable & Multiplicable & Arithmos & Equatable & Dividable { 262 | 263 | // http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient 264 | func pearson 265 | (_ with: W) -> Self.Iterator.Element? where W.Iterator.Element == Self.Iterator.Element { 266 | if let cov = self.covariancePopulation(with), 267 | let σself = self.standardDeviationPopulation, 268 | let σwith = with.standardDeviationPopulation { 269 | 270 | let zero = Self.Iterator.Element() 271 | if σself == zero || σwith == zero { 272 | return nil 273 | } 274 | return cov / (σself * σwith) 275 | } 276 | return nil 277 | } 278 | } 279 | 280 | // MARK: percentile 281 | // https://en.wikipedia.org/wiki/Percentile 282 | // NOT IMPLEMENTED YET 283 | 284 | // MARK: linear regression 285 | // https://en.wikipedia.org/wiki/Linear_regression 286 | 287 | public enum LinearRegressionMethod { 288 | case ols 289 | case multiply 290 | // case Accelerate (use upsurge?) 291 | } 292 | 293 | // Use with Double and fFloat (not Int) 294 | public extension Collection where Self.Iterator.Element: Averagable & Initializable & Substractable & Multiplicable & Dividable { 295 | 296 | // @return (intercept, slope) where with = slope * self + intercept 297 | func linearRegression 298 | (_ with: W, method: LinearRegressionMethod = .ols) -> (Self.Iterator.Element, Self.Iterator.Element)? where W.Iterator.Element == Self.Iterator.Element { 299 | 300 | guard self.count > 1 else { 301 | return nil 302 | } 303 | 304 | guard self.count == with.count else { 305 | return nil 306 | } 307 | 308 | let average = self.average 309 | let withAverage = with.average 310 | 311 | var sum1 = Self.Iterator.Element() 312 | var sum2 = Self.Iterator.Element() 313 | switch method { 314 | case .multiply: 315 | let m1 = multiply(with).average 316 | sum1 = m1 - average * withAverage 317 | let m2 = multiply(self).average 318 | sum2 = m2 - average * average 319 | case .ols: 320 | for (element, withElement) in zip(self, with) { 321 | let elMinusAverage = (element - average) 322 | sum1 += elMinusAverage * (withElement - withAverage) 323 | sum2 += elMinusAverage * elMinusAverage 324 | } 325 | } 326 | 327 | let slope = sum1 / sum2 // ISSUE Int will failed here by dividing by zero (Int linear regression must return float result) 328 | let intercept = withAverage - slope * average 329 | return (intercept, slope) 330 | } 331 | 332 | func linearRegressionClosure 333 | (_ with: W, method: LinearRegressionMethod = .ols) -> ((Self.Iterator.Element) -> Self.Iterator.Element)? where W.Iterator.Element == Self.Iterator.Element { 334 | guard let (intercept, slope) = self.linearRegression(with) else { 335 | return nil 336 | } 337 | // y = slope * x + intercept 338 | return { intercept + slope * $0 } 339 | } 340 | 341 | // Create a closure : slope * x + intercept with x closure parameters 342 | static func linearRegressionClosure(_ intercept: Self.Iterator.Element, slope: Self.Iterator.Element) -> ((Self.Iterator.Element) -> Self.Iterator.Element) { 343 | return { intercept + slope * $0 } 344 | } 345 | 346 | // https://en.wikipedia.org/wiki/Coefficient_of_determination 347 | func coefficientOfDetermination 348 | (_ with: W, linearRegressionClosure: ((Self.Iterator.Element) -> Self.Iterator.Element)) -> Self.Iterator.Element where W.Iterator.Element == Self.Iterator.Element { 349 | 350 | let withAverage = with.average 351 | var sumSquareModel = Self.Iterator.Element() // sum of squares of the deviations of the estimated values of the response variable of the model 352 | var sumSquareTotal = Self.Iterator.Element() // sum of squares of the deviations of the observed 353 | 354 | for (element, withElement) in zip(self, with) { 355 | let predictedValue = linearRegressionClosure(element) 356 | let sub1 = predictedValue - withAverage 357 | sumSquareModel += sub1 * sub1 358 | let sub2 = withElement - withAverage 359 | sumSquareTotal += sub2 * sub2 360 | } 361 | return sumSquareModel / sumSquareTotal 362 | } 363 | 364 | func coefficientOfDetermination 365 | (_ with: W, intercept: Self.Iterator.Element, slope: Self.Iterator.Element) -> Self.Iterator.Element where W.Iterator.Element == Self.Iterator.Element { 366 | return self.coefficientOfDetermination(with, linearRegressionClosure: Self.linearRegressionClosure(intercept, slope: slope)) 367 | } 368 | 369 | } 370 | 371 | // MARK: geometric mean 372 | public extension Sequence where Self.Element: Addable & Arithmos & Dividable & Multiplicable & ExpressibleByIntegerLiteral { 373 | 374 | var geometricMean: Self.Element? { 375 | let zero: Self.Element = 0 376 | var result = zero 377 | var n = zero 378 | for value in self { 379 | // swiftlint:disable:next shorthand_operator 380 | result = result * value 381 | n += 1 382 | } 383 | if n == 0 { 384 | return 0 385 | } 386 | return result.pow(1 / n) 387 | } 388 | 389 | } 390 | 391 | public extension Collection where Self.Element: Hashable { 392 | 393 | typealias HashableElement = Self.Element 394 | 395 | // Most frequent value in data set 396 | // https://en.wikipedia.org/wiki/Mode_(statistics) 397 | var mode: [Self.Element] { 398 | var counter = [HashableElement: Int]() 399 | var mode = [HashableElement]() 400 | var max = 0 401 | for value in self { 402 | if let c = counter[value] { 403 | counter[value] = c + 1 404 | } else { 405 | counter[value] = 0 406 | } 407 | 408 | let c = counter[value]! 409 | if c == max { 410 | mode.append(value) 411 | } else if c > max { 412 | max = c 413 | mode = [value] 414 | } 415 | } 416 | return mode 417 | } 418 | 419 | } 420 | 421 | // MARK: - collection operations 422 | 423 | // MARK: multiply 424 | private extension Sequence where Self.Element: Multiplicable { 425 | 426 | func multiply 427 | (_ with: W) -> [Self.Element] where W.Element == Self.Element { 428 | return zip(self, with).map { s, w in 429 | return s * w 430 | } 431 | } 432 | 433 | } 434 | 435 | // MARK: add 436 | private extension Sequence where Self.Element: Addable { 437 | 438 | func add 439 | (_ array: W) -> [Self.Iterator.Element] where W.Element == Self.Element { 440 | return zip(self, array).map { s, w in 441 | return s + w 442 | } 443 | } 444 | 445 | } 446 | 447 | // MARK: subtract 448 | private extension Sequence where Self.Element: Substractable { 449 | 450 | func subtract 451 | (_ array: W) -> [Self.Iterator.Element] where W.Element == Self.Element { 452 | return zip(self, array).map { s, w in 453 | return s - w 454 | } 455 | } 456 | 457 | } 458 | 459 | // MARK: divide 460 | private extension Sequence where Self.Element: Dividable { 461 | 462 | func divide 463 | (_ with: W) -> [Self.Iterator.Element] where W.Element == Self.Element { 464 | return zip(self, with).map { s, w in 465 | return s / w // NO ZERO valu 466 | } 467 | } 468 | 469 | } 470 | -------------------------------------------------------------------------------- /Sources/Statheros.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Statheros.swift 3 | // Arithmosophi 4 | /* 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 Eric Marchand (phimage) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | 28 | #if os(Linux) 29 | import Glibc 30 | #else 31 | import Darwin 32 | import CoreGraphics 33 | #if os(watchOS) 34 | import UIKit 35 | #endif 36 | #endif 37 | 38 | public protocol Statheros { 39 | static var π: Self {get} 40 | static var pi: Self {get} 41 | static var π_2: Self {get} 42 | static var pi_2: Self {get} 43 | static var π_4: Self {get} 44 | static var pi_4: Self {get} 45 | static var π2: Self {get} 46 | static var pi2: Self {get} 47 | static var _1_π: Self {get} 48 | static var _1_pi: Self {get} 49 | static var _2_π: Self {get} 50 | static var _2_pi: Self {get} 51 | 52 | static var SQRT2: Self {get} 53 | 54 | static var e: Self {get} 55 | static var LOG2E: Self {get} 56 | static var LOG10E: Self {get} 57 | static var LN2: Self {get} 58 | static var LN10: Self {get} 59 | 60 | static var φ: Self {get} 61 | static var phi: Self {get} 62 | } 63 | 64 | extension Double: Statheros { 65 | public static var π = Double.pi 66 | public static var π_2 = Double.pi / 2 67 | public static var pi_2 = Double.pi / 2 68 | public static var π_4 = Double.pi / 4 69 | public static var pi_4 = Double.pi / 4 70 | public static var π2 = 2 * Double.pi 71 | public static var pi2 = 2 * Double.pi 72 | public static var _1_π = M_1_PI 73 | public static var _1_pi = M_1_PI 74 | public static var _2_π = M_2_PI 75 | public static var _2_pi = M_2_PI 76 | 77 | public static var SQRT2: Double = 2.squareRoot() 78 | 79 | public static var e = M_E 80 | public static var LOG2E = M_LOG2E 81 | public static var LOG10E = M_LOG10E 82 | public static var LN2 = M_LN2 83 | public static var LN10 = M_LN10 84 | 85 | public static var φ = (1.0 + Darwin.sqrt(5.0)) / 2.0 // 1.618033988749895 86 | public static var phi = Double.φ 87 | } 88 | 89 | extension Float: Statheros { 90 | public static var π = Float.pi 91 | public static var π_2 = Float(Double.pi / 2) 92 | public static var pi_2 = Float(Double.pi / 2) 93 | public static var π_4 = Float(Double.pi / 4) 94 | public static var pi_4 = Float(Double.pi / 4) 95 | public static var π2 = Float(2 * Double.pi) 96 | public static var pi2 = Float(2 * Double.pi) 97 | public static var _1_π = Float(M_1_PI) 98 | public static var _1_pi = Float(M_1_PI) 99 | public static var _2_π = Float(M_2_PI) 100 | public static var _2_pi = Float(M_2_PI) 101 | 102 | public static var SQRT2 = Float(2.squareRoot()) 103 | 104 | public static var e = Float(M_E) 105 | public static var LOG2E = Float(M_LOG2E) 106 | public static var LOG10E = Float(M_LOG10E) 107 | public static var LN2 = Float(M_LN2) 108 | public static var LN10 = Float(M_LN10) 109 | 110 | public static var φ = Float((1.0 + Darwin.sqrt(5.0)) / 2.0) 111 | public static var phi = Float.φ 112 | } 113 | 114 | #if !os(Linux) 115 | extension CGFloat: Statheros { 116 | public static var π = CGFloat.pi 117 | public static var π_2 = CGFloat(Double.pi / 2) 118 | public static var pi_2 = CGFloat(Double.pi / 2) 119 | public static var π_4 = CGFloat(Double.pi / 4) 120 | public static var pi_4 = CGFloat(Double.pi / 4) 121 | public static var π2 = CGFloat(2 * Double.pi) 122 | public static var pi2 = CGFloat(2 * Double.pi) 123 | public static var _1_π = CGFloat(M_1_PI) 124 | public static var _1_pi = CGFloat(M_1_PI) 125 | public static var _2_π = CGFloat(M_2_PI) 126 | public static var _2_pi = CGFloat(M_2_PI) 127 | 128 | public static var SQRT2 = CGFloat(2.squareRoot()) 129 | 130 | public static var e = CGFloat(M_E) 131 | public static var LOG2E = CGFloat(M_LOG2E) 132 | public static var LOG10E = CGFloat(M_LOG10E) 133 | public static var LN2 = CGFloat(M_LN2) 134 | public static var LN10 = CGFloat(M_LN10) 135 | 136 | public static var φ = CGFloat((1.0 + CoreGraphics.sqrt(5.0)) / 2.0) 137 | public static var phi = CGFloat.φ 138 | } 139 | #endif 140 | -------------------------------------------------------------------------------- /Tests/ArithmosophiOSXTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ArithmosophiOSXTests.swift 3 | // ArithmosophiOSXTests 4 | // 5 | // Created by phimage on 16/06/15. 6 | // Copyright (c) 2015 phimage. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | import Arithmosophi 11 | 12 | class ArithmosophiOSXTests: XCTestCase { 13 | 14 | let aInt = [1, 2, 3, 4] 15 | let aString = ["a", "b", "c", "d"] 16 | let aArray = [["a", "b"], ["c"], ["d"]] 17 | 18 | override func setUp() { 19 | super.setUp() 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | override func tearDown() { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | super.tearDown() 26 | } 27 | 28 | func testSumInt() { 29 | let value = aInt.sum 30 | let expected = 1 + 2 + 3 + 4 31 | XCTAssertEqual(value, expected) 32 | } 33 | func testProductInt() { 34 | let value = aInt.product 35 | let expected = 1 * 2 * 3 * 4 36 | XCTAssertEqual(value, expected) 37 | } 38 | func testSumString() { 39 | let value = aString.sum 40 | let expected = aString.joined(separator: "") 41 | XCTAssertEqual(value, expected) 42 | } 43 | func testSumArray() { 44 | let value = aArray.sum 45 | let expected = aArray.flatMap {$0} 46 | XCTAssertEqual(value, expected) 47 | } 48 | 49 | // MARK: - Complex 50 | 51 | func testComplex() { 52 | 53 | let c = Complex(real: 2, imaginary: 3) 54 | let c2 = Complex(real: 4, imaginary: 2) 55 | 56 | let c3 = c + c2 57 | XCTAssertEqual(c3.real, c.real + c2.real) 58 | XCTAssertEqual(c3.imaginary, c.imaginary + c2.imaginary) 59 | 60 | let c3p = c - c2 61 | XCTAssertEqual(c3p.real, c.real - c2.real) 62 | XCTAssertEqual(c3p.imaginary, c.imaginary - c2.imaginary) 63 | 64 | let r4 = 1 65 | let i4 = 3 66 | let c4: Complex = r4 + i4.i 67 | XCTAssertEqual(c4.real, r4) 68 | XCTAssertEqual(c4.imaginary, i4) 69 | 70 | let c5 = c4 * 1.i 71 | XCTAssertEqual(c5.real, -i4) 72 | XCTAssertEqual(c5.imaginary, r4) 73 | 74 | let c6 = c5 * 1.i 75 | XCTAssertEqual(c4, -c6) 76 | 77 | var c7 = c6 78 | c7 += c6 79 | XCTAssertEqual(c7, c6 + c6) 80 | 81 | let sqrt = Complex(real: 4, imaginary: 9).sqrt() 82 | XCTAssertEqual(sqrt, Complex(real: 2, imaginary: 3)) 83 | } 84 | 85 | // MARK: - Average 86 | 87 | func testAverage() { 88 | let result = [1, 12, 19.5, -5, 3, 8].average 89 | XCTAssertEqual(6.4166666667, round10(result)) 90 | } 91 | 92 | func testAverage_whenEmpty() { 93 | let result = [Double]().average 94 | XCTAssert(result == 0) 95 | } 96 | 97 | func testAverageInt() { 98 | var result = [1, 2, 3, 4].average 99 | XCTAssertEqual(2, result) 100 | 101 | result = [0, 1, 2, 3, 4].average 102 | XCTAssertEqual(2, result) 103 | 104 | result = [1, 2, 3, 4, 5].average 105 | XCTAssertEqual(3, result) 106 | } 107 | 108 | // MARK: - Median 109 | 110 | func testGcd() { 111 | XCTAssertEqual(3.gcd(with: 0), 3) 112 | XCTAssertEqual(0.gcd(with: 3), 3) 113 | 114 | XCTAssertEqual(3.gcd(with: 4), 1) 115 | XCTAssertEqual(3.gcd(with: 1), 1) 116 | XCTAssertEqual(34.gcd(with: 1), 1) 117 | XCTAssertEqual(4.gcd(with: 2), 2) 118 | XCTAssertEqual(2.gcd(with: 4), 2) 119 | XCTAssertEqual(4.gcd(with: 4), 4) 120 | XCTAssertEqual(3.gcd(with: 3), 3) 121 | XCTAssertEqual(1024.gcd(with: 4), 4) 122 | 123 | XCTAssertEqual([0, 5, 4].gcd, 1) 124 | XCTAssertEqual([0, 5].gcd, 5) 125 | XCTAssertEqual([2, 4, 8, 16, 32, 64, 128].gcd, 2) 126 | XCTAssertEqual([4, 8, 16, 32, 64, 128].gcd, 4) 127 | } 128 | 129 | // MARK: - Median 130 | 131 | func testMedian_oddNumberOfItems() { 132 | if let result = [1.0, 12.0, 19.5, 3.0, -5.0].median { 133 | XCTAssertEqual(3, result) 134 | } else { 135 | XCTFail("no result") 136 | } 137 | } 138 | 139 | func testMedian_evenNumberOfItems() { 140 | if let result = [1, 12, 19.5, 3, -5, 8].median { 141 | XCTAssertEqual(5.5, result) 142 | } else { 143 | XCTFail("no result") 144 | } 145 | } 146 | 147 | func testMedian_oneItem() { 148 | if let result = [8].median { 149 | XCTAssertEqual(8, result) 150 | } else { 151 | XCTFail("no result") 152 | } 153 | } 154 | 155 | func testMedian_whenEmpty() { 156 | let result = [Double]().median 157 | XCTAssertNil(result) 158 | } 159 | 160 | // MARK: - Median Low 161 | 162 | func testMedianLow_oddNumberOfItems() { 163 | if let result = [1, 12, 19.5, 3, -5].medianLow { 164 | XCTAssertEqual(3, result) 165 | } else { 166 | XCTFail("no result") 167 | } 168 | } 169 | 170 | func testMedianLow_evenNumberOfItems() { 171 | if let result = [1, 12, 19.5, 3, -5, 8].medianLow { 172 | XCTAssertEqual(3, result) 173 | } else { 174 | XCTFail("no result") 175 | } 176 | } 177 | 178 | func testMedianLow_oneItem() { 179 | if let result = [8].medianLow { 180 | XCTAssertEqual(8, result) 181 | } else { 182 | XCTFail("no result") 183 | } 184 | } 185 | 186 | func testMedianLow_whenEmpty() { 187 | let a = [Double]() 188 | let result = a.medianLow 189 | XCTAssertNil(result) 190 | } 191 | 192 | // MARK: - Median High 193 | 194 | func testMedianHigh_oddNumberOfItems() { 195 | if let result = [1, 12, 19.5, 3, -5].medianHigh { 196 | XCTAssertEqual(3, result) 197 | } else { 198 | XCTFail("no result") 199 | } 200 | } 201 | 202 | func testMedianHigh_evenNumberOfItems() { 203 | if let result = [1, 12, 19.5, 3, -5, 8].medianHigh { 204 | XCTAssertEqual(8, result) 205 | } else { 206 | XCTFail("no result") 207 | } 208 | } 209 | 210 | func testMedianHigh_oneItem() { 211 | if let result = [Double(8.0)].medianHigh { 212 | XCTAssertEqual(8.0, Double(result)) 213 | } else { 214 | XCTFail("no result") 215 | } 216 | } 217 | 218 | func testMedianHigh_whenEmpty() { 219 | let a = [Double]() 220 | let result = a.medianHigh 221 | XCTAssertNil(result) 222 | } 223 | 224 | // MARK: - Sample variance 225 | 226 | func testVarianceSample() { 227 | if let result = [1, 12, 19.5, -5, 3, 8].varianceSample { 228 | XCTAssertEqual(75.2416666667, round10(result)) 229 | } else { 230 | XCTFail("no result") 231 | } 232 | } 233 | 234 | func testVarianceSample_whenSame() { 235 | if let result = [3, 3].varianceSample { 236 | XCTAssertEqual(0, result) 237 | } else { 238 | XCTFail("no result") 239 | } 240 | } 241 | 242 | func testVarianceSample_whenOne() { 243 | let result = [1].varianceSample 244 | XCTAssertNil(result) 245 | 246 | } 247 | 248 | func testVariancePopulation() { 249 | if let result = [1, 12, 19.5, -5, 3, 8].variancePopulation { 250 | XCTAssertEqual(62.7013888889, round10(result)) 251 | } else { 252 | XCTFail("no result") 253 | } 254 | 255 | } 256 | 257 | func testVariancePopulation_whenSame() { 258 | if let result = [3, 3].variancePopulation { 259 | XCTAssertEqual(0, result) 260 | } else { 261 | XCTFail("no result") 262 | } 263 | 264 | } 265 | 266 | func testVariancePopulation_whenOne() { 267 | if let result = [1].variancePopulation { 268 | XCTAssertEqual(0, result) 269 | } else { 270 | XCTFail("no result") 271 | } 272 | 273 | } 274 | 275 | func testVariancePopulation_whenEmpty() { 276 | let result = [Double]().variancePopulation 277 | XCTAssertNil(result ) 278 | } 279 | 280 | // MARK: - Sample standard deviation 281 | 282 | func testSampleStandardDeviation() { 283 | if let result = [1, 12, 19.5, -5, 3, 8].standardDeviationSample { 284 | XCTAssertEqual(8.6741954478, round10(result)) 285 | } else { 286 | XCTFail("no result") 287 | } 288 | 289 | } 290 | 291 | func testSampleStandardDeviation_whenSame() { 292 | if let result = [3, 3].standardDeviationSample { 293 | XCTAssertEqual(0, round10(result)) 294 | } else { 295 | XCTFail("no result") 296 | } 297 | 298 | } 299 | 300 | func testSampleStandardDeviation_whenOne() { 301 | let result = [Double(1.0)].standardDeviationSample 302 | XCTAssertNil(result) 303 | } 304 | 305 | func testSampleStandardDeviation_whenEmpty() { 306 | let result = [Double]().standardDeviationSample 307 | XCTAssertNil(result ) 308 | } 309 | 310 | // MARK: - Population standard deviation 311 | 312 | func testPopulationStandardDeviation() { 313 | if let result = [1, 12, 19.5, -5, 3, 8].standardDeviationPopulation { 314 | XCTAssertEqual(7.9184208583, round10(result)) 315 | } else { 316 | XCTFail("no result") 317 | } 318 | 319 | if let result = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0].standardDeviationPopulation { 320 | XCTAssertEqual(2.0, result) 321 | } else { 322 | XCTFail("no result") 323 | } 324 | 325 | } 326 | 327 | func testPopulationStandardDeviation_whenOne() { 328 | if let result = [1].standardDeviationPopulation { 329 | XCTAssertEqual(0, result) 330 | } else { 331 | XCTFail("no result") 332 | } 333 | 334 | } 335 | 336 | func testPopulationStandardDeviation_whenEmpty() { 337 | let result = [Double]().standardDeviationPopulation 338 | XCTAssertNil(result ) 339 | } 340 | 341 | // MARK: - Sample covariance 342 | 343 | func testSampleCovariance() { 344 | if let result = [1, 2, 3.5, 3.7, 8, 12].covarianceSample([0.5, 1, 2.1, 3.4, 3.4, 4]) { 345 | 346 | XCTAssertEqual(5.03, round10(result)) 347 | } else { 348 | XCTFail("no result") 349 | } 350 | 351 | } 352 | 353 | func testSampleCovariance_unequalSamples() { 354 | let result = [1, 2, 3.5, 3.7, 8, 12].covarianceSample([0.5, 4]) 355 | 356 | XCTAssertNil(result ) 357 | } 358 | 359 | func testSampleCovariance_whenGivenSingleSetOfValues() { 360 | let result = [Double(1.2)].covarianceSample([0.5]) 361 | 362 | XCTAssertNil(result ) 363 | } 364 | 365 | func testSampleCovariance_samplesAreEmpty() { 366 | let result = [Double]().covarianceSample([]) 367 | 368 | XCTAssertNil(result ) 369 | } 370 | 371 | // MARK: - Population covariance 372 | 373 | func testPopulationCovariance() { 374 | if let result = [1, 2, 3.5, 3.7, 8, 12].covariancePopulation([0.5, 1, 2.1, 3.4, 3.4, 4]) { 375 | XCTAssertEqual(4.1916666667, round10(result)) 376 | } else { 377 | XCTFail("no result") 378 | } 379 | 380 | } 381 | 382 | func testPopulationCovariance_unequalSamples() { 383 | let result = [1, 2, 3.5, 3.7, 8, 12].covariancePopulation([0.5]) 384 | XCTAssertNil(result ) 385 | } 386 | 387 | func testPopulationCovariance_emptySamples() { 388 | let result = [Double]().covariancePopulation([]) 389 | 390 | XCTAssertNil(result ) 391 | } 392 | 393 | // MARK: - Pearson product-moment correlation coefficient 394 | 395 | func testPearson() { 396 | if let result = [1, 2, 3.5, 3.7, 8, 12].pearson([0.5, 1, 2.1, 3.4, 3.4, 4]) { 397 | 398 | XCTAssertEqual(0.8437608594, round10(result)) 399 | } else { 400 | XCTFail("no result") 401 | } 402 | 403 | } 404 | 405 | func testPearson_unequalSamples() { 406 | let result = [1, 2, 3.5, 3.7, 8, 12].pearson([0.5]) 407 | 408 | XCTAssertNil(result) 409 | } 410 | 411 | func testPearson_emptySamples() { 412 | let result = [Double]().pearson([]) 413 | 414 | XCTAssertNil(result) 415 | } 416 | 417 | // MARK: - Linear regression 418 | 419 | public typealias LinearRegressionTestData = (x: [Double], y: [Double], intercept: Double, slope: Double) 420 | 421 | func testLinearRegression() { 422 | 423 | let tests: [LinearRegressionTestData] = [ 424 | (x: [1.0, 2.0, 3], y: [2.0, 3, 4], intercept: 1.0, slope: 1.0), 425 | (x: [1.0, 2, 3], y: [2.0, 4, 6], intercept: 0.0, slope: 2.0), 426 | (x: [2.0, 4, 6], y: [1.0, 2, 3], intercept: 0.0, slope: 0.5) 427 | ] 428 | 429 | for test in tests { 430 | testLinearRegression( test, method: .ols) 431 | } 432 | 433 | // List of points 434 | let data = [(0.1, 0.2), (338.8, 337.4), (118.1, 118.2), 435 | (888.0, 884.6), (9.2, 10.1), (228.1, 226.5), (668.5, 666.3), (998.5, 996.3), 436 | (449.1, 448.6), (778.9, 777.0), (559.2, 558.2), (0.3, 0.4), (0.1, 0.6), (778.1, 775.5), 437 | (668.8, 666.9), (339.3, 338.0), (448.9, 447.5), (10.8, 11.6), (557.7, 556.0), 438 | (228.3, 228.1), (998.0, 995.8), (888.8, 887.6), (119.6, 120.2), (0.3, 0.3), 439 | (0.6, 0.3), (557.6, 556.8), (339.3, 339.1), (888.0, 887.2), (998.5, 999.0), 440 | (778.9, 779.0), (10.2, 11.1), (117.6, 118.3), (228.9, 229.2), (668.4, 669.1), 441 | (449.2, 448.9), (0.2, 0.5)] 442 | 443 | let x = data.map { $0.0 } 444 | let y = data.map { $0.1 } 445 | 446 | if let (intercept, slope) = y.linearRegression(x, method: .multiply) { 447 | XCTAssertEqual(-0.262/*323073774029*/, round3(intercept)) 448 | XCTAssertEqual(1.0021168180/*204547*/, round10(slope)) 449 | } else { 450 | XCTFail("no result") 451 | } 452 | 453 | } 454 | 455 | func testLinearRegression(_ data: LinearRegressionTestData, method: LinearRegressionMethod) { 456 | if let (intercept, slope) = data.x.linearRegression(data.y, method: method) { 457 | XCTAssertEqual(data.intercept, intercept) 458 | XCTAssertEqual(data.slope, slope) 459 | } else { 460 | XCTFail("no result") 461 | } 462 | } 463 | 464 | func testLinearRegression_same() { 465 | let array = [1, 2, 3, 4, 5] 466 | if let (intercept, slope) = array.linearRegression(array) { 467 | XCTAssertEqual(0, intercept) 468 | XCTAssertEqual(1, slope) 469 | } else { 470 | XCTFail("no result") 471 | } 472 | } 473 | 474 | func testLinearRegression_sameX() { 475 | let x: Double = 12 476 | if let (intercept, slope) = [1, 2, 3.5, 3.7, 8, 12].linearRegression([x, x, x, x, x, x]) { 477 | XCTAssertEqual(x, intercept) 478 | XCTAssertEqual(0, round10(slope)) 479 | } else { 480 | XCTFail("no result") 481 | } 482 | 483 | } 484 | 485 | func testLinearRegression_unequalSamples() { 486 | let result = [1, 2, 3.5, 3.7, 8, 12].linearRegression([0.5]) 487 | 488 | XCTAssertNil(result) 489 | } 490 | 491 | func testLinearRegression_emptySamples() { 492 | let result = [Double]().linearRegression([]) 493 | 494 | XCTAssertNil(result) 495 | } 496 | // from https://www.random.org/gaussian-distributions/ 497 | let normal = [ -5.2915953320, -3.6772947140, 498 | 1.4557255930, -9.6071756130, 499 | -1.1790649220, -7.0769571490, 500 | -8.5630216570, 2.7092033120, 501 | 1.0354204630, -4.7601903490, 502 | -2.4656553830, -8.4457472370, 503 | 1.3116860800, 5.3932010560, 504 | -8.3067210290, -2.9978551230, 505 | -1.5617564410, 2.8172913100, 506 | -7.4367589440, 5.5079234150, 507 | -3.1174784250, 5.0074376570, 508 | 7.6770023300, -6.9221058010, 509 | 8.9388762580, -7.0601278450, 510 | -1.5599111900, -7.4661002020, 511 | 9.0819772330, 1.7047414380, 512 | -8.7470589310, 5.6994461800, 513 | 5.7906965610, -1.2354097290, 514 | -1.1406516450, -7.0258626380, 515 | 5.2256994890, -1.4152811050, 516 | 1.1831176040, 1.8354849160, 517 | -8.1424724470, 2.1366773060, 518 | 8.4985054710, 1.2962314850, 519 | -1.5712894080, -7.0212303740, 520 | -3.2147250270, -4.1866789920, 521 | -4.6732570270, -1.4273105910, 522 | 3.9407343060, 5.5349683550, 523 | 8.7855289880, 1.6035290570, 524 | 1.0786710480, 6.0958136180, 525 | 2.4547870210, 1.5011664410, 526 | -9.8014391980, -5.3496840540, 527 | 5.4229997770, 2.1089126870, 528 | -5.5912587730, 6.5240664240, 529 | -6.7618207180, -1.6253052660, 530 | -6.4307974200, -1.3235495380, 531 | 2.9666389180, 6.3338374900, 532 | -1.3078702770, -2.5370415940, 533 | 1.4439756110, -7.0100303580, 534 | 1.1005042140, 1.1959076320, 535 | 9.4533489840, 1.1038169390, 536 | 5.6982039450, -2.4824358710, 537 | -8.1115556390, 4.7546579320, 538 | -2.8402880120, 2.3448283340, 539 | 7.0971058070, -4.7399041990, 540 | -6.7958303030, 1.2216677600, 541 | -1.1084760130, 1.1861440530, 542 | 6.5609134430, 1.8454490790, 543 | 1.0109369680, 5.1013568660, 544 | -9.1403339340, -1.0025365860, 545 | 4.5729001100, 1.3266714800, 546 | -2.5922245540, 4.3362012520] 547 | // MARK: - moment 548 | func testMoment() { 549 | let a = [1, 2, 3.5, 3.7, 8, 12] 550 | var moment = a.moment 551 | 552 | XCTAssertNotNil(moment) 553 | 554 | XCTAssertEqual(round10(moment?.average ?? Double.max), round10(a.average)) 555 | 556 | XCTAssertEqual(round10(moment?.varianceSample ?? Double.max), round10(a.varianceSample ?? Double.min)) 557 | 558 | moment = normal.moment 559 | 560 | guard let skewness = moment?.skewness, let excessKurtosis = moment?.excessKurtosis else { 561 | XCTFail("cannot get moments") 562 | return 563 | } 564 | 565 | XCTAssertTrue( -1 < skewness && skewness < 1 ) 566 | XCTAssertTrue( -1 < excessKurtosis && excessKurtosis < 1 ) 567 | } 568 | 569 | } 570 | 571 | func roundToPlaces(_ value: Double, places: Int) -> Double { 572 | let divisor = pow(10.0, Double(places)) 573 | return round(value * divisor) / divisor 574 | } 575 | 576 | func round10(_ value: Double) -> Double { 577 | return roundToPlaces(value, places: 10) 578 | } 579 | 580 | func round3(_ value: Double) -> Double { 581 | return roundToPlaces(value, places: 3) 582 | } 583 | -------------------------------------------------------------------------------- /Xcode/OSX/ArithmosophiOSX.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArithmosophiOSX.h 3 | // ArithmosophiOSX 4 | // 5 | // Created by phimage on 16/06/15. 6 | // Copyright (c) 2015 phimage. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ArithmosophiOSX. 12 | FOUNDATION_EXPORT double ArithmosophiOSXVersionNumber; 13 | 14 | //! Project version string for ArithmosophiOSX. 15 | FOUNDATION_EXPORT const unsigned char ArithmosophiOSXVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Xcode/OSX/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2015 phimage. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Xcode/TVOS/ArithmosophiTVOS.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArithmosophiTVOS.h 3 | // ArithmosophiTVOS 4 | // 5 | // Created by phimage on 07/12/15. 6 | // Copyright © 2015 phimage. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ArithmosophiTVOS. 12 | FOUNDATION_EXPORT double ArithmosophiTVOSVersionNumber; 13 | 14 | //! Project version string for ArithmosophiTVOS. 15 | FOUNDATION_EXPORT const unsigned char ArithmosophiTVOSVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Xcode/TVOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Xcode/WatchOS/ArithmosophiWatchOS.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArithmosophiWatchOS.h 3 | // ArithmosophiWatchOS 4 | // 5 | // Created by phimage on 07/12/15. 6 | // Copyright © 2015 phimage. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ArithmosophiWatchOS. 12 | FOUNDATION_EXPORT double ArithmosophiWatchOSVersionNumber; 13 | 14 | //! Project version string for ArithmosophiWatchOS. 15 | FOUNDATION_EXPORT const unsigned char ArithmosophiWatchOSVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Xcode/WatchOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Xcode/iOS/Arithmosophi.h: -------------------------------------------------------------------------------- 1 | // 2 | // Arithmosophi.h 3 | // Arithmosophi 4 | // 5 | // Created by phimage on 16/06/15. 6 | // Copyright (c) 2015 phimage. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Arithmosophi. 12 | FOUNDATION_EXPORT double ArithmosophiVersionNumber; 13 | 14 | //! Project version string for Arithmosophi. 15 | FOUNDATION_EXPORT const unsigned char ArithmosophiVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Xcode/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phimage/Arithmosophi/4d2b9ed8e0bbd2a91b67c070caa5d4e487b431b7/logo.png --------------------------------------------------------------------------------