Skip to content

Instantly share code, notes, and snippets.

@rfielding
Last active May 16, 2020 06:19
Show Gist options
  • Save rfielding/0c9a8aae48ca02fccdb8de0e5c06892e to your computer and use it in GitHub Desktop.
Save rfielding/0c9a8aae48ca02fccdb8de0e5c06892e to your computer and use it in GitHub Desktop.
calc ga
# Algebraic Calculus
# All rules with partials - on binary operators where BOTH args are not necessarily constant
d[f + C] : (d[C]==0) = d[f]
d[a + b] = d[a] + d[b]
d[a * b] = a * d[b] + d[a] * b
# a and b must commute for this definition
d[a^b] = b * a^(b-1) * d[a] + log_e[a] * a^b * d[b]
# a and b must commute for this definition
# Notice that log is a binary operator, where the base can vary, for completeness!
d[log_a[b] = (-1/a) ln[b]/(ln[a]^2) * d[a] + (1/b) * (1/ln[a]) * d[b]
# Special case that is very common... constant e
# Indeterminate when b==0
d[ln[b]] = d[log_e[b]] = (1/b) * d[b]
# S and d are opreators, and are not commutative
# This makes integration very algebraic than is standard
S[d[f]] = f
# Leibnitz notation can be made algebraic (with caveats to fix higher derivatives)
# !!! d^2[y] will mean something slightly different from standard calculus,
# so that differentials are completely algebraic
d^1[a] = d[a] = da
d^(n_1)[a] = d[d^(n)[a]]
# d[a] is an operator. dda = d[d[a]] = dd[a] = d[da] = d^2[a] = d^2a
# powers of differentials
d[a]^1 = d[a]
d[a]^(n+1) = d[a]^(n) * d[a]
# integration example
g = -9.8 m/(s^2)
v0 = 20 m/s
p0 = 0 m
a[t] = g
v[t] = S[ g * d[t] ] + v0
p[t] = S[ v[t] * d[t] ] + p0
# if d[b] == 0
d[a^b] = b * a^(b-1) * d[a]
# Same with higher b, and divide it out
d[a^(b+1)]/(b+1) = a^b + d[a]
v[t] = S[ g * d[t] ] + v0
= g * S[d[t]] + v0
= g * t + v0
p[t] = S[ v[t] * d[t] ] + p0
= S[ (g * t + v0) * d[t] ] + p0
= S[ g * t * d[t] + v0 * d[t] ] + p0
= S[ g * t * d[t]] + S[ v0 * d[t] ] + p0
= g * S[ t * d[t]] + v0 * S[d[t]] + p0
= g * S[ t * d[t]] + v0 * t + p0
= g * S[ t^1 * d[t]] + v0 * t + p0
= g * (1/2) * S[d[t^2]] + v0 * t + p0
= g * (1/2) * t^2 + v0 * t + p0
# Johnathan Bartlett's surprising fact about the real (algebraic) second derivative
# differential of an inverse differential...
d[d[x]^(-1)]
= -dx^(-2) * ddx
= -dx^(-2) * d^2x
d[ dy / dx]
= ddy * 1/dx + dy * d[1/dx]
= d^2y/dx + dy * (-d^2x/(dx^2))
= d^2y/dx - dy * d^2x/(dx^2)
so... this is the CORRECT formulation of the second derivative! It can be inverted to get dx/dy, etc
d[ dy / dx ]/dx
= d^2y/(dx^2) - dy/dx * d^2x/(dx^2)
These differentials CAN be algebraically manipulated.
But it means that "d^2/dx^2" you see in calculus books is wrong notation that we work around.
The answers come out correct when you neglect the subtracted term, because it's usually zero.
But without it, you cannot algebraically manipulate all differentials.
Being Algebraic is key to being easy to manipulate by machine, without exceptions to the rules.
######3
Gepmetric Algebra:
# Directions in space square to 1
right right = 1
up up = 1
# Direction in time squares to -1 (not used yet)
time time = -1 # creates special relativity
### Basic Euclidean space....
# Multiplying directions anticommutes
left = -right
up = -down
# Check that this goes counter-clockwise
right up = up left = left down = down right
# And forces this to happen... anti-commutative perpendicular directions
(right up) = -(up right)
g = -9.8 m/s^2 up
v0 = 1000 m/s right + 100 m/s up
p0 = 0 m right + 0 m up
# Be CAREFUL to not commute vectors during multiplication
# Scalars commute with everything, and t is a scalar
a[t] = g
v[t] = S[ g * d[t] ] + v0
= g * S[d[t]] + v0
= g * t + v0
p[t] = S[ v[t] * d[t] ] + p0
= S[ (g * t + v0) * d[t] ] + p0
= S[g * t * d[t] + v0 * d[t]] + p0
= S[g * t * d[t]] + S[v0 * d[t]] + p0
= g * S[t * d[t]] + v0 * S[d[t]] + p0
= g * S[t * d[t]] + v0 * t + p0
= g * (1/2) * S[d[t^2]] + v0 * t + p0
= g * (1/2) * t^2 + v0 * t + p0
# Looks the same with vector inputs...
p[2 s]
= (-9.8 m/(s^2) up) * (1/2) * (2 s)^2
+ (1000 m/s right + 100 m/s up) * 2 s
= (-19.6 m up)
+ (2000 m right + 200 m up)
= 2000 m right + (200 - 19.6) m up
= 2000 m right + 180.4 m up
In this case, no need to multiply vectors, which would do trig
You get distance squared where the vector units cancel:
(2000 m right + 180.4 m up)^2
=
(2000 m right + 180.4 m up)(2000 m right + 180.4 m up)
=
2000^2 m^2 + 180.4^2 m^2
=
(2000^2 + 180.4^2) m^2
=
4032544.16 m^2
sqrt of it is distance...
2008.11 m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment