
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (+ x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x + sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x + sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x + \sin y\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (cos y) z)) (t_1 (fma x (/ t_0 x) x))) (if (<= x -2.8e-34) t_1 (if (<= x 1.8e-18) (+ t_0 (sin y)) t_1))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double t_1 = fma(x, (t_0 / x), x);
double tmp;
if (x <= -2.8e-34) {
tmp = t_1;
} else if (x <= 1.8e-18) {
tmp = t_0 + sin(y);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * z) t_1 = fma(x, Float64(t_0 / x), x) tmp = 0.0 if (x <= -2.8e-34) tmp = t_1; elseif (x <= 1.8e-18) tmp = Float64(t_0 + sin(y)); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(t$95$0 / x), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[x, -2.8e-34], t$95$1, If[LessEqual[x, 1.8e-18], N[(t$95$0 + N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
t_1 := \mathsf{fma}\left(x, \frac{t\_0}{x}, x\right)\\
\mathbf{if}\;x \leq -2.8 \cdot 10^{-34}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-18}:\\
\;\;\;\;t\_0 + \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -2.79999999999999997e-34 or 1.80000000000000005e-18 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6485.3
Applied rewrites85.3%
Taylor expanded in x around -inf
mul-1-negN/A
sub-negN/A
metadata-evalN/A
distribute-lft-inN/A
*-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in z around inf
Applied rewrites97.1%
if -2.79999999999999997e-34 < x < 1.80000000000000005e-18Initial program 99.9%
Taylor expanded in x around 0
lower-sin.f6493.0
Applied rewrites93.0%
Final simplification95.2%
herbie shell --seed 2024233
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))