Created
December 1, 2010 04:41
-
-
Save vito/722958 to your computer and use it in GitHub Desktop.
derivatives in atomo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define: *variable* as: @no-variable | |
(b: Block) derive := | |
with: *variable* as: b arguments head name do: { | |
Block: b contents (map: @derive) arguments: b arguments | |
} | |
`(~x ^ ~y) derive := | |
condition: { | |
-- constant exponent | |
y constant? -> | |
`((~y * (~x ^ (~y - 1))) * ~(x derive)) | |
-- constant base | |
x constant? -> | |
`((~x ^ ~y) * ~(y derive)) | |
otherwise -> | |
`(e ^ (~y * ~x ln)) derive | |
} | |
`(~x sqrt) derive := `(~x ^ 1/2) derive | |
`(~x ln) derive := `(1 / ~x) | |
`(~x log: ~a) derive := | |
`(1 / (~x * ~a ln)) | |
`(~x / ~y) derive := | |
`((~(x derive) * ~y - ~x * ~(y derive)) / (~y ^ 2)) | |
`(~x * ~y) derive := | |
`(~x * ~(y derive) + ~(x derive) * ~y) | |
`(~x + ~y) derive := `(~(x derive) + ~(y derive)) | |
`(~x - ~y) derive := `(~(x derive) - ~(y derive)) | |
`(~x sin) derive := `(~x cos * ~(x derive)) | |
`(~x cos) derive := `(-1 * (~x sin) * ~(x derive)) | |
`(~x tan) derive := `((~x sec) ^ 2) | |
(e: Expression) derive := | |
condition: { | |
e type == @primitive -> 0 | |
e respect-to? -> 1 | |
otherwise -> `(~e unknown) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load: "util" | |
load: "derive" | |
load: "simplify" | |
{ x | 3 * (x ^ 3/2) } derive simplify print | |
{ x | (2 * x) cos } derive simplify print | |
{ x | (5 * x) * x sin } derive simplify print | |
{ x | (3 * (x ^ 3/2)) + (2 * x) cos - ((5 * x) * x sin) } derive simplify print |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(b: Block) simplify := | |
{ es = b contents map: | |
{ e | | |
old = e | |
new = old simplify | |
while: { old /= new } do: { | |
old = new | |
new = old simplify | |
} | |
new | |
} | |
Block: es arguments: b arguments | |
} call | |
`(e ln) simplify := `1 | |
`(~x ^ 1/2) simplify := | |
`(~x sqrt) | |
`(e ^ (~y ln * ~z)) simplify := | |
`(~y ^ ~z) | |
`(e ^ (~y * ~z ln)) simplify := | |
`(~z ^ ~y) | |
`(0 * ~_) simplify := `0 | |
`(~_ * 0) simplify := `0 | |
`(1 * ~y) simplify := y | |
`(~y * 1) simplify := y | |
`(0 + ~y) simplify := y | |
`(~y + 0) simplify := y | |
`(0 - ~y) simplify := y | |
`(~y - 0) simplify := y | |
`(~(x: Primitive) * (~(y: Primitive) * ~z)) simplify := | |
`(~(evaluate: x * evaluate: y) * ~z) | |
`((~x * ~(y: Primitive)) * ~(z: Primitive)) simplify := | |
`(~(evaluate: y * evaluate: z) * ~x) | |
`((~(x: Primitive) * ~y) * ~(z: Primitive)) simplify := | |
`(~(evaluate: x * evaluate: z) * ~y) | |
`(~(x: Primitive) * (~(y: Primitive) * ~z)) simplify := | |
`(~(evaluate: x * evaluate: y) * ~z) | |
`(~(x: Primitive) * (~y * ~(z: Primitive))) simplify := | |
`(~(evaluate: x * evaluate: z) * ~y) | |
`(~(x: Primitive) * ~(y: Primitive)) simplify := | |
`(~(evaluate: x * evaluate: y)) | |
`(~x * (1 / ~z)) simplify := | |
if: (x == z) | |
then: { `1 } | |
else: { `(~(x simplify) * (1 / ~(z simplify))) } | |
`(~(x: Primitive) / ~(y: Primitive)) simplify := | |
`(~(evaluate: x / evaluate: y)) | |
`(~(x: Primitive) + ~(y: Primitive)) simplify := | |
`(~(evaluate: x + evaluate: y)) | |
`(~(x: Primitive) - ~(y: Primitive)) simplify := | |
`(~(evaluate: x - evaluate: y)) | |
(e: Expression) simplify := | |
e type match: { | |
@(dispatch: _) -> | |
`Dispatch new: e particle to: e targets (map: @simplify) | |
_ -> e | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(e: Expression) respect-to? := | |
e type == @(dispatch: @single) && e name == *variable* | |
(e: Expression) constant? := | |
e type == @primitive || e == `e | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
more simplification: