Skip to content

Instantly share code, notes, and snippets.

@krawaller
Created September 18, 2011 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krawaller/1225258 to your computer and use it in GitHub Desktop.
Save krawaller/1225258 to your computer and use it in GitHub Desktop.
calc = (tool,a1,a2,toolarg)->
if tool is "relation"
throw "Only one relation allowed!" if a2.type is "relation"
type:"relation",objs:[a1,a2],val:toolarg
else if a2.type is "relation"
type: "relation",val:a2.val, objs:[calc(tool,a1,a2.objs[0]),a2.objs[1]]
else if a2.isblock
o tool,[a1,a2]
else if tool in ["sum","product"] and tool is a2.type
o tool, [a1].concat a2.objs
else if not (tool is "sum" and a2.type is "product") and (a2.type in ["sum","product"] or (tool is "power" and a2.type is "fraction"))
o a2.type, [calc(tool,a1,a2.objs[0])].concat a2.objs[1..]
else
o tool,[a1,a2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment