logo
P
Prompt Master

Prompt 大师

掌握和 AI 对话的艺术

Composite functions

function composition prompt example

#TL;DR(中文)

  • 这是一个
    code
    function composition
    的测试:给
    code
    g(x)=f^{-1}(x)
    与若干映射点,反推出
    code
    f
    的对应关系,再计算
    code
    f(f(f(6)))
  • 适合用来测:模型是否能把 inverse mapping 处理正确、是否会在多次 composition 时出错。
  • 落地建议:要求模型输出 mapping table,并在每一步 composition 后输出中间值。

#Background

This prompt tests an LLM's mathematical capabilities by prompting it to evaluate a function composition.

#How to Apply(中文)

建议按 “先建立映射,再逐步计算” 的流程:

  1. code
    g(x)=f^{-1}(x)
    得到:
    code
    f(g(x)) = x
    (也就是把
    code
    g
    的 pairs 反向得到
    code
    f
    的 pairs)
  2. 用表格列出
    code
    f
    的 mapping(例如
    code
    f(5)=0
    ,
    code
    f(7)=4
    等)
  3. 依次计算
    code
    f(6) → f(f(6)) → f(f(f(6)))

#How to Iterate(中文)

  1. 强制输出
    code
    mapping table
    (结构化)后再给最终答案
  2. code
    self-check
    :把
    code
    f
    code
    g
    互相验证(检查
    code
    g(f(x)) = x
    在给定点是否成立)
  3. 对抗测试:增加更多点、加入干扰点、或让
    code
    f
    非单射的情况看模型是否能发现矛盾

#Self-check rubric(中文)

  • 是否正确理解
    code
    inverse
    关系并构造了
    code
    f
    的映射?
  • composition 是否逐步计算且中间值正确?
  • 是否检查了映射是否一致(无冲突)?

#Practice(中文)

练习:把问题改成

code
f(f(2))
code
f(f(f(9)))
等不同目标,并要求模型输出:

  • mapping table
  • 每一步中间值
  • 简短的 consistency check

#Prompt

text
Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?

#Code / API

#OpenAI (Python)

python
from openai import OpenAI client = OpenAI() response = client.chat.completions.create( model="gpt-4", messages=[ { "role": "user", "content": "Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?", } ], temperature=1, max_tokens=256, top_p=1, frequency_penalty=0, presence_penalty=0, )

#Fireworks (Python)

python
import fireworks.client fireworks.client.api_key = "<FIREWORKS_API_KEY>" completion = fireworks.client.ChatCompletion.create( model="accounts/fireworks/models/mixtral-8x7b-instruct", messages=[ { "role": "user", "content": "Suppose g(x) = f^{-1}(x), g(0) = 5, g(4) = 7, g(3) = 2, g(7) = 9, g(9) = 6. What is f(f(f(6)))?", } ], stop=["<|im_start|>", "<|im_end|>", "<|endoftext|>"], stream=True, n=1, top_p=1, top_k=40, presence_penalty=0, frequency_penalty=0, prompt_truncate_len=1024, context_length_exceeded_behavior="truncate", temperature=0.9, max_tokens=4000, )

#Reference

1v1免费职业咨询