
(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 7 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 x (+ y z) (- z)))
double code(double x, double y, double z) {
return fma(x, (y + z), -z);
}
function code(x, y, z) return fma(x, Float64(y + z), Float64(-z)) end
code[x_, y_, z_] := N[(x * N[(y + z), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + z, -z\right)
\end{array}
Initial program 96.9%
*-commutative96.9%
sub-neg96.9%
distribute-rgt-in96.9%
associate-+r+96.9%
distribute-lft-out100.0%
fma-def100.0%
metadata-eval100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1e-7)
(* x z)
(if (<= x 3.7e-100)
(- z)
(if (<= x 6300000000000.0)
(* x y)
(if (or (<= x 8.8e+58) (and (not (<= x 4.1e+121)) (<= x 6.2e+214)))
(* x z)
(* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e-7) {
tmp = x * z;
} else if (x <= 3.7e-100) {
tmp = -z;
} else if (x <= 6300000000000.0) {
tmp = x * y;
} else if ((x <= 8.8e+58) || (!(x <= 4.1e+121) && (x <= 6.2e+214))) {
tmp = x * 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 <= (-1d-7)) then
tmp = x * z
else if (x <= 3.7d-100) then
tmp = -z
else if (x <= 6300000000000.0d0) then
tmp = x * y
else if ((x <= 8.8d+58) .or. (.not. (x <= 4.1d+121)) .and. (x <= 6.2d+214)) then
tmp = x * 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 <= -1e-7) {
tmp = x * z;
} else if (x <= 3.7e-100) {
tmp = -z;
} else if (x <= 6300000000000.0) {
tmp = x * y;
} else if ((x <= 8.8e+58) || (!(x <= 4.1e+121) && (x <= 6.2e+214))) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1e-7: tmp = x * z elif x <= 3.7e-100: tmp = -z elif x <= 6300000000000.0: tmp = x * y elif (x <= 8.8e+58) or (not (x <= 4.1e+121) and (x <= 6.2e+214)): tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1e-7) tmp = Float64(x * z); elseif (x <= 3.7e-100) tmp = Float64(-z); elseif (x <= 6300000000000.0) tmp = Float64(x * y); elseif ((x <= 8.8e+58) || (!(x <= 4.1e+121) && (x <= 6.2e+214))) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1e-7) tmp = x * z; elseif (x <= 3.7e-100) tmp = -z; elseif (x <= 6300000000000.0) tmp = x * y; elseif ((x <= 8.8e+58) || (~((x <= 4.1e+121)) && (x <= 6.2e+214))) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1e-7], N[(x * z), $MachinePrecision], If[LessEqual[x, 3.7e-100], (-z), If[LessEqual[x, 6300000000000.0], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, 8.8e+58], And[N[Not[LessEqual[x, 4.1e+121]], $MachinePrecision], LessEqual[x, 6.2e+214]]], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-7}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-100}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 6300000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 8.8 \cdot 10^{+58} \lor \neg \left(x \leq 4.1 \cdot 10^{+121}\right) \land x \leq 6.2 \cdot 10^{+214}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -9.9999999999999995e-8 or 6.3e12 < x < 8.8000000000000003e58 or 4.1e121 < x < 6.19999999999999957e214Initial program 93.7%
*-commutative93.7%
sub-neg93.7%
distribute-rgt-in93.7%
associate-+r+93.7%
metadata-eval93.7%
mul-1-neg93.7%
unsub-neg93.7%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 63.8%
Taylor expanded in x around inf 63.9%
if -9.9999999999999995e-8 < x < 3.70000000000000018e-100Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 72.7%
mul-1-neg72.7%
Simplified72.7%
if 3.70000000000000018e-100 < x < 6.3e12 or 8.8000000000000003e58 < x < 4.1e121 or 6.19999999999999957e214 < x Initial program 95.3%
*-commutative95.3%
sub-neg95.3%
distribute-rgt-in95.3%
associate-+r+95.3%
metadata-eval95.3%
mul-1-neg95.3%
unsub-neg95.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 79.4%
Taylor expanded in y around inf 67.9%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.65e-11) (not (<= x 4e-100))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e-11) || !(x <= 4e-100)) {
tmp = x * (y + z);
} 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 <= (-1.65d-11)) .or. (.not. (x <= 4d-100))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e-11) || !(x <= 4e-100)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.65e-11) or not (x <= 4e-100): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.65e-11) || !(x <= 4e-100)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.65e-11) || ~((x <= 4e-100))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.65e-11], N[Not[LessEqual[x, 4e-100]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-11} \lor \neg \left(x \leq 4 \cdot 10^{-100}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.6500000000000001e-11 or 4.0000000000000001e-100 < x Initial program 94.4%
*-commutative94.4%
sub-neg94.4%
distribute-rgt-in94.4%
associate-+r+94.4%
metadata-eval94.4%
mul-1-neg94.4%
unsub-neg94.4%
distribute-lft-out100.0%
Simplified100.0%
sub-neg100.0%
distribute-lft-in94.4%
associate-+l+94.4%
neg-mul-194.4%
distribute-rgt-in94.4%
*-commutative94.4%
+-commutative94.4%
fma-def96.5%
Applied egg-rr96.5%
Taylor expanded in x around inf 93.6%
if -1.6500000000000001e-11 < x < 4.0000000000000001e-100Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 72.7%
mul-1-neg72.7%
Simplified72.7%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (+ y z)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = x * (y + z);
} else {
tmp = (x * 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.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (y + z)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = x * (y + z) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 1.0))) tmp = x * (y + z); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 93.3%
*-commutative93.3%
sub-neg93.3%
distribute-rgt-in93.3%
associate-+r+93.3%
metadata-eval93.3%
mul-1-neg93.3%
unsub-neg93.3%
distribute-lft-out100.0%
Simplified100.0%
sub-neg100.0%
distribute-lft-in93.3%
associate-+l+93.3%
neg-mul-193.3%
distribute-rgt-in93.3%
*-commutative93.3%
+-commutative93.3%
fma-def95.9%
Applied egg-rr95.9%
Taylor expanded in x around inf 99.5%
if -1 < x < 1Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 99.3%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.45e-11) (* x y) (if (<= x 4.3e-103) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-11) {
tmp = x * y;
} else if (x <= 4.3e-103) {
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 <= (-1.45d-11)) then
tmp = x * y
else if (x <= 4.3d-103) 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 <= -1.45e-11) {
tmp = x * y;
} else if (x <= 4.3e-103) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.45e-11: tmp = x * y elif x <= 4.3e-103: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.45e-11) tmp = Float64(x * y); elseif (x <= 4.3e-103) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.45e-11) tmp = x * y; elseif (x <= 4.3e-103) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.45e-11], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.3e-103], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.3 \cdot 10^{-103}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.45e-11 or 4.30000000000000023e-103 < x Initial program 94.4%
*-commutative94.4%
sub-neg94.4%
distribute-rgt-in94.4%
associate-+r+94.4%
metadata-eval94.4%
mul-1-neg94.4%
unsub-neg94.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 57.2%
Taylor expanded in y around inf 51.5%
if -1.45e-11 < x < 4.30000000000000023e-103Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
associate-+r+100.0%
metadata-eval100.0%
mul-1-neg100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 72.7%
mul-1-neg72.7%
Simplified72.7%
Final simplification60.8%
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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 + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 96.9%
*-commutative96.9%
sub-neg96.9%
distribute-rgt-in96.9%
associate-+r+96.9%
metadata-eval96.9%
mul-1-neg96.9%
unsub-neg96.9%
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 96.9%
*-commutative96.9%
sub-neg96.9%
distribute-rgt-in96.9%
associate-+r+96.9%
metadata-eval96.9%
mul-1-neg96.9%
unsub-neg96.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 36.4%
mul-1-neg36.4%
Simplified36.4%
Final simplification36.4%
herbie shell --seed 2023192
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))