
(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 8 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 (fma (+ y z) x (- z)))
double code(double x, double y, double z) {
return fma((y + z), x, -z);
}
function code(x, y, z) return fma(Float64(y + z), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(y + z), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + z, x, -z\right)
\end{array}
Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
metadata-eval98.8%
distribute-rgt-in98.8%
neg-mul-198.8%
associate-+l+98.8%
distribute-lft-in100.0%
*-commutative100.0%
fma-def100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -7.5e+190)
(* z x)
(if (<= x -2.2e+128)
(* y x)
(if (<= x -5.4e+57)
(* z x)
(if (<= x -5.7e-14)
(* y x)
(if (<= x 8e-99)
(- z)
(if (or (<= x 1.25e+20) (and (not (<= x 2.2e+87)) (<= x 4.8e+141)))
(* y x)
(* z x))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e+190) {
tmp = z * x;
} else if (x <= -2.2e+128) {
tmp = y * x;
} else if (x <= -5.4e+57) {
tmp = z * x;
} else if (x <= -5.7e-14) {
tmp = y * x;
} else if (x <= 8e-99) {
tmp = -z;
} else if ((x <= 1.25e+20) || (!(x <= 2.2e+87) && (x <= 4.8e+141))) {
tmp = y * x;
} else {
tmp = z * 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 <= (-7.5d+190)) then
tmp = z * x
else if (x <= (-2.2d+128)) then
tmp = y * x
else if (x <= (-5.4d+57)) then
tmp = z * x
else if (x <= (-5.7d-14)) then
tmp = y * x
else if (x <= 8d-99) then
tmp = -z
else if ((x <= 1.25d+20) .or. (.not. (x <= 2.2d+87)) .and. (x <= 4.8d+141)) then
tmp = y * x
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e+190) {
tmp = z * x;
} else if (x <= -2.2e+128) {
tmp = y * x;
} else if (x <= -5.4e+57) {
tmp = z * x;
} else if (x <= -5.7e-14) {
tmp = y * x;
} else if (x <= 8e-99) {
tmp = -z;
} else if ((x <= 1.25e+20) || (!(x <= 2.2e+87) && (x <= 4.8e+141))) {
tmp = y * x;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.5e+190: tmp = z * x elif x <= -2.2e+128: tmp = y * x elif x <= -5.4e+57: tmp = z * x elif x <= -5.7e-14: tmp = y * x elif x <= 8e-99: tmp = -z elif (x <= 1.25e+20) or (not (x <= 2.2e+87) and (x <= 4.8e+141)): tmp = y * x else: tmp = z * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.5e+190) tmp = Float64(z * x); elseif (x <= -2.2e+128) tmp = Float64(y * x); elseif (x <= -5.4e+57) tmp = Float64(z * x); elseif (x <= -5.7e-14) tmp = Float64(y * x); elseif (x <= 8e-99) tmp = Float64(-z); elseif ((x <= 1.25e+20) || (!(x <= 2.2e+87) && (x <= 4.8e+141))) tmp = Float64(y * x); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.5e+190) tmp = z * x; elseif (x <= -2.2e+128) tmp = y * x; elseif (x <= -5.4e+57) tmp = z * x; elseif (x <= -5.7e-14) tmp = y * x; elseif (x <= 8e-99) tmp = -z; elseif ((x <= 1.25e+20) || (~((x <= 2.2e+87)) && (x <= 4.8e+141))) tmp = y * x; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.5e+190], N[(z * x), $MachinePrecision], If[LessEqual[x, -2.2e+128], N[(y * x), $MachinePrecision], If[LessEqual[x, -5.4e+57], N[(z * x), $MachinePrecision], If[LessEqual[x, -5.7e-14], N[(y * x), $MachinePrecision], If[LessEqual[x, 8e-99], (-z), If[Or[LessEqual[x, 1.25e+20], And[N[Not[LessEqual[x, 2.2e+87]], $MachinePrecision], LessEqual[x, 4.8e+141]]], N[(y * x), $MachinePrecision], N[(z * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+190}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{+128}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -5.4 \cdot 10^{+57}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -5.7 \cdot 10^{-14}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 8 \cdot 10^{-99}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+20} \lor \neg \left(x \leq 2.2 \cdot 10^{+87}\right) \land x \leq 4.8 \cdot 10^{+141}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if x < -7.4999999999999994e190 or -2.20000000000000017e128 < x < -5.3999999999999997e57 or 1.25e20 < x < 2.2000000000000001e87 or 4.79999999999999995e141 < x Initial program 96.3%
Taylor expanded in x around inf 99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 73.3%
if -7.4999999999999994e190 < x < -2.20000000000000017e128 or -5.3999999999999997e57 < x < -5.69999999999999969e-14 or 8.0000000000000002e-99 < x < 1.25e20 or 2.2000000000000001e87 < x < 4.79999999999999995e141Initial program 100.0%
Taylor expanded in y around inf 78.1%
if -5.69999999999999969e-14 < x < 8.0000000000000002e-99Initial program 100.0%
Taylor expanded in x around 0 78.4%
neg-mul-178.4%
Simplified78.4%
Final simplification76.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-14) (not (<= x 8e-99))) (* (+ y z) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-14) || !(x <= 8e-99)) {
tmp = (y + z) * x;
} else {
tmp = -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 <= (-6d-14)) .or. (.not. (x <= 8d-99))) then
tmp = (y + z) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-14) || !(x <= 8e-99)) {
tmp = (y + z) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-14) or not (x <= 8e-99): tmp = (y + z) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-14) || !(x <= 8e-99)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e-14) || ~((x <= 8e-99))) tmp = (y + z) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-14], N[Not[LessEqual[x, 8e-99]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-14} \lor \neg \left(x \leq 8 \cdot 10^{-99}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.9999999999999997e-14 or 8.0000000000000002e-99 < x Initial program 97.8%
Taylor expanded in x around inf 95.2%
+-commutative95.2%
Simplified95.2%
if -5.9999999999999997e-14 < x < 8.0000000000000002e-99Initial program 100.0%
Taylor expanded in x around 0 78.4%
neg-mul-178.4%
Simplified78.4%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e-14) (not (<= x 3.4e-91))) (* (+ y z) x) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-14) || !(x <= 3.4e-91)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-3.3d-14)) .or. (.not. (x <= 3.4d-91))) then
tmp = (y + z) * x
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-14) || !(x <= 3.4e-91)) {
tmp = (y + z) * x;
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e-14) or not (x <= 3.4e-91): tmp = (y + z) * x else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e-14) || !(x <= 3.4e-91)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.3e-14) || ~((x <= 3.4e-91))) tmp = (y + z) * x; else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e-14], N[Not[LessEqual[x, 3.4e-91]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-14} \lor \neg \left(x \leq 3.4 \cdot 10^{-91}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -3.2999999999999998e-14 or 3.40000000000000027e-91 < x Initial program 97.8%
Taylor expanded in x around inf 95.2%
+-commutative95.2%
Simplified95.2%
if -3.2999999999999998e-14 < x < 3.40000000000000027e-91Initial program 100.0%
Taylor expanded in y around 0 78.6%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e-14) (not (<= x 1.25e-96))) (* (+ y z) x) (- (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-14) || !(x <= 1.25e-96)) {
tmp = (y + z) * x;
} else {
tmp = (z * 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.55d-14)) .or. (.not. (x <= 1.25d-96))) then
tmp = (y + z) * x
else
tmp = (z * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e-14) || !(x <= 1.25e-96)) {
tmp = (y + z) * x;
} else {
tmp = (z * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e-14) or not (x <= 1.25e-96): tmp = (y + z) * x else: tmp = (z * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e-14) || !(x <= 1.25e-96)) tmp = Float64(Float64(y + z) * x); else tmp = Float64(Float64(z * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.55e-14) || ~((x <= 1.25e-96))) tmp = (y + z) * x; else tmp = (z * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e-14], N[Not[LessEqual[x, 1.25e-96]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-14} \lor \neg \left(x \leq 1.25 \cdot 10^{-96}\right):\\
\;\;\;\;\left(y + z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x - z\\
\end{array}
\end{array}
if x < -1.55000000000000002e-14 or 1.24999999999999999e-96 < x Initial program 97.8%
Taylor expanded in x around inf 95.2%
+-commutative95.2%
Simplified95.2%
if -1.55000000000000002e-14 < x < 1.24999999999999999e-96Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 78.6%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e-14) (not (<= x 4e-90))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-14) || !(x <= 4e-90)) {
tmp = y * x;
} else {
tmp = -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.8d-14)) .or. (.not. (x <= 4d-90))) then
tmp = y * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-14) || !(x <= 4e-90)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-14) or not (x <= 4e-90): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-14) || !(x <= 4e-90)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.8e-14) || ~((x <= 4e-90))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-14], N[Not[LessEqual[x, 4e-90]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-14} \lor \neg \left(x \leq 4 \cdot 10^{-90}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.8e-14 or 3.99999999999999998e-90 < x Initial program 97.8%
Taylor expanded in y around inf 51.7%
if -4.8e-14 < x < 3.99999999999999998e-90Initial program 100.0%
Taylor expanded in x around 0 78.4%
neg-mul-178.4%
Simplified78.4%
Final simplification63.9%
(FPCore (x y z) :precision binary64 (- (* (+ y z) x) z))
double code(double x, double y, double z) {
return ((y + z) * 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 = ((y + z) * x) - z
end function
public static double code(double x, double y, double z) {
return ((y + z) * x) - z;
}
def code(x, y, z): return ((y + z) * x) - z
function code(x, y, z) return Float64(Float64(Float64(y + z) * x) - z) end
function tmp = code(x, y, z) tmp = ((y + z) * x) - z; end
code[x_, y_, z_] := N[(N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + z\right) \cdot x - z
\end{array}
Initial program 98.8%
*-commutative98.8%
distribute-rgt-out--98.8%
cancel-sign-sub-inv98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(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.8%
Taylor expanded in x around 0 39.7%
neg-mul-139.7%
Simplified39.7%
Final simplification39.7%
herbie shell --seed 2023322
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))