
(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 9 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%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e-47) (not (<= x 2.8e-153))) (+ x (* z (cos y))) (+ (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e-47) || !(x <= 2.8e-153)) {
tmp = x + (z * cos(y));
} else {
tmp = sin(y) + z;
}
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.6d-47)) .or. (.not. (x <= 2.8d-153))) then
tmp = x + (z * cos(y))
else
tmp = sin(y) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e-47) || !(x <= 2.8e-153)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = Math.sin(y) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e-47) or not (x <= 2.8e-153): tmp = x + (z * math.cos(y)) else: tmp = math.sin(y) + z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e-47) || !(x <= 2.8e-153)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(sin(y) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.6e-47) || ~((x <= 2.8e-153))) tmp = x + (z * cos(y)); else tmp = sin(y) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e-47], N[Not[LessEqual[x, 2.8e-153]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-47} \lor \neg \left(x \leq 2.8 \cdot 10^{-153}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y + z\\
\end{array}
\end{array}
if x < -2.6e-47 or 2.8000000000000001e-153 < x Initial program 99.9%
Taylor expanded in x around inf 90.9%
if -2.6e-47 < x < 2.8000000000000001e-153Initial program 99.9%
Taylor expanded in x around 0 95.8%
Taylor expanded in y around 0 79.5%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -22.5) (not (<= z 1.1))) (+ x (* z (cos y))) (+ (+ x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -22.5) || !(z <= 1.1)) {
tmp = x + (z * cos(y));
} else {
tmp = (x + sin(y)) + z;
}
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 ((z <= (-22.5d0)) .or. (.not. (z <= 1.1d0))) then
tmp = x + (z * cos(y))
else
tmp = (x + sin(y)) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -22.5) || !(z <= 1.1)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = (x + Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -22.5) or not (z <= 1.1): tmp = x + (z * math.cos(y)) else: tmp = (x + math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -22.5) || !(z <= 1.1)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(Float64(x + sin(y)) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -22.5) || ~((z <= 1.1))) tmp = x + (z * cos(y)); else tmp = (x + sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -22.5], N[Not[LessEqual[z, 1.1]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -22.5 \lor \neg \left(z \leq 1.1\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\end{array}
\end{array}
if z < -22.5 or 1.1000000000000001 < z Initial program 99.8%
Taylor expanded in x around inf 98.5%
if -22.5 < z < 1.1000000000000001Initial program 100.0%
Taylor expanded in y around 0 99.0%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= y -1.05e+139) (sin y) (if (<= y 9.5e+37) (+ z (+ x y)) (if (<= y 8.5e+199) (sin y) (+ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.05e+139) {
tmp = sin(y);
} else if (y <= 9.5e+37) {
tmp = z + (x + y);
} else if (y <= 8.5e+199) {
tmp = sin(y);
} else {
tmp = x + z;
}
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 <= (-1.05d+139)) then
tmp = sin(y)
else if (y <= 9.5d+37) then
tmp = z + (x + y)
else if (y <= 8.5d+199) then
tmp = sin(y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.05e+139) {
tmp = Math.sin(y);
} else if (y <= 9.5e+37) {
tmp = z + (x + y);
} else if (y <= 8.5e+199) {
tmp = Math.sin(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.05e+139: tmp = math.sin(y) elif y <= 9.5e+37: tmp = z + (x + y) elif y <= 8.5e+199: tmp = math.sin(y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.05e+139) tmp = sin(y); elseif (y <= 9.5e+37) tmp = Float64(z + Float64(x + y)); elseif (y <= 8.5e+199) tmp = sin(y); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.05e+139) tmp = sin(y); elseif (y <= 9.5e+37) tmp = z + (x + y); elseif (y <= 8.5e+199) tmp = sin(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.05e+139], N[Sin[y], $MachinePrecision], If[LessEqual[y, 9.5e+37], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.5e+199], N[Sin[y], $MachinePrecision], N[(x + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{+139}:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+37}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+199}:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -1.0499999999999999e139 or 9.4999999999999995e37 < y < 8.49999999999999923e199Initial program 99.8%
Taylor expanded in x around 0 75.0%
Taylor expanded in z around 0 36.7%
if -1.0499999999999999e139 < y < 9.4999999999999995e37Initial program 100.0%
Taylor expanded in y around 0 94.4%
Taylor expanded in y around 0 86.1%
if 8.49999999999999923e199 < y Initial program 99.8%
Taylor expanded in x around inf 71.8%
Taylor expanded in y around 0 47.6%
Final simplification68.3%
(FPCore (x y z) :precision binary64 (if (<= x -6.5e-16) (+ x z) (if (<= x 1.1e-83) (+ (sin y) z) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.5e-16) {
tmp = x + z;
} else if (x <= 1.1e-83) {
tmp = sin(y) + z;
} else {
tmp = x + z;
}
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 <= (-6.5d-16)) then
tmp = x + z
else if (x <= 1.1d-83) then
tmp = sin(y) + z
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6.5e-16) {
tmp = x + z;
} else if (x <= 1.1e-83) {
tmp = Math.sin(y) + z;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.5e-16: tmp = x + z elif x <= 1.1e-83: tmp = math.sin(y) + z else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.5e-16) tmp = Float64(x + z); elseif (x <= 1.1e-83) tmp = Float64(sin(y) + z); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.5e-16) tmp = x + z; elseif (x <= 1.1e-83) tmp = sin(y) + z; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.5e-16], N[(x + z), $MachinePrecision], If[LessEqual[x, 1.1e-83], N[(N[Sin[y], $MachinePrecision] + z), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-16}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{-83}:\\
\;\;\;\;\sin y + z\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -6.50000000000000011e-16 or 1.10000000000000004e-83 < x Initial program 99.9%
Taylor expanded in x around inf 95.4%
Taylor expanded in y around 0 77.8%
if -6.50000000000000011e-16 < x < 1.10000000000000004e-83Initial program 99.9%
Taylor expanded in x around 0 94.4%
Taylor expanded in y around 0 73.7%
Final simplification75.9%
(FPCore (x y z) :precision binary64 (if (<= y -1050000000000.0) (+ x z) (if (<= y 8e+53) (+ (+ x y) (* z (+ 1.0 (* -0.5 (* y y))))) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1050000000000.0) {
tmp = x + z;
} else if (y <= 8e+53) {
tmp = (x + y) + (z * (1.0 + (-0.5 * (y * y))));
} else {
tmp = x + z;
}
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 <= (-1050000000000.0d0)) then
tmp = x + z
else if (y <= 8d+53) then
tmp = (x + y) + (z * (1.0d0 + ((-0.5d0) * (y * y))))
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1050000000000.0) {
tmp = x + z;
} else if (y <= 8e+53) {
tmp = (x + y) + (z * (1.0 + (-0.5 * (y * y))));
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1050000000000.0: tmp = x + z elif y <= 8e+53: tmp = (x + y) + (z * (1.0 + (-0.5 * (y * y)))) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1050000000000.0) tmp = Float64(x + z); elseif (y <= 8e+53) tmp = Float64(Float64(x + y) + Float64(z * Float64(1.0 + Float64(-0.5 * Float64(y * y))))); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1050000000000.0) tmp = x + z; elseif (y <= 8e+53) tmp = (x + y) + (z * (1.0 + (-0.5 * (y * y)))); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1050000000000.0], N[(x + z), $MachinePrecision], If[LessEqual[y, 8e+53], N[(N[(x + y), $MachinePrecision] + N[(z * N[(1.0 + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1050000000000:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+53}:\\
\;\;\;\;\left(x + y\right) + z \cdot \left(1 + -0.5 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -1.05e12 or 7.9999999999999999e53 < y Initial program 99.8%
Taylor expanded in x around inf 69.3%
Taylor expanded in y around 0 34.5%
if -1.05e12 < y < 7.9999999999999999e53Initial program 100.0%
Taylor expanded in y around 0 96.6%
Taylor expanded in y around 0 91.5%
unpow291.5%
Simplified91.5%
Final simplification66.1%
(FPCore (x y z) :precision binary64 (if (<= y -7e+67) (+ x z) (if (<= y 8e+53) (+ z (+ x y)) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+67) {
tmp = x + z;
} else if (y <= 8e+53) {
tmp = z + (x + y);
} else {
tmp = x + z;
}
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 <= (-7d+67)) then
tmp = x + z
else if (y <= 8d+53) then
tmp = z + (x + y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7e+67) {
tmp = x + z;
} else if (y <= 8e+53) {
tmp = z + (x + y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7e+67: tmp = x + z elif y <= 8e+53: tmp = z + (x + y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7e+67) tmp = Float64(x + z); elseif (y <= 8e+53) tmp = Float64(z + Float64(x + y)); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7e+67) tmp = x + z; elseif (y <= 8e+53) tmp = z + (x + y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7e+67], N[(x + z), $MachinePrecision], If[LessEqual[y, 8e+53], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+67}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+53}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -7e67 or 7.9999999999999999e53 < y Initial program 99.8%
Taylor expanded in x around inf 69.1%
Taylor expanded in y around 0 35.2%
if -7e67 < y < 7.9999999999999999e53Initial program 100.0%
Taylor expanded in y around 0 94.9%
Taylor expanded in y around 0 86.9%
Final simplification65.9%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in x around inf 80.6%
Taylor expanded in y around 0 62.2%
Final simplification62.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 68.8%
Taylor expanded in y around 0 53.6%
unpow253.6%
Simplified53.6%
Taylor expanded in x around inf 34.3%
Final simplification34.3%
herbie shell --seed 2023196
(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))))