Average Error: 33.8 → 31.5
Time: 9.2s
Precision: 64
Internal Precision: 3392
\[\left(x + a \cdot b\right) - \mathsf{trunc} \left(x + a \cdot b\right)\]
\[\begin{array}{l} \mathbf{if}\;a \cdot b \le -1.3813191841365653 \cdot 10^{+24}:\\ \;\;\;\;\left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\\ \mathbf{elif}\;a \cdot b \le -8.577372520513698 \cdot 10^{-62}:\\ \;\;\;\;\frac{{\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}^{3} + {\left(a \cdot b\right)}^{3}}{\left(\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) - \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(a \cdot b\right)\right) + \left(a \cdot b\right) \cdot \left(a \cdot b\right)}\\ \mathbf{elif}\;a \cdot b \le 2.5636777858009 \cdot 10^{-314}:\\ \;\;\;\;\left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\\ \mathbf{elif}\;a \cdot b \le 2.218366817853852 \cdot 10^{-271}:\\ \;\;\;\;\sqrt{x - \mathsf{trunc} \left(a \cdot b + x\right)} \cdot \sqrt{x - \mathsf{trunc} \left(a \cdot b + x\right)} + a \cdot b\\ \mathbf{elif}\;a \cdot b \le 8.917141739686254 \cdot 10^{-99}:\\ \;\;\;\;a \cdot b + \left(x - \mathsf{trunc} \left(\frac{\left(a \cdot b\right) \cdot \left(a \cdot b\right) - x \cdot x}{a \cdot b - x}\right)\right)\\ \mathbf{elif}\;a \cdot b \le 0.0006421839767505757:\\ \;\;\;\;\frac{{\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}^{3} + {\left(a \cdot b\right)}^{3}}{\left(\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) - \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(a \cdot b\right)\right) + \left(a \cdot b\right) \cdot \left(a \cdot b\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\\ \end{array}\]

Error

Bits error versus x

Bits error versus a

Bits error versus b

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 4 regimes
  2. if (* a b) < -1.3813191841365653e+24 or -8.577372520513698e-62 < (* a b) < 2.5636777858009e-314 or 0.0006421839767505757 < (* a b)

    1. Initial program 35.0

      \[\left(x + a \cdot b\right) - \mathsf{trunc} \left(x + a \cdot b\right)\]
    2. Initial simplification35.0

      \[\leadsto \left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\]

    if -1.3813191841365653e+24 < (* a b) < -8.577372520513698e-62 or 8.917141739686254e-99 < (* a b) < 0.0006421839767505757

    1. Initial program 33.6

      \[\left(x + a \cdot b\right) - \mathsf{trunc} \left(x + a \cdot b\right)\]
    2. Initial simplification33.6

      \[\leadsto \left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\]
    3. Using strategy rm
    4. Applied associate--l+19.8

      \[\leadsto \color{blue}{a \cdot b + \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}\]
    5. Using strategy rm
    6. Applied flip3-+19.9

      \[\leadsto \color{blue}{\frac{{\left(a \cdot b\right)}^{3} + {\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}^{3}}{\left(a \cdot b\right) \cdot \left(a \cdot b\right) + \left(\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) - \left(a \cdot b\right) \cdot \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)\right)}}\]

    if 2.5636777858009e-314 < (* a b) < 2.218366817853852e-271

    1. Initial program 25.2

      \[\left(x + a \cdot b\right) - \mathsf{trunc} \left(x + a \cdot b\right)\]
    2. Initial simplification25.2

      \[\leadsto \left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\]
    3. Using strategy rm
    4. Applied associate--l+12.4

      \[\leadsto \color{blue}{a \cdot b + \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt30.1

      \[\leadsto a \cdot b + \color{blue}{\sqrt{x - \mathsf{trunc} \left(a \cdot b + x\right)} \cdot \sqrt{x - \mathsf{trunc} \left(a \cdot b + x\right)}}\]

    if 2.218366817853852e-271 < (* a b) < 8.917141739686254e-99

    1. Initial program 26.8

      \[\left(x + a \cdot b\right) - \mathsf{trunc} \left(x + a \cdot b\right)\]
    2. Initial simplification26.8

      \[\leadsto \left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\]
    3. Using strategy rm
    4. Applied associate--l+13.4

      \[\leadsto \color{blue}{a \cdot b + \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}\]
    5. Using strategy rm
    6. Applied flip-+21.6

      \[\leadsto a \cdot b + \left(x - \mathsf{trunc} \color{blue}{\left(\frac{\left(a \cdot b\right) \cdot \left(a \cdot b\right) - x \cdot x}{a \cdot b - x}\right)}\right)\]
  3. Recombined 4 regimes into one program.
  4. Final simplification31.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \le -1.3813191841365653 \cdot 10^{+24}:\\ \;\;\;\;\left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\\ \mathbf{elif}\;a \cdot b \le -8.577372520513698 \cdot 10^{-62}:\\ \;\;\;\;\frac{{\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}^{3} + {\left(a \cdot b\right)}^{3}}{\left(\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) - \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(a \cdot b\right)\right) + \left(a \cdot b\right) \cdot \left(a \cdot b\right)}\\ \mathbf{elif}\;a \cdot b \le 2.5636777858009 \cdot 10^{-314}:\\ \;\;\;\;\left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\\ \mathbf{elif}\;a \cdot b \le 2.218366817853852 \cdot 10^{-271}:\\ \;\;\;\;\sqrt{x - \mathsf{trunc} \left(a \cdot b + x\right)} \cdot \sqrt{x - \mathsf{trunc} \left(a \cdot b + x\right)} + a \cdot b\\ \mathbf{elif}\;a \cdot b \le 8.917141739686254 \cdot 10^{-99}:\\ \;\;\;\;a \cdot b + \left(x - \mathsf{trunc} \left(\frac{\left(a \cdot b\right) \cdot \left(a \cdot b\right) - x \cdot x}{a \cdot b - x}\right)\right)\\ \mathbf{elif}\;a \cdot b \le 0.0006421839767505757:\\ \;\;\;\;\frac{{\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right)}^{3} + {\left(a \cdot b\right)}^{3}}{\left(\left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) - \left(x - \mathsf{trunc} \left(a \cdot b + x\right)\right) \cdot \left(a \cdot b\right)\right) + \left(a \cdot b\right) \cdot \left(a \cdot b\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot b + x\right) - \mathsf{trunc} \left(a \cdot b + x\right)\\ \end{array}\]

Runtime

Time bar (total: 9.2s)Debug log

herbie shell --seed '#(2775764126 3555076145 3898259844 1891440260 2599947619 1948460636)' 
(FPCore (x a b)
  :name "(x + a * b) - trunc(x + a * b)"
  (- (+ x (* a b)) (trunc (+ x (* a b)))))