
(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 99.2%
*-commutative99.2%
distribute-rgt-out--99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
neg-mul-199.2%
associate-+r+99.2%
unsub-neg99.2%
+-commutative99.2%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.25e+176)
(* x y)
(if (<= x -3.5e+140)
(* x z)
(if (<= x -7e+14)
(* x y)
(if (<= x 3.6e-122)
(- z)
(if (or (<= x 9.6e+117) (and (not (<= x 8.6e+143)) (<= x 5.8e+174)))
(* x y)
(* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e+176) {
tmp = x * y;
} else if (x <= -3.5e+140) {
tmp = x * z;
} else if (x <= -7e+14) {
tmp = x * y;
} else if (x <= 3.6e-122) {
tmp = -z;
} else if ((x <= 9.6e+117) || (!(x <= 8.6e+143) && (x <= 5.8e+174))) {
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.25d+176)) then
tmp = x * y
else if (x <= (-3.5d+140)) then
tmp = x * z
else if (x <= (-7d+14)) then
tmp = x * y
else if (x <= 3.6d-122) then
tmp = -z
else if ((x <= 9.6d+117) .or. (.not. (x <= 8.6d+143)) .and. (x <= 5.8d+174)) 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.25e+176) {
tmp = x * y;
} else if (x <= -3.5e+140) {
tmp = x * z;
} else if (x <= -7e+14) {
tmp = x * y;
} else if (x <= 3.6e-122) {
tmp = -z;
} else if ((x <= 9.6e+117) || (!(x <= 8.6e+143) && (x <= 5.8e+174))) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.25e+176: tmp = x * y elif x <= -3.5e+140: tmp = x * z elif x <= -7e+14: tmp = x * y elif x <= 3.6e-122: tmp = -z elif (x <= 9.6e+117) or (not (x <= 8.6e+143) and (x <= 5.8e+174)): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.25e+176) tmp = Float64(x * y); elseif (x <= -3.5e+140) tmp = Float64(x * z); elseif (x <= -7e+14) tmp = Float64(x * y); elseif (x <= 3.6e-122) tmp = Float64(-z); elseif ((x <= 9.6e+117) || (!(x <= 8.6e+143) && (x <= 5.8e+174))) 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.25e+176) tmp = x * y; elseif (x <= -3.5e+140) tmp = x * z; elseif (x <= -7e+14) tmp = x * y; elseif (x <= 3.6e-122) tmp = -z; elseif ((x <= 9.6e+117) || (~((x <= 8.6e+143)) && (x <= 5.8e+174))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.25e+176], N[(x * y), $MachinePrecision], If[LessEqual[x, -3.5e+140], N[(x * z), $MachinePrecision], If[LessEqual[x, -7e+14], N[(x * y), $MachinePrecision], If[LessEqual[x, 3.6e-122], (-z), If[Or[LessEqual[x, 9.6e+117], And[N[Not[LessEqual[x, 8.6e+143]], $MachinePrecision], LessEqual[x, 5.8e+174]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+176}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -3.5 \cdot 10^{+140}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7 \cdot 10^{+14}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{-122}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{+117} \lor \neg \left(x \leq 8.6 \cdot 10^{+143}\right) \land x \leq 5.8 \cdot 10^{+174}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.25e176 or -3.49999999999999989e140 < x < -7e14 or 3.59999999999999994e-122 < x < 9.5999999999999996e117 or 8.60000000000000003e143 < x < 5.7999999999999999e174Initial program 98.4%
Taylor expanded in y around inf 63.4%
if -1.25e176 < x < -3.49999999999999989e140 or 9.5999999999999996e117 < x < 8.60000000000000003e143 or 5.7999999999999999e174 < x Initial program 100.0%
Taylor expanded in y around 0 81.4%
Taylor expanded in x around inf 81.4%
*-commutative81.4%
Simplified81.4%
if -7e14 < x < 3.59999999999999994e-122Initial program 100.0%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
Simplified76.8%
Final simplification70.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))))
(if (<= x -6.2e-15)
t_0
(if (<= x 9.5e-121)
(- z)
(if (<= x 2.25e-86) (* x y) (if (<= x 8.2e-26) (- z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -6.2e-15) {
tmp = t_0;
} else if (x <= 9.5e-121) {
tmp = -z;
} else if (x <= 2.25e-86) {
tmp = x * y;
} else if (x <= 8.2e-26) {
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 <= (-6.2d-15)) then
tmp = t_0
else if (x <= 9.5d-121) then
tmp = -z
else if (x <= 2.25d-86) then
tmp = x * y
else if (x <= 8.2d-26) 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 <= -6.2e-15) {
tmp = t_0;
} else if (x <= 9.5e-121) {
tmp = -z;
} else if (x <= 2.25e-86) {
tmp = x * y;
} else if (x <= 8.2e-26) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) tmp = 0 if x <= -6.2e-15: tmp = t_0 elif x <= 9.5e-121: tmp = -z elif x <= 2.25e-86: tmp = x * y elif x <= 8.2e-26: 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 <= -6.2e-15) tmp = t_0; elseif (x <= 9.5e-121) tmp = Float64(-z); elseif (x <= 2.25e-86) tmp = Float64(x * y); elseif (x <= 8.2e-26) 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 <= -6.2e-15) tmp = t_0; elseif (x <= 9.5e-121) tmp = -z; elseif (x <= 2.25e-86) tmp = x * y; elseif (x <= 8.2e-26) 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, -6.2e-15], t$95$0, If[LessEqual[x, 9.5e-121], (-z), If[LessEqual[x, 2.25e-86], N[(x * y), $MachinePrecision], If[LessEqual[x, 8.2e-26], (-z), t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -6.2 \cdot 10^{-15}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-121}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.25 \cdot 10^{-86}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{-26}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -6.1999999999999998e-15 or 8.1999999999999997e-26 < x Initial program 98.6%
Taylor expanded in x around inf 95.2%
+-commutative95.2%
Simplified95.2%
if -6.1999999999999998e-15 < x < 9.4999999999999994e-121 or 2.2499999999999999e-86 < x < 8.1999999999999997e-26Initial program 100.0%
Taylor expanded in x around 0 79.2%
neg-mul-179.2%
Simplified79.2%
if 9.4999999999999994e-121 < x < 2.2499999999999999e-86Initial program 100.0%
Taylor expanded in y around inf 100.0%
Final simplification88.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z y))))
(if (<= x -7e+14)
t_0
(if (<= x 6.5e-121)
(* z (+ x -1.0))
(if (<= x 1.8e-88) (* x y) (if (<= x 6.5e-25) (- z) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z + y);
double tmp;
if (x <= -7e+14) {
tmp = t_0;
} else if (x <= 6.5e-121) {
tmp = z * (x + -1.0);
} else if (x <= 1.8e-88) {
tmp = x * y;
} else if (x <= 6.5e-25) {
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 <= (-7d+14)) then
tmp = t_0
else if (x <= 6.5d-121) then
tmp = z * (x + (-1.0d0))
else if (x <= 1.8d-88) then
tmp = x * y
else if (x <= 6.5d-25) 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 <= -7e+14) {
tmp = t_0;
} else if (x <= 6.5e-121) {
tmp = z * (x + -1.0);
} else if (x <= 1.8e-88) {
tmp = x * y;
} else if (x <= 6.5e-25) {
tmp = -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + y) tmp = 0 if x <= -7e+14: tmp = t_0 elif x <= 6.5e-121: tmp = z * (x + -1.0) elif x <= 1.8e-88: tmp = x * y elif x <= 6.5e-25: 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 <= -7e+14) tmp = t_0; elseif (x <= 6.5e-121) tmp = Float64(z * Float64(x + -1.0)); elseif (x <= 1.8e-88) tmp = Float64(x * y); elseif (x <= 6.5e-25) 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 <= -7e+14) tmp = t_0; elseif (x <= 6.5e-121) tmp = z * (x + -1.0); elseif (x <= 1.8e-88) tmp = x * y; elseif (x <= 6.5e-25) 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, -7e+14], t$95$0, If[LessEqual[x, 6.5e-121], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.8e-88], N[(x * y), $MachinePrecision], If[LessEqual[x, 6.5e-25], (-z), t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -7 \cdot 10^{+14}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-121}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-88}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-25}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -7e14 or 6.5e-25 < x Initial program 98.6%
Taylor expanded in x around inf 96.9%
+-commutative96.9%
Simplified96.9%
if -7e14 < x < 6.5000000000000003e-121Initial program 100.0%
Taylor expanded in y around 0 80.3%
if 6.5000000000000003e-121 < x < 1.8e-88Initial program 100.0%
Taylor expanded in y around inf 100.0%
if 1.8e-88 < x < 6.5e-25Initial program 100.0%
Taylor expanded in x around 0 71.1%
neg-mul-171.1%
Simplified71.1%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e+14) (not (<= x 9.5e-121))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e+14) || !(x <= 9.5e-121)) {
tmp = x * y;
} 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 <= (-7d+14)) .or. (.not. (x <= 9.5d-121))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7e+14) || !(x <= 9.5e-121)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e+14) or not (x <= 9.5e-121): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e+14) || !(x <= 9.5e-121)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e+14) || ~((x <= 9.5e-121))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e+14], N[Not[LessEqual[x, 9.5e-121]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+14} \lor \neg \left(x \leq 9.5 \cdot 10^{-121}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7e14 or 9.4999999999999994e-121 < x Initial program 98.7%
Taylor expanded in y around inf 55.3%
if -7e14 < x < 9.4999999999999994e-121Initial program 100.0%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
Simplified76.8%
Final simplification63.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 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 99.2%
Taylor expanded in x around 0 35.2%
neg-mul-135.2%
Simplified35.2%
Final simplification35.2%
herbie shell --seed 2024019
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))