Average Error: 0.1 → 0.1
Time: 8.2s
Precision: binary64
Cost: 704
\[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
\[\left(x \cdot \left(x \cdot 9\right) + x \cdot -12\right) + 3 \]
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
(FPCore (x) :precision binary64 (+ (+ (* x (* x 9.0)) (* x -12.0)) 3.0))
double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
double code(double x) {
	return ((x * (x * 9.0)) + (x * -12.0)) + 3.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 3.0d0 * ((((x * 3.0d0) * x) - (x * 4.0d0)) + 1.0d0)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((x * (x * 9.0d0)) + (x * (-12.0d0))) + 3.0d0
end function
public static double code(double x) {
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
public static double code(double x) {
	return ((x * (x * 9.0)) + (x * -12.0)) + 3.0;
}
def code(x):
	return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
def code(x):
	return ((x * (x * 9.0)) + (x * -12.0)) + 3.0
function code(x)
	return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0))
end
function code(x)
	return Float64(Float64(Float64(x * Float64(x * 9.0)) + Float64(x * -12.0)) + 3.0)
end
function tmp = code(x)
	tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
end
function tmp = code(x)
	tmp = ((x * (x * 9.0)) + (x * -12.0)) + 3.0;
end
code[x_] := N[(3.0 * N[(N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(N[(x * N[(x * 9.0), $MachinePrecision]), $MachinePrecision] + N[(x * -12.0), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision]
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\left(x \cdot \left(x \cdot 9\right) + x \cdot -12\right) + 3

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.1
Target0.1
Herbie0.1
\[3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right) \]

Derivation

  1. Initial program 0.1

    \[3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right) \]
  2. Simplified0.1

    \[\leadsto \color{blue}{3 \cdot \mathsf{fma}\left(3 \cdot x, x, -x \cdot 4\right) + 3} \]
    Proof
    (+.f64 (*.f64 3 (fma.f64 (*.f64 3 x) x (neg.f64 (*.f64 x 4)))) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 3 (fma.f64 (Rewrite<= *-commutative_binary64 (*.f64 x 3)) x (neg.f64 (*.f64 x 4)))) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 3 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 (*.f64 x 3) x) (*.f64 x 4)))) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 3 (-.f64 (*.f64 (*.f64 x 3) x) (*.f64 x 4))) (Rewrite<= metadata-eval (*.f64 3 1))): 5 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft-in_binary64 (*.f64 3 (+.f64 (-.f64 (*.f64 (*.f64 x 3) x) (*.f64 x 4)) 1))): 0 points increase in error, 0 points decrease in error
  3. Taylor expanded in x around 0 0.1

    \[\leadsto \color{blue}{\left(-12 \cdot x + 9 \cdot {x}^{2}\right)} + 3 \]
  4. Simplified0.1

    \[\leadsto \color{blue}{x \cdot \left(-12 + x \cdot 9\right)} + 3 \]
    Proof
    (+.f64 (*.f64 x (+.f64 -12 (*.f64 x 9))) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x (+.f64 -12 (Rewrite<= *-commutative_binary64 (*.f64 9 x)))) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x -12) (*.f64 x (*.f64 9 x)))) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 x -12) (*.f64 x (Rewrite=> *-commutative_binary64 (*.f64 x 9)))) 3): 4 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 x -12) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x x) 9))) 3): 0 points increase in error, 4 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 -12 x)) (*.f64 (*.f64 x x) 9)) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 -12 x) (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) 9)) 3): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 -12 x) (Rewrite<= *-commutative_binary64 (*.f64 9 (pow.f64 x 2)))) 3): 0 points increase in error, 0 points decrease in error
  5. Applied egg-rr0.1

    \[\leadsto \color{blue}{\left(x \cdot \left(x \cdot 9\right) + x \cdot -12\right)} + 3 \]
  6. Final simplification0.1

    \[\leadsto \left(x \cdot \left(x \cdot 9\right) + x \cdot -12\right) + 3 \]

Alternatives

Alternative 1
Error0.9
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -0.58 \lor \neg \left(x \leq 0.58\right):\\ \;\;\;\;x \cdot \left(x \cdot 9 + -12\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot -12 + 3\\ \end{array} \]
Alternative 2
Error1.8
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.58 \lor \neg \left(x \leq 1.7\right):\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \mathbf{else}:\\ \;\;\;\;3\\ \end{array} \]
Alternative 3
Error1.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -0.58:\\ \;\;\;\;9 \cdot \left(x \cdot x\right)\\ \mathbf{elif}\;x \leq 1.7:\\ \;\;\;\;3\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \end{array} \]
Alternative 4
Error1.3
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55:\\ \;\;\;\;9 \cdot \left(x \cdot x\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x \cdot -12 + 3\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(x \cdot 9\right)\\ \end{array} \]
Alternative 5
Error0.1
Cost576
\[3 + x \cdot \left(x \cdot 9 + -12\right) \]
Alternative 6
Error20.8
Cost64
\[3 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x)
  :name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"
  :precision binary64

  :herbie-target
  (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x)))

  (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))