Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
exponents power rule functions
  • Loading branch information
jmreddig committed Oct 17, 2025
commit d82c0558907cf33250681d2bbd1b75e25c0041e7
34 changes: 34 additions & 0 deletions apprentice/agents/cre_agents/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@
register_func = new_register_decorator("func", full_descr="CREFunc")
register_all_funcs = new_register_all("func", types=[CREFunc], full_descr="CREFunc")

@CREFunc(signature=string(string), shorthand='exp_mult_pow({0})')
def MultiplyExponents(s):
i_close = s.index(')') # position of ')'
j_open = s.index('^{', i_close + 1) # must be right after ')'
k_end = s.index('}', j_open + 2)
e2 = s[j_open + 2 : k_end]

inner = s[1 : i_close] # "base^{e1}"
i_pow = inner.index('^{')
k1_end = inner.index('}', i_pow + 2)
base = inner[:i_pow]
e1 = inner[i_pow + 2 : k1_end]

out = base + "^{" + e1 + " \\cdot " + e2 + "}"
return out

@CREFunc(signature=string(string), shorthand='exp_power_rule({0})')
def PowerRule(s):
s = s.rsplit("/", 1)[-1].strip() # e.g., "675^{6 \cdot 6}"

i_pow = s.index('^{') # start of exponent
j_open = i_pow + 2 # first char inside '{'
k_end = s.index('}', j_open) # closing '}'

base = s[:i_pow] # "675"
exp_str = s[j_open:k_end] # "6 \cdot 6"

a_str, b_str = exp_str.split(r'\cdot') # exactly two factors
a = int(a_str.strip())
b = int(b_str.strip())

out = base + "^{" + str(a * b) + "}"
return out

@CREFunc(signature=boolean(string,string),
shorthand = '{0} == {1}',
commutes=True)
Expand Down