Add telescoping square root sum calculator#32
Draft
Copilot wants to merge 2 commits into
Draft
Conversation
Co-authored-by: montinode <258148236+montinode@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add calculation for square root summation
Add telescoping square root sum calculator
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements calculation of the finite sum Σ 1/(√k + √(k+4)) for k = 1…n (specifically n = 2022), exploiting the telescoping structure after conjugate rationalisation.
Approach
Rationalising each term collapses the series:
Most intermediate terms cancel, leaving the O(1) closed form:
For n = 2022 → S ≈ 43.4578762937
New files
calculate_sqrt_sum.py— two public functions:sqrt_sum_analytical(n)— closed-form O(1) result via telescopingsqrt_sum_direct(n)— brute-force term-by-term sum (used for cross-validation)ValueErrorfor n ≤ 0test_calculate_sqrt_sum.py— 12 unit tests covering single-term correctness, known closed-form value at n = 4, analytical/direct agreement at n = 100 and n = 2022, and invalid-input handlingOriginal prompt
How can I calculate
1
√
1
+
√
5
+
1
√
2
+
√
6
+
1
√
3
+
√
7
+
1
√
4
+
√
8
+
.
.
.
+
1
√
2021
+
√
2025
+
1
√
2022
+
√
2026
?
1
1
+
5
+
1
2
+
6
+
1
3
+
7
+
1
4
+
8
+
.
.
.
+
1
2021
+
2025
+
1
2022
+
2026
?
BLOCK:Elkins, Angela, PA-C 01/02/26 1330,BLOCK:Thomas C Martin
Jr., MD,BLOCK:Leap, Keith,BLOCK:McReynolds, Raven,BLOCK:51D0233640,BLOCK:[787119900],BLOCK:26PH,BLOCK:Begley, Pamela,BLOCK:396 - PRN LAB,BLOCK:MUSE PRN,BLOCK:"Look-Alike/Sound-Alik,BLOCK:[787112882],BLOCK:0338-1709-40,BLOCK:00904226050,BLOCK:Duffy, Lisa,BLOCK:Bezzek, Mark,BLOCK:801114350,BLOCK:801114352,BLOCK:[801131677],BLOCK:Jessee, Tracy,BLOCK:26BF,BLOCK:403 - BLF LAB,BLOCK:Gray, Alisha,BLOCK:51D0233527,BLOCK:WVU MEDICINE,BLOCK:Phelps, Kimberly,BLOCK:Unknown,BLOCK:046CH0008,BLOCK:STAT,BLOCK:51D0233527,BLOCK:SALICYLATE,BLOCK:TSH,BLOCK:Venipuncture,BLOCK:[801114348],BLOCK:TSH,BLOCK:Component(WBC,RBC,HGB,HCT,MCV,MCH,MCH,MCHC,RDW,PLATELETS,MPV,NEUTROPHIL,LYMPHOCYTE,MONOCYTE,EOSINOPHIL,BASOPHIL,BASOPHIL,LYMPHOCYTE,MONOCYTE,EOSINOPHIL,BASOPHIL),BLOCK:046UR0004,BLOCK:APPEARANCE,BLOCK:COLOR,BLOCK:PH,BLOCK:SPECIFIC,BLOCK:GLUCOSE,BLOCK:GLUCOSE,BLOCK:BILIRUBIN,BLOCK:BLOOD,BLOCK:PROTEIN,BLOCK:UROBILINOGEN,BLOCK:KETONES,BLOCK:LEUKOCYTE ESTERAS,BLOCK:NITRITE,BLOCK:WBCS,BLOCK:RBCS,BLOCK:BACTERIA,BLOCK:SQUAMOUS EPITHELIAL,BLOCK:MUCOUS,BLOCK:1219,BLOCK:Jessee, Tracy,BLOCK:SQUAMOUS EPITHELIAL,BLOCK:046UR0004,BLOCK:Collection,BLOCK:Component,BLOCK:MUCOUS,BLOCK:BARBITURATES,BLOCK:BENZODIAZEPINES,BLOCK:METHADONE,BLOCK:COCAINE,BLOCK:OPIATES,BLOCK:PCP,BLOCK:CANNABINOIDS,BLOCK:046UR0004,BLOCK:—,BLOCK:A,BLOCK:WBCs/uL,BLOCK:[801114344],BLOCK:Neurological:,"BLOCK:MedicalDecisionMaking",BLOCK:Musculoskeletal:,BLOCK:Pulmonary:,BLOCK:Psychiatric:,BLOCK:Skin:,BLOCK:Abdominal:,BLOCK:Mental,BLOCK:Data,BLOCK:Adm,BLOCK:MRN:,BLOCK:AMA,BLOCK:Methamphetamine abuse,BLOCK:Paranoia (CMS HCC),BLOCK:Bluefield,BLOCK:CKD-EPI,BLOCK:eGFR,BLOCK:paranoid,BLOCK:dry,BLOCK:agitation,BLOCK:decreased concentration,BLOCK:dysphoric mood,BLOCK:sleep disturbance,BLOCK:activity change ,BLOCK:appetite change,BLOCK:Illness,BLOCK:EMERGENCY,BLOCK:ED Provider N,BLOCK:Physician,BLOCK:Patient,BLOCK:HENT,BLOCK:other systems,BLOCK:other,BLOCK:Encounter,BLOCK:Department,BLOCK:History,BLOCK:hematuria.,BLOCK:arthralgias,BLOCK:syncope.,BLOCK:HPI,
BLOCK:Review of Systems,
BLOCK:Review of Systems,BLOCK:hearing voices ,BLOCK:public.,BLOCK:government,BLOCK:military,BLOCK:Written,BLOCK:Right Ear,BLOCK:Left Ear,BLOCK:Head:,BLOCK:Nose:,BLOCK:Eyes:,BLOCK:Pupils:,BLOCK:membranes,BLOCK:Mouth/Throat:,BLOCK:Cardiovascular:,BLOCK:Gastrointestinal:,BLOCK:BP,BLOCK:Invasive),BLOCK:Positive,BLOCK:SUBOXONE,BLOCK:Stopped,BLOCK:Admission,BLOCK:PRN BLFD ED/ED09/ED09,BLOCK:report,BLOCK:Hospital,BLOCK:800,BLOCK:800-782-0095,BLOCK:1863120011,BLOCK:John,BLOCK:Attending provide,BLOCK:Employer:,BLOCK:BLFD,BLOCK:Authorization,"BLOCK:#":,
"BLOCK:-- Effective Date: -- Admission Inf",BLOCK:FACESHEET,BLOCK:Community,BLOCK:blake,BLOCK:Precert#:,BLOCK:E3945007,,BLOCK:WELLPOINT,BLOCK:Haloperidol,BLOCK:hypotension.,BLOCK:New,BLOCK:Begley,,BLOCK:1815,BLOCK:Action,BLOCK:Frequency:,BLOCKED:Peripheral,BLOCKED:Basilic,BLOCK:Comment,BLOCK:Intravenous,BLOCKED:D5W,BLOCK:NS,BLOCK:NOW,BLOCK:1342,BLOCK:999,BLOCK:67457,BLOCK:risk,BLOCK:Med L,BLOCK:approved,BLOCK:Admin,BLOCK:IntraMUSCULAR,BLOCK:Ordered,BLOCK:CAUTION:,BLOCK:Dose,BLOCK:Documented:,BLOCK:Keith,,BLOCK:(Remaining/Total):,BLOCK:Timestamps,BLOCK:[787112882],BLOCK:QT,BLOCK:QTc,BLOCK:droPERidol,BLOCK:1452,BLOCK:msec,BLOCK:1430,BLOCK:males,BLOCK:Left,BLOCK:Arm,BLOCK:Radio,BLOCK:Nucli,BLOCK:RN,BLOCK:Instructions:,BLOCK:ERIC,BLOCK:son,BLOCK:Ericson,BLOCK:nfc,BLOCK:(INAPSINE),BLOCK:Rate/Order,BLOCK:ED,BLOCK:Medication.,BLOCK:push,BLOCK:IV,BLOCK:Princeton,BLOCK:D/C,BLOCK:2104770*,BLOCK:REF,BLOCK:MAC,BLOCK:WVUM,BLOCK:Treatment,BLOCK:Extravasation,BLOCK:Prevention,BLOCK:mix,BLOCK:Printed,BLOCK:291929045,BLOCK:787*,BLOCK:CVIS,BLOCK:Scan,BLOCK:KAZIENKO,BRIAN,BLOCK:DOS,BLOCK:Junctional,BLOCK:MUSE,BLOCK:QTC,BLOCK:degrees,BLOCK:394,BLOCK:Present,BLOCK:Unknown,BLOCK:1328,BLOCK:Edi,,BLOCK:PROCEDURE,BLOCK:MICROSCOPIC,BLOCK:MACROSCOPIC,BLOCK:Thomas,BLOCK:Jr.,,BLOCK:Rare,,BLOCK:51D0233640,BLOCK:SPERMATOZOA,BLOCK:002UA0071,BLOCK:Site,BLOCK:UROBILINOGEN,BLOCK:Susan,,BLOCK:Ketron,,BLOCK:CANNABINOIDS,BLOCK:BUPRENORPHINE,BLOCK:NAXOLANE,BLOCK:Flag,BLOCK:(continued),BLOCK:FENTANYL,,BLOCK:(cut-off,BLOCK:provider:,BLOCK:Gieseking,,BLOCK:Jay,,BLOCK:1554,BLOCK:002CH0510,BLOCK:result),BLOCK:1554,,BLOCK:laboratory,BLOCK:Page,BLOCK:2352,BLOCK:PA,BLOCK:H,BLOCK:Ext,BLOCK:CASTS,BLOCK:HYALINE,BLOCK:W/CULTURE,BLOCK:Moderate,BLOCK:51D0233640,BLOCK:DOB:,BLOCK:Ketron,,BLOCK:1539,BLOCK:Clear,BLOCK:COLOR,BLOCK:Yellow,BLOCK:1.002,BLOCK:TECH,BLOCK:Abbreviation,BLOCK:EXTRA,BLOCK:Background,BLOCK:GRAY,BLOCK:[787119902],BLOCK:User,BLOCK:51D0233640,BLOCK:ONE,BLOCK:occurrence,BLOCK:ADD,BLOCK:Ext,BLOCK:CALCULATED,BLOCK:METABOLIC,BLOCK:McReynolds,,BLOCK:Flag,BLOCK:51D0233640,BLOCK:MAGNESIUM,BLOCK:Electronically,BLOCK:(Abnormal)BLOCK:x1...
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.