
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.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
public static double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
def code(x): return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
function code(x) return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0)) end
function tmp = code(x) tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.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]
\begin{array}{l}
\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.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
public static double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
def code(x): return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
function code(x) return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0)) end
function tmp = code(x) tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.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]
\begin{array}{l}
\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.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
public static double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
def code(x): return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
function code(x) return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0)) end
function tmp = code(x) tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.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]
\begin{array}{l}
\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}
Initial program 99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (* (* x 3.0) x))) (if (<= (- t_0 (* x 4.0)) 0.5) (+ (+ t_0 1.0) 1.0) (* 3.0 t_0))))
double code(double x) {
double t_0 = (x * 3.0) * x;
double tmp;
if ((t_0 - (x * 4.0)) <= 0.5) {
tmp = (t_0 + 1.0) + 1.0;
} else {
tmp = 3.0 * t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * x
if ((t_0 - (x * 4.0d0)) <= 0.5d0) then
tmp = (t_0 + 1.0d0) + 1.0d0
else
tmp = 3.0d0 * t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x * 3.0) * x;
double tmp;
if ((t_0 - (x * 4.0)) <= 0.5) {
tmp = (t_0 + 1.0) + 1.0;
} else {
tmp = 3.0 * t_0;
}
return tmp;
}
def code(x): t_0 = (x * 3.0) * x tmp = 0 if (t_0 - (x * 4.0)) <= 0.5: tmp = (t_0 + 1.0) + 1.0 else: tmp = 3.0 * t_0 return tmp
function code(x) t_0 = Float64(Float64(x * 3.0) * x) tmp = 0.0 if (Float64(t_0 - Float64(x * 4.0)) <= 0.5) tmp = Float64(Float64(t_0 + 1.0) + 1.0); else tmp = Float64(3.0 * t_0); end return tmp end
function tmp_2 = code(x) t_0 = (x * 3.0) * x; tmp = 0.0; if ((t_0 - (x * 4.0)) <= 0.5) tmp = (t_0 + 1.0) + 1.0; else tmp = 3.0 * t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[(x * 4.0), $MachinePrecision]), $MachinePrecision], 0.5], N[(N[(t$95$0 + 1.0), $MachinePrecision] + 1.0), $MachinePrecision], N[(3.0 * t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot x\\
\mathbf{if}\;t\_0 - x \cdot 4 \leq 0.5:\\
\;\;\;\;\left(t\_0 + 1\right) + 1\\
\mathbf{else}:\\
\;\;\;\;3 \cdot t\_0\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 0.5Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites17.8%
Taylor expanded in x around 0
Applied rewrites17.7%
Taylor expanded in x around 0
Applied rewrites20.1%
if 0.5 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites98.1%
(FPCore (x) :precision binary64 (let* ((t_0 (* (* x 3.0) x))) (if (<= (- t_0 (* x 4.0)) 0.5) (+ t_0 1.0) (* 3.0 t_0))))
double code(double x) {
double t_0 = (x * 3.0) * x;
double tmp;
if ((t_0 - (x * 4.0)) <= 0.5) {
tmp = t_0 + 1.0;
} else {
tmp = 3.0 * t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x * 3.0d0) * x
if ((t_0 - (x * 4.0d0)) <= 0.5d0) then
tmp = t_0 + 1.0d0
else
tmp = 3.0d0 * t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x * 3.0) * x;
double tmp;
if ((t_0 - (x * 4.0)) <= 0.5) {
tmp = t_0 + 1.0;
} else {
tmp = 3.0 * t_0;
}
return tmp;
}
def code(x): t_0 = (x * 3.0) * x tmp = 0 if (t_0 - (x * 4.0)) <= 0.5: tmp = t_0 + 1.0 else: tmp = 3.0 * t_0 return tmp
function code(x) t_0 = Float64(Float64(x * 3.0) * x) tmp = 0.0 if (Float64(t_0 - Float64(x * 4.0)) <= 0.5) tmp = Float64(t_0 + 1.0); else tmp = Float64(3.0 * t_0); end return tmp end
function tmp_2 = code(x) t_0 = (x * 3.0) * x; tmp = 0.0; if ((t_0 - (x * 4.0)) <= 0.5) tmp = t_0 + 1.0; else tmp = 3.0 * t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[(x * 4.0), $MachinePrecision]), $MachinePrecision], 0.5], N[(t$95$0 + 1.0), $MachinePrecision], N[(3.0 * t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot x\\
\mathbf{if}\;t\_0 - x \cdot 4 \leq 0.5:\\
\;\;\;\;t\_0 + 1\\
\mathbf{else}:\\
\;\;\;\;3 \cdot t\_0\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 0.5Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites17.8%
Taylor expanded in x around 0
Applied rewrites17.7%
if 0.5 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites98.1%
(FPCore (x) :precision binary64 (+ (+ (* 3.0 (* (* x 3.0) x)) 1.0) 1.0))
double code(double x) {
return ((3.0 * ((x * 3.0) * x)) + 1.0) + 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((3.0d0 * ((x * 3.0d0) * x)) + 1.0d0) + 1.0d0
end function
public static double code(double x) {
return ((3.0 * ((x * 3.0) * x)) + 1.0) + 1.0;
}
def code(x): return ((3.0 * ((x * 3.0) * x)) + 1.0) + 1.0
function code(x) return Float64(Float64(Float64(3.0 * Float64(Float64(x * 3.0) * x)) + 1.0) + 1.0) end
function tmp = code(x) tmp = ((3.0 * ((x * 3.0) * x)) + 1.0) + 1.0; end
code[x_] := N[(N[(N[(3.0 * N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot \left(\left(x \cdot 3\right) \cdot x\right) + 1\right) + 1
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites38.3%
Taylor expanded in x around 0
Applied rewrites38.3%
Taylor expanded in x around 0
Applied rewrites61.2%
(FPCore (x) :precision binary64 (+ (* 3.0 (* (* x 3.0) x)) 1.0))
double code(double x) {
return (3.0 * ((x * 3.0) * x)) + 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (3.0d0 * ((x * 3.0d0) * x)) + 1.0d0
end function
public static double code(double x) {
return (3.0 * ((x * 3.0) * x)) + 1.0;
}
def code(x): return (3.0 * ((x * 3.0) * x)) + 1.0
function code(x) return Float64(Float64(3.0 * Float64(Float64(x * 3.0) * x)) + 1.0) end
function tmp = code(x) tmp = (3.0 * ((x * 3.0) * x)) + 1.0; end
code[x_] := N[(N[(3.0 * N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(\left(x \cdot 3\right) \cdot x\right) + 1
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites38.3%
Taylor expanded in x around 0
Applied rewrites60.1%
(FPCore (x) :precision binary64 (+ (* (* x 3.0) x) 1.0))
double code(double x) {
return ((x * 3.0) * x) + 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * 3.0d0) * x) + 1.0d0
end function
public static double code(double x) {
return ((x * 3.0) * x) + 1.0;
}
def code(x): return ((x * 3.0) * x) + 1.0
function code(x) return Float64(Float64(Float64(x * 3.0) * x) + 1.0) end
function tmp = code(x) tmp = ((x * 3.0) * x) + 1.0; end
code[x_] := N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot x + 1
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites38.3%
Taylor expanded in x around 0
Applied rewrites38.3%
(FPCore (x) :precision binary64 (* (* x 3.0) x))
double code(double x) {
return (x * 3.0) * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 3.0d0) * x
end function
public static double code(double x) {
return (x * 3.0) * x;
}
def code(x): return (x * 3.0) * x
function code(x) return Float64(Float64(x * 3.0) * x) end
function tmp = code(x) tmp = (x * 3.0) * x; end
code[x_] := N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 3\right) \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites31.7%
Taylor expanded in x around 0
Applied rewrites31.8%
(FPCore (x) :precision binary64 (* x 3.0))
double code(double x) {
return x * 3.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 3.0d0
end function
public static double code(double x) {
return x * 3.0;
}
def code(x): return x * 3.0
function code(x) return Float64(x * 3.0) end
function tmp = code(x) tmp = x * 3.0; end
code[x_] := N[(x * 3.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 3
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites38.3%
Taylor expanded in x around 0
Applied rewrites3.6%
(FPCore (x) :precision binary64 (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x))))
double code(double x) {
return 3.0 + (((9.0 * x) * x) - (12.0 * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 3.0d0 + (((9.0d0 * x) * x) - (12.0d0 * x))
end function
public static double code(double x) {
return 3.0 + (((9.0 * x) * x) - (12.0 * x));
}
def code(x): return 3.0 + (((9.0 * x) * x) - (12.0 * x))
function code(x) return Float64(3.0 + Float64(Float64(Float64(9.0 * x) * x) - Float64(12.0 * x))) end
function tmp = code(x) tmp = 3.0 + (((9.0 * x) * x) - (12.0 * x)); end
code[x_] := N[(3.0 + N[(N[(N[(9.0 * x), $MachinePrecision] * x), $MachinePrecision] - N[(12.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)
\end{array}
herbie shell --seed 2024321
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (+ 3 (- (* (* 9 x) x) (* 12 x))))
(* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))