
(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%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.25e-283) (not (<= x 1.7e-140))) (+ x (* z (cos y))) (+ (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.25e-283) || !(x <= 1.7e-140)) {
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 <= (-4.25d-283)) .or. (.not. (x <= 1.7d-140))) 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 <= -4.25e-283) || !(x <= 1.7e-140)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = Math.sin(y) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.25e-283) or not (x <= 1.7e-140): tmp = x + (z * math.cos(y)) else: tmp = math.sin(y) + z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.25e-283) || !(x <= 1.7e-140)) 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 <= -4.25e-283) || ~((x <= 1.7e-140))) tmp = x + (z * cos(y)); else tmp = sin(y) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.25e-283], N[Not[LessEqual[x, 1.7e-140]], $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 -4.25 \cdot 10^{-283} \lor \neg \left(x \leq 1.7 \cdot 10^{-140}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y + z\\
\end{array}
\end{array}
if x < -4.24999999999999998e-283 or 1.70000000000000004e-140 < x Initial program 99.9%
Taylor expanded in x around inf 89.5%
if -4.24999999999999998e-283 < x < 1.70000000000000004e-140Initial program 99.9%
Taylor expanded in x around 0 99.9%
Taylor expanded in y around 0 84.3%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -150000.0) (not (<= z 7e-22))) (+ x (* z (cos y))) (+ (+ x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -150000.0) || !(z <= 7e-22)) {
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 <= (-150000.0d0)) .or. (.not. (z <= 7d-22))) 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 <= -150000.0) || !(z <= 7e-22)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = (x + Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -150000.0) or not (z <= 7e-22): 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 <= -150000.0) || !(z <= 7e-22)) 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 <= -150000.0) || ~((z <= 7e-22))) tmp = x + (z * cos(y)); else tmp = (x + sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -150000.0], N[Not[LessEqual[z, 7e-22]], $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 -150000 \lor \neg \left(z \leq 7 \cdot 10^{-22}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\end{array}
\end{array}
if z < -1.5e5 or 7.00000000000000011e-22 < z Initial program 99.9%
Taylor expanded in x around inf 99.6%
if -1.5e5 < z < 7.00000000000000011e-22Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= x -5.5e-30) (+ x z) (if (<= x 1.5e-281) (+ z (+ x y)) (if (<= x 7.6e-171) (sin y) (+ x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e-30) {
tmp = x + z;
} else if (x <= 1.5e-281) {
tmp = z + (x + y);
} else if (x <= 7.6e-171) {
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 <= (-5.5d-30)) then
tmp = x + z
else if (x <= 1.5d-281) then
tmp = z + (x + y)
else if (x <= 7.6d-171) 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 <= -5.5e-30) {
tmp = x + z;
} else if (x <= 1.5e-281) {
tmp = z + (x + y);
} else if (x <= 7.6e-171) {
tmp = Math.sin(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.5e-30: tmp = x + z elif x <= 1.5e-281: tmp = z + (x + y) elif x <= 7.6e-171: tmp = math.sin(y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.5e-30) tmp = Float64(x + z); elseif (x <= 1.5e-281) tmp = Float64(z + Float64(x + y)); elseif (x <= 7.6e-171) tmp = sin(y); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.5e-30) tmp = x + z; elseif (x <= 1.5e-281) tmp = z + (x + y); elseif (x <= 7.6e-171) tmp = sin(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.5e-30], N[(x + z), $MachinePrecision], If[LessEqual[x, 1.5e-281], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.6e-171], N[Sin[y], $MachinePrecision], N[(x + z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-30}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{-281}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-171}:\\
\;\;\;\;\sin y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -5.49999999999999976e-30 or 7.60000000000000043e-171 < x Initial program 100.0%
Taylor expanded in x around inf 91.6%
Taylor expanded in y around 0 77.4%
if -5.49999999999999976e-30 < x < 1.49999999999999987e-281Initial program 99.9%
Taylor expanded in y around 0 68.4%
Taylor expanded in y around 0 56.4%
+-commutative56.4%
Simplified56.4%
if 1.49999999999999987e-281 < x < 7.60000000000000043e-171Initial program 99.9%
Taylor expanded in x around 0 99.9%
Taylor expanded in y around 0 86.4%
Taylor expanded in z around 0 69.0%
Final simplification71.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e-91) (not (<= x 8.8e-30))) (+ x z) (+ (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e-91) || !(x <= 8.8e-30)) {
tmp = x + z;
} 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.95d-91)) .or. (.not. (x <= 8.8d-30))) then
tmp = x + z
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.95e-91) || !(x <= 8.8e-30)) {
tmp = x + z;
} else {
tmp = Math.sin(y) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.95e-91) or not (x <= 8.8e-30): tmp = x + z else: tmp = math.sin(y) + z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e-91) || !(x <= 8.8e-30)) tmp = Float64(x + z); else tmp = Float64(sin(y) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.95e-91) || ~((x <= 8.8e-30))) tmp = x + z; else tmp = sin(y) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e-91], N[Not[LessEqual[x, 8.8e-30]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-91} \lor \neg \left(x \leq 8.8 \cdot 10^{-30}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;\sin y + z\\
\end{array}
\end{array}
if x < -1.94999999999999997e-91 or 8.79999999999999933e-30 < x Initial program 100.0%
Taylor expanded in x around inf 96.2%
Taylor expanded in y around 0 85.0%
if -1.94999999999999997e-91 < x < 8.79999999999999933e-30Initial program 99.9%
Taylor expanded in x around 0 94.3%
Taylor expanded in y around 0 67.2%
Final simplification77.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e+72) (not (<= y 1.02e+34))) (+ x z) (+ z (+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e+72) || !(y <= 1.02e+34)) {
tmp = x + z;
} else {
tmp = z + (x + 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 ((y <= (-1.1d+72)) .or. (.not. (y <= 1.02d+34))) then
tmp = x + z
else
tmp = z + (x + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e+72) || !(y <= 1.02e+34)) {
tmp = x + z;
} else {
tmp = z + (x + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e+72) or not (y <= 1.02e+34): tmp = x + z else: tmp = z + (x + y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e+72) || !(y <= 1.02e+34)) tmp = Float64(x + z); else tmp = Float64(z + Float64(x + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.1e+72) || ~((y <= 1.02e+34))) tmp = x + z; else tmp = z + (x + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e+72], N[Not[LessEqual[y, 1.02e+34]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+72} \lor \neg \left(y \leq 1.02 \cdot 10^{+34}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + y\right)\\
\end{array}
\end{array}
if y < -1.1e72 or 1.02e34 < y Initial program 99.9%
Taylor expanded in x around inf 75.0%
Taylor expanded in y around 0 38.4%
if -1.1e72 < y < 1.02e34Initial program 100.0%
Taylor expanded in y around 0 93.2%
Taylor expanded in y around 0 88.4%
+-commutative88.4%
Simplified88.4%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.6e-177) (not (<= x 4e-142))) (+ x z) (+ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.6e-177) || !(x <= 4e-142)) {
tmp = x + z;
} else {
tmp = 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 <= (-6.6d-177)) .or. (.not. (x <= 4d-142))) then
tmp = x + z
else
tmp = y + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.6e-177) || !(x <= 4e-142)) {
tmp = x + z;
} else {
tmp = y + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.6e-177) or not (x <= 4e-142): tmp = x + z else: tmp = y + z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.6e-177) || !(x <= 4e-142)) tmp = Float64(x + z); else tmp = Float64(y + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.6e-177) || ~((x <= 4e-142))) tmp = x + z; else tmp = y + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.6e-177], N[Not[LessEqual[x, 4e-142]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{-177} \lor \neg \left(x \leq 4 \cdot 10^{-142}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;y + z\\
\end{array}
\end{array}
if x < -6.5999999999999999e-177 or 4.0000000000000002e-142 < x Initial program 100.0%
Taylor expanded in x around inf 90.1%
Taylor expanded in y around 0 74.5%
if -6.5999999999999999e-177 < x < 4.0000000000000002e-142Initial program 99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in y around 0 74.1%
Taylor expanded in y around 0 51.2%
+-commutative51.2%
Simplified51.2%
Final simplification68.5%
(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.7%
Taylor expanded in y around 0 63.6%
Final simplification63.6%
herbie shell --seed 2024013
(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))))