Module 1 · Mathematical Language and Quantitative Reasoning Lesson 5 of 120
Exponents, Roots, and Logarithms
Finding the growth factor and the time it takes.
Transcript
25 sentences · select one to jump thereCheck your understanding
Does the cube root return 5% or 1.05?
Code lab
Run it yourself
The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.
/**
* Fintech Math Bootcamp · Lesson 005 of 120
* Exponents, Roots, and Logarithms
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Finding the growth factor and the time it takes
* Rule: 100 × 1.05³ = 115.7625
*
* Try it: Does the cube root return 5% or 1.05?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/exponents-roots-and-logarithms/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*/
export function lesson005() {
const start = 100, factor = 1.05, periods = 3;
const future = start * factor ** periods;
const root = (future / start) ** (1 / periods);
const doublingPeriods = Math.log(2) / Math.log(factor);
const result = {future, root, doublingPeriods};
return result;
}
export const checkedResult = {"future":115.76250000000002,"root":1.05,"doublingPeriods":14.206699082890461};
// Run this file directly: npx tsx lessons/01-mathematical-language-and-quantitative-reasoning/005-exponents-roots-and-logarithms.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
console.log(JSON.stringify(lesson005(), null, 2));
}
Your output
Press Run to execute the code in your browser.
Expected output
{
"future": 115.76250000000002,
"root": 1.05,
"doublingPeriods": 14.206699082890461
}"""
Fintech Math Bootcamp · Lesson 005 of 120
Exponents, Roots, and Logarithms
Module 01: Mathematical Language and Quantitative Reasoning
Scenario: Finding the growth factor and the time it takes
Rule: 100 × 1.05³ = 115.7625
Try it: Does the cube root return 5% or 1.05?
Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/exponents-roots-and-logarithms/
Free course: https://courses.thefintechbuilder.com
Synthetic teaching example, not financial advice or a production library.
Run it: python main.py
"""
import json
import math
def lesson005() -> dict:
start, factor, periods = 100, 1.05, 3
future = start * factor**periods
root = (future / start) ** (1 / periods)
doubling_periods = math.log(2) / math.log(factor)
result = {"future": future, "root": root, "doublingPeriods": doubling_periods}
return result
if __name__ == "__main__":
print(json.dumps(lesson005(), indent=2))
Your output
Press Run to execute the code in your browser.
Expected output
{
"future": 115.76250000000002,
"root": 1.05,
"doublingPeriods": 14.206699082890461
}/**
* Fintech Math Bootcamp · Lesson 005 of 120
* Exponents, Roots, and Logarithms
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Finding the growth factor and the time it takes
* Rule: 100 × 1.05³ = 115.7625
*
* Try it: Does the cube root return 5% or 1.05?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/exponents-roots-and-logarithms/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: javac Main.java && java Main
*/
public class Main {
static final class GrowthFacts {
final double future;
final double root;
final double doublingPeriods;
GrowthFacts(double future, double root, double doublingPeriods) {
this.future = future;
this.root = root;
this.doublingPeriods = doublingPeriods;
}
}
static GrowthFacts lesson005() {
double start = 100, factor = 1.05, periods = 3;
double future = start * Math.pow(factor, periods);
double root = Math.pow(future / start, 1 / periods);
double doublingPeriods = Math.log(2) / Math.log(factor);
GrowthFacts result = new GrowthFacts(future, root, doublingPeriods);
return result;
}
public static void main(String[] args) {
GrowthFacts result = lesson005();
System.out.println(object(
"future", num(result.future),
"root", num(result.root),
"doublingPeriods", num(result.doublingPeriods)));
}
// Formats a double the way JSON.stringify does: whole numbers without ".0", null for NaN or infinity.
static String num(double x) {
if (Double.isNaN(x) || Double.isInfinite(x)) return "null";
if (x == Math.rint(x) && Math.abs(x) < 1e15) return String.valueOf((long) x);
return String.valueOf(x);
}
static String quote(String text) {
return "\"" + text.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
}
// Indents an already formatted JSON value by one level.
static String nested(String json) {
return json.replace("\n", "\n ");
}
static String object(String... keysAndValues) {
if (keysAndValues.length == 0) return "{}";
StringBuilder out = new StringBuilder("{");
for (int i = 0; i < keysAndValues.length; i += 2) {
out.append(i == 0 ? "\n " : ",\n ")
.append(quote(keysAndValues[i])).append(": ").append(nested(keysAndValues[i + 1]));
}
return out.append("\n}").toString();
}
}
No browser runner for Java yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"future": 115.76250000000002,
"root": 1.05,
"doublingPeriods": 14.206699082890461
}// Fintech Math Bootcamp · Lesson 005 of 120
// Exponents, Roots, and Logarithms
// Module 01: Mathematical Language and Quantitative Reasoning
//
// Scenario: Finding the growth factor and the time it takes
// Rule: 100 × 1.05³ = 115.7625
//
// Try it: Does the cube root return 5% or 1.05?
//
// Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/exponents-roots-and-logarithms/
// Free course: https://courses.thefintechbuilder.com
// Synthetic teaching example, not financial advice or a production library.
//
// Run it: go run main.go
package main
import (
"encoding/json"
"fmt"
"math"
)
type GrowthFacts struct {
Future float64 `json:"future"`
Root float64 `json:"root"`
DoublingPeriods float64 `json:"doublingPeriods"`
}
func lesson005() GrowthFacts {
start, factor, periods := 100.0, 1.05, 3.0
future := start * math.Pow(factor, periods)
root := math.Pow(future/start, 1/periods)
doublingPeriods := math.Log(2) / math.Log(factor)
result := GrowthFacts{Future: future, Root: root, DoublingPeriods: doublingPeriods}
return result
}
func main() {
printJSON(lesson005())
}
// printJSON prints a value as JSON indented with two spaces, like JSON.stringify(value, null, 2).
func printJSON(value any) {
out, err := json.MarshalIndent(value, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(out))
}
No browser runner for Go yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"future": 115.76250000000002,
"root": 1.05,
"doublingPeriods": 14.206699082890461
}/**
* Fintech Math Bootcamp · Lesson 005 of 120
* Exponents, Roots, and Logarithms
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Finding the growth factor and the time it takes
* Rule: 100 × 1.05³ = 115.7625
*
* Try it: Does the cube root return 5% or 1.05?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/exponents-roots-and-logarithms/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: g++ -std=c++17 -o main main.cpp && ./main
*/
#include <charconv>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
// Formats a double the way JSON.stringify does: shortest round-trip form, null for NaN or infinity.
std::string num(double x) {
if (!std::isfinite(x)) return "null";
char buffer[32];
auto [end, error] = std::to_chars(buffer, buffer + sizeof buffer, x);
(void)error;
return std::string(buffer, end);
}
std::string quote(const std::string& text) {
std::string out = "\"";
for (char c : text) {
if (c == '"' || c == '\\') out += '\\';
out += c;
}
return out + "\"";
}
// Indents an already formatted JSON value by one level.
std::string nested(const std::string& json) {
std::string out;
for (char c : json) {
out += c;
if (c == '\n') out += " ";
}
return out;
}
std::string object(const std::vector<std::pair<std::string, std::string>>& fields) {
if (fields.empty()) return "{}";
std::string out = "{";
for (std::size_t i = 0; i < fields.size(); ++i) {
out += i == 0 ? "\n " : ",\n ";
out += quote(fields[i].first) + ": " + nested(fields[i].second);
}
return out + "\n}";
}
struct GrowthFacts {
double future;
double root;
double doublingPeriods;
};
GrowthFacts lesson005() {
const double start = 100, factor = 1.05, periods = 3;
const double future = start * std::pow(factor, periods);
const double root = std::pow(future / start, 1 / periods);
const double doublingPeriods = std::log(2.0) / std::log(factor);
const GrowthFacts result{future, root, doublingPeriods};
return result;
}
int main() {
const GrowthFacts result = lesson005();
std::cout << object({
{"future", num(result.future)},
{"root", num(result.root)},
{"doublingPeriods", num(result.doublingPeriods)}
}) << "\n";
}
No browser runner for C++ yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"future": 115.76250000000002,
"root": 1.05,
"doublingPeriods": 14.206699082890461
}//! Fintech Math Bootcamp · Lesson 005 of 120
//! Exponents, Roots, and Logarithms
//! Module 01: Mathematical Language and Quantitative Reasoning
//!
//! Scenario: Finding the growth factor and the time it takes
//! Rule: 100 × 1.05³ = 115.7625
//!
//! Try it: Does the cube root return 5% or 1.05?
//!
//! Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/exponents-roots-and-logarithms/
//! Free course: https://courses.thefintechbuilder.com
//! Synthetic teaching example, not financial advice or a production library.
//!
//! Run it: rustc main.rs && ./main
struct GrowthFacts {
future: f64,
root: f64,
doubling_periods: f64,
}
fn lesson005() -> GrowthFacts {
let (start, factor, periods): (f64, f64, f64) = (100.0, 1.05, 3.0);
let future = start * factor.powf(periods);
let root = (future / start).powf(1.0 / periods);
let doubling_periods = 2.0_f64.ln() / factor.ln();
let result = GrowthFacts { future, root, doubling_periods };
result
}
fn main() {
let result = lesson005();
println!(
"{}",
object(&[
("future", num(result.future)),
("root", num(result.root)),
("doublingPeriods", num(result.doubling_periods)),
])
);
}
/// Formats a number the way JSON.stringify does: shortest round-trip form, null for NaN or infinity.
fn num(x: f64) -> String {
if x.is_finite() {
format!("{}", x)
} else {
"null".to_string()
}
}
fn quote(text: &str) -> String {
format!("\"{}\"", text.replace('\\', "\\\\").replace('"', "\\\""))
}
/// Indents an already formatted JSON value by one level.
fn nested(json: &str) -> String {
json.replace('\n', "\n ")
}
fn object(fields: &[(&str, String)]) -> String {
if fields.is_empty() {
return "{}".to_string();
}
let lines: Vec<String> = fields
.iter()
.map(|(key, value)| format!(" {}: {}", quote(key), nested(value)))
.collect();
format!("{{\n{}\n}}", lines.join(",\n"))
}
No browser runner for Rust yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"future": 115.76250000000002,
"root": 1.05,
"doublingPeriods": 14.206699082890461
}/**
* Fintech Math Bootcamp · Lesson 005 of 120
* Exponents, Roots, and Logarithms
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Finding the growth factor and the time it takes
* Rule: 100 × 1.05³ = 115.7625
*
* Try it: Does the cube root return 5% or 1.05?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/exponents-roots-and-logarithms/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: dotnet run (inside a console project that holds this Program.cs)
*/
using System.Text.Json;
var jsonOptions = new JsonSerializerOptions { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
Console.WriteLine(JsonSerializer.Serialize(Lesson005(), jsonOptions));
static GrowthFacts Lesson005()
{
double start = 100, factor = 1.05, periods = 3;
var future = start * Math.Pow(factor, periods);
var root = Math.Pow(future / start, 1 / periods);
var doublingPeriods = Math.Log(2) / Math.Log(factor);
var result = new GrowthFacts(future, root, doublingPeriods);
return result;
}
record GrowthFacts(double Future, double Root, double DoublingPeriods);
No browser runner for C# yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"future": 115.76250000000002,
"root": 1.05,
"doublingPeriods": 14.206699082890461
}Prefer your own machine? Every file is in the course repository · open it in Codespaces.
Lesson notes
The rule
100 × 1.05³ = 115.7625