From bbe97da1b5dd55f97ae5bf8db20cb2ccb72712f5 Mon Sep 17 00:00:00 2001 From: Akshit Gulyan <103456810+AkshitGulyan@users.noreply.github.com> Date: Sat, 22 Oct 2022 12:01:59 +0530 Subject: [PATCH 01/13] Created sum_of_harmonic_series.py Here in this code the formula for Harmonic sum is not used, Sum of the series is calculated by creating a list of the elements in the given Harmonic series and adding all the elements of that list ! --- maths/sum_of_harmonic_series.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 maths/sum_of_harmonic_series.py diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py new file mode 100644 index 000000000000..e146ca4e06a4 --- /dev/null +++ b/maths/sum_of_harmonic_series.py @@ -0,0 +1,38 @@ +def sum_of_hp(first_term, common_difference, no_of_terms): + + """ + + Find the sum of n terms in an harmonic progression. + common_diff is the common difference of Arithmetic + Progression by which the given Harmonic Progression is linked. + + + """ + + l1=[1/first_term] + i=0 + first_term=1/first_term + while i Date: Sat, 22 Oct 2022 06:40:51 +0000 Subject: [PATCH 02/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/sum_of_harmonic_series.py | 39 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index e146ca4e06a4..75853419f8ff 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -1,38 +1,37 @@ def sum_of_hp(first_term, common_difference, no_of_terms): - + """ - + Find the sum of n terms in an harmonic progression. - common_diff is the common difference of Arithmetic - Progression by which the given Harmonic Progression is linked. - - + common_diff is the common difference of Arithmetic + Progression by which the given Harmonic Progression is linked. + + """ - - l1=[1/first_term] - i=0 - first_term=1/first_term - while i Date: Sat, 22 Oct 2022 23:51:25 +0530 Subject: [PATCH 03/13] Update maths/sum_of_harmonic_series.py Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com> --- maths/sum_of_harmonic_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 75853419f8ff..c7a58efec56b 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -1,4 +1,4 @@ -def sum_of_hp(first_term, common_difference, no_of_terms): +def sum_of_harmonic_progression(first_term: float, common_difference: float, no_of_terms: int) -> float: """ From 4ef0e17d48ac514734cbd5133155a91f27625e79 Mon Sep 17 00:00:00 2001 From: Akshit Gulyan <103456810+AkshitGulyan@users.noreply.github.com> Date: Sat, 22 Oct 2022 23:52:16 +0530 Subject: [PATCH 04/13] Update maths/sum_of_harmonic_series.py Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com> --- maths/sum_of_harmonic_series.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index c7a58efec56b..0aa8cf96f075 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -27,8 +27,6 @@ def sum_of_harmonic_progression(first_term: float, common_difference: float, no_ return sum(l2) -def main(): - print(sum_of_hp(1 / 2, 2, 2)) if __name__ == "__main__": From 82dedcbd00b7d3e77d08d9ab7ebb060d0d46e1df Mon Sep 17 00:00:00 2001 From: Akshit Gulyan <103456810+AkshitGulyan@users.noreply.github.com> Date: Sat, 22 Oct 2022 23:52:26 +0530 Subject: [PATCH 05/13] Update maths/sum_of_harmonic_series.py Co-authored-by: Chris O <46587501+ChrisO345@users.noreply.github.com> --- maths/sum_of_harmonic_series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 0aa8cf96f075..167cdbab366a 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -31,5 +31,6 @@ def sum_of_harmonic_progression(first_term: float, common_difference: float, no_ if __name__ == "__main__": import doctest - doctest.testmod() + + print(sum_of_hp(1 / 2, 2, 2)) From e9cb59014e61c3200cf54e89055c190d53aae3f8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Oct 2022 18:22:33 +0000 Subject: [PATCH 06/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/sum_of_harmonic_series.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 167cdbab366a..f354b4147225 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -1,4 +1,6 @@ -def sum_of_harmonic_progression(first_term: float, common_difference: float, no_of_terms: int) -> float: +def sum_of_harmonic_progression( + first_term: float, common_difference: float, no_of_terms: int +) -> float: """ From eb631495267ce326b427e7b7f2951ec8741a13cc Mon Sep 17 00:00:00 2001 From: Akshit Gulyan <103456810+AkshitGulyan@users.noreply.github.com> Date: Sat, 22 Oct 2022 23:53:23 +0530 Subject: [PATCH 07/13] Update maths/sum_of_harmonic_series.py Co-authored-by: Christian Clauss --- maths/sum_of_harmonic_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index f354b4147225..db3a30a40d0b 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -11,7 +11,7 @@ def sum_of_harmonic_progression( """ - l1 = [1 / first_term] + arithmetic_progression = [1 / first_term] i = 0 first_term = 1 / first_term while i < no_of_terms - 1: From ae928a5fc878bb97f4c680db61d0b43f64cda3ce Mon Sep 17 00:00:00 2001 From: Akshit Gulyan <103456810+AkshitGulyan@users.noreply.github.com> Date: Sat, 22 Oct 2022 23:53:32 +0530 Subject: [PATCH 08/13] Update maths/sum_of_harmonic_series.py Co-authored-by: Christian Clauss --- maths/sum_of_harmonic_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index db3a30a40d0b..11c666970adb 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -25,7 +25,7 @@ def sum_of_harmonic_progression( """ i += 1 - l2 = [1 / x for x in l1] + harmonic_series = [1 / step for step in arithmetic_progression] return sum(l2) From 2dfcc1e44ad071fe32fe09c031822c126083bc49 Mon Sep 17 00:00:00 2001 From: Akshit Gulyan <103456810+AkshitGulyan@users.noreply.github.com> Date: Sat, 22 Oct 2022 23:54:01 +0530 Subject: [PATCH 09/13] Update maths/sum_of_harmonic_series.py Co-authored-by: Christian Clauss --- maths/sum_of_harmonic_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 11c666970adb..013252dc68de 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -15,7 +15,7 @@ def sum_of_harmonic_progression( i = 0 first_term = 1 / first_term while i < no_of_terms - 1: - first_term = first_term + common_difference + first_term += common_difference l1.append(first_term) """ From 24b20053c0a93b4da233ad3aa9d705921689e03a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Oct 2022 18:24:34 +0000 Subject: [PATCH 10/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/sum_of_harmonic_series.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 013252dc68de..35f48a0fdaf8 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -29,10 +29,9 @@ def sum_of_harmonic_progression( return sum(l2) - - if __name__ == "__main__": import doctest + doctest.testmod() - + print(sum_of_hp(1 / 2, 2, 2)) From 1cea14e41a4ebbe9d2ae820c4a3f15b9433e3b4b Mon Sep 17 00:00:00 2001 From: Akshit Gulyan <103456810+AkshitGulyan@users.noreply.github.com> Date: Sat, 22 Oct 2022 23:58:01 +0530 Subject: [PATCH 11/13] Update sum_of_harmonic_series.py --- maths/sum_of_harmonic_series.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 35f48a0fdaf8..c36b58927c25 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -16,7 +16,7 @@ def sum_of_harmonic_progression( first_term = 1 / first_term while i < no_of_terms - 1: first_term += common_difference - l1.append(first_term) + arithmetic_progression.append(first_term) """ l1 is the Arithmetic Progression linked to the given Harmonic Series @@ -26,7 +26,7 @@ def sum_of_harmonic_progression( i += 1 harmonic_series = [1 / step for step in arithmetic_progression] - return sum(l2) + return sum(harmonic_series) if __name__ == "__main__": @@ -34,4 +34,4 @@ def sum_of_harmonic_progression( doctest.testmod() - print(sum_of_hp(1 / 2, 2, 2)) + print(sum_of_harmonic_progression(1 / 2, 2, 2)) From 634f320dd459b6a0f95c0f5c321d8c15b1ca4514 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 23 Oct 2022 06:15:35 +0200 Subject: [PATCH 12/13] Add doctests --- maths/sum_of_harmonic_series.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index c36b58927c25..9f4cfcd53318 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -1,30 +1,23 @@ def sum_of_harmonic_progression( - first_term: float, common_difference: float, no_of_terms: int + first_term: float, common_difference: float, number_of_terms: int ) -> float: - """ + https://en.wikipedia.org/wiki/Harmonic_progression_(mathematics) - Find the sum of n terms in an harmonic progression. - common_diff is the common difference of Arithmetic - Progression by which the given Harmonic Progression is linked. - + Find the sum of n terms in an harmonic progression. The calculation starts with the + first_term and loops adding the common difference of Arithmetic Progression by which + the given Harmonic Progression is linked. + >>> sum_of_harmonic_progression(1 / 2, 2, 2) + 0.75 + >>> sum_of_harmonic_progression(1 / 5, 5, 5) + 0.45666666666666667 """ - arithmetic_progression = [1 / first_term] - i = 0 first_term = 1 / first_term - while i < no_of_terms - 1: + for _ in range(number_of_terms - 1): first_term += common_difference arithmetic_progression.append(first_term) - - """ - l1 is the Arithmetic Progression linked to the given Harmonic Series - l2 is the given Harmonic Series - - """ - - i += 1 harmonic_series = [1 / step for step in arithmetic_progression] return sum(harmonic_series) @@ -33,5 +26,4 @@ def sum_of_harmonic_progression( import doctest doctest.testmod() - print(sum_of_harmonic_progression(1 / 2, 2, 2)) From 646e16622df1780aaf375f15be1b92464c03c445 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 23 Oct 2022 06:22:05 +0200 Subject: [PATCH 13/13] Update sum_of_harmonic_series.py --- maths/sum_of_harmonic_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/sum_of_harmonic_series.py b/maths/sum_of_harmonic_series.py index 9f4cfcd53318..9e0d6b19b95a 100644 --- a/maths/sum_of_harmonic_series.py +++ b/maths/sum_of_harmonic_series.py @@ -18,7 +18,7 @@ def sum_of_harmonic_progression( for _ in range(number_of_terms - 1): first_term += common_difference arithmetic_progression.append(first_term) - harmonic_series = [1 / step for step in arithmetic_progression] + harmonic_series = [1 / step for step in arithmetic_progression] return sum(harmonic_series)