
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - 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 + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
metadata-eval98.4%
neg-mul-198.4%
associate-+r+98.4%
unsub-neg98.4%
+-commutative98.4%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.05e+93)
(* x z)
(if (<= x -9.5e-66)
(* x y)
(if (<= x 1.55e-138)
(- z)
(if (<= x 3.5e-79)
(* x y)
(if (<= x 1.0)
(- z)
(if (<= x 4.5e+255)
(* x z)
(if (<= x 1.6e+303) (* x y) (* x z)))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e+93) {
tmp = x * z;
} else if (x <= -9.5e-66) {
tmp = x * y;
} else if (x <= 1.55e-138) {
tmp = -z;
} else if (x <= 3.5e-79) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 4.5e+255) {
tmp = x * z;
} else if (x <= 1.6e+303) {
tmp = 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 (x <= (-1.05d+93)) then
tmp = x * z
else if (x <= (-9.5d-66)) then
tmp = x * y
else if (x <= 1.55d-138) then
tmp = -z
else if (x <= 3.5d-79) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = -z
else if (x <= 4.5d+255) then
tmp = x * z
else if (x <= 1.6d+303) then
tmp = 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 (x <= -1.05e+93) {
tmp = x * z;
} else if (x <= -9.5e-66) {
tmp = x * y;
} else if (x <= 1.55e-138) {
tmp = -z;
} else if (x <= 3.5e-79) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else if (x <= 4.5e+255) {
tmp = x * z;
} else if (x <= 1.6e+303) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e+93: tmp = x * z elif x <= -9.5e-66: tmp = x * y elif x <= 1.55e-138: tmp = -z elif x <= 3.5e-79: tmp = x * y elif x <= 1.0: tmp = -z elif x <= 4.5e+255: tmp = x * z elif x <= 1.6e+303: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e+93) tmp = Float64(x * z); elseif (x <= -9.5e-66) tmp = Float64(x * y); elseif (x <= 1.55e-138) tmp = Float64(-z); elseif (x <= 3.5e-79) tmp = Float64(x * y); elseif (x <= 1.0) tmp = Float64(-z); elseif (x <= 4.5e+255) tmp = Float64(x * z); elseif (x <= 1.6e+303) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.05e+93) tmp = x * z; elseif (x <= -9.5e-66) tmp = x * y; elseif (x <= 1.55e-138) tmp = -z; elseif (x <= 3.5e-79) tmp = x * y; elseif (x <= 1.0) tmp = -z; elseif (x <= 4.5e+255) tmp = x * z; elseif (x <= 1.6e+303) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e+93], N[(x * z), $MachinePrecision], If[LessEqual[x, -9.5e-66], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.55e-138], (-z), If[LessEqual[x, 3.5e-79], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], (-z), If[LessEqual[x, 4.5e+255], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.6e+303], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{+93}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{-66}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-138}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-79}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+255}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+303}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.0499999999999999e93 or 1 < x < 4.49999999999999964e255 or 1.6000000000000001e303 < x Initial program 97.8%
Taylor expanded in y around 0 68.8%
sub-neg68.8%
metadata-eval68.8%
distribute-rgt-in68.8%
neg-mul-168.8%
sub-neg68.8%
*-commutative68.8%
Simplified68.8%
Taylor expanded in x around inf 68.6%
*-commutative68.6%
Simplified68.6%
if -1.0499999999999999e93 < x < -9.5000000000000004e-66 or 1.5499999999999999e-138 < x < 3.5000000000000003e-79 or 4.49999999999999964e255 < x < 1.6000000000000001e303Initial program 96.1%
Taylor expanded in y around inf 67.9%
if -9.5000000000000004e-66 < x < 1.5499999999999999e-138 or 3.5000000000000003e-79 < x < 1Initial program 100.0%
Taylor expanded in x around 0 76.1%
neg-mul-176.1%
Simplified76.1%
Final simplification71.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))))
(if (<= x -1.6e-65)
t_0
(if (<= x 1.55e-138)
(- z)
(if (<= x 3.3e-79) (* x y) (if (<= x 4.6e-10) (- z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -1.6e-65) {
tmp = t_0;
} else if (x <= 1.55e-138) {
tmp = -z;
} else if (x <= 3.3e-79) {
tmp = x * y;
} else if (x <= 4.6e-10) {
tmp = -z;
} 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 = x * (z + y)
if (x <= (-1.6d-65)) then
tmp = t_0
else if (x <= 1.55d-138) then
tmp = -z
else if (x <= 3.3d-79) then
tmp = x * y
else if (x <= 4.6d-10) then
tmp = -z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -1.6e-65) {
tmp = t_0;
} else if (x <= 1.55e-138) {
tmp = -z;
} else if (x <= 3.3e-79) {
tmp = x * y;
} else if (x <= 4.6e-10) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) tmp = 0 if x <= -1.6e-65: tmp = t_0 elif x <= 1.55e-138: tmp = -z elif x <= 3.3e-79: tmp = x * y elif x <= 4.6e-10: tmp = -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + y)) tmp = 0.0 if (x <= -1.6e-65) tmp = t_0; elseif (x <= 1.55e-138) tmp = Float64(-z); elseif (x <= 3.3e-79) tmp = Float64(x * y); elseif (x <= 4.6e-10) tmp = Float64(-z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + y); tmp = 0.0; if (x <= -1.6e-65) tmp = t_0; elseif (x <= 1.55e-138) tmp = -z; elseif (x <= 3.3e-79) tmp = x * y; elseif (x <= 4.6e-10) tmp = -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.6e-65], t$95$0, If[LessEqual[x, 1.55e-138], (-z), If[LessEqual[x, 3.3e-79], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.6e-10], (-z), t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -1.6 \cdot 10^{-65}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-138}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{-79}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{-10}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.6e-65 or 4.60000000000000014e-10 < x Initial program 97.0%
Taylor expanded in x around inf 98.0%
+-commutative98.0%
Simplified98.0%
if -1.6e-65 < x < 1.5499999999999999e-138 or 3.2999999999999998e-79 < x < 4.60000000000000014e-10Initial program 100.0%
Taylor expanded in x around 0 76.1%
neg-mul-176.1%
Simplified76.1%
if 1.5499999999999999e-138 < x < 3.2999999999999998e-79Initial program 100.0%
Taylor expanded in y around inf 73.4%
Final simplification87.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))) (t_1 (- (* x z) z)))
(if (<= x -2.6e-65)
t_0
(if (<= x 1.55e-138)
t_1
(if (<= x 3.3e-79) (* x y) (if (<= x 1020000000000.0) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double t_1 = (x * z) - z;
double tmp;
if (x <= -2.6e-65) {
tmp = t_0;
} else if (x <= 1.55e-138) {
tmp = t_1;
} else if (x <= 3.3e-79) {
tmp = x * y;
} else if (x <= 1020000000000.0) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = x * (z + y)
t_1 = (x * z) - z
if (x <= (-2.6d-65)) then
tmp = t_0
else if (x <= 1.55d-138) then
tmp = t_1
else if (x <= 3.3d-79) then
tmp = x * y
else if (x <= 1020000000000.0d0) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (z + y);
double t_1 = (x * z) - z;
double tmp;
if (x <= -2.6e-65) {
tmp = t_0;
} else if (x <= 1.55e-138) {
tmp = t_1;
} else if (x <= 3.3e-79) {
tmp = x * y;
} else if (x <= 1020000000000.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) t_1 = (x * z) - z tmp = 0 if x <= -2.6e-65: tmp = t_0 elif x <= 1.55e-138: tmp = t_1 elif x <= 3.3e-79: tmp = x * y elif x <= 1020000000000.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + y)) t_1 = Float64(Float64(x * z) - z) tmp = 0.0 if (x <= -2.6e-65) tmp = t_0; elseif (x <= 1.55e-138) tmp = t_1; elseif (x <= 3.3e-79) tmp = Float64(x * y); elseif (x <= 1020000000000.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + y); t_1 = (x * z) - z; tmp = 0.0; if (x <= -2.6e-65) tmp = t_0; elseif (x <= 1.55e-138) tmp = t_1; elseif (x <= 3.3e-79) tmp = x * y; elseif (x <= 1020000000000.0) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[x, -2.6e-65], t$95$0, If[LessEqual[x, 1.55e-138], t$95$1, If[LessEqual[x, 3.3e-79], N[(x * y), $MachinePrecision], If[LessEqual[x, 1020000000000.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
t_1 := x \cdot z - z\\
\mathbf{if}\;x \leq -2.6 \cdot 10^{-65}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-138}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{-79}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1020000000000:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -2.6000000000000001e-65 or 1.02e12 < x Initial program 97.0%
Taylor expanded in x around inf 98.1%
+-commutative98.1%
Simplified98.1%
if -2.6000000000000001e-65 < x < 1.5499999999999999e-138 or 3.2999999999999998e-79 < x < 1.02e12Initial program 100.0%
Taylor expanded in y around 0 76.8%
sub-neg76.8%
metadata-eval76.8%
distribute-rgt-in76.8%
neg-mul-176.8%
sub-neg76.8%
*-commutative76.8%
Simplified76.8%
if 1.5499999999999999e-138 < x < 3.2999999999999998e-79Initial program 100.0%
Taylor expanded in y around inf 73.4%
Final simplification87.9%
(FPCore (x y z)
:precision binary64
(if (<= x -2.65e-65)
(* x y)
(if (or (<= x 1.55e-138) (and (not (<= x 3.3e-79)) (<= x 3.4e-9)))
(- z)
(* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.65e-65) {
tmp = x * y;
} else if ((x <= 1.55e-138) || (!(x <= 3.3e-79) && (x <= 3.4e-9))) {
tmp = -z;
} else {
tmp = 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 (x <= (-2.65d-65)) then
tmp = x * y
else if ((x <= 1.55d-138) .or. (.not. (x <= 3.3d-79)) .and. (x <= 3.4d-9)) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.65e-65) {
tmp = x * y;
} else if ((x <= 1.55e-138) || (!(x <= 3.3e-79) && (x <= 3.4e-9))) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.65e-65: tmp = x * y elif (x <= 1.55e-138) or (not (x <= 3.3e-79) and (x <= 3.4e-9)): tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.65e-65) tmp = Float64(x * y); elseif ((x <= 1.55e-138) || (!(x <= 3.3e-79) && (x <= 3.4e-9))) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.65e-65) tmp = x * y; elseif ((x <= 1.55e-138) || (~((x <= 3.3e-79)) && (x <= 3.4e-9))) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.65e-65], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 1.55e-138], And[N[Not[LessEqual[x, 3.3e-79]], $MachinePrecision], LessEqual[x, 3.4e-9]]], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.65 \cdot 10^{-65}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{-138} \lor \neg \left(x \leq 3.3 \cdot 10^{-79}\right) \land x \leq 3.4 \cdot 10^{-9}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.65000000000000019e-65 or 1.5499999999999999e-138 < x < 3.2999999999999998e-79 or 3.3999999999999998e-9 < x Initial program 97.2%
Taylor expanded in y around inf 47.3%
if -2.65000000000000019e-65 < x < 1.5499999999999999e-138 or 3.2999999999999998e-79 < x < 3.3999999999999998e-9Initial program 100.0%
Taylor expanded in x around 0 76.1%
neg-mul-176.1%
Simplified76.1%
Final simplification59.8%
(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 Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.4%
Taylor expanded in x around 0 36.1%
neg-mul-136.1%
Simplified36.1%
Final simplification36.1%
herbie shell --seed 2023271
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))