
(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 (+ (* z (cos y)) (+ x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x + 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 = (z * cos(y)) + (x + sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x + Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x + math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x + sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x + sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + \left(x + \sin y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1350000000.0) (not (<= x 4.3e+43))) (+ x z) (+ (sin y) (* z (cos y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1350000000.0) || !(x <= 4.3e+43)) {
tmp = x + z;
} else {
tmp = sin(y) + (z * cos(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 <= (-1350000000.0d0)) .or. (.not. (x <= 4.3d+43))) then
tmp = x + z
else
tmp = sin(y) + (z * cos(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1350000000.0) || !(x <= 4.3e+43)) {
tmp = x + z;
} else {
tmp = Math.sin(y) + (z * Math.cos(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1350000000.0) or not (x <= 4.3e+43): tmp = x + z else: tmp = math.sin(y) + (z * math.cos(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1350000000.0) || !(x <= 4.3e+43)) tmp = Float64(x + z); else tmp = Float64(sin(y) + Float64(z * cos(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1350000000.0) || ~((x <= 4.3e+43))) tmp = x + z; else tmp = sin(y) + (z * cos(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1350000000.0], N[Not[LessEqual[x, 4.3e+43]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1350000000 \lor \neg \left(x \leq 4.3 \cdot 10^{+43}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;\sin y + z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.35e9 or 4.3e43 < x Initial program 100.0%
Taylor expanded in y around 0 91.1%
+-commutative91.1%
Simplified91.1%
if -1.35e9 < x < 4.3e43Initial program 99.9%
Taylor expanded in x around 0 91.7%
Final simplification91.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= x -780000000.0)
(+ x z)
(if (<= x -9e-147)
t_0
(if (<= x -2.5e-180)
(sin y)
(if (<= x -1.7e-255)
t_0
(if (<= x 1.35e-278) (sin y) (if (<= x 4.3e+43) t_0 (+ x z)))))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (x <= -780000000.0) {
tmp = x + z;
} else if (x <= -9e-147) {
tmp = t_0;
} else if (x <= -2.5e-180) {
tmp = sin(y);
} else if (x <= -1.7e-255) {
tmp = t_0;
} else if (x <= 1.35e-278) {
tmp = sin(y);
} else if (x <= 4.3e+43) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (x <= (-780000000.0d0)) then
tmp = x + z
else if (x <= (-9d-147)) then
tmp = t_0
else if (x <= (-2.5d-180)) then
tmp = sin(y)
else if (x <= (-1.7d-255)) then
tmp = t_0
else if (x <= 1.35d-278) then
tmp = sin(y)
else if (x <= 4.3d+43) then
tmp = t_0
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (x <= -780000000.0) {
tmp = x + z;
} else if (x <= -9e-147) {
tmp = t_0;
} else if (x <= -2.5e-180) {
tmp = Math.sin(y);
} else if (x <= -1.7e-255) {
tmp = t_0;
} else if (x <= 1.35e-278) {
tmp = Math.sin(y);
} else if (x <= 4.3e+43) {
tmp = t_0;
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if x <= -780000000.0: tmp = x + z elif x <= -9e-147: tmp = t_0 elif x <= -2.5e-180: tmp = math.sin(y) elif x <= -1.7e-255: tmp = t_0 elif x <= 1.35e-278: tmp = math.sin(y) elif x <= 4.3e+43: tmp = t_0 else: tmp = x + z return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (x <= -780000000.0) tmp = Float64(x + z); elseif (x <= -9e-147) tmp = t_0; elseif (x <= -2.5e-180) tmp = sin(y); elseif (x <= -1.7e-255) tmp = t_0; elseif (x <= 1.35e-278) tmp = sin(y); elseif (x <= 4.3e+43) tmp = t_0; else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (x <= -780000000.0) tmp = x + z; elseif (x <= -9e-147) tmp = t_0; elseif (x <= -2.5e-180) tmp = sin(y); elseif (x <= -1.7e-255) tmp = t_0; elseif (x <= 1.35e-278) tmp = sin(y); elseif (x <= 4.3e+43) tmp = t_0; else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -780000000.0], N[(x + z), $MachinePrecision], If[LessEqual[x, -9e-147], t$95$0, If[LessEqual[x, -2.5e-180], N[Sin[y], $MachinePrecision], If[LessEqual[x, -1.7e-255], t$95$0, If[LessEqual[x, 1.35e-278], N[Sin[y], $MachinePrecision], If[LessEqual[x, 4.3e+43], t$95$0, N[(x + z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;x \leq -780000000:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq -9 \cdot 10^{-147}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -2.5 \cdot 10^{-180}:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;x \leq -1.7 \cdot 10^{-255}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1.35 \cdot 10^{-278}:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;x \leq 4.3 \cdot 10^{+43}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -7.8e8 or 4.3e43 < x Initial program 100.0%
Taylor expanded in y around 0 91.1%
+-commutative91.1%
Simplified91.1%
if -7.8e8 < x < -8.99999999999999946e-147 or -2.5000000000000001e-180 < x < -1.69999999999999992e-255 or 1.3500000000000001e-278 < x < 4.3e43Initial program 99.8%
Taylor expanded in z around inf 68.4%
if -8.99999999999999946e-147 < x < -2.5000000000000001e-180 or -1.69999999999999992e-255 < x < 1.3500000000000001e-278Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around 0 71.2%
Final simplification79.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -3.2e+144)
t_0
(if (<= z -1.4e-50) (+ x z) (if (<= z 4.5e+89) (+ x (sin y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -3.2e+144) {
tmp = t_0;
} else if (z <= -1.4e-50) {
tmp = x + z;
} else if (z <= 4.5e+89) {
tmp = x + 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 = z * cos(y)
if (z <= (-3.2d+144)) then
tmp = t_0
else if (z <= (-1.4d-50)) then
tmp = x + z
else if (z <= 4.5d+89) then
tmp = x + 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 = z * Math.cos(y);
double tmp;
if (z <= -3.2e+144) {
tmp = t_0;
} else if (z <= -1.4e-50) {
tmp = x + z;
} else if (z <= 4.5e+89) {
tmp = x + Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -3.2e+144: tmp = t_0 elif z <= -1.4e-50: tmp = x + z elif z <= 4.5e+89: tmp = x + math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -3.2e+144) tmp = t_0; elseif (z <= -1.4e-50) tmp = Float64(x + z); elseif (z <= 4.5e+89) tmp = Float64(x + sin(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -3.2e+144) tmp = t_0; elseif (z <= -1.4e-50) tmp = x + z; elseif (z <= 4.5e+89) tmp = x + sin(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -3.2e+144], t$95$0, If[LessEqual[z, -1.4e-50], N[(x + z), $MachinePrecision], If[LessEqual[z, 4.5e+89], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -3.2 \cdot 10^{+144}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{-50}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+89}:\\
\;\;\;\;x + \sin y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.2000000000000001e144 or 4.5e89 < z Initial program 99.8%
Taylor expanded in z around inf 79.3%
if -3.2000000000000001e144 < z < -1.3999999999999999e-50Initial program 99.9%
Taylor expanded in y around 0 74.8%
+-commutative74.8%
Simplified74.8%
if -1.3999999999999999e-50 < z < 4.5e89Initial program 100.0%
Taylor expanded in z around 0 87.3%
+-commutative87.3%
Simplified87.3%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.5e+48) (not (<= y 2.4e+122))) (+ x z) (+ z (+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e+48) || !(y <= 2.4e+122)) {
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 <= (-3.5d+48)) .or. (.not. (y <= 2.4d+122))) 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 <= -3.5e+48) || !(y <= 2.4e+122)) {
tmp = x + z;
} else {
tmp = z + (x + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.5e+48) or not (y <= 2.4e+122): tmp = x + z else: tmp = z + (x + y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.5e+48) || !(y <= 2.4e+122)) 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 <= -3.5e+48) || ~((y <= 2.4e+122))) tmp = x + z; else tmp = z + (x + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.5e+48], N[Not[LessEqual[y, 2.4e+122]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+48} \lor \neg \left(y \leq 2.4 \cdot 10^{+122}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + y\right)\\
\end{array}
\end{array}
if y < -3.4999999999999997e48 or 2.4000000000000002e122 < y Initial program 99.8%
Taylor expanded in y around 0 40.4%
+-commutative40.4%
Simplified40.4%
if -3.4999999999999997e48 < y < 2.4000000000000002e122Initial program 100.0%
Taylor expanded in y around 0 83.8%
associate-+r+83.8%
Simplified83.8%
Final simplification68.2%
(FPCore (x y z) :precision binary64 (if (<= x -750000000.0) x (if (<= x 2.4e-43) (+ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -750000000.0) {
tmp = x;
} else if (x <= 2.4e-43) {
tmp = y + z;
} else {
tmp = 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 (x <= (-750000000.0d0)) then
tmp = x
else if (x <= 2.4d-43) then
tmp = y + z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -750000000.0) {
tmp = x;
} else if (x <= 2.4e-43) {
tmp = y + z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -750000000.0: tmp = x elif x <= 2.4e-43: tmp = y + z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -750000000.0) tmp = x; elseif (x <= 2.4e-43) tmp = Float64(y + z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -750000000.0) tmp = x; elseif (x <= 2.4e-43) tmp = y + z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -750000000.0], x, If[LessEqual[x, 2.4e-43], N[(y + z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -750000000:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{-43}:\\
\;\;\;\;y + z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -7.5e8 or 2.4000000000000002e-43 < x Initial program 99.9%
Taylor expanded in x around inf 75.5%
if -7.5e8 < x < 2.4000000000000002e-43Initial program 99.9%
Taylor expanded in x around 0 94.2%
Taylor expanded in y around 0 41.1%
Final simplification59.9%
(FPCore (x y z) :precision binary64 (if (<= x -750000000.0) x (if (<= x 7e-41) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -750000000.0) {
tmp = x;
} else if (x <= 7e-41) {
tmp = z;
} else {
tmp = 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 (x <= (-750000000.0d0)) then
tmp = x
else if (x <= 7d-41) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -750000000.0) {
tmp = x;
} else if (x <= 7e-41) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -750000000.0: tmp = x elif x <= 7e-41: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -750000000.0) tmp = x; elseif (x <= 7e-41) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -750000000.0) tmp = x; elseif (x <= 7e-41) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -750000000.0], x, If[LessEqual[x, 7e-41], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -750000000:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-41}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -7.5e8 or 6.9999999999999999e-41 < x Initial program 99.9%
Taylor expanded in x around inf 76.0%
if -7.5e8 < x < 6.9999999999999999e-41Initial program 99.9%
Taylor expanded in z around inf 60.7%
Taylor expanded in y around 0 34.9%
Final simplification57.2%
(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 y around 0 64.5%
+-commutative64.5%
Simplified64.5%
Final simplification64.5%
(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 x around inf 44.7%
Final simplification44.7%
herbie shell --seed 2024020
(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))))