From ca67140361b26b2bc7261264f203c4f314c14cb3 Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Wed, 27 Apr 2022 14:49:15 -0400 Subject: [PATCH] `Language.mdx` changes and `examples` Value: [1e-2 to 2e-1] --- examples/decay.squiggle | 20 ++++++++ examples/givedirectly.squiggle | 38 +++++++++++++++ .../wholenumberassignmentevaluation.squiggle | 3 ++ packages/website/docs/Features/Language.mdx | 48 ++++++++++++------- 4 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 examples/decay.squiggle create mode 100644 examples/givedirectly.squiggle create mode 100644 examples/wholenumberassignmentevaluation.squiggle diff --git a/examples/decay.squiggle b/examples/decay.squiggle new file mode 100644 index 00000000..60f4c95e --- /dev/null +++ b/examples/decay.squiggle @@ -0,0 +1,20 @@ +# The following code was provided by Nuño Sempere, it comes directly from the post https://www.lesswrong.com/s/rDe8QE5NvXcZYzgZ3/p/j8o6sgRerE3tqNWdj +## Initial setup +yearly_probability_max = 0.95 +yearly_probability_min = 0.66 +period_probability_function(epsilon, yearly_probability) = 1 - (1 - yearly_probability) ^ (1 / epsilon) +probability_decayed(t, time_periods, period_probability) = 1 - (1 - period_probability) ^ (time_periods - t) + +## Monthly decomposition +months_in_a_year=12 + +monthly_probability_min = period_probability_function(months_in_a_year, yearly_probability_min) +monthly_probability_max = period_probability_function(months_in_a_year, yearly_probability_max) + +probability_decayed_monthly_min(t) = probability_decayed(t, months_in_a_year, monthly_probability_min) +probability_decayed_monthly_max(t) = probability_decayed(t, months_in_a_year, monthly_probability_max) +probability_decayed_monthly(t) = probability_decayed_monthly_min(t) to probability_decayed_monthly_max(t) + +probability_decayed_monthly +## probability_decayed_monthly(6) +## mean(probability_decayed_monthly(6)) diff --git a/examples/givedirectly.squiggle b/examples/givedirectly.squiggle new file mode 100644 index 00000000..16dda3a7 --- /dev/null +++ b/examples/givedirectly.squiggle @@ -0,0 +1,38 @@ +# This is a cost effectiveness analysis of givedirectly, originally done by givewell, and translated into Squiggle by Sam Nolan +donation_size = 10000 +proportion_of_funding_available = beta(10, 2) +total_funding_available = donation_size * proportion_of_funding_available +household_size = 3.7 to 5.7 +size_of_transfer = 800 to 1200 +size_of_transfer_per_person = size_of_transfer / household_size + +portion_invested = 0.3 to 0.5 +amount_invested = portion_invested * size_of_transfer_per_person +amount_consumed = (1 - portion_invested) * size_of_transfer_per_person +return_on_investment = 0.08 to 0.12 +increase_in_consumption_from_investments = return_on_investment * amount_invested +baseline_consumption = 200 to 350 +log_increase_in_consumption = log(amount_consumed + baseline_consumption) + log(baseline_consumption) +log_increase_in_consumption_from_investment = log(increase_in_consumption_from_investments + baseline_consumption) + log(baseline_consumption) +investment_duration = 8 to 12 +discount_rate = beta(1.004, 20) + +present_value_excluding_last_year = log_increase_in_consumption_from_investment * (1 - (1 + discount_rate) ^ (-investment_duration)) / (log(1 + discount_rate)) + +percent_of_investment_returned = 0.15 to 0.25 + +pv_consumption_last_year = (log(baseline_consumption + amount_invested * (return_on_investment + percent_of_investment_returned)) - log(baseline_consumption)) / (1 + discount_rate)^investment_duration + +total_pv_of_cash_transfer = pv_consumption_last_year + present_value_excluding_last_year + log_increase_in_consumption + +discount_negative_spoiler = 0.03 to 0.07 + +value_discounting_spoiler = discount_negative_spoiler * total_pv_of_cash_transfer + +consumption_increase_per_household = value_discounting_spoiler * household_size + +amount_of_transfers_made = total_funding_available / size_of_transfer + +total_increase_in_ln_consumption = amount_of_transfers_made * consumption_increase_per_household + +total_increase_in_ln_consumption diff --git a/examples/wholenumberassignmentevaluation.squiggle b/examples/wholenumberassignmentevaluation.squiggle new file mode 100644 index 00000000..f441c67e --- /dev/null +++ b/examples/wholenumberassignmentevaluation.squiggle @@ -0,0 +1,3 @@ +xY1 = 99 +aBa3 = xY1 * 2 + 1 +aBa3 * xY1 + aBa3 diff --git a/packages/website/docs/Features/Language.mdx b/packages/website/docs/Features/Language.mdx index e559fb60..57dcaa0a 100644 --- a/packages/website/docs/Features/Language.mdx +++ b/packages/website/docs/Features/Language.mdx @@ -1,39 +1,51 @@ --- sidebar_position: 2 +title: Squiggle Language --- import { SquiggleEditor } from "../../src/components/SquiggleEditor"; -# Squiggle Language - The squiggle language has a very simple syntax. The best way to get to understand it is by simply looking at examples. -## Basic Language +## Expressions and statements -As an example: +A squiggle **expression** is a value like a float or a distribution or a data structure like an array or a record. + + + +The bottom line of your squiggle buffer should be an expression, which we evaluate (i.e., render). Sometimes we call the last expression of a squiggle file an _export_. + +A squiggle **assignment** is a statement, when you want to bind an expression to a name. -Squiggle can declare variables (`value_of_work = 10 to 70`) and declare exports -(the lone `value_of_work` line). Variables can be used later in a squiggle program -and even in other notebooks! +### Functions -An export is rendered to the output view so you can see your result. - -the exports can be expressions, such as: - - - -## Functions - -Squiggle supports functions, including the rendering of functions: +Some assignments are functions + +## Data structures + +A squiggle **array** is a list of expressions, which is interpretable as an export. + + + +A squiggle **record** is a key-value store with dot accessors. + +