From ca8f06955e9f46216d31d225fdbb158fc7511966 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Thu, 29 Jun 2017 00:27:44 +0100 Subject: [PATCH] Made it work in Gorilla --- project.clj | 6 +- src/exponential_tax/core.clj | 166 ++++++++++++++++++++++++++++++++--- 2 files changed, 159 insertions(+), 13 deletions(-) diff --git a/project.clj b/project.clj index 4750505..373db13 100644 --- a/project.clj +++ b/project.clj @@ -4,6 +4,6 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.6.0"] - [org.clojure/tools.namespace "0.2.4"] - [org.clojure/math.numeric-tower "0.0.4"] - [lein-gorilla "0.3.3"]]) + [org.clojure/tools.namespace "0.2.10"] + [org.clojure/math.numeric-tower "0.0.4"]] + :plugins [[lein-gorilla "0.4.0"]]) diff --git a/src/exponential_tax/core.clj b/src/exponential_tax/core.clj index c3ec916..01d1caf 100644 --- a/src/exponential_tax/core.clj +++ b/src/exponential_tax/core.clj @@ -1,6 +1,52 @@ -(ns exponential-tax.core - (:require [clojure.math.numeric-tower :as math])) +;; gorilla-repl.fileformat = 1 +;; ** +;;; # Exponential Tax worksheet +;;; +;;; This worksheet illustrates the effect of an exponential land tax on holdings of different sizes. +;;; +;;; ## Background +;;; +;;; In Scotland (and in many third world countries), ownership of land is highly concentrated in the hands of a very few, very rich people. This is bad from many points of view; this document isn't really the place to make those arguments. +;;; +;;; For more of the argument, read: +;;; +;;; * [Quarter of a million crofts](http://blog.journeyman.cc/2014/12/quarter-of-million-crofts.html) +;;; * [The Law of Freedom in a Web Page](http://blog.journeyman.cc/2015/03/the-law-of-freedom-in-web-page-or-true.html) +;;; * [Me and you and the Duke of Buccleuch](http://blog.journeyman.cc/2014/12/me-and-you-and-duke-of-buccleuch.html) +;;; +;;; So, having made that introduction, onto the code. +;;; +;;; ## First, some definitions +;;; +;;; ### The namespace +;;; +;;; First of all, we need to declare a namespace and the libraries on which this code depends. +;; ** + +;; @@ +(ns exponential-tax.core + (:require + [clojure.math.numeric-tower :as math] + [gorilla-repl.table :refer :all])) +;; @@ +;; => +;;; {"type":"html","content":"nil","value":"nil"} +;; <= + +;; ** +;;; ## Summing an exponential series +;;; +;;; My proposal for exponential land tax is based on the idea that you pay *a little bit on the first hectare, a bit more on the next, a bit more on the next, and so on*. It's based on that because I started with the legend of the [grains of rice on a chess-board](http://www.singularitysymposium.com/exponential-growth.html). +;;; +;;; So the amount of tax you pay is Σ1..n(cn)e, where *n* is the number of hectares you own. +;;; +;;; Actually, this is almost a purposeless complication; simply applying the exponential function to the number of hectares in a holding scales almost as rapidly. But I think the concept of *a little bit for the first hectare, a bit more for the next, and so on* is easy for folk to grasp. +;;; +;;; But to be able to compute this, we need to be able to construct and sum exponential series. So here's a function to do that. +;; ** + +;; @@ (defn summed-exponential-series "Sum an exponential series from 1 to limit. @@ -8,8 +54,25 @@ `exponent`: the exponent to which they are raised; `limit`: the limit of the range to be summed." [constant exponent limit] - (reduce + (map #(math/expt (* constant %) exponent) (range limit)))) + (reduce + + + (map + #(math/expt + (* constant %) + exponent) + (range limit)))) +;; @@ +;; => +;;; {"type":"html","content":"#'exponential-tax.core/summed-exponential-series","value":"#'exponential-tax.core/summed-exponential-series"} +;; <= +;; ** +;;; ## Formatting money +;;; +;;; It may be convenient to be able to format amounts of money, so here's a function to do this. +;; ** + +;; @@ (defn format-money-amount "Format the number passed as argument as an amount of money (pounds and pence). @@ -17,6 +80,43 @@ [n] (format "£ %,12.2f" n)) +;; @@ +;; => +;;; {"type":"html","content":"#'exponential-tax.core/format-money-amount","value":"#'exponential-tax.core/format-money-amount"} +;; <= + +;; ** +;;; ## Print out sample taxes given a table of holdings +;;; +;;; Since we need to know who will pay how much tax, we're going to want to be able to format a table of taxes due. +;; ** + +;; @@ +(defn sample-taxes + "Prints sample taxable amounts for a table of holdings." + [constant exponent holdings] + (table-view + (map + #(list (first %) + (format-money-amount + (summed-exponential-series + constant + exponent + (second %)))) + holdings) + :columns ["Holding" "Tax"])) +;; @@ +;; => +;;; {"type":"html","content":"#'exponential-tax.core/sample-taxes","value":"#'exponential-tax.core/sample-taxes"} +;; <= + +;; ** +;;; ## And then, of course, we need the actual sizes of holdings +;;; +;;; These numbers are, as far as I can establish, more or less accurate. Add holdings you're interested in to this list. +;; ** + +;; @@ (def holding-sizes [["Average croft" 5] ["Average farm" 101] @@ -32,10 +132,56 @@ ["Duke of Atholl" 58700] ["Duke of Buccleuch" 109000]]) -(defn sample-taxes - "Prints sample taxable amounts for a table of holdings." - [constant exponent holdings] - (map #(print (format "\n%s: £ %,.2f" - (first %) - (summed-exponential-series constant exponent (second %)))) - holdings)) \ No newline at end of file +;; @@ +;; => +;;; {"type":"html","content":"#'exponential-tax.core/holding-sizes","value":"#'exponential-tax.core/holding-sizes"} +;; <= + +;; ** +;;; +;; ** + +;; ** +;;; ## The Variables +;;; +;;; There are two key variables in this scheme, the constant and the exponent. +;;; +;;; ### The constant +;;; +;;; The constant is the amount the first hectare is taxed. It can be very small - a few pennies will do to start. +;; ** + +;; @@ +(def c 1) +;; @@ +;; => +;;; {"type":"html","content":"#'exponential-tax.core/c","value":"#'exponential-tax.core/c"} +;; <= + +;; ** +;;; ### The exponent +;;; +;;; The exponent is the amount each successive hectare's tax is multiplied by. It, too, can be surprisingly small - it needs to be above one, but it doesn't need to be much above one. +;; ** + +;; @@ +(def e 1.05) +;; @@ +;; => +;;; {"type":"html","content":"#'exponential-tax.core/e","value":"#'exponential-tax.core/e"} +;; <= + +;; ** +;;; ## Right, let's put that all together! +;; ** + +;; @@ +(sample-taxes c e holding-sizes) +;; @@ +;; => +;;; {"type":"list-like","open":"
","close":"
","separator":"\n","items":[{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Holding"","value":"\"Holding\""},{"type":"html","content":""Tax"","value":"\"Tax\""}],"value":"[\"Holding\" \"Tax\"]"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Average croft"","value":"\"Average croft\""},{"type":"html","content":""£ 10.53"","value":"\"£ 10.53\""}],"value":"(\"Average croft\" \"£ 10.53\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Average farm"","value":"\"Average farm\""},{"type":"html","content":""£ 6,204.08"","value":"\"£ 6,204.08\""}],"value":"(\"Average farm\" \"£ 6,204.08\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Glasgow Airport"","value":"\"Glasgow Airport\""},{"type":"html","content":""£ 58,191.38"","value":"\"£ 58,191.38\""}],"value":"(\"Glasgow Airport\" \"£ 58,191.38\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Edinburgh Airport"","value":"\"Edinburgh Airport\""},{"type":"html","content":""£ 105,040.07"","value":"\"£ 105,040.07\""}],"value":"(\"Edinburgh Airport\" \"£ 105,040.07\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Grangemouth Refinery"","value":"\"Grangemouth Refinery\""},{"type":"html","content":""£ 331,177.47"","value":"\"£ 331,177.47\""}],"value":"(\"Grangemouth Refinery\" \"£ 331,177.47\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Thousand hectares"","value":"\"Thousand hectares\""},{"type":"html","content":""£ 688,336.48"","value":"\"£ 688,336.48\""}],"value":"(\"Thousand hectares\" \"£ 688,336.48\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Ten thousand hectares"","value":"\"Ten thousand hectares\""},{"type":"html","content":""£ 77,303,938.64"","value":"\"£ 77,303,938.64\""}],"value":"(\"Ten thousand hectares\" \"£ 77,303,938.64\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Countess of Sutherland"","value":"\"Countess of Sutherland\""},{"type":"html","content":""£ 893,688,616.49"","value":"\"£ 893,688,616.49\""}],"value":"(\"Countess of Sutherland\" \"£ 893,688,616.49\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Earl of Seafield"","value":"\"Earl of Seafield\""},{"type":"html","content":""£ 1,325,738,877.59"","value":"\"£ 1,325,738,877.59\""}],"value":"(\"Earl of Seafield\" \"£ 1,325,738,877.59\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Captain Alwynn Farquharson"","value":"\"Captain Alwynn Farquharson\""},{"type":"html","content":""£ 2,252,234,219.56"","value":"\"£ 2,252,234,219.56\""}],"value":"(\"Captain Alwynn Farquharson\" \"£ 2,252,234,219.56\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Duke of Westminster"","value":"\"Duke of Westminster\""},{"type":"html","content":""£ 2,452,703,794.50"","value":"\"£ 2,452,703,794.50\""}],"value":"(\"Duke of Westminster\" \"£ 2,452,703,794.50\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Duke of Atholl"","value":"\"Duke of Atholl\""},{"type":"html","content":""£ 2,910,359,665.77"","value":"\"£ 2,910,359,665.77\""}],"value":"(\"Duke of Atholl\" \"£ 2,910,359,665.77\")"},{"type":"list-like","open":"","close":"","separator":"","items":[{"type":"html","content":""Duke of Buccleuch"","value":"\"Duke of Buccleuch\""},{"type":"html","content":""£ 10,350,620,262.71"","value":"\"£ 10,350,620,262.71\""}],"value":"(\"Duke of Buccleuch\" \"£ 10,350,620,262.71\")"}],"value":"#gorilla_repl.table.TableView{:contents ((\"Average croft\" \"£ 10.53\") (\"Average farm\" \"£ 6,204.08\") (\"Glasgow Airport\" \"£ 58,191.38\") (\"Edinburgh Airport\" \"£ 105,040.07\") (\"Grangemouth Refinery\" \"£ 331,177.47\") (\"Thousand hectares\" \"£ 688,336.48\") (\"Ten thousand hectares\" \"£ 77,303,938.64\") (\"Countess of Sutherland\" \"£ 893,688,616.49\") (\"Earl of Seafield\" \"£ 1,325,738,877.59\") (\"Captain Alwynn Farquharson\" \"£ 2,252,234,219.56\") (\"Duke of Westminster\" \"£ 2,452,703,794.50\") (\"Duke of Atholl\" \"£ 2,910,359,665.77\") (\"Duke of Buccleuch\" \"£ 10,350,620,262.71\")), :opts (:columns [\"Holding\" \"Tax\"])}"} +;; <= + +;; @@ + +;; @@