
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Initial program 99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (cos y)))) (if (<= x -840.0) t_0 (if (<= x 0.75) (- (cos y) (* z (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = x + cos(y);
double tmp;
if (x <= -840.0) {
tmp = t_0;
} else if (x <= 0.75) {
tmp = cos(y) - (z * sin(y));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x + cos(y)
if (x <= (-840.0d0)) then
tmp = t_0
else if (x <= 0.75d0) then
tmp = cos(y) - (z * sin(y))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + Math.cos(y);
double tmp;
if (x <= -840.0) {
tmp = t_0;
} else if (x <= 0.75) {
tmp = Math.cos(y) - (z * Math.sin(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + math.cos(y) tmp = 0 if x <= -840.0: tmp = t_0 elif x <= 0.75: tmp = math.cos(y) - (z * math.sin(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + cos(y)) tmp = 0.0 if (x <= -840.0) tmp = t_0; elseif (x <= 0.75) tmp = Float64(cos(y) - Float64(z * sin(y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + cos(y); tmp = 0.0; if (x <= -840.0) tmp = t_0; elseif (x <= 0.75) tmp = cos(y) - (z * sin(y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -840.0], t$95$0, If[LessEqual[x, 0.75], N[(N[Cos[y], $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \cos y\\
\mathbf{if}\;x \leq -840:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.75:\\
\;\;\;\;\cos y - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -840 or 0.75 < x Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites87.3%
if -840 < x < 0.75Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.9%
(FPCore (x y z) :precision binary64 (+ x (cos y)))
double code(double x, double y, double z) {
return x + 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 + cos(y)
end function
public static double code(double x, double y, double z) {
return x + Math.cos(y);
}
def code(x, y, z): return x + math.cos(y)
function code(x, y, z) return Float64(x + cos(y)) end
function tmp = code(x, y, z) tmp = x + cos(y); end
code[x_, y_, z_] := N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \cos y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites71.7%
(FPCore (x y z) :precision binary64 (cos y))
double code(double x, double y, double z) {
return 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 = cos(y)
end function
public static double code(double x, double y, double z) {
return Math.cos(y);
}
def code(x, y, z): return math.cos(y)
function code(x, y, z) return cos(y) end
function tmp = code(x, y, z) tmp = cos(y); end
code[x_, y_, z_] := N[Cos[y], $MachinePrecision]
\begin{array}{l}
\\
\cos y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites71.7%
Taylor expanded in x around 0
Applied rewrites26.6%
herbie shell --seed 2024313
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
:precision binary64
(- (+ x (cos y)) (* z (sin y))))