
(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 8 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 (+ (+ 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}
Initial program 99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (+ x (sin y)) (* z (cos y)))))
(if (or (<= t_0 -0.2) (not (<= t_0 0.9)))
(+ z x)
(fma (fma (fma -0.16666666666666666 y (* -0.5 z)) y 1.0) y (+ z x)))))
double code(double x, double y, double z) {
double t_0 = (x + sin(y)) + (z * cos(y));
double tmp;
if ((t_0 <= -0.2) || !(t_0 <= 0.9)) {
tmp = z + x;
} else {
tmp = fma(fma(fma(-0.16666666666666666, y, (-0.5 * z)), y, 1.0), y, (z + x));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x + sin(y)) + Float64(z * cos(y))) tmp = 0.0 if ((t_0 <= -0.2) || !(t_0 <= 0.9)) tmp = Float64(z + x); else tmp = fma(fma(fma(-0.16666666666666666, y, Float64(-0.5 * z)), y, 1.0), y, Float64(z + x)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.2], N[Not[LessEqual[t$95$0, 0.9]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * y + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + 1.0), $MachinePrecision] * y + N[(z + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + \sin y\right) + z \cdot \cos y\\
\mathbf{if}\;t\_0 \leq -0.2 \lor \neg \left(t\_0 \leq 0.9\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y, -0.5 \cdot z\right), y, 1\right), y, z + x\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < -0.20000000000000001 or 0.900000000000000022 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6472.6
Applied rewrites72.6%
if -0.20000000000000001 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 0.900000000000000022Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6470.7
Applied rewrites70.7%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.8e+59) (not (<= z 1.9e+56))) (fma (cos y) z (+ x y)) (fma 1.0 z (+ (sin y) x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.8e+59) || !(z <= 1.9e+56)) {
tmp = fma(cos(y), z, (x + y));
} else {
tmp = fma(1.0, z, (sin(y) + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -3.8e+59) || !(z <= 1.9e+56)) tmp = fma(cos(y), z, Float64(x + y)); else tmp = fma(1.0, z, Float64(sin(y) + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.8e+59], N[Not[LessEqual[z, 1.9e+56]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+59} \lor \neg \left(z \leq 1.9 \cdot 10^{+56}\right):\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\end{array}
\end{array}
if z < -3.8000000000000001e59 or 1.89999999999999998e56 < z Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6494.7
Applied rewrites94.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-lft-identityN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6494.7
lift-*.f64N/A
*-lft-identity94.7
Applied rewrites94.7%
if -3.8000000000000001e59 < z < 1.89999999999999998e56Initial program 100.0%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites96.0%
Applied rewrites96.0%
Final simplification95.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e-40) (not (<= x 1.55e-46))) (+ z x) (+ (sin y) (* z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-40) || !(x <= 1.55e-46)) {
tmp = z + x;
} else {
tmp = sin(y) + (z * 1.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) :: tmp
if ((x <= (-2.3d-40)) .or. (.not. (x <= 1.55d-46))) then
tmp = z + x
else
tmp = sin(y) + (z * 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-40) || !(x <= 1.55e-46)) {
tmp = z + x;
} else {
tmp = Math.sin(y) + (z * 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3e-40) or not (x <= 1.55e-46): tmp = z + x else: tmp = math.sin(y) + (z * 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e-40) || !(x <= 1.55e-46)) tmp = Float64(z + x); else tmp = Float64(sin(y) + Float64(z * 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.3e-40) || ~((x <= 1.55e-46))) tmp = z + x; else tmp = sin(y) + (z * 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e-40], N[Not[LessEqual[x, 1.55e-46]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + N[(z * 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-40} \lor \neg \left(x \leq 1.55 \cdot 10^{-46}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\sin y + z \cdot 1\\
\end{array}
\end{array}
if x < -2.3e-40 or 1.55e-46 < x Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6484.9
Applied rewrites84.9%
if -2.3e-40 < x < 1.55e-46Initial program 99.9%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites76.1%
Taylor expanded in x around 0
lower-sin.f6474.7
Applied rewrites74.7%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (fma 1.0 z (+ (sin y) x)))
double code(double x, double y, double z) {
return fma(1.0, z, (sin(y) + x));
}
function code(x, y, z) return fma(1.0, z, Float64(sin(y) + x)) end
code[x_, y_, z_] := N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, z, \sin y + x\right)
\end{array}
Initial program 99.9%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites83.0%
Applied rewrites83.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -8000000000.0) (not (<= y 8.5e-17))) (+ z x) (+ (+ z y) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8000000000.0) || !(y <= 8.5e-17)) {
tmp = z + x;
} else {
tmp = (z + y) + x;
}
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) :: tmp
if ((y <= (-8000000000.0d0)) .or. (.not. (y <= 8.5d-17))) then
tmp = z + x
else
tmp = (z + y) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -8000000000.0) || !(y <= 8.5e-17)) {
tmp = z + x;
} else {
tmp = (z + y) + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8000000000.0) or not (y <= 8.5e-17): tmp = z + x else: tmp = (z + y) + x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8000000000.0) || !(y <= 8.5e-17)) tmp = Float64(z + x); else tmp = Float64(Float64(z + y) + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8000000000.0) || ~((y <= 8.5e-17))) tmp = z + x; else tmp = (z + y) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8000000000.0], N[Not[LessEqual[y, 8.5e-17]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(z + y), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8000000000 \lor \neg \left(y \leq 8.5 \cdot 10^{-17}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) + x\\
\end{array}
\end{array}
if y < -8e9 or 8.5e-17 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6447.2
Applied rewrites47.2%
if -8e9 < y < 8.5e-17Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
Final simplification72.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1e-69) (not (<= x 1.45e-65))) (+ z x) (+ z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-69) || !(x <= 1.45e-65)) {
tmp = z + x;
} else {
tmp = z + y;
}
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) :: tmp
if ((x <= (-1d-69)) .or. (.not. (x <= 1.45d-65))) then
tmp = z + x
else
tmp = z + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1e-69) || !(x <= 1.45e-65)) {
tmp = z + x;
} else {
tmp = z + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1e-69) or not (x <= 1.45e-65): tmp = z + x else: tmp = z + y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1e-69) || !(x <= 1.45e-65)) tmp = Float64(z + x); else tmp = Float64(z + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1e-69) || ~((x <= 1.45e-65))) tmp = z + x; else tmp = z + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1e-69], N[Not[LessEqual[x, 1.45e-65]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(z + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-69} \lor \neg \left(x \leq 1.45 \cdot 10^{-65}\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;z + y\\
\end{array}
\end{array}
if x < -9.9999999999999996e-70 or 1.4499999999999999e-65 < x Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6483.2
Applied rewrites83.2%
if -9.9999999999999996e-70 < x < 1.4499999999999999e-65Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6498.3
Applied rewrites98.3%
Taylor expanded in y around 0
Applied rewrites54.4%
Final simplification71.4%
(FPCore (x y z) :precision binary64 (+ z y))
double code(double x, double y, double z) {
return z + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + y
end function
public static double code(double x, double y, double z) {
return z + y;
}
def code(x, y, z): return z + y
function code(x, y, z) return Float64(z + y) end
function tmp = code(x, y, z) tmp = z + y; end
code[x_, y_, z_] := N[(z + y), $MachinePrecision]
\begin{array}{l}
\\
z + y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6459.6
Applied rewrites59.6%
Taylor expanded in y around 0
Applied rewrites32.3%
herbie shell --seed 2024339
(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))))