
(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 (<= x -3.4e-41)
(+ x z)
(if (<= x -4.8e-66)
(sin y)
(if (<= x -9.6e-292) (+ z (+ x y)) (if (<= x 8e-300) (sin y) (+ x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.4e-41) {
tmp = x + z;
} else if (x <= -4.8e-66) {
tmp = sin(y);
} else if (x <= -9.6e-292) {
tmp = z + (x + y);
} else if (x <= 8e-300) {
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 (x <= (-3.4d-41)) then
tmp = x + z
else if (x <= (-4.8d-66)) then
tmp = sin(y)
else if (x <= (-9.6d-292)) then
tmp = z + (x + y)
else if (x <= 8d-300) 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 (x <= -3.4e-41) {
tmp = x + z;
} else if (x <= -4.8e-66) {
tmp = Math.sin(y);
} else if (x <= -9.6e-292) {
tmp = z + (x + y);
} else if (x <= 8e-300) {
tmp = Math.sin(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.4e-41: tmp = x + z elif x <= -4.8e-66: tmp = math.sin(y) elif x <= -9.6e-292: tmp = z + (x + y) elif x <= 8e-300: tmp = math.sin(y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.4e-41) tmp = Float64(x + z); elseif (x <= -4.8e-66) tmp = sin(y); elseif (x <= -9.6e-292) tmp = Float64(z + Float64(x + y)); elseif (x <= 8e-300) tmp = sin(y); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.4e-41) tmp = x + z; elseif (x <= -4.8e-66) tmp = sin(y); elseif (x <= -9.6e-292) tmp = z + (x + y); elseif (x <= 8e-300) tmp = sin(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.4e-41], N[(x + z), $MachinePrecision], If[LessEqual[x, -4.8e-66], N[Sin[y], $MachinePrecision], If[LessEqual[x, -9.6e-292], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8e-300], N[Sin[y], $MachinePrecision], N[(x + z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-41}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq -4.8 \cdot 10^{-66}:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;x \leq -9.6 \cdot 10^{-292}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{elif}\;x \leq 8 \cdot 10^{-300}:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -3.3999999999999998e-41 or 8.0000000000000002e-300 < x Initial program 99.9%
Taylor expanded in x around inf 91.3%
Taylor expanded in y around 0 81.0%
if -3.3999999999999998e-41 < x < -4.80000000000000052e-66 or -9.6000000000000005e-292 < x < 8.0000000000000002e-300Initial program 100.0%
Taylor expanded in x around 0 94.9%
Taylor expanded in z around 0 84.7%
if -4.80000000000000052e-66 < x < -9.6000000000000005e-292Initial program 99.8%
Taylor expanded in y around 0 82.5%
Taylor expanded in y around 0 64.0%
+-commutative64.0%
Simplified64.0%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e-16) (not (<= x 5.5e-225))) (+ x (* z (cos y))) (+ (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e-16) || !(x <= 5.5e-225)) {
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 <= (-1.3d-16)) .or. (.not. (x <= 5.5d-225))) 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 <= -1.3e-16) || !(x <= 5.5e-225)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = Math.sin(y) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e-16) or not (x <= 5.5e-225): tmp = x + (z * math.cos(y)) else: tmp = math.sin(y) + z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e-16) || !(x <= 5.5e-225)) 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 <= -1.3e-16) || ~((x <= 5.5e-225))) tmp = x + (z * cos(y)); else tmp = sin(y) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e-16], N[Not[LessEqual[x, 5.5e-225]], $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 -1.3 \cdot 10^{-16} \lor \neg \left(x \leq 5.5 \cdot 10^{-225}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y + z\\
\end{array}
\end{array}
if x < -1.2999999999999999e-16 or 5.5000000000000002e-225 < x Initial program 99.9%
Taylor expanded in x around inf 92.8%
if -1.2999999999999999e-16 < x < 5.5000000000000002e-225Initial program 99.9%
Taylor expanded in x around 0 91.5%
Taylor expanded in y around 0 78.4%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.5e+32) (not (<= z 5.5e-5))) (+ x (* z (cos y))) (+ (+ x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e+32) || !(z <= 5.5e-5)) {
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 <= (-5.5d+32)) .or. (.not. (z <= 5.5d-5))) 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 <= -5.5e+32) || !(z <= 5.5e-5)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = (x + Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.5e+32) or not (z <= 5.5e-5): 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 <= -5.5e+32) || !(z <= 5.5e-5)) 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 <= -5.5e+32) || ~((z <= 5.5e-5))) tmp = x + (z * cos(y)); else tmp = (x + sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.5e+32], N[Not[LessEqual[z, 5.5e-5]], $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 -5.5 \cdot 10^{+32} \lor \neg \left(z \leq 5.5 \cdot 10^{-5}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\end{array}
\end{array}
if z < -5.49999999999999984e32 or 5.5000000000000002e-5 < z Initial program 99.9%
Taylor expanded in x around inf 99.9%
if -5.49999999999999984e32 < z < 5.5000000000000002e-5Initial program 100.0%
Taylor expanded in y around 0 99.7%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= x -8.2e-14) (+ x z) (if (<= x 0.00023) (+ (sin y) z) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.2e-14) {
tmp = x + z;
} else if (x <= 0.00023) {
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 <= (-8.2d-14)) then
tmp = x + z
else if (x <= 0.00023d0) 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 <= -8.2e-14) {
tmp = x + z;
} else if (x <= 0.00023) {
tmp = Math.sin(y) + z;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.2e-14: tmp = x + z elif x <= 0.00023: tmp = math.sin(y) + z else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.2e-14) tmp = Float64(x + z); elseif (x <= 0.00023) 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 <= -8.2e-14) tmp = x + z; elseif (x <= 0.00023) tmp = sin(y) + z; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.2e-14], N[(x + z), $MachinePrecision], If[LessEqual[x, 0.00023], N[(N[Sin[y], $MachinePrecision] + z), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-14}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 0.00023:\\
\;\;\;\;\sin y + z\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -8.2000000000000004e-14 or 2.3000000000000001e-4 < x Initial program 100.0%
Taylor expanded in x around inf 97.9%
Taylor expanded in y around 0 93.2%
if -8.2000000000000004e-14 < x < 2.3000000000000001e-4Initial program 99.9%
Taylor expanded in x around 0 92.4%
Taylor expanded in y around 0 72.6%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (<= y -6.5e+20) (+ x z) (if (<= y 8.5e-6) (+ z (+ x y)) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e+20) {
tmp = x + z;
} else if (y <= 8.5e-6) {
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 <= (-6.5d+20)) then
tmp = x + z
else if (y <= 8.5d-6) 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 <= -6.5e+20) {
tmp = x + z;
} else if (y <= 8.5e-6) {
tmp = z + (x + y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.5e+20: tmp = x + z elif y <= 8.5e-6: tmp = z + (x + y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.5e+20) tmp = Float64(x + z); elseif (y <= 8.5e-6) 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 <= -6.5e+20) tmp = x + z; elseif (y <= 8.5e-6) tmp = z + (x + y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.5e+20], N[(x + z), $MachinePrecision], If[LessEqual[y, 8.5e-6], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+20}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-6}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -6.5e20 or 8.4999999999999999e-6 < y Initial program 99.9%
Taylor expanded in x around inf 69.6%
Taylor expanded in y around 0 45.1%
if -6.5e20 < y < 8.4999999999999999e-6Initial program 100.0%
Taylor expanded in y around 0 99.2%
Taylor expanded in y around 0 98.7%
+-commutative98.7%
Simplified98.7%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (if (<= x -3.3e-86) (+ x z) (if (<= x 1.05e-174) (+ y z) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.3e-86) {
tmp = x + z;
} else if (x <= 1.05e-174) {
tmp = 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 <= (-3.3d-86)) then
tmp = x + z
else if (x <= 1.05d-174) then
tmp = 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 <= -3.3e-86) {
tmp = x + z;
} else if (x <= 1.05e-174) {
tmp = y + z;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.3e-86: tmp = x + z elif x <= 1.05e-174: tmp = y + z else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.3e-86) tmp = Float64(x + z); elseif (x <= 1.05e-174) tmp = Float64(y + z); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.3e-86) tmp = x + z; elseif (x <= 1.05e-174) tmp = y + z; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.3e-86], N[(x + z), $MachinePrecision], If[LessEqual[x, 1.05e-174], N[(y + z), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-86}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 1.05 \cdot 10^{-174}:\\
\;\;\;\;y + z\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -3.29999999999999987e-86 or 1.05000000000000005e-174 < x Initial program 100.0%
Taylor expanded in x around inf 89.8%
Taylor expanded in y around 0 80.6%
if -3.29999999999999987e-86 < x < 1.05000000000000005e-174Initial program 99.9%
Taylor expanded in x around 0 96.5%
Taylor expanded in y around 0 50.1%
+-commutative50.1%
Simplified50.1%
Final simplification73.8%
(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 81.8%
Taylor expanded in y around 0 70.7%
Final simplification70.7%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 55.0%
Taylor expanded in y around 0 43.6%
Taylor expanded in y around 0 26.7%
Final simplification26.7%
herbie shell --seed 2023293
(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))))